]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/textlayout/attributes/TextAttribute.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / textlayout / attributes / TextAttribute.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2007.  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 // Requires Java2\r
14 package com.ibm.richtext.textlayout.attributes;\r
15 \r
16 import java.util.Hashtable;\r
17 import java.text.AttributedCharacterIterator.Attribute;\r
18 import java.io.InvalidObjectException;\r
19 \r
20 /**\r
21  * This class contains a number of keys (or attributes) for specifying text styles\r
22  * in a Map.  A text style is a collection of key-value pairs, where\r
23  * the key represents a certain characteristic (such as size) and\r
24  * the value tells how that characteristic is realized (ie what the\r
25  * size is).\r
26  * <p>\r
27  * All of the attributes in TextAttribute specify a class for their value.\r
28  * Map does not enforce these class specifications;  however, text rendering code\r
29  * will tend to fail with a ClassCastException if a key's value\r
30  * has an unexpected class.\r
31  * <p>\r
32  * Some attributes are meaningful for entire paragraphs, not individual\r
33  * characters.  These attributes are documented as applying to paragraphs.\r
34  * All other attributes apply to characters.\r
35  * <p>\r
36  * Many of the field names and values in this class\r
37  * are taken from the JDK 1.2\r
38  * <code>java.awt.font.TextAttribute class</code>.\r
39  * @see Map\r
40  */\r
41 public class TextAttribute extends Attribute {\r
42 \r
43     /**\r
44      * For serialization\r
45      */\r
46     private static final long serialVersionUID = 1831947517687597324L;\r
47 \r
48     private static final Hashtable instanceMap = new Hashtable(9);\r
49 \r
50     protected TextAttribute(String name) {\r
51         super(name);\r
52         if (this.getClass() == TextAttribute.class) {\r
53             instanceMap.put(name, this);\r
54         }\r
55     }\r
56 \r
57     protected Object readResolve() throws InvalidObjectException {\r
58         if (this.getClass() != TextAttribute.class) {\r
59             throw new InvalidObjectException("subclass didn't correctly implement readResolve");\r
60         }\r
61 \r
62         TextAttribute instance = (TextAttribute) instanceMap.get(getName());\r
63         if (instance != null) {\r
64             return instance;\r
65         } else {\r
66             throw new InvalidObjectException("unknown attribute name");\r
67         }\r
68     }\r
69 \r
70     public static final Object FONT = java.awt.font.TextAttribute.FONT;\r
71 \r
72     public static final Object FAMILY = java.awt.font.TextAttribute.FAMILY;\r
73 \r
74     public static final Object WEIGHT = java.awt.font.TextAttribute.WEIGHT;\r
75     public static final Float WEIGHT_BOLD = java.awt.font.TextAttribute.WEIGHT_BOLD;\r
76 \r
77     public static final Object POSTURE = java.awt.font.TextAttribute.POSTURE;\r
78     public static final Float POSTURE_OBLIQUE = java.awt.font.TextAttribute.POSTURE_OBLIQUE;\r
79 \r
80     public static final Object SIZE = java.awt.font.TextAttribute.SIZE;\r
81 \r
82     public static final Object SUPERSCRIPT = java.awt.font.TextAttribute.SUPERSCRIPT;\r
83     public static final Integer SUPERSCRIPT_SUPER = java.awt.font.TextAttribute.SUPERSCRIPT_SUPER;\r
84     public static final Integer SUPERSCRIPT_SUB = java.awt.font.TextAttribute.SUPERSCRIPT_SUB;\r
85 \r
86     /**\r
87      * Attribute key for the foreground and background color adornment.\r
88      */\r
89     public static final Object FOREGROUND = java.awt.font.TextAttribute.FOREGROUND;\r
90     public static final Object BACKGROUND = java.awt.font.TextAttribute.BACKGROUND;\r
91 \r
92     public static final Object UNDERLINE = java.awt.font.TextAttribute.UNDERLINE;\r
93     public static final Integer UNDERLINE_ON = java.awt.font.TextAttribute.UNDERLINE_ON;\r
94 \r
95     public static final Object STRIKETHROUGH = java.awt.font.TextAttribute.STRIKETHROUGH;\r
96     public static final Boolean STRIKETHROUGH_ON = java.awt.font.TextAttribute.STRIKETHROUGH_ON;\r
97 \r
98     public static final Object OFFSET = new TextAttribute("offset");\r
99 \r
100     public static final Object CHAR_REPLACEMENT = java.awt.font.TextAttribute.CHAR_REPLACEMENT;\r
101 // Paragraph Styles\r
102 \r
103 // values are Floats:\r
104     public static final Object EXTRA_LINE_SPACING = new TextAttribute("extra_line_spacing");\r
105     public static final Object EXTRA_FIRST_LINE_SPACING = new TextAttribute("extra_first_line_spacing");\r
106 \r
107     /**\r
108      * Amount beyond leading margin to indent the first line of a paragraph.\r
109      */\r
110     public static final Object FIRST_LINE_INDENT = new TextAttribute("first_line_indent");\r
111 \r
112     public static final Object MIN_LINE_SPACING = new TextAttribute("min_line_spacing");\r
113     public static final Object MIN_FIRST_LINE_SPACING = new TextAttribute("min_first_line_spacing");\r
114 \r
115     /**\r
116      * Flush lines left, right, or center.\r
117      */\r
118     public static final Object LINE_FLUSH = new TextAttribute("line_flush");\r
119 \r
120     public static final Integer FLUSH_LEADING = new Integer(0);\r
121     public static final Integer FLUSH_CENTER = new Integer(1);\r
122     public static final Integer FLUSH_TRAILING = new Integer(2);\r
123     /**\r
124      * Value of <code>LINE_FLUSH</code> for full justification.\r
125      */\r
126     public static final Integer FULLY_JUSTIFIED = new Integer(3);\r
127 \r
128     /**\r
129      * Leading and trailing margin in paragraph.\r
130      */\r
131     public static final Object LEADING_MARGIN = new TextAttribute("leading_margin");\r
132     public static final Object TRAILING_MARGIN = new TextAttribute("trailing_margin");\r
133 \r
134     /**\r
135      * Tab ruler.  Values are MTabRuler instances.\r
136      */\r
137     public static final Object TAB_RULER = new TextAttribute("tab_ruler");\r
138     \r
139     /**\r
140      * Attribute key for the run direction of the line.\r
141      *\r
142      * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">\r
143      * <TR>\r
144      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>\r
145      * <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>\r
146      * <TR>\r
147      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>\r
148      * <TD VALIGN="TOP">Boolean</TD></TR>\r
149      * <TR>\r
150      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>\r
151      * <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false\r
152      * </TD></TR>\r
153      * <TR>\r
154      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>\r
155      * <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI \r
156      * algorithm.</TD></TR>\r
157      * <TR>\r
158      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>\r
159      * <TD VALIGN="TOP"><P>Specifies which base run direction to use when \r
160      * positioning mixed directional runs within a paragraph. If this value is\r
161      * RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode\r
162      * base direction from the BIDI algorithm.</P>\r
163      * <P><I>This attribute should have the same value over the whole \r
164      * paragraph.</I></TD></TR>\r
165      * </TABLE>\r
166      */\r
167     public static final Object RUN_DIRECTION = java.awt.font.TextAttribute.RUN_DIRECTION;\r
168 \r
169     /**\r
170      * Left-to-right run direction.\r
171      * @see #RUN_DIRECTION\r
172      */\r
173     public static final Boolean RUN_DIRECTION_LTR = java.awt.font.TextAttribute.RUN_DIRECTION_LTR;\r
174 \r
175     /**\r
176      * Right-to-left run direction.\r
177      * @see #RUN_DIRECTION\r
178      */\r
179     public static final Boolean RUN_DIRECTION_RTL = java.awt.font.TextAttribute.RUN_DIRECTION_RTL;\r
180 \r
181     /**\r
182      * Attribute key for the embedding level for nested bidirectional runs.\r
183      *\r
184      * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">\r
185      * <TR>\r
186      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>\r
187      * <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>\r
188      * <TR>\r
189      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>\r
190      * <TD VALIGN="TOP">Integer</TD></TR>\r
191      * <TR>\r
192      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>\r
193      * <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>\r
194      * levels, negative values<BR> through -15 are <I>override</I> levels\r
195      * </TD></TR>\r
196      * <TR>\r
197      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>\r
198      * <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting\r
199      * characters in the text.</TD></TR>\r
200      * <TR>\r
201      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>\r
202      * <TD VALIGN="TOP">Specifies the bidi embedding level of the character.\r
203      * When this attribute is present anywhere in a paragraph, then the \r
204      * Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI \r
205      * analysis of that paragraph. \r
206      * See the Unicode Standard v. 2.0, section 3-11.\r
207      * </TD></TR>\r
208      * </TABLE>\r
209      */\r
210     public static final Object BIDI_EMBEDDING = java.awt.font.TextAttribute.BIDI_EMBEDDING;\r
211 \r
212     /**\r
213      * Attribute key for the justification of a paragraph.\r
214      *\r
215      * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">\r
216      * <TR>\r
217      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>\r
218      * <TD VALIGN="TOP">JUSTIFICATION</TD></TR>\r
219      * <TR>\r
220      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>\r
221      * <TD VALIGN="TOP">Float</TD></TR>\r
222      * <TR>\r
223      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>\r
224      * <TD VALIGN="TOP">0.0 through1.0</TD></TR>\r
225      * <TR>\r
226      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>\r
227      * <TD VALIGN="TOP">1.0</TD></TR>\r
228      * <TR>\r
229      * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>\r
230      * <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use \r
231      * when justification is requested. For example, if the line is 50 points\r
232      * wide and the margins are 70 points apart, a value of 0.5 means that the\r
233      * line is padded to reach a width of 60 points.</P>\r
234      * <P><I>This attribute should have the same value over the whole\r
235      * paragraph.</I></TD></TR>\r
236      * </TABLE>\r
237      */\r
238     public static final Object JUSTIFICATION = java.awt.font.TextAttribute.JUSTIFICATION;\r
239 \r
240     /**\r
241      * Justify the line to the full requested width.\r
242      * @see #JUSTIFICATION\r
243      */\r
244     public static final Float JUSTIFICATION_FULL = java.awt.font.TextAttribute.JUSTIFICATION_FULL;\r
245 \r
246     /**\r
247      * Do not allow the line to be justified.\r
248      * @see #JUSTIFICATION\r
249      */\r
250     public static final Float JUSTIFICATION_NONE = java.awt.font.TextAttribute.JUSTIFICATION_NONE;\r
251 }\r