~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/swing/text/StyleConstants.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* StyleConstants.java --
2
 
   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 
2
   Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
3
3
 
4
4
This file is part of GNU Classpath.
5
5
 
43
43
 
44
44
import javax.swing.Icon;
45
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
 */
46
53
public class StyleConstants
47
54
{
 
55
  /** 
 
56
   * A value representing left alignment for the 
 
57
   * {@link ParagraphConstants#Alignment} attribute. 
 
58
   */
48
59
  public static final int ALIGN_LEFT = 0;
 
60
 
 
61
  /** 
 
62
   * A value representing center alignment for the 
 
63
   * {@link ParagraphConstants#Alignment} attribute. 
 
64
   */
49
65
  public static final int ALIGN_CENTER = 1;
 
66
 
 
67
  /** 
 
68
   * A value representing right alignment for the 
 
69
   * {@link ParagraphConstants#Alignment} attribute. 
 
70
   */
50
71
  public static final int ALIGN_RIGHT = 2;
 
72
 
 
73
  /** 
 
74
   * A value representing ful justification for the 
 
75
   * {@link ParagraphConstants#Alignment} attribute. 
 
76
   */
51
77
  public static final int ALIGN_JUSTIFIED = 3;
52
78
 
 
79
  /** An alias for {@link CharacterConstants#Background}. */
53
80
  public static final Object Background = CharacterConstants.Background;
 
81
 
 
82
  /** An alias for {@link CharacterConstants#BidiLevel}. */
54
83
  public static final Object BidiLevel = CharacterConstants.BidiLevel;
 
84
  
 
85
  /** An alias for {@link CharacterConstants#Bold}. */
55
86
  public static final Object Bold = CharacterConstants.Bold;
56
 
  public static final Object ComponentAttribute = CharacterConstants.ComponentAttribute;
57
 
  public static final Object FontFamily = CharacterConstants.Family;
 
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}. */
58
99
  public static final Object FontSize = CharacterConstants.Size;
 
100
  
 
101
  /** An alias for {@link CharacterConstants#Foreground}. */
59
102
  public static final Object Foreground = CharacterConstants.Foreground;
 
103
  
 
104
  /** An alias for {@link CharacterConstants#IconAttribute}. */
60
105
  public static final Object IconAttribute = CharacterConstants.IconAttribute;
 
106
  
 
107
  /** An alias for {@link CharacterConstants#Italic}. */
61
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}. */
62
114
  public static final Object StrikeThrough = CharacterConstants.StrikeThrough;
 
115
  
 
116
  /** An alias for {@link CharacterConstants#Subscript}. */
63
117
  public static final Object Subscript = CharacterConstants.Subscript;
 
118
  
 
119
  /** An alias for {@link CharacterConstants#Superscript}. */
64
120
  public static final Object Superscript = CharacterConstants.Superscript;
 
121
  
 
122
  /** An alias for {@link CharacterConstants#Underline}. */
65
123
  public static final Object Underline = CharacterConstants.Underline;
66
124
 
 
125
  /** An alias for {@link ParagraphConstants#Alignment}. */
67
126
  public static final Object Alignment = ParagraphConstants.Alignment;
68
 
  public static final Object FirstLineIndent = ParagraphConstants.FirstLineIndent;
 
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}. */
69
133
  public static final Object LeftIndent = ParagraphConstants.LeftIndent;
 
134
  
 
135
  /** An alias for {@link ParagraphConstants#LineSpacing}. */
70
136
  public static final Object LineSpacing = ParagraphConstants.LineSpacing;
 
137
  
 
138
  /** An alias for {@link ParagraphConstants#Orientation}. */
71
139
  public static final Object Orientation = ParagraphConstants.Orientation;
 
140
  
 
141
  /** An alias for {@link ParagraphConstants#RightIndent}. */
72
142
  public static final Object RightIndent = ParagraphConstants.RightIndent;
 
