FileDocCategorySizeDatePackage
StyleConstants.javaAPI DocJava SE 5 API23136Fri Aug 26 14:58:16 BST 2005javax.swing.text

StyleConstants

public class StyleConstants extends Object

A collection of well known or common attribute keys and methods to apply to an AttributeSet or MutableAttributeSet to get/set the properties in a typesafe manner.

The paragraph attributes form the definition of a paragraph to be rendered. All sizes are specified in points (such as found in postscript), a device independent measure.

Diagram shows SpaceAbove, FirstLineIndent, LeftIndent, RightIndent,
and SpaceBelow a paragraph.

author
Timothy Prinzing
version
1.36 12/19/03

Fields Summary
public static final String
ComponentElementName
Name of elements used to represent components.
public static final String
IconElementName
Name of elements used to represent icons.
public static final Object
NameAttribute
Attribute name used to name the collection of attributes.
public static final Object
ResolveAttribute
Attribute name used to identifiy the resolving parent set of attributes, if one is defined.
public static final Object
ModelAttribute
Attribute used to identify the model for embedded objects that have a model view separation.
public static final Object
BidiLevel
Bidirectional level of a character as assigned by the Unicode bidi algorithm.
public static final Object
FontFamily
Name of the font family.
public static final Object
Family
Name of the font family.
public static final Object
FontSize
Name of the font size.
public static final Object
Size
Name of the font size.
public static final Object
Bold
Name of the bold attribute.
public static final Object
Italic
Name of the italic attribute.
public static final Object
Underline
Name of the underline attribute.
public static final Object
StrikeThrough
Name of the Strikethrough attribute.
public static final Object
Superscript
Name of the Superscript attribute.
public static final Object
Subscript
Name of the Subscript attribute.
public static final Object
Foreground
Name of the foreground color attribute.
public static final Object
Background
Name of the background color attribute.
public static final Object
ComponentAttribute
Name of the component attribute.
public static final Object
IconAttribute
Name of the icon attribute.
public static final Object
ComposedTextAttribute
Name of the input method composed text attribute. The value of this attribute is an instance of AttributedString which represents the composed text.
public static final Object
FirstLineIndent
The amount of space to indent the first line of the paragraph. This value may be negative to offset in the reverse direction. The type is Float and specifies the size of the space in points.
public static final Object
LeftIndent
The amount to indent the left side of the paragraph. Type is float and specifies the size in points.
public static final Object
RightIndent
The amount to indent the right side of the paragraph. Type is float and specifies the size in points.
public static final Object
LineSpacing
The amount of space between lines of the paragraph. Type is float and specifies the size as a factor of the line height
public static final Object
SpaceAbove
The amount of space above the paragraph. Type is float and specifies the size in points.
public static final Object
SpaceBelow
The amount of space below the paragraph. Type is float and specifies the size in points.
public static final Object
Alignment
Alignment for the paragraph. The type is Integer. Valid values are:
  • ALIGN_LEFT
  • ALIGN_RIGHT
  • ALIGN_CENTER
  • ALIGN_JUSTIFED
public static final Object
TabSet
TabSet for the paragraph, type is a TabSet containing TabStops.
public static final Object
Orientation
Orientation for a paragraph.
public static final int
ALIGN_LEFT
A possible value for paragraph alignment. This specifies that the text is aligned to the left indent and extra whitespace should be placed on the right.
public static final int
ALIGN_CENTER
A possible value for paragraph alignment. This specifies that the text is aligned to the center and extra whitespace should be placed equally on the left and right.
public static final int
ALIGN_RIGHT
A possible value for paragraph alignment. This specifies that the text is aligned to the right indent and extra whitespace should be placed on the left.
public static final int
ALIGN_JUSTIFIED
A possible value for paragraph alignment. This specifies that extra whitespace should be spread out through the rows of the paragraph with the text lined up with the left and right indent except on the last line which should be aligned to the left.
static Object[]
keys
private String
representation
Constructors Summary
StyleConstants(String representation)


      
        this.representation = representation;
    
