001/* TextAttribute.java --
002   Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package java.awt.font;
040
041import java.io.InvalidObjectException;
042import java.text.AttributedCharacterIterator;
043
044/**
045 * Attributes (and associated values) that can be used to define an
046 * {@link java.text.AttributedString}.
047 */
048public final class TextAttribute extends AttributedCharacterIterator.Attribute
049{
050  private static final long serialVersionUID = 7744112784117861702L;
051  
052  /** A key for the background paint attribute. */
053  public static final TextAttribute BACKGROUND =
054    new TextAttribute("background");
055  
056  /** A key for the BIDI_EMBEDDING attribute. */
057  public static final TextAttribute BIDI_EMBEDDING =
058    new TextAttribute("bidi_embedding");
059  
060  /** A key for the CHAR_REPLACEMENT attribute. */
061  public static final TextAttribute CHAR_REPLACEMENT =
062    new TextAttribute("char_replacement");
063  
064  /** A key for the FAMILY attribute. */
065  public static final TextAttribute FAMILY = new TextAttribute("family");
066  
067  /** A key for the font attribute. */
068  public static final TextAttribute FONT = new TextAttribute("font");
069  
070  /** A key for the foreground paint attribute. */
071  public static final TextAttribute FOREGROUND = 
072    new TextAttribute("foreground");
073  
074  /** A key for the INPUT_METHOD_HIGHLIGHT attribute. */
075  public static final TextAttribute INPUT_METHOD_HIGHLIGHT =
076    new TextAttribute("input method highlight");
077  
078  /** A key for the INPUT_METHOD_UNDERLINE attribute. */
079  public static final TextAttribute INPUT_METHOD_UNDERLINE =
080    new TextAttribute("input method underline");
081  
082  /** A key for the text justification attribute. */
083  public static final TextAttribute JUSTIFICATION =
084    new TextAttribute("justification");
085  
086  /** 
087   * A value that can be used with the {@link #JUSTIFICATION} attribute to
088   * indicate full justification of the text. 
089   */
090  public static final Float JUSTIFICATION_FULL = new Float(1.0);
091  
092  /** 
093   * A value that can be used with the {@link #JUSTIFICATION} attribute to
094   * indicate no justification of the text. 
095   */
096  public static final Float JUSTIFICATION_NONE = new Float(0.0);
097  
098  /** A key for the NUMERIC_SHAPING attribute. */
099  public static final TextAttribute NUMERIC_SHAPING =
100    new TextAttribute("numeric_shaping");
101  
102  /** A key for the POSTURE attribute. */
103  public static final TextAttribute POSTURE = new TextAttribute("posture");
104  
105  /** A value that can be used with the {@link #POSTURE} attribute. */
106  public static final Float POSTURE_OBLIQUE = new Float(0.2);
107  
108  /** A value that can be used with the {@link #POSTURE} attribute. */
109  public static final Float POSTURE_REGULAR = new Float(0.0);
110  
111  /** A key for the RUN_DIRECTION attribute. */
112  public static final TextAttribute RUN_DIRECTION =
113    new TextAttribute("run_direction");
114  
115  /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */
116  public static final Boolean RUN_DIRECTION_LTR = Boolean.FALSE;
117  
118  /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */
119  public static final Boolean RUN_DIRECTION_RTL = Boolean.TRUE;
120  
121  /** A key for the text size attribute. */
122  public static final TextAttribute SIZE = new TextAttribute("size");
123  
124  /** A key for the STRIKETHROUGH attribute. */
125  public static final TextAttribute STRIKETHROUGH =
126    new TextAttribute("strikethrough");
127  
128  /** A value that can be used with the {@link #STRIKETHROUGH} attribute. */
129  public static final Boolean STRIKETHROUGH_ON = Boolean.TRUE;
130  
131  /** A key for the SUPERSCRIPT attribute. */
132  public static final TextAttribute SUPERSCRIPT =
133    new TextAttribute("superscript");
134  
135  /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */
136  public static final Integer SUPERSCRIPT_SUB = new Integer(-1);
137  
138  /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */
139  public static final Integer SUPERSCRIPT_SUPER = new Integer(1);
140  
141  /** A key for the SWAP_COLORS attribute. */
142  public static final TextAttribute SWAP_COLORS =
143    new TextAttribute("swap_colors");
144  
145  /** A value that can be used with the {@link #SWAP_COLORS} attribute. */
146  public static final Boolean SWAP_COLORS_ON = Boolean.TRUE;
147  
148  /** A key for the TRANFORM attribute. */
149  public static final TextAttribute TRANSFORM = new TextAttribute("transform");
150  
151  /** A key for the UNDERLINE attribute. */
152  public static final TextAttribute UNDERLINE = new TextAttribute("underline");
153  
154  /** A value that can be used with the {@link #UNDERLINE} attribute. */
155  public static final Integer UNDERLINE_LOW_DASHED = new Integer(5);
156  
157  /** A value that can be used with the {@link #UNDERLINE} attribute. */
158  public static final Integer UNDERLINE_LOW_DOTTED = new Integer(3);
159  
160  /** A value that can be used with the {@link #UNDERLINE} attribute. */
161  public static final Integer UNDERLINE_LOW_GRAY = new Integer(4);
162  
163  /** A value that can be used with the {@link #UNDERLINE} attribute. */
164  public static final Integer UNDERLINE_LOW_ONE_PIXEL = new Integer(1);
165  
166  /** A value that can be used with the {@link #UNDERLINE} attribute. */
167  public static final Integer UNDERLINE_LOW_TWO_PIXEL = new Integer(2);
168  
169  /** A value that can be used with the {@link #UNDERLINE} attribute. */
170  public static final Integer UNDERLINE_ON = new Integer(0);
171  
172  /** A key for the WEIGHT attribute. */
173  public static final TextAttribute WEIGHT = new TextAttribute("weight");
174  
175  /** A value that can be used with the {@link #WEIGHT} attribute. */
176  public static final Float WEIGHT_BOLD = new Float(2.0);
177  
178  /** A value that can be used with the {@link #WEIGHT} attribute. */
179  public static final Float WEIGHT_DEMIBOLD = new Float(1.75);
180  
181  /** A value that can be used with the {@link #WEIGHT} attribute. */
182  public static final Float WEIGHT_DEMILIGHT = new Float(0.875);
183  
184  /** A value that can be used with the {@link #WEIGHT} attribute. */
185  public static final Float WEIGHT_EXTRA_LIGHT = new Float(0.5);
186  
187  /** A value that can be used with the {@link #WEIGHT} attribute. */
188  public static final Float WEIGHT_EXTRABOLD = new Float(2.5);
189  
190  /** A value that can be used with the {@link #WEIGHT} attribute. */
191  public static final Float WEIGHT_HEAVY = new Float(2.25);
192  
193  /** A value that can be used with the {@link #WEIGHT} attribute. */
194  public static final Float WEIGHT_LIGHT = new Float(0.75);
195  
196  /** A value that can be used with the {@link #WEIGHT} attribute. */
197  public static final Float WEIGHT_MEDIUM = new Float(1.5);
198  
199  /** A value that can be used with the {@link #WEIGHT} attribute. */
200  public static final Float WEIGHT_REGULAR = new Float(1.0);
201  
202  /** A value that can be used with the {@link #WEIGHT} attribute. */
203  public static final Float WEIGHT_SEMIBOLD = new Float(1.25);
204  
205  /** A value that can be used with the {@link #WEIGHT} attribute. */
206  public static final Float WEIGHT_ULTRABOLD = new Float(2.75);
207  
208  /** A key for the WIDTH attribute. */
209  public static final TextAttribute WIDTH = new TextAttribute("width");
210  
211  /** A value that can be used with the {@link #WIDTH} attribute. */
212  public static final Float WIDTH_CONDENSED = new Float(0.75);
213  
214  /** A value that can be used with the {@link #WIDTH} attribute. */
215  public static final Float WIDTH_EXTENDED = new Float(1.5);
216  
217  /** A value that can be used with the {@link #WIDTH} attribute. */
218  public static final Float WIDTH_REGULAR = new Float(1.0);
219  
220  /** A value that can be used with the {@link #WIDTH} attribute. */
221  public static final Float WIDTH_SEMI_CONDENSED = new Float(0.875);
222  
223  /** A value that can be used with the {@link #WIDTH} attribute. */
224  public static final Float WIDTH_SEMI_EXTENDED = new Float(1.25);
225          
226  /**
227   * Creates a new attribute.
228   * 
229   * @param name  the name.
230   */
231  protected TextAttribute(String name)
232  {
233    super(name);
234  }
235  
236  /**
237   * After deserialization, this method ensures that only one instance of
238   * each attribute is used.
239   * 
240   * @return The (single) attribute instance.
241   * 
242   * @throws InvalidObjectException if the attribute is not recognised.
243   */
244  protected Object readResolve()
245    throws InvalidObjectException
246  {
247    if (this.getName().equals("background"))
248      return BACKGROUND;
249
250    if (this.getName().equals("bidi_embedding"))
251      return BIDI_EMBEDDING;
252
253    if (this.getName().equals("char_replacement"))
254      return CHAR_REPLACEMENT;
255
256    if (this.getName().equals("family"))
257      return FAMILY;
258
259    if (this.getName().equals("font"))
260      return FONT;
261
262    if (this.getName().equals("foreground"))
263      return FOREGROUND;
264
265    if (this.getName().equals("input method highlight"))
266      return INPUT_METHOD_HIGHLIGHT;
267
268    if (this.getName().equals("input method underline"))
269      return INPUT_METHOD_UNDERLINE;
270
271    if (this.getName().equals("justification"))
272      return JUSTIFICATION;
273
274    if (this.getName().equals("numeric_shaping"))
275      return NUMERIC_SHAPING;
276
277    if (this.getName().equals("posture"))
278      return POSTURE;
279
280    if (this.getName().equals("run_direction"))
281      return RUN_DIRECTION;
282
283    if (this.getName().equals("size"))
284      return SIZE;
285
286    if (this.getName().equals("strikethrough"))
287      return STRIKETHROUGH;
288
289    if (this.getName().equals("superscript"))
290      return SUPERSCRIPT;
291
292    if (this.getName().equals("swap_colors"))
293      return SWAP_COLORS;
294
295    if (this.getName().equals("transform"))
296      return TRANSFORM;
297
298    if (this.getName().equals("underline"))
299      return UNDERLINE;
300
301    if (this.getName().equals("weight"))
302      return WEIGHT;
303
304    if (this.getName().equals("width"))
305      return WIDTH;
306
307    throw new InvalidObjectException("Can't resolve Attribute: " + getName());
308  }
309}