Merge from mainline
[official-gcc.git] / libjava / classpath / javax / swing / text / html / CSS.java
blobc248e758ec29744cf2f63154a69b72fd22e43f63
1 /* CSS.java -- Provides CSS attributes
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing.text.html;
40 import java.io.Serializable;
41 import java.util.HashMap;
43 /**
44 * Provides CSS attributes to be used by the HTML view classes. The constants
45 * defined here are used as keys for text attributes for use in
46 * {@link javax.swing.text.AttributeSet}s of {@link javax.swing.text.Element}s.
48 * @author Roman Kennke (kennke@aicas.com)
50 public class CSS implements Serializable
52 /**
53 * Returns an array of all CSS attributes.
55 * @return All available CSS.Attribute objects.
57 public static CSS.Attribute[] getAllAttributeKeys()
59 Object[] src = Attribute.attributeMap.values().toArray();
60 CSS.Attribute[] dst = new CSS.Attribute[ src.length ];
61 System.arraycopy(src, 0, dst, 0, src.length);
62 return dst;
65 /**
66 * Returns an a given CSS attribute.
68 * @param name - The name of the attribute.
69 * @return The CSS attribute with the given name, or <code>null</code> if
70 * no attribute with that name exists.
72 public static CSS.Attribute getAttribute(String name)
74 return (CSS.Attribute)Attribute.attributeMap.get( name );
77 public static final class Attribute
79 /**
80 * The CSS attribute 'background'.
82 public static final Attribute BACKGROUND =
83 new Attribute("background", false, null);
85 /**
86 * The CSS attribute 'background-attachment'.
88 public static final Attribute BACKGROUND_ATTACHMENT =
89 new Attribute("background-attachment", false, "scroll");
91 /**
92 * The CSS attribute 'background-color'.
94 public static final Attribute BACKGROUND_COLOR =
95 new Attribute("background-color", false, "transparent");
97 /**
98 * The CSS attribute 'background-image'.
100 public static final Attribute BACKGROUND_IMAGE =
101 new Attribute("background-image", false, "none");
104 * The CSS attribute 'background-position'.
106 public static final Attribute BACKGROUND_POSITION =
107 new Attribute("background-position", false, null);
110 * The CSS attribute 'background-repeat'.
112 public static final Attribute BACKGROUND_REPEAT =
113 new Attribute("background-repeat", false, "repeat");
116 * The CSS attribute 'border'.
118 public static final Attribute BORDER = new Attribute("border", false, null);
121 * The CSS attribute 'border-bottom'.
123 public static final Attribute BORDER_BOTTOM =
124 new Attribute("border-bottom", false, null);
127 * The CSS attribute 'border-bottom-width'.
129 public static final Attribute BORDER_BOTTOM_WIDTH =
130 new Attribute("border-bottom-width", false, "medium");
133 * The CSS attribute 'border-color'.
135 public static final Attribute BORDER_COLOR =
136 new Attribute("border-color", false, "black");
139 * The CSS attribute 'border-left'.
141 public static final Attribute BORDER_LEFT =
142 new Attribute("border-left", false, null);
145 * The CSS attribute 'border-left-width'.
147 public static final Attribute BORDER_LEFT_WIDTH =
148 new Attribute("border-left-width", false, "medium");
151 * The CSS attribute 'border-right'.
153 public static final Attribute BORDER_RIGHT =
154 new Attribute("border-right", false, null);
157 * The CSS attribute 'border-right-width'.
159 public static final Attribute BORDER_RIGHT_WIDTH =
160 new Attribute("border-right-width", false, "medium");
163 * The CSS attribute 'border-style'.
165 public static final Attribute BORDER_STYLE =
166 new Attribute("border-style", false, "none");
169 * The CSS attribute 'border-top'.
171 public static final Attribute BORDER_TOP =
172 new Attribute("border-top", false, null);
175 * The CSS attribute 'border-top-width'.
177 public static final Attribute BORDER_TOP_WIDTH =
178 new Attribute("border-top-width", false, "medium");
181 * The CSS attribute 'border-width'.
183 public static final Attribute BORDER_WIDTH =
184 new Attribute("border-width", false, "medium");
187 * The CSS attribute 'clear'.
189 public static final Attribute CLEAR = new Attribute("clear", false, "none");
192 * The CSS attribute 'color'.
194 public static final Attribute COLOR = new Attribute("color", true, "black");
197 * The CSS attribute 'display'.
199 public static final Attribute DISPLAY =
200 new Attribute("display", false, "block");
203 * The CSS attribute 'float'.
205 public static final Attribute FLOAT = new Attribute("float", false, "none");
208 * The CSS attribute 'font'.
210 public static final Attribute FONT = new Attribute("font", true, null);
213 * The CSS attribute 'font-family'.
215 public static final Attribute FONT_FAMILY =
216 new Attribute("font-family", true, null);
219 * The CSS attribute 'font-size'.
221 public static final Attribute FONT_SIZE =
222 new Attribute("font-size", true, "medium");
225 * The CSS attribute 'font-style'.
227 public static final Attribute FONT_STYLE =
228 new Attribute("font-style", true, "normal");
231 * The CSS attribute 'font-variant'.
233 public static final Attribute FONT_VARIANT =
234 new Attribute("font-variant", true, "normal");
237 * The CSS attribute 'font-weight'.
239 public static final Attribute FONT_WEIGHT =
240 new Attribute("font-weight", true, "normal");
243 * The CSS attribute 'height'.
245 public static final Attribute HEIGHT =
246 new Attribute("height", false, "auto");
249 * The CSS attribute 'letter-spacing'.
251 public static final Attribute LETTER_SPACING =
252 new Attribute("letter-spacing", true, "normal");
255 * The CSS attribute 'line-height'.
257 public static final Attribute LINE_HEIGHT =
258 new Attribute("line-height", true, "normal");
261 * The CSS attribute 'list-style'.
263 public static final Attribute LIST_STYLE =
264 new Attribute("list-style", true, null);
267 * The CSS attribute 'list-style-image'.
269 public static final Attribute LIST_STYLE_IMAGE =
270 new Attribute("list-style-image", true, "none");
273 * The CSS attribute 'list-style-position'.
275 public static final Attribute LIST_STYLE_POSITION =
276 new Attribute("list-style-position", true, "outside");
279 * The CSS attribute 'list-style-type'.
281 public static final Attribute LIST_STYLE_TYPE =
282 new Attribute("list-style-type", true, "disc");
285 * The CSS attribute 'margin'.
287 public static final Attribute MARGIN = new Attribute("margin", false, null);
290 * The CSS attribute 'margin-bottom'.
292 public static final Attribute MARGIN_BOTTOM =
293 new Attribute("margin-bottom", false, "0");
296 * The CSS attribute 'margin-left'.
298 public static final Attribute MARGIN_LEFT =
299 new Attribute("margin-left", false, "0");
302 * The CSS attribute 'margin-right'.
304 public static final Attribute MARGIN_RIGHT =
305 new Attribute("margin-right", false, "0");
308 * The CSS attribute 'margin-top'.
310 public static final Attribute MARGIN_TOP =
311 new Attribute("margin-top", false, "0");
314 * The CSS attribute 'padding'.
316 public static final Attribute PADDING =
317 new Attribute("padding", false, null);
320 * The CSS attribute 'padding-bottom'.
322 public static final Attribute PADDING_BOTTOM =
323 new Attribute("padding-bottom", false, "0");
326 * The CSS attribute 'padding-left'.
328 public static final Attribute PADDING_LEFT =
329 new Attribute("padding-left", false, "0");
332 * The CSS attribute 'padding-right'.
334 public static final Attribute PADDING_RIGHT =
335 new Attribute("padding-right", false, "0");
338 * The CSS attribute 'padding-top'.
340 public static final Attribute PADDING_TOP =
341 new Attribute("padding-top", false, "0");
344 * The CSS attribute 'text-align'.
346 public static final Attribute TEXT_ALIGN =
347 new Attribute("text-align", true, null);
350 * The CSS attribute 'text-decoration'.
352 public static final Attribute TEXT_DECORATION =
353 new Attribute("text-decoration", true, "none");
356 * The CSS attribute 'text-indent'.
358 public static final Attribute TEXT_INDENT =
359 new Attribute("text-indent", true, "0");
362 * The CSS attribute 'text-transform'.
364 public static final Attribute TEXT_TRANSFORM =
365 new Attribute("text-transform", true, "none");
368 * The CSS attribute 'vertical-align'.
370 public static final Attribute VERTICAL_ALIGN =
371 new Attribute("vertical-align", false, "baseline");
374 * The CSS attribute 'white-space'.
376 public static final Attribute WHITE_SPACE =
377 new Attribute("white-space", true, "normal");
380 * The CSS attribute 'width'.
382 public static final Attribute WIDTH =
383 new Attribute("width", false, "auto");
386 * The CSS attribute 'word-spacing'.
388 public static final Attribute WORD_SPACING =
389 new Attribute("word-spacing", true, "normal");
392 * The attribute string.
394 String attStr;
397 * Indicates if this attribute should be inherited from it's parent or
398 * not.
400 boolean isInherited;
403 * A default value for this attribute if one exists, otherwise null.
405 String defaultValue;
408 * A HashMap of all attributes.
410 static HashMap attributeMap;
413 * Creates a new Attribute instance with the specified values.
415 * @param attr the attribute string
416 * @param inherited if the attribute should be inherited or not
417 * @param def a default value; may be <code>null</code>
419 Attribute(String attr, boolean inherited, String def)
421 attStr = attr;
422 isInherited = inherited;
423 defaultValue = def;
424 if( attributeMap == null)
425 attributeMap = new HashMap();
426 attributeMap.put( attr, this );
430 * Returns the string representation of this attribute as specified
431 * in the CSS specification.
433 public String toString()
435 return attStr;
439 * Returns <code>true</code> if the attribute should be inherited from
440 * the parent, <code>false</code> otherwise.
442 * @return <code>true</code> if the attribute should be inherited from
443 * the parent, <code>false</code> otherwise
445 public boolean isInherited()
447 return isInherited;
451 * Returns the default value of this attribute if one exists,
452 * <code>null</code> otherwise.
454 * @return the default value of this attribute if one exists,
455 * <code>null</code> otherwise
457 public String getDefaultValue()
459 return defaultValue;