1 7 package javax.swing.text; 8 9 import java.awt.Color ; 10 import java.awt.Component ; 11 import java.awt.Toolkit ; 12 import javax.swing.Icon ; 13 14 32 public class StyleConstants { 33 34 37 public static final String ComponentElementName = "component"; 38 39 42 public static final String IconElementName = "icon"; 43 44 48 public static final Object NameAttribute = new StyleConstants ("name"); 49 50 54 public static final Object ResolveAttribute = new StyleConstants ("resolver"); 55 56 60 public static final Object ModelAttribute = new StyleConstants ("model"); 61 62 67 public String toString() { 68 return representation; 69 } 70 71 73 77 public static final Object BidiLevel = new CharacterConstants("bidiLevel"); 78 79 82 public static final Object FontFamily = new FontConstants("family"); 83 84 89 public static final Object Family = FontFamily; 90 91 94 public static final Object FontSize = new FontConstants("size"); 95 96 101 public static final Object Size = FontSize; 102 103 106 public static final Object Bold = new FontConstants("bold"); 107 108 111 public static final Object Italic = new FontConstants("italic"); 112 113 116 public static final Object Underline = new CharacterConstants("underline"); 117 118 121 public static final Object StrikeThrough = new CharacterConstants("strikethrough"); 122 123 126 public static final Object Superscript = new CharacterConstants("superscript"); 127 128 131 public static final Object Subscript = new CharacterConstants("subscript"); 132 133 136 public static final Object Foreground = new ColorConstants("foreground"); 137 138 141 public static final Object Background = new ColorConstants("background"); 142 143 146 public static final Object ComponentAttribute = new CharacterConstants("component"); 147 148 151 public static final Object IconAttribute = new CharacterConstants("icon"); 152 153 158 public static final Object ComposedTextAttribute = new StyleConstants ("composed text"); 159 160 167 public static final Object FirstLineIndent = new ParagraphConstants("FirstLineIndent"); 168 169 174 public static final Object LeftIndent = new ParagraphConstants("LeftIndent"); 175 176 181 public static final Object RightIndent = new ParagraphConstants("RightIndent"); 182 183 188 public static final Object LineSpacing = new ParagraphConstants("LineSpacing"); 189 190 194 public static final Object SpaceAbove = new ParagraphConstants("SpaceAbove"); 195 196 200 public static final Object SpaceBelow = new ParagraphConstants("SpaceBelow"); 201 202 213 public static final Object Alignment = new ParagraphConstants("Alignment"); 214 215 219 public static final Object TabSet = new ParagraphConstants("TabSet"); 220 221 224 public static final Object Orientation = new ParagraphConstants("Orientation"); 225 231 public static final int ALIGN_LEFT = 0; 232 233 239 public static final int ALIGN_CENTER = 1; 240 241 247 public static final int ALIGN_RIGHT = 2; 248 249 257 public static final int ALIGN_JUSTIFIED = 3; 258 259 261 267 public static int getBidiLevel(AttributeSet a) { 268 Integer o = (Integer ) a.getAttribute(BidiLevel); 269 if (o != null) { 270 return o.intValue(); 271 } 272 return 0; } 274 275 281 public static void setBidiLevel(MutableAttributeSet a, int o) { 282 a.addAttribute(BidiLevel, new Integer (o)); 283 } 284 285 291 public static Component getComponent(AttributeSet a) { 292 return (Component ) a.getAttribute(ComponentAttribute); 293 } 294 295 301 public static void setComponent(MutableAttributeSet a, Component c) { 302 a.addAttribute(AbstractDocument.ElementNameAttribute, ComponentElementName); 303 a.addAttribute(ComponentAttribute, c); 304 } 305 306 312 public static Icon getIcon(AttributeSet a) { 313 return (Icon ) a.getAttribute(IconAttribute); 314 } 315 316 322 public static void setIcon(MutableAttributeSet a, Icon c) { 323 a.addAttribute(AbstractDocument.ElementNameAttribute, IconElementName); 324 a.addAttribute(IconAttribute, c); 325 } 326 327 333 public static String getFontFamily(AttributeSet a) { 334 String family = (String ) a.getAttribute(FontFamily); 335 if (family == null) { 336 family = "Monospaced"; 337 } 338 return family; 339 } 340 341 347 public static void setFontFamily(MutableAttributeSet a, String fam) { 348 a.addAttribute(FontFamily, fam); 349 } 350 351 357 public static int getFontSize(AttributeSet a) { 358 Integer size = (Integer ) a.getAttribute(FontSize); 359 if (size != null) { 360 return size.intValue(); 361 } 362 return 12; 363 } 364 365 371 public static void setFontSize(MutableAttributeSet a, int s) { 372 a.addAttribute(FontSize, new Integer (s)); 373 } 374 375 381 public static boolean isBold(AttributeSet a) { 382 Boolean bold = (Boolean ) a.getAttribute(Bold); 383 if (bold != null) { 384 return bold.booleanValue(); 385 } 386 return false; 387 } 388 389 395 public static void setBold(MutableAttributeSet a, boolean b) { 396 a.addAttribute(Bold, Boolean.valueOf(b)); 397 } 398 399 405 public static boolean isItalic(AttributeSet a) { 406 Boolean italic = (Boolean ) a.getAttribute(Italic); 407 if (italic != null) { 408 return italic.booleanValue(); 409 } 410 return false; 411 } 412 413 419 public static void setItalic(MutableAttributeSet a, boolean b) { 420 a.addAttribute(Italic, Boolean.valueOf(b)); 421 } 422 423 429 public static boolean isUnderline(AttributeSet a) { 430 Boolean underline = (Boolean ) a.getAttribute(Underline); 431 if (underline != null) { 432 return underline.booleanValue(); 433 } 434 return false; 435 } 436 437 443 public static boolean isStrikeThrough(AttributeSet a) { 444 Boolean strike = (Boolean ) a.getAttribute(StrikeThrough); 445 if (strike != null) { 446 return strike.booleanValue(); 447 } 448 return false; 449 } 450 451 452 458 public static boolean isSuperscript(AttributeSet a) { 459 Boolean superscript = (Boolean ) a.getAttribute(Superscript); 460 if (superscript != null) { 461 return superscript.booleanValue(); 462 } 463 return false; 464 } 465 466 467 473 public static boolean isSubscript(AttributeSet a) { 474 Boolean subscript = (Boolean ) a.getAttribute(Subscript); 475 if (subscript != null) { 476 return subscript.booleanValue(); 477 } 478 return false; 479 } 480 481 482 488 public static void setUnderline(MutableAttributeSet a, boolean b) { 489 a.addAttribute(Underline, Boolean.valueOf(b)); 490 } 491 492 498 public static void setStrikeThrough(MutableAttributeSet a, boolean b) { 499 a.addAttribute(StrikeThrough, Boolean.valueOf(b)); 500 } 501 502 508 public static void setSuperscript(MutableAttributeSet a, boolean b) { 509 a.addAttribute(Superscript, Boolean.valueOf(b)); 510 } 511 512 518 public static void setSubscript(MutableAttributeSet a, boolean b) { 519 a.addAttribute(Subscript, Boolean.valueOf(b)); 520 } 521 522 523 529 public static Color getForeground(AttributeSet a) { 530 Color fg = (Color ) a.getAttribute(Foreground); 531 if (fg == null) { 532 fg = Color.black; 533 } 534 return fg; 535 } 536 537 543 public static void setForeground(MutableAttributeSet a, Color fg) { 544 a.addAttribute(Foreground, fg); 545 } 546 547 553 public static Color getBackground(AttributeSet a) { 554 Color fg = (Color ) a.getAttribute(Background); 555 if (fg == null) { 556 fg = Color.black; 557 } 558 return fg; 559 } 560 561 567 public static void setBackground(MutableAttributeSet a, Color fg) { 568 a.addAttribute(Background, fg); 569 } 570 571 572 574 580 public static float getFirstLineIndent(AttributeSet a) { 581 Float indent = (Float ) a.getAttribute(FirstLineIndent); 582 if (indent != null) { 583 return indent.floatValue(); 584 } 585 return 0; 586 } 587 588 594 public static void setFirstLineIndent(MutableAttributeSet a, float i) { 595 a.addAttribute(FirstLineIndent, new Float (i)); 596 } 597 598 604 public static float getRightIndent(AttributeSet a) { 605 Float indent = (Float ) a.getAttribute(RightIndent); 606 if (indent != null) { 607 return indent.floatValue(); 608 } 609 return 0; 610 } 611 612 618 public static void setRightIndent(MutableAttributeSet a, float i) { 619 a.addAttribute(RightIndent, new Float (i)); 620 } 621 622 628 public static float getLeftIndent(AttributeSet a) { 629 Float indent = (Float ) a.getAttribute(LeftIndent); 630 if (indent != null) { 631 return indent.floatValue(); 632 } 633 return 0; 634 } 635 636 642 public static void setLeftIndent(MutableAttributeSet a, float i) { 643 a.addAttribute(LeftIndent, new Float (i)); 644 } 645 646 652 public static float getLineSpacing(AttributeSet a) { 653 Float space = (Float ) a.getAttribute(LineSpacing); 654 if (space != null) { 655 return space.floatValue(); 656 } 657 return 0; 658 } 659 660 666 public static void setLineSpacing(MutableAttributeSet a, float i) { 667 a.addAttribute(LineSpacing, new Float (i)); 668 } 669 670 676 public static float getSpaceAbove(AttributeSet a) { 677 Float space = (Float ) a.getAttribute(SpaceAbove); 678 if (space != null) { 679 return space.floatValue(); 680 } 681 return 0; 682 } 683 684 690 public static void setSpaceAbove(MutableAttributeSet a, float i) { 691 a.addAttribute(SpaceAbove, new Float (i)); 692 } 693 694 700 public static float getSpaceBelow(AttributeSet a) { 701 Float space = (Float ) a.getAttribute(SpaceBelow); 702 if (space != null) { 703 return space.floatValue(); 704 } 705 return 0; 706 } 707 708 714 public static void setSpaceBelow(MutableAttributeSet a, float i) { 715 a.addAttribute(SpaceBelow, new Float (i)); 716 } 717 718 724 public static int getAlignment(AttributeSet a) { 725 Integer align = (Integer ) a.getAttribute(Alignment); 726 if (align != null) { 727 return align.intValue(); 728 } 729 return ALIGN_LEFT; 730 } 731 732 738 public static void setAlignment(MutableAttributeSet a, int align) { 739 a.addAttribute(Alignment, new Integer (align)); 740 } 741 742 748 public static TabSet getTabSet(AttributeSet a) { 749 TabSet tabs = (TabSet )a.getAttribute(TabSet); 750 return tabs; 752 } 753 754 760 public static void setTabSet(MutableAttributeSet a, TabSet tabs) { 761 a.addAttribute(TabSet, tabs); 762 } 763 764 766 static Object [] keys = { 767 NameAttribute, ResolveAttribute, BidiLevel, 768 FontFamily, FontSize, Bold, Italic, Underline, 769 StrikeThrough, Superscript, Subscript, Foreground, 770 Background, ComponentAttribute, IconAttribute, 771 FirstLineIndent, LeftIndent, RightIndent, LineSpacing, 772 SpaceAbove, SpaceBelow, Alignment, TabSet, Orientation, 773 ModelAttribute, ComposedTextAttribute 774 }; 775 776 StyleConstants(String representation) { 777 this.representation = representation; 778 } 779 780 private String representation; 781 782 787 public static class ParagraphConstants extends StyleConstants 788 implements AttributeSet.ParagraphAttribute { 789 790 private ParagraphConstants(String representation) { 791 super(representation); 792 } 793 } 794 795 800 public static class CharacterConstants extends StyleConstants 801 implements AttributeSet.CharacterAttribute { 802 803 private CharacterConstants(String representation) { 804 super(representation); 805 } 806 } 807 808 813 public static class ColorConstants extends StyleConstants 814 implements AttributeSet.ColorAttribute , AttributeSet.CharacterAttribute { 815 816 private ColorConstants(String representation) { 817 super(representation); 818 } 819 } 820 821 826 public static class FontConstants extends StyleConstants 827 implements AttributeSet.FontAttribute , AttributeSet.CharacterAttribute { 828 829 private FontConstants(String representation) { 830 super(representation); 831 } 832 } 833 834 835 } 836 | Popular Tags |