summaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/text/StyleConstants.java
blob: bdc63719d3367b0cf8e86fcb82065d67ea776337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
/* StyleConstants.java --
   Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


package javax.swing.text;

import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;

import javax.swing.Icon;

/**
 * Represents standard attribute keys.  This class also contains a set of
 * useful static utility methods for querying and populating an
 * {@link AttributeSet}.
 *
 * @since 1.2
 */
public class StyleConstants
{
  /**
   * A value representing left alignment for the
   * {@link ParagraphConstants#Alignment} attribute.
   */
  public static final int ALIGN_LEFT = 0;

  /**
   * A value representing center alignment for the
   * {@link ParagraphConstants#Alignment} attribute.
   */
  public static final int ALIGN_CENTER = 1;

  /**
   * A value representing right alignment for the
   * {@link ParagraphConstants#Alignment} attribute.
   */
  public static final int ALIGN_RIGHT = 2;

  /**
   * A value representing ful justification for the
   * {@link ParagraphConstants#Alignment} attribute.
   */
  public static final int ALIGN_JUSTIFIED = 3;

  /** An alias for {@link CharacterConstants#Background}. */
  public static final Object Background = CharacterConstants.Background;

  /** An alias for {@link CharacterConstants#BidiLevel}. */
  public static final Object BidiLevel = CharacterConstants.BidiLevel;

  /** An alias for {@link CharacterConstants#Bold}. */
  public static final Object Bold = CharacterConstants.Bold;

  /** An alias for {@link CharacterConstants#ComponentAttribute}. */
  public static final Object ComponentAttribute
      = CharacterConstants.ComponentAttribute;

  /** An alias for {@link CharacterConstants#Family}. */
  public static final Object Family = CharacterConstants.Family;

  /** An alias for {@link CharacterConstants#Family}. */
  public static final Object FontFamily = CharacterConstants.Family;

  /** An alias for {@link CharacterConstants#Size}. */
  public static final Object FontSize = CharacterConstants.Size;

  /** An alias for {@link CharacterConstants#Foreground}. */
  public static final Object Foreground = CharacterConstants.Foreground;

  /** An alias for {@link CharacterConstants#IconAttribute}. */
  public static final Object IconAttribute = CharacterConstants.IconAttribute;

  /** An alias for {@link CharacterConstants#Italic}. */
  public static final Object Italic = CharacterConstants.Italic;

  /** An alias for {@link CharacterConstants#Size}. */
  public static final Object Size = CharacterConstants.Size;

  /** An alias for {@link CharacterConstants#StrikeThrough}. */
  public static final Object StrikeThrough = CharacterConstants.StrikeThrough;

  /** An alias for {@link CharacterConstants#Subscript}. */
  public static final Object Subscript = CharacterConstants.Subscript;

  /** An alias for {@link CharacterConstants#Superscript}. */
  public static final Object Superscript = CharacterConstants.Superscript;

  /** An alias for {@link CharacterConstants#Underline}. */
  public static final Object Underline = CharacterConstants.Underline;

  /** An alias for {@link ParagraphConstants#Alignment}. */
  public static final Object Alignment = ParagraphConstants.Alignment;

  /** An alias for {@link ParagraphConstants#FirstLineIndent}. */
  public static final Object FirstLineIndent
      = ParagraphConstants.FirstLineIndent;

  /** An alias for {@link ParagraphConstants#LeftIndent}. */
  public static final Object LeftIndent = ParagraphConstants.LeftIndent;

  /** An alias for {@link ParagraphConstants#LineSpacing}. */
  public static final Object LineSpacing = ParagraphConstants.LineSpacing;

  /** An alias for {@link ParagraphConstants#Orientation}. */
  public static final Object Orientation = ParagraphConstants.Orientation;

  /** An alias for {@link ParagraphConstants#RightIndent}. */
  public static final Object RightIndent = ParagraphConstants.RightIndent;

  /** An alias for {@link ParagraphConstants#SpaceAbove}. */
  public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;

  /** An alias for {@link ParagraphConstants#SpaceBelow}. */
  public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;

  /** An alias for {@link ParagraphConstants#TabSet}. */
  public static final Object TabSet = ParagraphConstants.TabSet;

