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