143
  
 
144
  /** An alias for {@link ParagraphConstants#SpaceAbove}. */
73
145
  public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;
 
146
  
 
147
  /** An alias for {@link ParagraphConstants#SpaceBelow}. */
74
148
  public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;
 
149
  
 
150
  /** An alias for {@link ParagraphConstants#TabSet}. */
75
151
  public static final Object TabSet = ParagraphConstants.TabSet;
76
152
 
77
153
  public static final String ComponentElementName = "component";
 
154
 
78
155
  public static final String IconElementName = "icon";
79
156
 
80
 
  public static final Object ComposedTextAttribute = new StyleConstants("composed text");
 
157
  public static final Object ComposedTextAttribute 
 
158
      = new StyleConstants("composed text");
 
159
  
81
160
  public static final Object ModelAttribute = new StyleConstants("model");
 
161
  
82
162
  public static final Object NameAttribute = new StyleConstants("name");
 
163
  
83
164
  public static final Object ResolveAttribute = new StyleConstants("resolver");
84
165
 
85
166
  String keyname;
91
172
    keyname = k;
92
173
  }
93
174
 
 
175
  /**
 
176
   * Returns a string representation of the attribute key.
 
177
   * 
 
178
   * @return A string representation of the attribute key.
 
179
   */
94
180
  public String toString()
95
181
  {
96
182
    return keyname;
97
183
  }
98
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
   */
99
197
  public static int getAlignment(AttributeSet a)
100
198
  {
101
 
    if (a.isDefined(Alignment))
102
 
      return ((Integer)a.getAttribute(Alignment)).intValue();
 
199
    Integer i = (Integer) a.getAttribute(Alignment);
 
200
    if (i != null)
 
201
      return i.intValue();
103
202
    else
104
203
      return ALIGN_LEFT;      
105
204
  } 
106
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
   */
107
216
  public static Color getBackground(AttributeSet a)
108
217
  {
109
 
    if (a.isDefined(Background))
110
 
      return (Color) a.getAttribute(Background);
 
218
    Color c = (Color) a.getAttribute(Background);
 
219
    if (c != null) 
 
220
      return c;
111
221
    else
112
 
      return Color.WHITE;
 
222
      return Color.BLACK;
113
223
  } 
114
 
  
 
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
   */  
115
235
  public static int getBidiLevel(AttributeSet a)
116
236
  {
117
 
    if (a.isDefined(BidiLevel))
118
 
      return ((Integer)a.getAttribute(BidiLevel)).intValue();
 
237
    Integer i = (Integer) a.getAttribute(BidiLevel);
 
238
    if (i != null)
 
239
      return i.intValue();
119
240
    else
120
241
      return 0;
121
242
  } 
122
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
   */    
123
254
  public static Component getComponent(AttributeSet a)
124
255
  {
125
 
    if (a.isDefined(ComponentAttribute))
126
 
      return (Component) a.getAttribute(ComponentAttribute);
 
256
    Component c = (Component) a.getAttribute(ComponentAttribute);
 
257
    if (c != null)
 
258
      return c;
127
259
    else
128
 
      return (Component) null;
 
260
      return null;
129
261
  } 
130
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
   */    
131
273
  public static float getFirstLineIndent(AttributeSet a)
132
274
  {
133
 
    if (a.isDefined(FirstLineIndent))
134
 
      return ((Float)a.getAttribute(FirstLineIndent)).floatValue();
 
275
    Float f = (Float) a.getAttribute(FirstLineIndent);
 
276
    if (f != null)
 
277
      return f.floatValue();
135
278
    else
136
 
      return 0.f;
 
279
      return 0.0f;
137
280
  } 
138
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
   */    
139
292
  public static String getFontFamily(AttributeSet a)
140
293
  {
141
 
    if (a.isDefined(FontFamily))
142
 
      return (String) a.getAttribute(FontFamily);
 
294
    String ff = (String) a.getAttribute(FontFamily);
 
295
    if (ff != null)
 
296
      return ff;
143
297
    else
144
298
      return "Monospaced";
145
299
  } 