  public static final String ComponentElementName = "component";

  public static final String IconElementName = "icon";

  public static final Object ComposedTextAttribute
      = new StyleConstants("composed text");

  public static final Object ModelAttribute = new StyleConstants("model");

  public static final Object NameAttribute = new StyleConstants("name");

  public static final Object ResolveAttribute = new StyleConstants("resolver");

  /**
   * All StyleConstants keys. This is used in StyleContext to register
   * all known keys as static attribute keys for serialization.
   */
  static ArrayList keys;

  String keyname;

  // Package-private to avoid accessor constructor for use by
  // subclasses.
  StyleConstants(String k)
  {
    keyname = k;
    if (keys == null)
      keys = new ArrayList();
    keys.add(this);
  }

  /**
   * Returns a string representation of the attribute key.
   *
   * @return A string representation of the attribute key.
   */
  public String toString()
  {
    return keyname;
  }

  /**
   * Returns the alignment specified in the given attributes, or
   * {@link #ALIGN_LEFT} if no alignment is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The alignment (typically one of {@link #ALIGN_LEFT},
   *         {@link #ALIGN_RIGHT}, {@link #ALIGN_CENTER} or
   *         {@link #ALIGN_JUSTIFIED}).
   *
   * @see #setAlignment(MutableAttributeSet, int)
   */
  public static int getAlignment(AttributeSet a)
  {
    Integer i = (Integer) a.getAttribute(Alignment);
    if (i != null)
      return i.intValue();
    else
      return ALIGN_LEFT;
  }

  /**
   * Returns the background color specified in the given attributes, or
   * {@link Color#BLACK} if no background color is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The background color.
   *
   * @see #setBackground(MutableAttributeSet, Color)
   */
  public static Color getBackground(AttributeSet a)
  {
    Color c = (Color) a.getAttribute(Background);
    if (c != null)
      return c;
    else
      return Color.BLACK;
  }

  /**
   * Returns the bidi level specified in the given attributes, or
   * <code>0</code> if no bidi level is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The bidi level.
   *
   * @see #setBidiLevel(MutableAttributeSet, int)
   */
  public static int getBidiLevel(AttributeSet a)
  {
    Integer i = (Integer) a.getAttribute(BidiLevel);
    if (i != null)
      return i.intValue();
    else
      return 0;
  }

  /**
   * Returns the component specified in the given attributes, or
   * <code>null</code> if no component is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The component (possibly <code>null</code>).
   *
   * @see #setComponent(MutableAttributeSet, Component)
   */
  public static Component getComponent(AttributeSet a)
  {
    Component c = (Component) a.getAttribute(ComponentAttribute);
    if (c != null)
      return c;
    else
      return null;
  }

  /**
   * Returns the indentation specified in the given attributes, or
   * <code>0.0f</code> if no indentation is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The indentation.
   *
   * @see #setFirstLineIndent(MutableAttributeSet, float)
   */
  public static float getFirstLineIndent(AttributeSet a)
  {
    Float f = (Float) a.getAttribute(FirstLineIndent);
    if (f != null)
      return f.floatValue();
    else
      return 0.0f;
  }

  /**
   * Returns the font family specified in the given attributes, or
   * <code>Monospaced</code> if no font family is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The font family.
   *
   * @see #setFontFamily(MutableAttributeSet, String)
   */
  public static String getFontFamily(AttributeSet a)
  {
    String ff = (String) a.getAttribute(FontFamily);
    if (ff != null)
      return ff;
    else
      return "Monospaced";
  }

  /**
   * Returns the font size specified in the given attributes, or
   * <code>12</code> if no font size is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The font size.
   *
   * @see #setFontSize(MutableAttributeSet, int)
   */
  public static int getFontSize(AttributeSet a)
  {
    Integer i = (Integer) a.getAttribute(FontSize);
    if (i != null)
      return i.intValue();
    else
      return 12;
  }

  /**
   * Returns the foreground color specified in the given attributes, or
   * {@link Color#BLACK} if no foreground color is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The foreground color.
   *
   * @see #setForeground(MutableAttributeSet, Color)
   */
  public static Color getForeground(AttributeSet a)
  {
    Color c = (Color) a.getAttribute(Foreground);
    if (c != null)
      return c;
    else
      return Color.BLACK;
  }

