Source for javax.swing.text.html.CSS

   1: /* CSS.java -- Provides CSS attributes
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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.
  20: 
  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.
  25: 
  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. */
  37: 
  38: package javax.swing.text.html;
  39: 
  40: import java.io.Serializable;
  41: import java.util.HashMap;
  42: 
  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.
  47:  *
  48:  * @author Roman Kennke (kennke@aicas.com)
  49:  */
  50: public class CSS implements Serializable
  51: {
  52:   /**
  53:    * Returns an array of all CSS attributes.
  54:    *
  55:    * @return All available CSS.Attribute objects.
  56:    */
  57:   public static CSS.Attribute[] getAllAttributeKeys()
  58:   {
  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;
  63:   }
  64: 
  65:   /**
  66:    * Returns an a given CSS attribute.
  67:    *
  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.
  71:    */
  72:   public static CSS.Attribute getAttribute(String name)
  73:   {
  74:     return (CSS.Attribute)Attribute.attributeMap.get( name );
  75:   }
  76: 
  77:   public static final class Attribute
  78:   {
  79:     /**
  80:      * The CSS attribute 'background'.
  81:      */
  82:     public static final Attribute BACKGROUND =
  83:       new Attribute("background", false, null);
  84: 
  85:     /**
  86:      * The CSS attribute 'background-attachment'.
  87:      */
  88:     public static final Attribute BACKGROUND_ATTACHMENT =
  89:       new Attribute("background-attachment", false, "scroll");
  90: 
  91:     /**
  92:      * The CSS attribute 'background-color'.
  93:      */
  94:     public static final Attribute BACKGROUND_COLOR =
  95:       new Attribute("background-color", false, "transparent");
  96: 
  97:     /**
  98:      * The CSS attribute 'background-image'.
  99:      */
 100:     public static final Attribute BACKGROUND_IMAGE =
 101:       new Attribute("background-image", false, "none");
 102: 
 103:     /**
 104:      * The CSS attribute 'background-position'.
 105:      */
 106:     public static final Attribute BACKGROUND_POSITION =
 107:       new Attribute("background-position", false, null);
 108: 
 109:     /**
 110:      * The CSS attribute 'background-repeat'.
 111:      */
 112:     public static final Attribute BACKGROUND_REPEAT =
 113:       new Attribute("background-repeat", false, "repeat");
 114: 
 115:     /**
 116:      * The CSS attribute 'border'.
 117:      */
 118:     public static final Attribute BORDER = new Attribute("border", false, null);
 119: 
 120:     /**
 121:      * The CSS attribute 'border-bottom'.
 122:      */
 123:     public static final Attribute BORDER_BOTTOM =
 124:       new Attribute("border-bottom", false, null);
 125: 
 126:     /**
 127:      * The CSS attribute 'border-bottom-width'.
 128:      */
 129:     public static final Attribute BORDER_BOTTOM_WIDTH =
 130:       new Attribute("border-bottom-width", false, "medium");
 131: 
 132:     /**
 133:      * The CSS attribute 'border-color'.
 134:      */
 135:     public static final Attribute BORDER_COLOR =
 136:       new Attribute("border-color", false, "black");
 137: 
 138:     /**
 139:      * The CSS attribute 'border-left'.
 140:      */
 141:     public static final Attribute BORDER_LEFT =
 142:       new Attribute("border-left", false, null);
 143: 
 144:     /**
 145:      * The CSS attribute 'border-left-width'.
 146:      */
 147:     public static final Attribute BORDER_LEFT_WIDTH =
 148:       new Attribute("border-left-width", false, "medium");
 149: 
 150:     /**
 151:      * The CSS attribute 'border-right'.
 152:      */
 153:     public static final Attribute BORDER_RIGHT =
 154:       new Attribute("border-right", false, null);
 155: 
 156:     /**
 157:      * The CSS attribute 'border-right-width'.
 158:      */
 159:     public static final Attribute BORDER_RIGHT_WIDTH =
 160:       new Attribute("border-right-width", false, "medium");
 161: 
 162:     /**
 163:      * The CSS attribute 'border-style'.
 164:      */
 165:     public static final Attribute BORDER_STYLE =
 166:       new Attribute("border-style", false, "none");
 167: 
 168:     /**
 169:      * The CSS attribute 'border-top'.
 170:      */
 171:     public static final Attribute BORDER_TOP =
 172:       new Attribute("border-top", false, null);
 173: 
 174:     /**
 175:      * The CSS attribute 'border-top-width'.
 176:      */
 177:     public static final Attribute BORDER_TOP_WIDTH =
 178:       new Attribute("border-top-width", false, "medium");
 179: 
 180:     /**
 181:      * The CSS attribute 'border-width'.
 182:      */
 183:     public static final Attribute BORDER_WIDTH =
 184:       new Attribute("border-width", false, "medium");
 185: 
 186:     /**
 187:      * The CSS attribute 'clear'.
 188:      */
 189:     public static final Attribute CLEAR = new Attribute("clear", false, "none");
 190: 
 191:     /**
 192:      * The CSS attribute 'color'.
 193:      */
 194:     public static final Attribute COLOR = new Attribute("color", true, "black");
 195: 
 196:     /**
 197:      * The CSS attribute 'display'.
 198:      */
 199:     public static final Attribute DISPLAY =
 200:       new Attribute("display", false, "block");
 201: 
 202:     /**
 203:      * The CSS attribute 'float'.
 204:      */
 205:     public static final Attribute FLOAT = new Attribute("float", false, "none");
 206: 
 207:     /**
 208:      * The CSS attribute 'font'.
 209:      */
 210:     public static final Attribute FONT = new Attribute("font", true, null);
 211: 
 212:     /**
 213:      * The CSS attribute 'font-family'.
 214:      */
 215:     public static final Attribute FONT_FAMILY =
 216:       new Attribute("font-family", true, null);
 217: 
 218:     /**
 219:      * The CSS attribute 'font-size'.
 220:      */
 221:     public static final Attribute FONT_SIZE =
 222:       new Attribute("font-size", true, "medium");
 223: 
 224:     /**
 225:      * The CSS attribute 'font-style'.
 226:      */
 227:     public static final Attribute FONT_STYLE =
 228:       new Attribute("font-style", true, "normal");
 229: 
 230:     /**
 231:      * The CSS attribute 'font-variant'.
 232:      */
 233:     public static final Attribute FONT_VARIANT =
 234:       new Attribute("font-variant", true, "normal");
 235: 
 236:     /**
 237:      * The CSS attribute 'font-weight'.
 238:      */
 239:     public static final Attribute FONT_WEIGHT =
 240:       new Attribute("font-weight", true, "normal");
 241: 
 242:     /**
 243:      * The CSS attribute 'height'.
 244:      */
 245:     public static final Attribute HEIGHT =
 246:       new Attribute("height", false, "auto");
 247: 
 248:     /**
 249:      * The CSS attribute 'letter-spacing'.
 250:      */
 251:     public static final Attribute LETTER_SPACING =
 252:       new Attribute("letter-spacing", true, "normal");
 253: 
 254:     /**
 255:      * The CSS attribute 'line-height'.
 256:      */
 257:     public static final Attribute LINE_HEIGHT =
 258:       new Attribute("line-height", true, "normal");
 259: 
 260:     /**
 261:      * The CSS attribute 'list-style'.
 262:      */
 263:     public static final Attribute LIST_STYLE =
 264:       new Attribute("list-style", true, null);
 265: 
 266:     /**
 267:      * The CSS attribute 'list-style-image'.
 268:      */
 269:     public static final Attribute LIST_STYLE_IMAGE =
 270:       new Attribute("list-style-image", true, "none");
 271: 
 272:     /**
 273:      * The CSS attribute 'list-style-position'.
 274:      */
 275:     public static final Attribute LIST_STYLE_POSITION =
 276:       new Attribute("list-style-position", true, "outside");
 277: 
 278:     /**
 279:      * The CSS attribute 'list-style-type'.
 280:      */
 281:     public static final Attribute LIST_STYLE_TYPE =
 282:       new Attribute("list-style-type", true, "disc");
 283: 
 284:     /**
 285:      * The CSS attribute 'margin'.
 286:      */
 287:     public static final Attribute MARGIN = new Attribute("margin", false, null);
 288: 
 289:     /**
 290:      * The CSS attribute 'margin-bottom'.
 291:      */
 292:     public static final Attribute MARGIN_BOTTOM =
 293:       new Attribute("margin-bottom", false, "0");
 294: 
 295:     /**
 296:      * The CSS attribute 'margin-left'.
 297:      */
 298:     public static final Attribute MARGIN_LEFT =
 299:       new Attribute("margin-left", false, "0");
 300: 
 301:     /**
 302:      * The CSS attribute 'margin-right'.
 303:      */
 304:     public static final Attribute MARGIN_RIGHT =
 305:       new Attribute("margin-right", false, "0");
 306: 
 307:     /**
 308:      * The CSS attribute 'margin-top'.
 309:      */
 310:     public static final Attribute MARGIN_TOP =
 311:       new Attribute("margin-top", false, "0");
 312: 
 313:     /**
 314:      * The CSS attribute 'padding'.
 315:      */
 316:     public static final Attribute PADDING =
 317:       new Attribute("padding", false, null);
 318: 
 319:     /**
 320:      * The CSS attribute 'padding-bottom'.
 321:      */
 322:     public static final Attribute PADDING_BOTTOM =
 323:       new Attribute("padding-bottom", false, "0");
 324: 
 325:     /**
 326:      * The CSS attribute 'padding-left'.
 327:      */
 328:     public static final Attribute PADDING_LEFT =
 329:       new Attribute("padding-left", false, "0");
 330: 
 331:     /**
 332:      * The CSS attribute 'padding-right'.
 333:      */
 334:     public static final Attribute PADDING_RIGHT =
 335:       new Attribute("padding-right", false, "0");
 336: 
 337:     /**
 338:      * The CSS attribute 'padding-top'.
 339:      */
 340:     public static final Attribute PADDING_TOP =
 341:       new Attribute("padding-top", false, "0");
 342: 
 343:     /**
 344:      * The CSS attribute 'text-align'.
 345:      */
 346:     public static final Attribute TEXT_ALIGN =
 347:       new Attribute("text-align", true, null);
 348: 
 349:     /**
 350:      * The CSS attribute 'text-decoration'.
 351:      */
 352:     public static final Attribute TEXT_DECORATION =
 353:       new Attribute("text-decoration", true, "none");
 354: 
 355:     /**
 356:      * The CSS attribute 'text-indent'.
 357:      */
 358:     public static final Attribute TEXT_INDENT =
 359:       new Attribute("text-indent", true, "0");
 360: 
 361:     /**
 362:      * The CSS attribute 'text-transform'.
 363:      */
 364:     public static final Attribute TEXT_TRANSFORM =
 365:       new Attribute("text-transform", true, "none");
 366: 
 367:     /**
 368:      * The CSS attribute 'vertical-align'.
 369:      */
 370:     public static final Attribute VERTICAL_ALIGN =
 371:       new Attribute("vertical-align", false, "baseline");
 372: 
 373:     /**
 374:      * The CSS attribute 'white-space'.
 375:      */
 376:     public static final Attribute WHITE_SPACE =
 377:       new Attribute("white-space", true, "normal");
 378: 
 379:     /**
 380:      * The CSS attribute 'width'.
 381:      */
 382:     public static final Attribute WIDTH =
 383:       new Attribute("width", false, "auto");
 384: 
 385:     /**
 386:      * The CSS attribute 'word-spacing'.
 387:      */
 388:     public static final Attribute WORD_SPACING =
 389:       new Attribute("word-spacing", true, "normal");
 390: 
 391:     /**
 392:      * The attribute string.
 393:      */
 394:     String attStr;
 395: 
 396:     /**
 397:      * Indicates if this attribute should be inherited from it's parent or
 398:      * not.
 399:      */
 400:     boolean isInherited;
 401: 
 402:     /**
 403:      * A default value for this attribute if one exists, otherwise null.
 404:      */
 405:     String defaultValue;
 406: 
 407:     /**
 408:      * A HashMap of all attributes.
 409:      */
 410:     static HashMap attributeMap;
 411: 
 412:     /**
 413:      * Creates a new Attribute instance with the specified values.
 414:      *
 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> 
 418:      */
 419:     Attribute(String attr, boolean inherited, String def)
 420:     {
 421:       attStr = attr;
 422:       isInherited = inherited;
 423:       defaultValue = def;
 424:       if( attributeMap == null)
 425:     attributeMap = new HashMap();
 426:       attributeMap.put( attr, this );
 427:     }
 428: 
 429:     /**
 430:      * Returns the string representation of this attribute as specified
 431:      * in the CSS specification.
 432:      */
 433:     public String toString()
 434:     {
 435:       return attStr;
 436:     }
 437: 
 438:     /**
 439:      * Returns <code>true</code> if the attribute should be inherited from
 440:      * the parent, <code>false</code> otherwise.
 441:      *
 442:      * @return <code>true</code> if the attribute should be inherited from
 443:      *         the parent, <code>false</code> otherwise
 444:      */
 445:     public boolean isInherited()
 446:     {
 447:       return isInherited;
 448:     }
 449: 
 450:     /**
 451:      * Returns the default value of this attribute if one exists,
 452:      * <code>null</code> otherwise.
 453:      *
 454:      * @return the default value of this attribute if one exists,
 455:      *         <code>null</code> otherwise
 456:      */
 457:     public String getDefaultValue()
 458:     {
 459:       return defaultValue;
 460:     }
 461:   }
 462: }