146
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
   */  
147
311
  public static int getFontSize(AttributeSet a)
148
312
  {
149
 
    if (a.isDefined(FontSize))
150
 
      return ((Integer)a.getAttribute(FontSize)).intValue();
 
313
    Integer i = (Integer) a.getAttribute(FontSize);
 
314
    if (i != null)
 
315
      return i.intValue();
151
316
    else
152
317
      return 12;
153
318
  } 
154
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
   */
155
330
  public static Color getForeground(AttributeSet a)
156
331
  {
157
 
    if (a.isDefined(Foreground))
158
 
      return (Color) a.getAttribute(Foreground);
 
332
    Color c = (Color) a.getAttribute(Foreground);
 
333
    if (c != null)
 
334
      return c;
159
335
    else
160
336
      return Color.BLACK;
161
337
  } 
162
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
   */    
163
349
  public static Icon getIcon(AttributeSet a)
164
350
  {
165
 
    if (a.isDefined(IconAttribute))
166
 
      return (Icon) a.getAttribute(IconAttribute);
167
 
    else
168
 
      return (Icon) null;
 
351
    return (Icon) a.getAttribute(IconAttribute);
169
352
  } 
170
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
   */    
171
364
  public static float getLeftIndent(AttributeSet a)
172
365
  {
173
 
    if (a.isDefined(LeftIndent))
174
 
      return ((Float)a.getAttribute(LeftIndent)).floatValue();
 
366
    Float f = (Float) a.getAttribute(LeftIndent);
 
367
    if (f != null)
 
368
      return f.floatValue();
175
369
    else
176
 
      return 0.f;  
 
370
      return 0.0f;
177
371
  } 
178
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
   */    
179
383
  public static float getLineSpacing(AttributeSet a)
180
384
  {
181
 
    if (a.isDefined(LineSpacing))
182
 
      return ((Float)a.getAttribute(LineSpacing)).floatValue();
 
385
    Float f = (Float) a.getAttribute(LineSpacing);
 
386
    if (f != null)
 
387
      return f.floatValue();
183
388
    else
184
 
      return 0.f;  
 
389
      return 0.0f;
185
390
  } 
186
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
   */    
187
402
  public static float getRightIndent(AttributeSet a)
188
403
  {
189
 
    if (a.isDefined(RightIndent))
190
 
      return ((Float)a.getAttribute(RightIndent)).floatValue();
 
404
    Float f = (Float) a.getAttribute(RightIndent);
 
405
    if (f != null)
 
406
      return f.floatValue();
191
407
    else
192
 
      return 0.f;  
 
408
      return 0.0f;
193
409
  } 
194
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
   */    
195
421
  public static float getSpaceAbove(AttributeSet a)
196
422
  {
197
 
    if (a.isDefined(SpaceAbove))
198
 
      return ((Float)a.getAttribute(SpaceAbove)).floatValue();
199
 
    else
200
 
      return 0.f;  
 
423
    Float f = (Float) a.getAttribute(SpaceAbove);
 
424
    if (f != null)
 
425
      return f.floatValue();
 
426
    else 
 
427
      return 0.0f;
201
428
  } 
202
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
   */    
203
440
  public static float getSpaceBelow(AttributeSet a)
204
441
  {
205
 
    if (a.isDefined(SpaceBelow))
206
 
      return ((Float)a.getAttribute(SpaceBelow)).floatValue();
 
442
    Float f = (Float) a.getAttribute(SpaceBelow);
 
443
    if (f != null)
 
444
      return f.floatValue();
207
445
    else
208
 
      return 0.f;  
 
446
      return 0.0f;
209
447
  } 
210
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
   */    
211
459
  public static javax.swing.text.TabSet getTabSet(AttributeSet a)