  /**
   * Returns the icon specified in the given attributes, or
   * <code>null</code> if no icon is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The icon (possibly <code>null</code>).
   *
   * @see #setIcon(MutableAttributeSet, Icon)
   */
  public static Icon getIcon(AttributeSet a)
  {
    return (Icon) a.getAttribute(IconAttribute);
  }

  /**
   * Returns the left indentation specified in the given attributes, or
   * <code>0.0f</code> if no left indentation is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The left indentation.
   *
   * @see #setLeftIndent(MutableAttributeSet, float)
   */
  public static float getLeftIndent(AttributeSet a)
  {
    Float f = (Float) a.getAttribute(LeftIndent);
    if (f != null)
      return f.floatValue();
    else
      return 0.0f;
  }

  /**
   * Returns the line spacing specified in the given attributes, or
   * <code>0.0f</code> if no line spacing is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The line spacing.
   *
   * @see #setLineSpacing(MutableAttributeSet, float)
   */
  public static float getLineSpacing(AttributeSet a)
  {
    Float f = (Float) a.getAttribute(LineSpacing);
    if (f != null)
      return f.floatValue();
    else
      return 0.0f;
  }

  /**
   * Returns the right indentation specified in the given attributes, or
   * <code>0.0f</code> if no right indentation is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The right indentation.
   *
   * @see #setRightIndent(MutableAttributeSet, float)
   */
  public static float getRightIndent(AttributeSet a)
  {
    Float f = (Float) a.getAttribute(RightIndent);
    if (f != null)
      return f.floatValue();
    else
      return 0.0f;
  }

  /**
   * Returns the 'space above' specified in the given attributes, or
   * <code>0.0f</code> if no 'space above' is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The 'space above'.
   *
   * @see #setSpaceAbove(MutableAttributeSet, float)
   */
  public static float getSpaceAbove(AttributeSet a)
  {
    Float f = (Float) a.getAttribute(SpaceAbove);
    if (f != null)
      return f.floatValue();
    else
      return 0.0f;
  }

  /**
   * Returns the 'space below' specified in the given attributes, or
   * <code>0.0f</code> if no 'space below' is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The 'space below'.
   *
   * @see #setSpaceBelow(MutableAttributeSet, float)
   */
  public static float getSpaceBelow(AttributeSet a)
  {
    Float f = (Float) a.getAttribute(SpaceBelow);
    if (f != null)
      return f.floatValue();
    else
      return 0.0f;
  }

  /**
   * Returns the tab set specified in the given attributes, or
   * <code>null</code> if no tab set is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The tab set.
   *
   * @see #setTabSet(MutableAttributeSet, javax.swing.text.TabSet)
   */
  public static javax.swing.text.TabSet getTabSet(AttributeSet a)
  {
    // I'm guessing that the fully qualified class name is to differentiate
    // between the TabSet class and the TabSet (attribute) instance on some
    // compiler...
    return (javax.swing.text.TabSet) a.getAttribute(StyleConstants.TabSet);
  }

  /**
   * Returns the value of the bold flag in the given attributes, or
   * <code>false</code> if no bold flag is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The bold flag.
   *
   * @see #setBold(MutableAttributeSet, boolean)
   */
  public static boolean isBold(AttributeSet a)
  {
    Boolean b = (Boolean) a.getAttribute(Bold);
    if (b != null)
      return b.booleanValue();
    else
      return false;
  }

  /**
   * Returns the value of the italic flag in the given attributes, or
   * <code>false</code> if no italic flag is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The italic flag.
   *
   * @see #setItalic(MutableAttributeSet, boolean)
   */
  public static boolean isItalic(AttributeSet a)
  {
    Boolean b = (Boolean) a.getAttribute(Italic);
    if (b != null)
      return b.booleanValue();
    else
      return false;
  }

  /**
   * Returns the value of the strike-through flag in the given attributes, or
   * <code>false</code> if no strike-through flag is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The strike-through flag.
   *
   * @see #setStrikeThrough(MutableAttributeSet, boolean)
   */
  public static boolean isStrikeThrough(AttributeSet a)
  {
    Boolean b = (Boolean) a.getAttribute(StrikeThrough);
    if (b != null)
      return b.booleanValue();
    else
      return false;
  }