Methods Summary
public static intgetAlignment(javax.swing.text.AttributeSet a)
Gets the alignment setting.

param
a the attribute set
return
the value StyleConstants.ALIGN_LEFT if not set

        Integer align = (Integer) a.getAttribute(Alignment);
        if (align != null) {
            return align.intValue();
        }
        return ALIGN_LEFT;
    
public static java.awt.ColorgetBackground(javax.swing.text.AttributeSet a)
Gets the background color setting from the attribute list.

param
a the attribute set
return
the color, Color.black as the default

        Color fg = (Color) a.getAttribute(Background);
        if (fg == null) {
            fg = Color.black;
        }
        return fg;
    
public static intgetBidiLevel(javax.swing.text.AttributeSet a)
Gets the BidiLevel setting.

param
a the attribute set
return
the value


    // --- character attribute accessors ---------------------------

                     
         
        Integer o = (Integer) a.getAttribute(BidiLevel);
        if (o != null) {
            return o.intValue();
        }
        return 0;  // Level 0 is base level (non-embedded) left-to-right
    
public static java.awt.ComponentgetComponent(javax.swing.text.AttributeSet a)
Gets the component setting from the attribute list.

param
a the attribute set
return
the component, null if none

        return (Component) a.getAttribute(ComponentAttribute);
    
public static floatgetFirstLineIndent(javax.swing.text.AttributeSet a)
Gets the first line indent setting.

param
a the attribute set
return
the value, 0 if not set

        Float indent = (Float) a.getAttribute(FirstLineIndent);
        if (indent != null) {
            return indent.floatValue();
        }
        return 0;
    
public static java.lang.StringgetFontFamily(javax.swing.text.AttributeSet a)
Gets the font family setting from the attribute list.

param
a the attribute set
return
the font family, "Monospaced" as the default

        String family = (String) a.getAttribute(FontFamily);
        if (family == null) {
            family = "Monospaced";
        }
        return family;
    
public static intgetFontSize(javax.swing.text.AttributeSet a)
Gets the font size setting from the attribute list.

param
a the attribute set
return
the font size, 12 as the default

        Integer size = (Integer) a.getAttribute(FontSize);
        if (size != null) {
            return size.intValue();
        }
        return 12;
    
public static java.awt.ColorgetForeground(javax.swing.text.AttributeSet a)
Gets the foreground color setting from the attribute list.

param
a the attribute set
return
the color, Color.black as the default

        Color fg = (Color) a.getAttribute(Foreground);
        if (fg == null) {
            fg = Color.black;
        }
        return fg;
    
public static javax.swing.IcongetIcon(javax.swing.text.AttributeSet a)
Gets the icon setting from the attribute list.

param
a the attribute set
return
the icon, null if none

        return (Icon) a.getAttribute(IconAttribute);
    
public static floatgetLeftIndent(javax.swing.text.AttributeSet a)
Gets the left indent setting.

param
a the attribute set
return
the value, 0 if not set

        Float indent = (Float) a.getAttribute(LeftIndent);
        if (indent != null) {
            return indent.floatValue();
        }
        return 0;
    
public static floatgetLineSpacing(javax.swing.text.AttributeSet a)
Gets the line spacing setting.

param
a the attribute set
return
the value, 0 if not set

        Float space = (Float) a.getAttribute(LineSpacing);
        if (space != null) {
            return space.floatValue();
        }
        return 0;
    
public static floatgetRightIndent(javax.swing.text.AttributeSet a)
Gets the right indent setting.

param
a the attribute set
return
the value, 0 if not set

        Float indent = (Float) a.getAttribute(RightIndent);
        if (indent != null) {
            return indent.floatValue();
        }
        return 0;
    
public static floatgetSpaceAbove(javax.swing.text.AttributeSet a)
Gets the space above setting.