212
460
  {
213
 
    if (a.isDefined(StyleConstants.TabSet))
214
 
      return (javax.swing.text.TabSet) a.getAttribute(StyleConstants.TabSet);
215
 
    else
216
 
      return (javax.swing.text.TabSet) null;
 
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);
217
465
  } 
218
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
   */
219
477
  public static boolean isBold(AttributeSet a)
220
478
  {
221
 
    if (a.isDefined(Bold))
222
 
      return ((Boolean) a.getAttribute(Bold)).booleanValue();
 
479
    Boolean b = (Boolean) a.getAttribute(Bold);
 
480
    if (b != null)
 
481
      return b.booleanValue();
223
482
    else
224
 
      return false;    
 
483
      return false;
225
484
  } 
226
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
   */
227
496
  public static boolean isItalic(AttributeSet a)
228
497
  {
229
 
    if (a.isDefined(Italic))
230
 
      return ((Boolean) a.getAttribute(Italic)).booleanValue();
 
498
    Boolean b = (Boolean) a.getAttribute(Italic);
 
499
    if (b != null)
 
500
      return b.booleanValue();
231
501
    else
232
 
      return false;    
 
502
      return false;
233
503
  } 
234
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
   */
235
515
  public static boolean isStrikeThrough(AttributeSet a)
236
516
  {
237
 
    if (a.isDefined(StrikeThrough))
238
 
      return ((Boolean) a.getAttribute(StrikeThrough)).booleanValue();
 
517
    Boolean b = (Boolean) a.getAttribute(StrikeThrough);
 
518
    if (b != null)
 
519
      return b.booleanValue();
239
520
    else
240
 
      return false;    
 
521
      return false;
241
522
  } 
242
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
   */
243
534
  public static boolean isSubscript(AttributeSet a)
244
535
  {
245
 
    if (a.isDefined(Subscript))
246
 
      return ((Boolean) a.getAttribute(Subscript)).booleanValue();
 
536
    Boolean b = (Boolean) a.getAttribute(Subscript);
 
537
    if (b != null)
 
538
      return b.booleanValue();
247
539
    else
248
 
      return false;    
 
540
      return false;
249
541
  } 
250
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
   */
251
553
  public static boolean isSuperscript(AttributeSet a)
252
554
  {
253
 
    if (a.isDefined(Superscript))
254
 
      return ((Boolean) a.getAttribute(Superscript)).booleanValue();
255
 
    else
256
 
      return false;    
 
555
    Boolean b = (Boolean) a.getAttribute(Superscript);
 
556
    if (b != null)
 
557
      return b.booleanValue();
 
558
    else 
 
559
      return false;
257
560
  } 
258
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
   */
259
572
  public static boolean isUnderline(AttributeSet a)
260
573
  {
261
 
    if (a.isDefined(Underline))
262
 
      return ((Boolean) a.getAttribute(Underline)).booleanValue();
 
574
    Boolean b = (Boolean) a.getAttribute(Underline);
 
575
    if (b != null)
 
576
      return b.booleanValue();
263
577
    else
264
 
      return false;    
 
578
      return false;
265
579
  } 
266
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
   */
267
595
  public static void setAlignment(MutableAttributeSet a, int align)
268
596
  {
269
597
    a.addAttribute(Alignment, new Integer(align));
270
598
  } 
271
599
 
272
 
  public static void setBackground(MutableAttributeSet a, Color fg)
 
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)
273
611
  {
274
 
    a.addAttribute(Background, fg);
 
612
    a.addAttribute(Background, bg);
275
613
  } 
276
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
   */
277
625
  public static void setBidiLevel(MutableAttributeSet a, int lev)
278
626
  {
279
627
    a.addAttribute(BidiLevel, new Integer(lev));
280
628
  } 
281
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
   */
282
640
  public static void setBold(MutableAttributeSet a, boolean b)
283
641
  {
284
642
    a.addAttribute(Bold, Boolean.valueOf(b));
285
643
  } 
286
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
   */
287
655
  public static void setComponent(MutableAttributeSet a, Component c)