  /**
   * Returns the value of the subscript flag in the given attributes, or
   * <code>false</code> if no subscript flag is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The subscript flag.
   *
   * @see #setSubscript(MutableAttributeSet, boolean)
   */
  public static boolean isSubscript(AttributeSet a)
  {
    Boolean b = (Boolean) a.getAttribute(Subscript);
    if (b != null)
      return b.booleanValue();
    else
      return false;
  }

  /**
   * Returns the value of the superscript flag in the given attributes, or
   * <code>false</code> if no superscript flag is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The superscript flag.
   *
   * @see #setSuperscript(MutableAttributeSet, boolean)
   */
  public static boolean isSuperscript(AttributeSet a)
  {
    Boolean b = (Boolean) a.getAttribute(Superscript);
    if (b != null)
      return b.booleanValue();
    else
      return false;
  }

  /**
   * Returns the value of the underline flag in the given attributes, or
   * <code>false</code> if no underline flag is specified.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   *
   * @return The underline flag.
   *
   * @see #setUnderline(MutableAttributeSet, boolean)
   */
  public static boolean isUnderline(AttributeSet a)
  {
    Boolean b = (Boolean) a.getAttribute(Underline);
    if (b != null)
      return b.booleanValue();
    else
      return false;
  }

  /**
   * Adds an alignment attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param align  the alignment (typically one of
   *               {@link StyleConstants#ALIGN_LEFT},
   *               {@link StyleConstants#ALIGN_RIGHT},
   *               {@link StyleConstants#ALIGN_CENTER} or
   *               {@link StyleConstants#ALIGN_JUSTIFIED}).
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getAlignment(AttributeSet)
   */
  public static void setAlignment(MutableAttributeSet a, int align)
  {
    a.addAttribute(Alignment, new Integer(align));
  }

  /**
   * Adds a background attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param bg  the background (<code>null</code> not permitted).
   *
   * @throws NullPointerException if either argument is <code>null</code>.
   *
   * @see #getBackground(AttributeSet)
   */
  public static void setBackground(MutableAttributeSet a, Color bg)
  {
    a.addAttribute(Background, bg);
  }

  /**
   * Adds a bidi-level attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param lev  the level.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getBidiLevel(AttributeSet)
   */
  public static void setBidiLevel(MutableAttributeSet a, int lev)
  {
    a.addAttribute(BidiLevel, new Integer(lev));
  }

  /**
   * Adds a bold attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param b  the new value of the bold attribute.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #isBold(AttributeSet)
   */
  public static void setBold(MutableAttributeSet a, boolean b)
  {
    a.addAttribute(Bold, Boolean.valueOf(b));
  }

  /**
   * Adds a component attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param c  the component (<code>null</code> not permitted).
   *
   * @throws NullPointerException if either argument is <code>null</code>.
   *
   * @see #getComponent(AttributeSet)
   */
  public static void setComponent(MutableAttributeSet a, Component c)
  {
    a.addAttribute(ComponentAttribute, c);
  }

  /**
   * Adds a first line indentation attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param i  the indentation.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getFirstLineIndent(AttributeSet)
   */
  public static void setFirstLineIndent(MutableAttributeSet a, float i)
  {
    a.addAttribute(FirstLineIndent, new Float(i));
  }

  /**
   * Adds a font family attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param fam  the font family name (<code>null</code> not permitted).
   *
   * @throws NullPointerException if either argument is <code>null</code>.
   *
   * @see #getFontFamily(AttributeSet)
   */
  public static void setFontFamily(MutableAttributeSet a, String fam)
  {
    a.addAttribute(FontFamily, fam);
  }

  /**
   * Adds a font size attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param s  the font size (in points).
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getFontSize(AttributeSet)
   */
  public static void setFontSize(MutableAttributeSet a, int s)
  {
    a.addAttribute(FontSize, new Integer(s));
  }

  /**
   * Adds a foreground color attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param fg  the foreground color (<code>null</code> not permitted).
   *
   * @throws NullPointerException if either argument is <code>null</code>.
   *
   * @see #getForeground(AttributeSet)
   */
  public static void setForeground(MutableAttributeSet a, Color fg)
  {
    a.addAttribute(Foreground, fg);
  }

