Source for javax.swing.text.StyleConstants

   1: /* StyleConstants.java --
   2:    Copyright (C) 2004, 2005, 2006 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: 
  39: package javax.swing.text;
  40: 
  41: import java.awt.Color;
  42: import java.awt.Component;
  43: 
  44: import javax.swing.Icon;
  45: 
  46: /**
  47:  * Represents standard attribute keys.  This class also contains a set of 
  48:  * useful static utility methods for querying and populating an 
  49:  * {@link AttributeSet}.
  50:  * 
  51:  * @since 1.2
  52:  */
  53: public class StyleConstants
  54: {
  55:   /** 
  56:    * A value representing left alignment for the 
  57:    * {@link ParagraphConstants#Alignment} attribute. 
  58:    */
  59:   public static final int ALIGN_LEFT = 0;
  60: 
  61:   /** 
  62:    * A value representing center alignment for the 
  63:    * {@link ParagraphConstants#Alignment} attribute. 
  64:    */
  65:   public static final int ALIGN_CENTER = 1;
  66: 
  67:   /** 
  68:    * A value representing right alignment for the 
  69:    * {@link ParagraphConstants#Alignment} attribute. 
  70:    */
  71:   public static final int ALIGN_RIGHT = 2;
  72: 
  73:   /** 
  74:    * A value representing ful justification for the 
  75:    * {@link ParagraphConstants#Alignment} attribute. 
  76:    */
  77:   public static final int ALIGN_JUSTIFIED = 3;
  78: 
  79:   /** An alias for {@link CharacterConstants#Background}. */
  80:   public static final Object Background = CharacterConstants.Background;
  81: 
  82:   /** An alias for {@link CharacterConstants#BidiLevel}. */
  83:   public static final Object BidiLevel = CharacterConstants.BidiLevel;
  84:   
  85:   /** An alias for {@link CharacterConstants#Bold}. */
  86:   public static final Object Bold = CharacterConstants.Bold;
  87:   
  88:   /** An alias for {@link CharacterConstants#ComponentAttribute}. */
  89:   public static final Object ComponentAttribute 
  90:       = CharacterConstants.ComponentAttribute;
  91:   
  92:   /** An alias for {@link CharacterConstants#Family}. */
  93:   public static final Object Family = CharacterConstants.Family;
  94:   
  95:   /** An alias for {@link CharacterConstants#Family}. */
  96:   public static final Object FontFamily = CharacterConstants.Family;  
  97:   
  98:   /** An alias for {@link CharacterConstants#Size}. */
  99:   public static final Object FontSize = CharacterConstants.Size;
 100:   
 101:   /** An alias for {@link CharacterConstants#Foreground}. */
 102:   public static final Object Foreground = CharacterConstants.Foreground;
 103:   
 104:   /** An alias for {@link CharacterConstants#IconAttribute}. */
 105:   public static final Object IconAttribute = CharacterConstants.IconAttribute;
 106:   
 107:   /** An alias for {@link CharacterConstants#Italic}. */
 108:   public static final Object Italic = CharacterConstants.Italic;
 109:   
 110:   /** An alias for {@link CharacterConstants#Size}. */
 111:   public static final Object Size = CharacterConstants.Size;
 112:   
 113:   /** An alias for {@link CharacterConstants#StrikeThrough}. */
 114:   public static final Object StrikeThrough = CharacterConstants.StrikeThrough;
 115:   
 116:   /** An alias for {@link CharacterConstants#Subscript}. */
 117:   public static final Object Subscript = CharacterConstants.Subscript;
 118:   
 119:   /** An alias for {@link CharacterConstants#Superscript}. */
 120:   public static final Object Superscript = CharacterConstants.Superscript;
 121:   
 122:   /** An alias for {@link CharacterConstants#Underline}. */
 123:   public static final Object Underline = CharacterConstants.Underline;
 124: 
 125:   /** An alias for {@link ParagraphConstants#Alignment}. */
 126:   public static final Object Alignment = ParagraphConstants.Alignment;
 127:   
 128:   /** An alias for {@link ParagraphConstants#FirstLineIndent}. */
 129:   public static final Object FirstLineIndent 
 130:       = ParagraphConstants.FirstLineIndent;
 131:   
 132:   /** An alias for {@link ParagraphConstants#LeftIndent}. */
 133:   public static final Object LeftIndent = ParagraphConstants.LeftIndent;
 134:   
 135:   /** An alias for {@link ParagraphConstants#LineSpacing}. */
 136:   public static final Object LineSpacing = ParagraphConstants.LineSpacing;
 137:   
 138:   /** An alias for {@link ParagraphConstants#Orientation}. */
 139:   public static final Object Orientation = ParagraphConstants.Orientation;
 140:   
 141:   /** An alias for {@link ParagraphConstants#RightIndent}. */
 142:   public static final Object RightIndent = ParagraphConstants.RightIndent;
 143:   
 144:   /** An alias for {@link ParagraphConstants#SpaceAbove}. */
 145:   public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;
 146:   
 147:   /** An alias for {@link ParagraphConstants#SpaceBelow}. */
 148:   public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;
 149:   
 150:   /** An alias for {@link ParagraphConstants#TabSet}. */
 151:   public static final Object TabSet = ParagraphConstants.TabSet;
 152: 
 153:   public static final String ComponentElementName = "component";
 154: 
 155:   public static final String IconElementName = "icon";
 156: 
 157:   public static final Object ComposedTextAttribute 
 158:       = new StyleConstants("composed text");
 159:   
 160:   public static final Object ModelAttribute = new StyleConstants("model");
 161:   
 162:   public static final Object NameAttribute = new StyleConstants("name");
 163:   
 164:   public static final Object ResolveAttribute = new StyleConstants("resolver");
 165: 
 166:   String keyname;
 167: 
 168:   // Package-private to avoid accessor constructor for use by
 169:   // subclasses.
 170:   StyleConstants(String k) 
 171:   {
 172:     keyname = k;
 173:   }
 174: 
 175:   /**
 176:    * Returns a string representation of the attribute key.
 177:    * 
 178:    * @return A string representation of the attribute key.
 179:    */
 180:   public String toString()
 181:   {
 182:     return keyname;
 183:   }
 184: 
 185:   /**
 186:    * Returns the alignment specified in the given attributes, or 
 187:    * {@link #ALIGN_LEFT} if no alignment is specified.
 188:    * 
 189:    * @param a  the attribute set (<code>null</code> not permitted).
 190:    * 
 191:    * @return The alignment (typically one of {@link #ALIGN_LEFT}, 
 192:    *         {@link #ALIGN_RIGHT}, {@link #ALIGN_CENTER} or 
 193:    *         {@link #ALIGN_JUSTIFIED}).
 194:    *         
 195:    * @see #setAlignment(MutableAttributeSet, int)
 196:    */
 197:   public static int getAlignment(AttributeSet a)
 198:   {
 199:     Integer i = (Integer) a.getAttribute(Alignment);
 200:     if (i != null)
 201:       return i.intValue();
 202:     else
 203:       return ALIGN_LEFT;      
 204:   } 
 205: 
 206:   /**
 207:    * Returns the background color specified in the given attributes, or
 208:    * {@link Color#BLACK} if no background color is specified.
 209:    * 
 210:    * @param a  the attribute set (<code>null</code> not permitted).
 211:    * 
 212:    * @return The background color.
 213:    * 
 214:    * @see #setBackground(MutableAttributeSet, Color)
 215:    */
 216:   public static Color getBackground(AttributeSet a)
 217:   {
 218:     Color c = (Color) a.getAttribute(Background);
 219:     if (c != null) 
 220:       return c;
 221:     else
 222:       return Color.BLACK;
 223:   } 
 224: 
 225:   /**
 226:    * Returns the bidi level specified in the given attributes, or 
 227:    * <code>0</code> if no bidi level is specified.
 228:    * 
 229:    * @param a  the attribute set (<code>null</code> not permitted).
 230:    * 
 231:    * @return The bidi level.
 232:    * 
 233:    * @see #setBidiLevel(MutableAttributeSet, int)
 234:    */  
 235:   public static int getBidiLevel(AttributeSet a)
 236:   {
 237:     Integer i = (Integer) a.getAttribute(BidiLevel);
 238:     if (i != null)
 239:       return i.intValue();
 240:     else
 241:       return 0;
 242:   } 
 243: 
 244:   /**
 245:    * Returns the component specified in the given attributes, or 
 246:    * <code>null</code> if no component is specified.
 247:    * 
 248:    * @param a  the attribute set (<code>null</code> not permitted).
 249:    * 
 250:    * @return The component (possibly <code>null</code>).
 251:    * 
 252:    * @see #setComponent(MutableAttributeSet, Component)
 253:    */    
 254:   public static Component getComponent(AttributeSet a)
 255:   {
 256:     Component c = (Component) a.getAttribute(ComponentAttribute);
 257:     if (c != null)
 258:       return c;
 259:     else
 260:       return null;
 261:   } 
 262: 
 263:   /**
 264:    * Returns the indentation specified in the given attributes, or 
 265:    * <code>0.0f</code> if no indentation is specified.
 266:    * 
 267:    * @param a  the attribute set (<code>null</code> not permitted).
 268:    * 
 269:    * @return The indentation.
 270:    * 
 271:    * @see #setFirstLineIndent(MutableAttributeSet, float)
 272:    */    
 273:   public static float getFirstLineIndent(AttributeSet a)
 274:   {
 275:     Float f = (Float) a.getAttribute(FirstLineIndent);
 276:     if (f != null)
 277:       return f.floatValue();
 278:     else
 279:       return 0.0f;
 280:   } 
 281: 
 282:   /**
 283:    * Returns the font family specified in the given attributes, or 
 284:    * <code>Monospaced</code> if no font family is specified.
 285:    * 
 286:    * @param a  the attribute set (<code>null</code> not permitted).
 287:    * 
 288:    * @return The font family.
 289:    * 
 290:    * @see #setFontFamily(MutableAttributeSet, String)
 291:    */    
 292:   public static String getFontFamily(AttributeSet a)
 293:   {
 294:     String ff = (String) a.getAttribute(FontFamily);
 295:     if (ff != null)
 296:       return ff;
 297:     else
 298:       return "Monospaced";
 299:   } 
 300: 
 301:   /**
 302:    * Returns the font size specified in the given attributes, or 
 303:    * <code>12</code> if no font size is specified.
 304:    * 
 305:    * @param a  the attribute set (<code>null</code> not permitted).
 306:    * 
 307:    * @return The font size.
 308:    * 
 309:    * @see #setFontSize(MutableAttributeSet, int)
 310:    */  
 311:   public static int getFontSize(AttributeSet a)
 312:   {
 313:     Integer i = (Integer) a.getAttribute(FontSize);
 314:     if (i != null)
 315:       return i.intValue();
 316:     else
 317:       return 12;
 318:   } 
 319: 
 320:   /**
 321:    * Returns the foreground color specified in the given attributes, or
 322:    * {@link Color#BLACK} if no foreground color is specified.
 323:    * 
 324:    * @param a  the attribute set (<code>null</code> not permitted).
 325:    * 
 326:    * @return The foreground color.
 327:    * 
 328:    * @see #setForeground(MutableAttributeSet, Color)
 329:    */
 330:   public static Color getForeground(AttributeSet a)
 331:   {
 332:     Color c = (Color) a.getAttribute(Foreground);
 333:     if (c != null)
 334:       return c;
 335:     else
 336:       return Color.BLACK;
 337:   } 
 338: 
 339:   /**
 340:    * Returns the icon specified in the given attributes, or 
 341:    * <code>null</code> if no icon is specified.
 342:    * 
 343:    * @param a  the attribute set (<code>null</code> not permitted).
 344:    * 
 345:    * @return The icon (possibly <code>null</code>).
 346:    * 
 347:    * @see #setIcon(MutableAttributeSet, Icon)
 348:    */    
 349:   public static Icon getIcon(AttributeSet a)
 350:   {
 351:     return (Icon) a.getAttribute(IconAttribute);
 352:   } 
 353: 
 354:   /**
 355:    * Returns the left indentation specified in the given attributes, or 
 356:    * <code>0.0f</code> if no left indentation is specified.
 357:    * 
 358:    * @param a  the attribute set (<code>null</code> not permitted).
 359:    * 
 360:    * @return The left indentation.
 361:    * 
 362:    * @see #setLeftIndent(MutableAttributeSet, float)
 363:    */    
 364:   public static float getLeftIndent(AttributeSet a)
 365:   {
 366:     Float f = (Float) a.getAttribute(LeftIndent);
 367:     if (f != null)
 368:       return f.floatValue();
 369:     else
 370:       return 0.0f;
 371:   } 
 372: 
 373:   /**
 374:    * Returns the line spacing specified in the given attributes, or 
 375:    * <code>0.0f</code> if no line spacing is specified.
 376:    * 
 377:    * @param a  the attribute set (<code>null</code> not permitted).
 378:    * 
 379:    * @return The line spacing.
 380:    * 
 381:    * @see #setLineSpacing(MutableAttributeSet, float)
 382:    */    
 383:   public static float getLineSpacing(AttributeSet a)
 384:   {
 385:     Float f = (Float) a.getAttribute(LineSpacing);
 386:     if (f != null)
 387:       return f.floatValue();
 388:     else
 389:       return 0.0f;
 390:   } 
 391: 
 392:   /**
 393:    * Returns the right indentation specified in the given attributes, or 
 394:    * <code>0.0f</code> if no right indentation is specified.
 395:    * 
 396:    * @param a  the attribute set (<code>null</code> not permitted).
 397:    * 
 398:    * @return The right indentation.
 399:    * 
 400:    * @see #setRightIndent(MutableAttributeSet, float)
 401:    */    
 402:   public static float getRightIndent(AttributeSet a)
 403:   {
 404:     Float f = (Float) a.getAttribute(RightIndent);
 405:     if (f != null)
 406:       return f.floatValue();
 407:     else
 408:       return 0.0f;
 409:   } 
 410: 
 411:   /**
 412:    * Returns the 'space above' specified in the given attributes, or 
 413:    * <code>0.0f</code> if no 'space above' is specified.
 414:    * 
 415:    * @param a  the attribute set (<code>null</code> not permitted).
 416:    * 
 417:    * @return The 'space above'.
 418:    * 
 419:    * @see #setSpaceAbove(MutableAttributeSet, float)
 420:    */    
 421:   public static float getSpaceAbove(AttributeSet a)
 422:   {
 423:     Float f = (Float) a.getAttribute(SpaceAbove);
 424:     if (f != null)
 425:       return f.floatValue();
 426:     else 
 427:       return 0.0f;
 428:   } 
 429: 
 430:   /**
 431:    * Returns the 'space below' specified in the given attributes, or 
 432:    * <code>0.0f</code> if no 'space below' is specified.
 433:    * 
 434:    * @param a  the attribute set (<code>null</code> not permitted).
 435:    * 
 436:    * @return The 'space below'.
 437:    * 
 438:    * @see #setSpaceBelow(MutableAttributeSet, float)
 439:    */    
 440:   public static float getSpaceBelow(AttributeSet a)
 441:   {
 442:     Float f = (Float) a.getAttribute(SpaceBelow);
 443:     if (f != null)
 444:       return f.floatValue();
 445:     else
 446:       return 0.0f;
 447:   } 
 448: 
 449:   /**
 450:    * Returns the tab set specified in the given attributes, or 
 451:    * <code>null</code> if no tab set is specified.
 452:    * 
 453:    * @param a  the attribute set (<code>null</code> not permitted).
 454:    * 
 455:    * @return The tab set.
 456:    * 
 457:    * @see #setTabSet(MutableAttributeSet, javax.swing.text.TabSet)
 458:    */    
 459:   public static javax.swing.text.TabSet getTabSet(AttributeSet a)
 460:   {
 461:     // I'm guessing that the fully qualified class name is to differentiate
 462:     // between the TabSet class and the TabSet (attribute) instance on some
 463:     // compiler...
 464:     return (javax.swing.text.TabSet) a.getAttribute(StyleConstants.TabSet);
 465:   } 
 466: 
 467:   /**
 468:    * Returns the value of the bold flag in the given attributes, or 
 469:    * <code>false</code> if no bold flag is specified.
 470:    * 
 471:    * @param a  the attribute set (<code>null</code> not permitted).
 472:    * 
 473:    * @return The bold flag.
 474:    * 
 475:    * @see #setBold(MutableAttributeSet, boolean)
 476:    */
 477:   public static boolean isBold(AttributeSet a)
 478:   {
 479:     Boolean b = (Boolean) a.getAttribute(Bold);
 480:     if (b != null)
 481:       return b.booleanValue();
 482:     else
 483:       return false;
 484:   } 
 485: 
 486:   /**
 487:    * Returns the value of the italic flag in the given attributes, or 
 488:    * <code>false</code> if no italic flag is specified.
 489:    * 
 490:    * @param a  the attribute set (<code>null</code> not permitted).
 491:    * 
 492:    * @return The italic flag.
 493:    * 
 494:    * @see #setItalic(MutableAttributeSet, boolean)
 495:    */
 496:   public static boolean isItalic(AttributeSet a)
 497:   {
 498:     Boolean b = (Boolean) a.getAttribute(Italic);
 499:     if (b != null)
 500:       return b.booleanValue();
 501:     else
 502:       return false;
 503:   } 
 504: 
 505:   /**
 506:    * Returns the value of the strike-through flag in the given attributes, or 
 507:    * <code>false</code> if no strike-through flag is specified.
 508:    * 
 509:    * @param a  the attribute set (<code>null</code> not permitted).
 510:    * 
 511:    * @return The strike-through flag.
 512:    * 
 513:    * @see #setStrikeThrough(MutableAttributeSet, boolean)
 514:    */
 515:   public static boolean isStrikeThrough(AttributeSet a)
 516:   {
 517:     Boolean b = (Boolean) a.getAttribute(StrikeThrough);
 518:     if (b != null)
 519:       return b.booleanValue();
 520:     else
 521:       return false;
 522:   } 
 523: 
 524:   /**
 525:    * Returns the value of the subscript flag in the given attributes, or 
 526:    * <code>false</code> if no subscript flag is specified.
 527:    * 
 528:    * @param a  the attribute set (<code>null</code> not permitted).
 529:    * 
 530:    * @return The subscript flag.
 531:    * 
 532:    * @see #setSubscript(MutableAttributeSet, boolean)
 533:    */
 534:   public static boolean isSubscript(AttributeSet a)
 535:   {
 536:     Boolean b = (Boolean) a.getAttribute(Subscript);
 537:     if (b != null)
 538:       return b.booleanValue();
 539:     else
 540:       return false;
 541:   } 
 542: 
 543:   /**
 544:    * Returns the value of the superscript flag in the given attributes, or 
 545:    * <code>false</code> if no superscript flag is specified.
 546:    * 
 547:    * @param a  the attribute set (<code>null</code> not permitted).
 548:    * 
 549:    * @return The superscript flag.
 550:    * 
 551:    * @see #setSuperscript(MutableAttributeSet, boolean)
 552:    */
 553:   public static boolean isSuperscript(AttributeSet a)
 554:   {
 555:     Boolean b = (Boolean) a.getAttribute(Superscript);
 556:     if (b != null)
 557:       return b.booleanValue();
 558:     else 
 559:       return false;
 560:   } 
 561: 
 562:   /**
 563:    * Returns the value of the underline flag in the given attributes, or 
 564:    * <code>false</code> if no underline flag is specified.
 565:    * 
 566:    * @param a  the attribute set (<code>null</code> not permitted).
 567:    * 
 568:    * @return The underline flag.
 569:    * 
 570:    * @see #setUnderline(MutableAttributeSet, boolean)
 571:    */
 572:   public static boolean isUnderline(AttributeSet a)
 573:   {
 574:     Boolean b = (Boolean) a.getAttribute(Underline);
 575:     if (b != null)
 576:       return b.booleanValue();
 577:     else
 578:       return false;
 579:   } 
 580: 
 581:   /**
 582:    * Adds an alignment attribute to the specified set.
 583:    * 
 584:    * @param a  the attribute set (<code>null</code> not permitted).
 585:    * @param align  the alignment (typically one of 
 586:    *               {@link StyleConstants#ALIGN_LEFT}, 
 587:    *               {@link StyleConstants#ALIGN_RIGHT}, 
 588:    *               {@link StyleConstants#ALIGN_CENTER} or 
 589:    *               {@link StyleConstants#ALIGN_JUSTIFIED}).
 590:    * 
 591:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 592:    * 
 593:    * @see #getAlignment(AttributeSet)
 594:    */
 595:   public static void setAlignment(MutableAttributeSet a, int align)
 596:   {
 597:     a.addAttribute(Alignment, new Integer(align));
 598:   } 
 599: 
 600:   /**
 601:    * Adds a background attribute to the specified set.
 602:    * 
 603:    * @param a  the attribute set (<code>null</code> not permitted).
 604:    * @param bg  the background (<code>null</code> not permitted).
 605:    * 
 606:    * @throws NullPointerException if either argument is <code>null</code>.
 607:    * 
 608:    * @see #getBackground(AttributeSet)
 609:    */
 610:   public static void setBackground(MutableAttributeSet a, Color bg)
 611:   {
 612:     a.addAttribute(Background, bg);
 613:   } 
 614: 
 615:   /**
 616:    * Adds a bidi-level attribute to the specified set.
 617:    * 
 618:    * @param a  the attribute set (<code>null</code> not permitted).
 619:    * @param lev  the level.
 620:    * 
 621:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 622:    * 
 623:    * @see #getBidiLevel(AttributeSet)
 624:    */
 625:   public static void setBidiLevel(MutableAttributeSet a, int lev)
 626:   {
 627:     a.addAttribute(BidiLevel, new Integer(lev));
 628:   } 
 629: 
 630:   /**
 631:    * Adds a bold attribute to the specified set.
 632:    * 
 633:    * @param a  the attribute set (<code>null</code> not permitted).
 634:    * @param b  the new value of the bold attribute.
 635:    * 
 636:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 637:    * 
 638:    * @see #isBold(AttributeSet)
 639:    */
 640:   public static void setBold(MutableAttributeSet a, boolean b)
 641:   {
 642:     a.addAttribute(Bold, Boolean.valueOf(b));
 643:   } 
 644:   
 645:   /**
 646:    * Adds a component attribute to the specified set.
 647:    * 
 648:    * @param a  the attribute set (<code>null</code> not permitted).
 649:    * @param c  the component (<code>null</code> not permitted).
 650:    * 
 651:    * @throws NullPointerException if either argument is <code>null</code>.
 652:    * 
 653:    * @see #getComponent(AttributeSet)
 654:    */
 655:   public static void setComponent(MutableAttributeSet a, Component c)
 656:   {
 657:     a.addAttribute(ComponentAttribute, c);
 658:   } 
 659: 
 660:   /**
 661:    * Adds a first line indentation attribute to the specified set.
 662:    * 
 663:    * @param a  the attribute set (<code>null</code> not permitted).
 664:    * @param i  the indentation.
 665:    * 
 666:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 667:    * 
 668:    * @see #getFirstLineIndent(AttributeSet)
 669:    */
 670:   public static void setFirstLineIndent(MutableAttributeSet a, float i)
 671:   {
 672:     a.addAttribute(FirstLineIndent, new Float(i));
 673:   } 
 674: 
 675:   /**
 676:    * Adds a font family attribute to the specified set.
 677:    * 
 678:    * @param a  the attribute set (<code>null</code> not permitted).
 679:    * @param fam  the font family name (<code>null</code> not permitted).
 680:    * 
 681:    * @throws NullPointerException if either argument is <code>null</code>.
 682:    * 
 683:    * @see #getFontFamily(AttributeSet)
 684:    */
 685:   public static void setFontFamily(MutableAttributeSet a, String fam)
 686:   {
 687:     a.addAttribute(FontFamily, fam);
 688:   } 
 689: 
 690:   /**
 691:    * Adds a font size attribute to the specified set.
 692:    * 
 693:    * @param a  the attribute set (<code>null</code> not permitted).
 694:    * @param s  the font size (in points).
 695:    * 
 696:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 697:    * 
 698:    * @see #getFontSize(AttributeSet)
 699:    */
 700:   public static void setFontSize(MutableAttributeSet a, int s)
 701:   {
 702:     a.addAttribute(FontSize, new Integer(s));
 703:   } 
 704: 
 705:   /**
 706:    * Adds a foreground color attribute to the specified set.
 707:    * 
 708:    * @param a  the attribute set (<code>null</code> not permitted).
 709:    * @param fg  the foreground color (<code>null</code> not permitted).
 710:    * 
 711:    * @throws NullPointerException if either argument is <code>null</code>.
 712:    * 
 713:    * @see #getForeground(AttributeSet)
 714:    */
 715:   public static void setForeground(MutableAttributeSet a, Color fg)
 716:   {
 717:     a.addAttribute(Foreground, fg);
 718:   }
 719: 
 720:   /**
 721:    * Adds an icon attribute to the specified set.
 722:    * 
 723:    * @param a  the attribute set (<code>null</code> not permitted).
 724:    * @param c  the icon (<code>null</code> not permitted).
 725:    * 
 726:    * @throws NullPointerException if either argument is <code>null</code>.
 727:    * 
 728:    * @see #getIcon(AttributeSet)
 729:    */
 730:   public static void setIcon(MutableAttributeSet a, Icon c)
 731:   {
 732:     a.addAttribute(IconAttribute, c);
 733:   }
 734:  
 735:   /**
 736:    * Adds an italic attribute to the specified set.
 737:    * 
 738:    * @param a  the attribute set (<code>null</code> not permitted).
 739:    * @param b  the new value of the italic attribute.
 740:    * 
 741:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 742:    * 
 743:    * @see #isItalic(AttributeSet)
 744:    */
 745:   public static void setItalic(MutableAttributeSet a, boolean b)
 746:   {
 747:     a.addAttribute(Italic, Boolean.valueOf(b));
 748:   }
 749:  
 750:   /**
 751:    * Adds a left indentation attribute to the specified set.
 752:    * 
 753:    * @param a  the attribute set (<code>null</code> not permitted).
 754:    * @param i  the indentation.
 755:    * 
 756:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 757:    * 
 758:    * @see #getLeftIndent(AttributeSet)
 759:    */
 760:   public static void setLeftIndent(MutableAttributeSet a, float i)
 761:   {
 762:     a.addAttribute(LeftIndent, new Float(i));
 763:   } 
 764: 
 765:   /**
 766:    * Adds a line spacing attribute to the specified set.
 767:    * 
 768:    * @param a  the attribute set (<code>null</code> not permitted).
 769:    * @param i  the line spacing.
 770:    * 
 771:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 772:    * 
 773:    * @see #getLineSpacing(AttributeSet)
 774:    */
 775:   public static void setLineSpacing(MutableAttributeSet a, float i)
 776:   {
 777:     a.addAttribute(LineSpacing, new Float(i));
 778:   } 
 779: 
 780:   /**
 781:    * Adds a right indentation attribute to the specified set.
 782:    * 
 783:    * @param a  the attribute set (<code>null</code> not permitted).
 784:    * @param i  the right indentation.
 785:    * 
 786:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 787:    * 
 788:    * @see #getRightIndent(AttributeSet)
 789:    */
 790:   public static void setRightIndent(MutableAttributeSet a, float i)
 791:   {
 792:     a.addAttribute(RightIndent, new Float(i));
 793:   } 
 794: 
 795:   /**
 796:    * Adds a 'space above' attribute to the specified set.
 797:    * 
 798:    * @param a  the attribute set (<code>null</code> not permitted).
 799:    * @param i  the space above attribute value.
 800:    * 
 801:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 802:    * 
 803:    * @see #getSpaceAbove(AttributeSet)
 804:    */
 805:   public static void setSpaceAbove(MutableAttributeSet a, float i)
 806:   {
 807:     a.addAttribute(SpaceAbove, new Float(i));
 808:   } 
 809: 
 810:   /**
 811:    * Adds a 'space below' attribute to the specified set.
 812:    * 
 813:    * @param a  the attribute set (<code>null</code> not permitted).
 814:    * @param i  the space below attribute value.
 815:    * 
 816:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 817:    * 
 818:    * @see #getSpaceBelow(AttributeSet)
 819:    */
 820:   public static void setSpaceBelow(MutableAttributeSet a, float i)
 821:   {
 822:     a.addAttribute(SpaceBelow, new Float(i));
 823:   } 
 824: 
 825:   /**
 826:    * Adds a strike-through attribue to the specified set.
 827:    * 
 828:    * @param a  the attribute set (<code>null</code> not permitted).
 829:    * @param b  the strike-through attribute value.
 830:    * 
 831:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 832:    * 
 833:    * @see #isStrikeThrough(AttributeSet)
 834:    */
 835:   public static void setStrikeThrough(MutableAttributeSet a, boolean b)
 836:   {
 837:     a.addAttribute(StrikeThrough, Boolean.valueOf(b));
 838:   } 
 839: 
 840:   /**
 841:    * Adds a subscript attribute to the specified set.
 842:    * 
 843:    * @param a  the attribute set (<code>null</code> not permitted).
 844:    * @param b  the subscript attribute value.
 845:    * 
 846:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 847:    * 
 848:    * @see #isSubscript(AttributeSet)
 849:    */
 850:   public static void setSubscript(MutableAttributeSet a, boolean b)
 851:   {
 852:     a.addAttribute(Subscript, Boolean.valueOf(b));
 853:   } 
 854: 
 855:   /**
 856:    * Adds a superscript attribute to the specified set.
 857:    * 
 858:    * @param a  the attribute set (<code>null</code> not permitted).
 859:    * @param b  the superscript attribute value.
 860:    * 
 861:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 862:    * 
 863:    * @see #isSuperscript(AttributeSet)
 864:    */
 865:   public static void setSuperscript(MutableAttributeSet a, boolean b)
 866:   {
 867:     a.addAttribute(Superscript, Boolean.valueOf(b));
 868:   } 
 869: 
 870:   /**
 871:    * Adds a {@link TabSet} attribute to the specified set.
 872:    * 
 873:    * @param a  the attribute set (<code>null</code> not permitted).
 874:    * @param tabs  the tab set (<code>null</code> not permitted).
 875:    * 
 876:    * @throws NullPointerException if either argument is <code>null</code>.
 877:    * 
 878:    * @see #getTabSet(AttributeSet)
 879:    */
 880:   public static void setTabSet(MutableAttributeSet a, 
 881:                                javax.swing.text.TabSet tabs)
 882:   {
 883:     a.addAttribute(StyleConstants.TabSet, tabs);
 884:   } 
 885: 
 886:   /**
 887:    * Adds an underline attribute to the specified set.
 888:    * 
 889:    * @param a  the attribute set (<code>null</code> not permitted).
 890:    * @param b  the underline attribute value.
 891:    * 
 892:    * @throws NullPointerException if <code>a</code> is <code>null</code>.
 893:    * 
 894:    * @see #isUnderline(AttributeSet)
 895:    */
 896:   public static void setUnderline(MutableAttributeSet a, boolean b)
 897:   {
 898:     a.addAttribute(Underline, Boolean.valueOf(b));
 899:   } 
 900: 
 901:   // The remainder are so-called "typesafe enumerations" which 
 902:   // alias subsets of the above constants.
 903: 
 904:   /**
 905:    * A set of keys for attributes that apply to characters.
 906:    */
 907:   public static class CharacterConstants
 908:     extends StyleConstants
 909:     implements AttributeSet.CharacterAttribute
 910:   {
 911:     /**
 912:      * Private constructor prevents new instances being created.
 913:      * 
 914:      * @param k  the key name.
 915:      */
 916:     private CharacterConstants(String k) 
 917:     {
 918:       super(k);
 919:     }
 920:     
 921:     /** An alias for {@link ColorConstants#Background}. */
 922:     public static final Object Background = ColorConstants.Background;
 923:     
 924:     /** A key for the bidi level character attribute. */
 925:     public static final Object BidiLevel = new CharacterConstants("bidiLevel");
 926:     
 927:     /** An alias for {@link FontConstants#Bold}. */
 928:     public static final Object Bold = FontConstants.Bold;
 929:     
 930:     /** A key for the component character attribute. */
 931:     public static final Object ComponentAttribute 
 932:         = new CharacterConstants("component");
 933:     
 934:     /** An alias for {@link FontConstants#Family}. */
 935:     public static final Object Family = FontConstants.Family;
 936:     
 937:     /** An alias for {@link FontConstants#Size}. */
 938:     public static final Object Size = FontConstants.Size;
 939:     
 940:     /** An alias for {@link ColorConstants#Foreground}. */
 941:     public static final Object Foreground = ColorConstants.Foreground;
 942:     
 943:     /** A key for the icon character attribute. */
 944:     public static final Object IconAttribute = new CharacterConstants("icon");
 945:     
 946:     /** A key for the italic character attribute. */
 947:     public static final Object Italic = FontConstants.Italic;
 948:     
 949:     /** A key for the strike through character attribute. */
 950:     public static final Object StrikeThrough 
 951:         = new CharacterConstants("strikethrough");
 952:     
 953:     /** A key for the subscript character attribute. */
 954:     public static final Object Subscript = new CharacterConstants("subscript");
 955:     
 956:     /** A key for the superscript character attribute. */
 957:     public static final Object Superscript 
 958:         = new CharacterConstants("superscript");
 959:     
 960:     /** A key for the underline character attribute. */
 961:     public static final Object Underline = new CharacterConstants("underline");
 962:   
 963:   }
 964: 
 965:   /**
 966:    * A set of keys for attributes that relate to colors.
 967:    */
 968:   public static class ColorConstants
 969:     extends StyleConstants
 970:     implements AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute
 971:   {
 972:     /**
 973:      * Private constructor prevents new instances being created.
 974:      * 
 975:      * @param k  the key name.
 976:      */
 977:     private ColorConstants(String k) 
 978:     {
 979:       super(k);
 980:     }
 981:     
 982:     /** A key for the foreground color attribute. */
 983:     public static final Object Foreground = new ColorConstants("foreground");
 984: 
 985:     /** A key for the background color attribute. */
 986:     public static final Object Background = new ColorConstants("background");
 987:   }
 988: 
 989:   /**
 990:    * A set of keys for attributes that apply to fonts.
 991:    */
 992:   public static class FontConstants
 993:     extends StyleConstants
 994:     implements AttributeSet.FontAttribute, AttributeSet.CharacterAttribute
 995:   {
 996:     /**
 997:      * Private constructor prevents new instances being created.
 998:      * 
 999:      * @param k  the key name.
1000:      */
1001:     private FontConstants(String k) 
1002:     {
1003:       super(k);
1004:     }
1005:     
1006:     /** A key for the bold font attribute. */
1007:     public static final Object Bold = new FontConstants("bold");
1008: 
1009:     /** A key for the family font attribute. */
1010:     public static final Object Family = new FontConstants("family");
1011:     
1012:     /** A key for the italic font attribute. */
1013:     public static final Object Italic = new FontConstants("italic");
1014:     
1015:     /** A key for the size font attribute. */
1016:     public static final Object Size = new FontConstants("size");
1017:   }
1018: 
1019:   /**
1020:    * A set of keys for attributes that apply to paragraphs.
1021:    */
1022:   public static class ParagraphConstants
1023:     extends StyleConstants
1024:     implements AttributeSet.ParagraphAttribute
1025:   {
1026:     /**
1027:      * Private constructor prevents new instances being created.
1028:      * 
1029:      * @param k  the key name.
1030:      */
1031:     private ParagraphConstants(String k) 
1032:     {
1033:       super(k);
1034:     }
1035:     
1036:     /** A key for the alignment paragraph attribute. */
1037:     public static final Object Alignment = new ParagraphConstants("Alignment");
1038: 
1039:     /** A key for the first line indentation paragraph attribute. */
1040:     public static final Object FirstLineIndent 
1041:         = new ParagraphConstants("FirstLineIndent");
1042:     
1043:     /** A key for the left indentation paragraph attribute. */
1044:     public static final Object LeftIndent 
1045:         = new ParagraphConstants("LeftIndent");
1046:     
1047:     /** A key for the line spacing paragraph attribute. */
1048:     public static final Object LineSpacing 
1049:         = new ParagraphConstants("LineSpacing");
1050:     
1051:     /** A key for the orientation paragraph attribute. */
1052:     public static final Object Orientation 
1053:         = new ParagraphConstants("Orientation");
1054:     
1055:     /** A key for the right indentation paragraph attribute. */
1056:     public static final Object RightIndent 
1057:         = new ParagraphConstants("RightIndent");
1058:     
1059:     /** A key for the 'space above' paragraph attribute. */
1060:     public static final Object SpaceAbove 
1061:         = new ParagraphConstants("SpaceAbove");
1062:     
1063:     /** A key for the 'space below' paragraph attribute. */
1064:     public static final Object SpaceBelow 
1065:         = new ParagraphConstants("SpaceBelow");
1066:     
1067:     /** A key for the tabset paragraph attribute. */
1068:     public static final Object TabSet = new ParagraphConstants("TabSet");
1069:     
1070:   }
1071: 
1072: }