288
656
  {
289
657
    a.addAttribute(ComponentAttribute, c);
290
658
  } 
291
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
   */
292
670
  public static void setFirstLineIndent(MutableAttributeSet a, float i)
293
671
  {
294
672
    a.addAttribute(FirstLineIndent, new Float(i));
295
673
  } 
296
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
   */
297
685
  public static void setFontFamily(MutableAttributeSet a, String fam)
298
686
  {
299
687
    a.addAttribute(FontFamily, fam);
300
688
  } 
301
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
   */
302
700
  public static void setFontSize(MutableAttributeSet a, int s)
303
701
  {
304
702
    a.addAttribute(FontSize, new Integer(s));
305
703
  } 
306
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
   */
307
715
  public static void setForeground(MutableAttributeSet a, Color fg)
308
716
  {
309
717
    a.addAttribute(Foreground, fg);
310
718
  }
311
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
   */
312
730
  public static void setIcon(MutableAttributeSet a, Icon c)
313
731
  {
314
732
    a.addAttribute(IconAttribute, c);
315
733
  }
316
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
   */
317
745
  public static void setItalic(MutableAttributeSet a, boolean b)
318
746
  {
319
747
    a.addAttribute(Italic, Boolean.valueOf(b));
320
748
  }
321
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
   */
322
760
  public static void setLeftIndent(MutableAttributeSet a, float i)
323
761
  {
324
762
    a.addAttribute(LeftIndent, new Float(i));
325
763
  } 
326
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
   */
327
775
  public static void setLineSpacing(MutableAttributeSet a, float i)
328
776
  {
329
777
    a.addAttribute(LineSpacing, new Float(i));
330
778
  } 
331
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
   */
332
790
  public static void setRightIndent(MutableAttributeSet a, float i)
333
791
  {
334
792
    a.addAttribute(RightIndent, new Float(i));
335
793
  } 
336
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
   */
337
805
  public static void setSpaceAbove(MutableAttributeSet a, float i)
338
806
  {
339
807
    a.addAttribute(SpaceAbove, new Float(i));
340
808
  } 
341
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
   */
342
820
  public static void setSpaceBelow(MutableAttributeSet a, float i)
343
821
  {
344
822
    a.addAttribute(SpaceBelow, new Float(i));
345
823
  } 
346
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
   */
347
835
  public static void setStrikeThrough(MutableAttributeSet a, boolean b)
348
836
  {
349
837
    a.addAttribute(StrikeThrough, Boolean.valueOf(b));
350
838
  } 
351
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
   */
352
850
  public static void setSubscript(MutableAttributeSet a, boolean b)
353
851
  {
354
852
    a.addAttribute(Subscript, Boolean.valueOf(b));
355
853
  } 
356
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
   */
357
865
  public static void setSuperscript(MutableAttributeSet a, boolean b)
358
866
  {
359
867
    a.addAttribute(Superscript, Boolean.valueOf(b));
360
868
  } 
361
869
 
362
 
  public static void setTabSet(MutableAttributeSet a, javax.swing.text.TabSet tabs)
 
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)
363
882
  {
364
883
    a.addAttribute(StyleConstants.TabSet, tabs);
365
884
  } 
366
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
   */
367
896
  public static void setUnderline(MutableAttributeSet a, boolean b)