  /**
   * Adds an icon attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param c  the icon (<code>null</code> not permitted).
   *
   * @throws NullPointerException if either argument is <code>null</code>.
   *
   * @see #getIcon(AttributeSet)
   */
  public static void setIcon(MutableAttributeSet a, Icon c)
  {
    a.addAttribute(AbstractDocument.ElementNameAttribute, IconElementName);
    a.addAttribute(IconAttribute, c);
  }

  /**
   * Adds an italic attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param b  the new value of the italic attribute.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #isItalic(AttributeSet)
   */
  public static void setItalic(MutableAttributeSet a, boolean b)
  {
    a.addAttribute(Italic, Boolean.valueOf(b));
  }

  /**
   * Adds a left indentation attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param i  the indentation.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getLeftIndent(AttributeSet)
   */
  public static void setLeftIndent(MutableAttributeSet a, float i)
  {
    a.addAttribute(LeftIndent, new Float(i));
  }

  /**
   * Adds a line spacing attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param i  the line spacing.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getLineSpacing(AttributeSet)
   */
  public static void setLineSpacing(MutableAttributeSet a, float i)
  {
    a.addAttribute(LineSpacing, new Float(i));
  }

  /**
   * Adds a right indentation attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param i  the right indentation.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getRightIndent(AttributeSet)
   */
  public static void setRightIndent(MutableAttributeSet a, float i)
  {
    a.addAttribute(RightIndent, new Float(i));
  }

  /**
   * Adds a 'space above' attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param i  the space above attribute value.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getSpaceAbove(AttributeSet)
   */
  public static void setSpaceAbove(MutableAttributeSet a, float i)
  {
    a.addAttribute(SpaceAbove, new Float(i));
  }

  /**
   * Adds a 'space below' attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param i  the space below attribute value.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #getSpaceBelow(AttributeSet)
   */
  public static void setSpaceBelow(MutableAttributeSet a, float i)
  {
    a.addAttribute(SpaceBelow, new Float(i));
  }

  /**
   * Adds a strike-through attribue to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param b  the strike-through attribute value.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #isStrikeThrough(AttributeSet)
   */
  public static void setStrikeThrough(MutableAttributeSet a, boolean b)
  {
    a.addAttribute(StrikeThrough, Boolean.valueOf(b));
  }

  /**
   * Adds a subscript attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param b  the subscript attribute value.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #isSubscript(AttributeSet)
   */
  public static void setSubscript(MutableAttributeSet a, boolean b)
  {
    a.addAttribute(Subscript, Boolean.valueOf(b));
  }

  /**
   * Adds a superscript attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param b  the superscript attribute value.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #isSuperscript(AttributeSet)
   */
  public static void setSuperscript(MutableAttributeSet a, boolean b)
  {
    a.addAttribute(Superscript, Boolean.valueOf(b));
  }

  /**
   * Adds a {@link TabSet} attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param tabs  the tab set (<code>null</code> not permitted).
   *
   * @throws NullPointerException if either argument is <code>null</code>.
   *
   * @see #getTabSet(AttributeSet)
   */
  public static void setTabSet(MutableAttributeSet a,
                               javax.swing.text.TabSet tabs)
  {
    a.addAttribute(StyleConstants.TabSet, tabs);
  }

  /**
   * Adds an underline attribute to the specified set.
   *
   * @param a  the attribute set (<code>null</code> not permitted).
   * @param b  the underline attribute value.
   *
   * @throws NullPointerException if <code>a</code> is <code>null</code>.
   *
   * @see #isUnderline(AttributeSet)
   */
  public static void setUnderline(MutableAttributeSet a, boolean b)
  {
    a.addAttribute(Underline, Boolean.valueOf(b));
  }

  // The remainder are so-called "typesafe enumerations" which
  // alias subsets of the above constants.

