]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/textpanel/TextPanelSettings.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / textpanel / TextPanelSettings.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2005.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 package com.ibm.richtext.textpanel;\r
14 \r
15 import java.awt.Color;\r
16 import java.io.Serializable;\r
17 import java.util.Hashtable;\r
18 \r
19 import com.ibm.richtext.textlayout.attributes.AttributeMap;\r
20 import com.ibm.richtext.textlayout.attributes.TextAttribute;\r
21 import com.ibm.richtext.styledtext.StandardTabRuler;\r
22 \r
23 /**\r
24  * This class contains settings used when constructing an MTextPanel.\r
25  * The settings controled by this class include:\r
26  * <ul>\r
27  * <li>whether the text in the MTextPanel can be scrolled</li>\r
28  * <li>whether scroll bars in the MTextPanel are visible</li>\r
29  * <li>whether the text in the MTextPanel can be selected</li>\r
30  * <li>whether the text in the MTextPanel can be edited</li>\r
31  * <li>whether lines of text wrap to the MTextPanel's width, or\r
32  * only end at paragraph separators</li>\r
33  * <li>the default values for unspecified styles</li>\r
34  * </ul>\r
35  * Some settings are dependent on others.  Scroll bars are visible\r
36  * only if the text is scrollable.  Also, text which is not editable\r
37  * if it is not selectable.\r
38  * <p>\r
39  *\r
40  * @see MTextPanel\r
41  */\r
42 public final class TextPanelSettings implements Cloneable, Serializable {\r
43 \r
44     static final String COPYRIGHT =\r
45                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
46     \r
47     static final long serialVersionUID = -4089186663018707478L;\r
48     \r
49     private static final AttributeMap DEFAULTS;\r
50     \r
51     static {\r
52         final Float floatZero = new Float(0.0f);\r
53 \r
54         Hashtable defaults = new Hashtable();\r
55         defaults.put(TextAttribute.FAMILY, "Serif");\r
56         defaults.put(TextAttribute.WEIGHT, new Float(1.0f));\r
57         defaults.put(TextAttribute.POSTURE, floatZero);\r
58         defaults.put(TextAttribute.SIZE, new Float(18.0f));\r
59         defaults.put(TextAttribute.SUPERSCRIPT, new Integer(0));\r
60         defaults.put(TextAttribute.FOREGROUND, Color.black);\r
61         defaults.put(TextAttribute.UNDERLINE, new Integer(-1));\r
62         defaults.put(TextAttribute.STRIKETHROUGH, Boolean.FALSE);\r
63 \r
64         defaults.put(TextAttribute.EXTRA_LINE_SPACING, floatZero);\r
65         defaults.put(TextAttribute.FIRST_LINE_INDENT, floatZero);\r
66         defaults.put(TextAttribute.MIN_LINE_SPACING, floatZero);\r
67         defaults.put(TextAttribute.LINE_FLUSH, TextAttribute.FLUSH_LEADING);\r
68         defaults.put(TextAttribute.LEADING_MARGIN, floatZero);\r
69         defaults.put(TextAttribute.TRAILING_MARGIN, floatZero);\r
70         defaults.put(TextAttribute.TAB_RULER, new StandardTabRuler());\r
71 \r
72         DEFAULTS = new AttributeMap(defaults);\r
73     }\r
74     \r
75     private boolean fScrollable = true;\r
76     private boolean fScrollBarsVisible = true;\r
77     private boolean fSelectable = true;\r
78     private boolean fEditable = true;\r
79     private boolean fWraps = true;\r
80     private AttributeMap fDefaultValues = DEFAULTS;\r
81     \r
82     /**\r
83      * Create a TextPanelSettings instance with all settings\r
84      * set to true.\r
85      */\r
86     public TextPanelSettings() {\r
87     }\r
88 \r
89     /**\r
90      * Return a new TextPanelSettings instance with the\r
91      * same settings as this.\r
92      * @return a new TextPanelSettings instance\r
93      */\r
94     public Object clone() {\r
95 \r
96         TextPanelSettings rhs = new TextPanelSettings();\r
97 \r
98         rhs.fScrollable = fScrollable;\r
99         rhs.fScrollBarsVisible = fScrollBarsVisible;\r
100         rhs.fSelectable = fSelectable;\r
101         rhs.fEditable = fEditable;\r
102         rhs.fWraps = fWraps;\r
103         rhs.fDefaultValues = fDefaultValues;\r
104         \r
105         return rhs;\r
106     }\r
107 \r
108     /**\r
109      * Return the scrollable setting, which determines whether text\r
110      * in an MTextPanel can be scrolled.\r
111      * @return the scrollable setting\r
112      */\r
113     public boolean getScrollable() {\r
114 \r
115         return fScrollable;\r
116     }\r
117 \r
118     /**\r
119      * Set the scrollable setting.\r
120      * @param scrollable the scrollable setting.  If false,\r
121      * the scrollBarsVisible setting is also set to false.\r
122      */\r
123     public void setScrollable(boolean scrollable) {\r
124 \r
125         fScrollable = scrollable;\r
126         fScrollBarsVisible &= scrollable;\r
127     }\r
128 \r
129     /**\r
130      * Return the scrollBarsVisible setting, which determines whether\r
131      * scroll bars in an MTextPanel are visible.\r
132      * @return the scrollBarsVisible setting\r
133      */\r
134     public boolean getScrollBarsVisible() {\r
135 \r
136         return fScrollBarsVisible;\r
137     }\r
138 \r
139     /**\r
140      * Set the scrollBarsVisible setting.\r
141      * @param vis the scrollBarsVisible setting.  If true,\r
142      * the scrollable setting is also set to true.\r
143      */\r
144     public void setScrollBarsVisible(boolean vis) {\r
145 \r
146         fScrollBarsVisible = vis;\r
147         fScrollable |= vis;\r
148     }\r
149 \r
150     /**\r
151      * Return the selectable setting, which determines whether\r
152      * text in an MTextPanel can be selected.\r
153      * @return the selectable setting\r
154      */\r
155     public boolean getSelectable() {\r
156 \r
157         return fSelectable;\r
158     }\r
159 \r
160     /**\r
161      * Set the selectable setting.\r
162      * @param selectable the selectable setting.  If false,\r
163      * the editable setting is also set to false.\r
164      */\r
165     public void setSelectable(boolean selectable) {\r
166 \r
167         fSelectable = selectable;\r
168         fEditable &= selectable;\r
169     }\r
170 \r
171     /**\r
172      * Return the editable setting, which determines whether\r
173      * text in an MTextPanel can be edited.\r
174      * @return the editable setting\r
175      */\r
176     public boolean getEditable() {\r
177 \r
178         return fEditable;\r
179     }\r
180 \r
181     /**\r
182      * Set the editable setting.\r
183      * @param editable the editable setting.  If true,\r
184      * the selectable setting is also set to true.\r
185      */\r
186     public void setEditable(boolean editable) {\r
187 \r
188         fEditable = editable;\r
189         fSelectable |= editable;\r
190     }\r
191 \r
192     /**\r
193      * Return the wraps setting, which determines whether\r
194      * lines of text wrap to the length of the MTextPanel,\r
195      * or only at paragraph separators.\r
196      * @return the wraps setting\r
197      */\r
198     public boolean getWraps() {\r
199 \r
200         return fWraps;\r
201     }\r
202 \r
203     /**\r
204      * Set the wraps setting.\r
205      * @param wraps the wraps setting\r
206      */\r
207     public void setWraps(boolean wraps) {\r
208 \r
209         fWraps = wraps;\r
210     }\r
211     \r
212     /**\r
213      * Return the AttributeMap of default values for certain keys.\r
214      * When a key in this AttributeMap is not specified, its value\r
215      * is taken from this AttributeMap.\r
216      * @return the AttributeMap of default values\r
217      * @see MTextPanel#getDefaultValues\r
218      */\r
219     public AttributeMap getDefaultValues() {\r
220     \r
221         return fDefaultValues;\r
222     }\r
223     \r
224     /**\r
225      * Add the key-value pairs in the given AttributeMap to the\r
226      * default values.  If a key does not appear in the given\r
227      * AttributeMap, its value in the default value map is\r
228      * unchanged.\r
229      * @param map an AttributeMap containing new default values\r
230      */\r
231     public void addDefaultValues(AttributeMap map) {\r
232     \r
233         fDefaultValues = fDefaultValues.addAttributes(map);\r
234     }\r
235     \r
236     /**\r
237      * Compare this to another Object.  This is equal\r
238      * to another Object if the other Object is a\r
239      * TextPanelSettings instance with the same\r
240      * settings as this one.\r
241      * @param rhs the Object to compare to\r
242      */\r
243     public boolean equals(Object rhs) {\r
244 \r
245         if (rhs == this) {\r
246             return true;\r
247         }\r
248 \r
249         if (rhs == null) {\r
250             return false;\r
251         }\r
252 \r
253         TextPanelSettings other;\r
254         try {\r
255             other = (TextPanelSettings) rhs;\r
256         }\r
257         catch(ClassCastException e) {\r
258             return false;\r
259         }\r
260         \r
261         return other.fScrollable == this.fScrollable &&\r
262                other.fScrollBarsVisible == this.fScrollBarsVisible &&\r
263                other.fSelectable == this.fSelectable &&\r
264                other.fEditable == this.fEditable &&\r
265                other.fWraps == this.fWraps &&\r
266                other.fDefaultValues.equals(this.fDefaultValues);\r
267     }\r
268 \r
269     /**\r
270      * Return the hash code for this Object.\r
271      * @return the hash code for this Object\r
272      */\r
273     public int hashCode() {\r
274 \r
275         int code = fDefaultValues.hashCode();\r
276         code = code*2 + (fScrollable? 1:0);\r
277         code = code*2 + (fScrollBarsVisible? 1:0);\r
278         code = code*2 + (fSelectable? 1:0);\r
279         code = code*2 + (fEditable? 1:0);\r
280         code = code*2 + (fWraps? 1:0);\r
281 \r
282         return code;\r
283     }\r
284 }\r