368
897
  {
369
898
    a.addAttribute(Underline, Boolean.valueOf(b));
371
900
 
372
901
  // The remainder are so-called "typesafe enumerations" which 
373
902
  // alias subsets of the above constants.
 
903
 
 
904
  /**
 
905
   * A set of keys for attributes that apply to characters.
 
906
   */
374
907
  public static class CharacterConstants
375
908
    extends StyleConstants
376
909
    implements AttributeSet.CharacterAttribute
377
910
  {
 
911
    /**
 
912
     * Private constructor prevents new instances being created.
 
913
     * 
 
914
     * @param k  the key name.
 
915
     */
378
916
    private CharacterConstants(String k) 
379
917
    {
380
918
      super(k);
381
919
    }
382
920
    
383
 
    public static Object Background = ColorConstants.Background;
384
 
    public static Object BidiLevel = new CharacterConstants("bidiLevel");
385
 
    public static Object Bold = FontConstants.Bold;
386
 
    public static Object ComponentAttribute = new CharacterConstants("component");
387
 
    public static Object Family = FontConstants.Family;
388
 
    public static Object Size = FontConstants.Size;
389
 
    public static Object Foreground = ColorConstants.Foreground;
390
 
    public static Object IconAttribute = new CharacterConstants("icon");
391
 
    public static Object Italic = FontConstants.Italic;
392
 
    public static Object StrikeThrough = new CharacterConstants("strikethrough");
393
 
    public static Object Subscript = new CharacterConstants("subscript");
394
 
    public static Object Superscript = new CharacterConstants("superscript");
395
 
    public static Object Underline = new CharacterConstants("underline");
 
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
  
396
963
  }
397
964
 
 
965
  /**
 
966
   * A set of keys for attributes that relate to colors.
 
967
   */
398
968
  public static class ColorConstants
399
969
    extends StyleConstants
400
970
    implements AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute
401
971
  {
 
972
    /**
 
973
     * Private constructor prevents new instances being created.
 
974
     * 
 
975
     * @param k  the key name.
 
976
     */
402
977
    private ColorConstants(String k) 
403
978
    {
404
979
      super(k);
405
980
    }
406
 
    public static Object Foreground = new ColorConstants("foreground");
407
 
    public static Object Background = new ColorConstants("background");
 
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");
408
987
  }
409
988
 
 
989
  /**
 
990
   * A set of keys for attributes that apply to fonts.
 
991
   */
410
992
  public static class FontConstants
411
993
    extends StyleConstants
412
994
    implements AttributeSet.FontAttribute, AttributeSet.CharacterAttribute
413
995
  {
 
996
    /**
 
997
     * Private constructor prevents new instances being created.
 
998
     * 
 
999
     * @param k  the key name.
 
1000
     */
414
1001
    private FontConstants(String k) 
415
1002
    {
416
1003
      super(k);
417
1004
    }
418
 
    public static Object Bold = new FontConstants("bold");
419
 
    public static Object Family = new FontConstants("family");
420
 
    public static Object Italic = new FontConstants("italic");
421
 
    public static Object Size = new FontConstants("size");
 
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");
422
1017
  }
423
1018
 
 
1019
  /**
 
1020
   * A set of keys for attributes that apply to paragraphs.
 
1021
   */
424
1022
  public static class ParagraphConstants
425
1023
    extends StyleConstants
426
1024
    implements AttributeSet.ParagraphAttribute
427
1025
  {
 
1026
    /**
 
1027
     * Private constructor prevents new instances being created.
 
1028
     * 
 
1029
     * @param k  the key name.
 
1030
     */
428
1031
    private ParagraphConstants(String k) 
429
1032
    {
430
1033
      super(k);
431
1034
    }
432
 
    public static Object Alignment = new ParagraphConstants("Alignment");
433
 
    public static Object FirstLineIndent = new ParagraphConstants("FirstLineIndent");
434
 
    public static Object LeftIndent = new ParagraphConstants("LeftIndent");
435
 
    public static Object LineSpacing = new ParagraphConstants("LineSpacing");
436
 
    public static Object Orientation = new ParagraphConstants("Orientation");
437
 
    public static Object RightIndent = new ParagraphConstants("RightIndent");
438
 
    public static Object SpaceAbove = new ParagraphConstants("SpaceAbove");
439
 
    public static Object SpaceBelow = new ParagraphConstants("SpaceBelow");
440
 
    public static Object TabSet = new ParagraphConstants("TabSet");
 
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
    
441
1070
  }
442
1071
 
443
1072
}