  /**
   * A set of keys for attributes that apply to characters.
   */
  public static class CharacterConstants
    extends StyleConstants
    implements AttributeSet.CharacterAttribute
  {
    /**
     * Private constructor prevents new instances being created.
     *
     * @param k  the key name.
     */
    private CharacterConstants(String k)
    {
      super(k);
    }

    /** An alias for {@link ColorConstants#Background}. */
    public static final Object Background = ColorConstants.Background;

    /** A key for the bidi level character attribute. */
    public static final Object BidiLevel = new CharacterConstants("bidiLevel");

    /** An alias for {@link FontConstants#Bold}. */
    public static final Object Bold = FontConstants.Bold;

    /** A key for the component character attribute. */
    public static final Object ComponentAttribute
        = new CharacterConstants("component");

    /** An alias for {@link FontConstants#Family}. */
    public static final Object Family = FontConstants.Family;

    /** An alias for {@link FontConstants#Size}. */
    public static final Object Size = FontConstants.Size;

    /** An alias for {@link ColorConstants#Foreground}. */
    public static final Object Foreground = ColorConstants.Foreground;

    /** A key for the icon character attribute. */
    public static final Object IconAttribute = new CharacterConstants("icon");

    /** A key for the italic character attribute. */
    public static final Object Italic = FontConstants.Italic;

    /** A key for the strike through character attribute. */
    public static final Object StrikeThrough
        = new CharacterConstants("strikethrough");

    /** A key for the subscript character attribute. */
    public static final Object Subscript = new CharacterConstants("subscript");

    /** A key for the superscript character attribute. */
    public static final Object Superscript
        = new CharacterConstants("superscript");

    /** A key for the underline character attribute. */
    public static final Object Underline = new CharacterConstants("underline");

  }

  /**
   * A set of keys for attributes that relate to colors.
   */
  public static class ColorConstants
    extends StyleConstants
    implements AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute
  {
    /**
     * Private constructor prevents new instances being created.
     *
     * @param k  the key name.
     */
    private ColorConstants(String k)
    {
      super(k);
    }

    /** A key for the foreground color attribute. */
    public static final Object Foreground = new ColorConstants("foreground");

    /** A key for the background color attribute. */
    public static final Object Background = new ColorConstants("background");
  }

  /**
   * A set of keys for attributes that apply to fonts.
   */
  public static class FontConstants
    extends StyleConstants
    implements AttributeSet.FontAttribute, AttributeSet.CharacterAttribute
  {
    /**
     * Private constructor prevents new instances being created.
     *
     * @param k  the key name.
     */
    private FontConstants(String k)
    {
      super(k);
    }

    /** A key for the bold font attribute. */
    public static final Object Bold = new FontConstants("bold");

    /** A key for the family font attribute. */
    public static final Object Family = new FontConstants("family");

    /** A key for the italic font attribute. */
    public static final Object Italic = new FontConstants("italic");

    /** A key for the size font attribute. */
    public static final Object Size = new FontConstants("size");
  }

  /**
   * A set of keys for attributes that apply to paragraphs.
   */
  public static class ParagraphConstants
    extends StyleConstants
    implements AttributeSet.ParagraphAttribute
  {
    /**
     * Private constructor prevents new instances being created.
     *
     * @param k  the key name.
     */
    private ParagraphConstants(String k)
    {
      super(k);
    }

    /** A key for the alignment paragraph attribute. */
    public static final Object Alignment = new ParagraphConstants("Alignment");

    /** A key for the first line indentation paragraph attribute. */
    public static final Object FirstLineIndent
        = new ParagraphConstants("FirstLineIndent");

    /** A key for the left indentation paragraph attribute. */
    public static final Object LeftIndent
        = new ParagraphConstants("LeftIndent");

    /** A key for the line spacing paragraph attribute. */
    public static final Object LineSpacing
        = new ParagraphConstants("LineSpacing");

    /** A key for the orientation paragraph attribute. */
    public static final Object Orientation
        = new ParagraphConstants("Orientation");

    /** A key for the right indentation paragraph attribute. */
    public static final Object RightIndent
        = new ParagraphConstants("RightIndent");

    /** A key for the 'space above' paragraph attribute. */
    public static final Object SpaceAbove
        = new ParagraphConstants("SpaceAbove");

    /** A key for the 'space below' paragraph attribute. */
    public static final Object SpaceBelow
        = new ParagraphConstants("SpaceBelow");

    /** A key for the tabset paragraph attribute. */
    public static final Object TabSet = new ParagraphConstants("TabSet");

  }

}