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