param
a the attribute set
return
the value, 0 if not set

        Float space = (Float) a.getAttribute(SpaceAbove);
        if (space != null) {
            return space.floatValue();
        }
        return 0;
    
public static floatgetSpaceBelow(javax.swing.text.AttributeSet a)
Gets the space below setting.

param
a the attribute set
return
the value, 0 if not set

        Float space = (Float) a.getAttribute(SpaceBelow);
        if (space != null) {
            return space.floatValue();
        }
        return 0;
    
public static javax.swing.text.TabSetgetTabSet(javax.swing.text.AttributeSet a)
Gets the TabSet.

param
a the attribute set
return
the TabSet

        TabSet tabs = (TabSet)a.getAttribute(TabSet);
        // PENDING: should this return a default?
        return tabs;
    
public static booleanisBold(javax.swing.text.AttributeSet a)
Checks whether the bold attribute is set.

param
a the attribute set
return
true if set else false

        Boolean bold = (Boolean) a.getAttribute(Bold);
        if (bold != null) {
            return bold.booleanValue();
        }
        return false;
    
public static booleanisItalic(javax.swing.text.AttributeSet a)
Checks whether the italic attribute is set.

param
a the attribute set
return
true if set else false

        Boolean italic = (Boolean) a.getAttribute(Italic);
        if (italic != null) {
            return italic.booleanValue();
        }
        return false;
    
public static booleanisStrikeThrough(javax.swing.text.AttributeSet a)
Checks whether the strikethrough attribute is set.

param
a the attribute set
return
true if set else false

        Boolean strike = (Boolean) a.getAttribute(StrikeThrough);
        if (strike != null) {
            return strike.booleanValue();
        }
        return false;
    
public static booleanisSubscript(javax.swing.text.AttributeSet a)
Checks whether the subscript attribute is set.

param
a the attribute set
return
true if set else false

        Boolean subscript = (Boolean) a.getAttribute(Subscript);
        if (subscript != null) {
            return subscript.booleanValue();
        }
        return false;
    
public static booleanisSuperscript(javax.swing.text.AttributeSet a)
Checks whether the superscript attribute is set.

param
a the attribute set
return
true if set else false

        Boolean superscript = (Boolean) a.getAttribute(Superscript);
        if (superscript != null) {
            return superscript.booleanValue();
        }
        return false;
    
public static booleanisUnderline(javax.swing.text.AttributeSet a)
Checks whether the underline attribute is set.

param
a the attribute set
return
true if set else false

        Boolean underline = (Boolean) a.getAttribute(Underline);
        if (underline != null) {
            return underline.booleanValue();
        }
        return false;
    
public static voidsetAlignment(javax.swing.text.MutableAttributeSet a, int align)
Sets alignment.

param
a the attribute set
param
align the alignment value

        a.addAttribute(Alignment, new Integer(align));
    
public static voidsetBackground(javax.swing.text.MutableAttributeSet a, java.awt.Color fg)
Sets the background color.

param
a the attribute set
param
fg the color

        a.addAttribute(Background, fg);
    
public static voidsetBidiLevel(javax.swing.text.MutableAttributeSet a, int o)
Sets the BidiLevel.

param
a the attribute set
param
o the bidi level value

        a.addAttribute(BidiLevel, new Integer(o));
    
public static voidsetBold(javax.swing.text.MutableAttributeSet a, boolean b)
Sets the bold attribute.

param
a the attribute set
param
b specifies true/false for setting the attribute

        a.addAttribute(Bold, Boolean.valueOf(b));
    
public static voidsetComponent(javax.swing.text.MutableAttributeSet a, java.awt.Component c)
Sets the component attribute.

param
a the attribute set
param
c the component

        a.addAttribute(AbstractDocument.ElementNameAttribute, ComponentElementName);
        a.addAttribute(ComponentAttribute, c);
    
public static voidsetFirstLineIndent(javax.swing.text.MutableAttributeSet a, float i)
Sets the first line indent.

param
a the attribute set
param
i the value

        a.addAttribute(FirstLineIndent, new Float(i));
    
public static voidsetFontFamily(javax.swing.text.MutableAttributeSet a, java.lang.String fam)
Sets the font attribute.

param
a the attribute set
param
fam the font

        a.addAttribute(FontFamily, fam);
    
public static voidsetFontSize(javax.swing.text.MutableAttributeSet a, int s)
Sets the font size attribute.

param
a the attribute set
param
s the font size

        a.addAttribute(FontSize, new Integer(s));
    
public static voidsetForeground(javax.swing.text.MutableAttributeSet a, java.awt.Color fg)
Sets the foreground color.

param
a the attribute set
param
fg the color

        a.addAttribute(Foreground, fg);
    
public static voidsetIcon(javax.swing.text.MutableAttributeSet a, javax.swing.Icon c)
Sets the icon attribute.

param
a the attribute set
param
c the icon

        a.addAttribute(AbstractDocument.ElementNameAttribute, IconElementName);
        a.addAttribute(IconAttribute, c);
    
public static voidsetItalic(javax.swing.text.MutableAttributeSet a, boolean b)
Sets the italic attribute.

param
a the attribute set
param
b specifies true/false for setting the attribute

        a.addAttribute(Italic, Boolean.valueOf(b));
    
public static voidsetLeftIndent(javax.swing.text.MutableAttributeSet a, float i)
Sets left indent.

param
a the attribute set
param
i the value

        a.addAttribute(LeftIndent, new Float(i));
    
public static voidsetLineSpacing(javax.swing.text.MutableAttributeSet a, float i)
Sets line spacing.

param
a the attribute set
param
i the value

        a.addAttribute(LineSpacing, new Float(i));
    
public static voidsetRightIndent(javax.swing.text.MutableAttributeSet a, float i)
Sets right indent.

param
a the attribute set
param
i the value

        a.addAttribute(RightIndent, new Float(i));
    
public static voidsetSpaceAbove(javax.swing.text.MutableAttributeSet a, float i)
Sets space above.

param
a the attribute set
param
i the value

        a.addAttribute(SpaceAbove, new Float(i));
    
public static voidsetSpaceBelow(javax.swing.text.MutableAttributeSet a, float i)
Sets space below.

param
a the attribute set
param
i the value

        a.addAttribute(SpaceBelow, new Float(i));
    
public static voidsetStrikeThrough(javax.swing.text.MutableAttributeSet a, boolean b)
Sets the strikethrough attribute.

param
a the attribute set
param
b specifies true/false for setting the attribute

        a.addAttribute(StrikeThrough, Boolean.valueOf(b));
    
public static voidsetSubscript(javax.swing.text.MutableAttributeSet a, boolean b)
Sets the subscript attribute.

param
a the attribute set
param
b specifies true/false for setting the attribute

        a.addAttribute(Subscript, Boolean.valueOf(b));
    
public static voidsetSuperscript(javax.swing.text.MutableAttributeSet a, boolean b)
Sets the superscript attribute.

param
a the attribute set
param
b specifies true/false for setting the attribute

        a.addAttribute(Superscript, Boolean.valueOf(b));
    
public static voidsetTabSet(javax.swing.text.MutableAttributeSet a, javax.swing.text.TabSet tabs)
Sets the TabSet.

param
a the attribute set.
param
tabs the TabSet

        a.addAttribute(TabSet, tabs);
    
public static voidsetUnderline(javax.swing.text.MutableAttributeSet a, boolean b)
Sets the underline attribute.

param
a the attribute set
param
b specifies true/false for setting the attribute

        a.addAttribute(Underline, Boolean.valueOf(b));
    
public java.lang.StringtoString()
Returns the string representation.

return
the string


                
       
        return representation;