Class TextStyle


  • public class TextStyle
    extends java.lang.Object
    A combination of TextAttributes that represents a particular style of text (a heading, for example).
    Author:
    Chris Jennings
    • Field Detail

      • SERIF_STYLE

        public static final TextStyle SERIF_STYLE
        A shared instance of a style that will render serif text. If this instance is modified, everyone using it is also affected.
      • SANSSERIF_STYLE

        public static final TextStyle SANSSERIF_STYLE
        A shared instance of a style that will render sans serif text. If this instance is modified, everyone using it is also affected.
      • TYPEWRITER_STYLE

        public static final TextStyle TYPEWRITER_STYLE
        A shared instance of a style that will render sans serif text. If this instance is modified, everyone using it is also affected.
      • BOLD_STYLE

        public static final TextStyle BOLD_STYLE
        A shared instance of a style that will render bold text. If this instance is modified, everyone using it is also affected.
      • ITALIC_STYLE

        public static final TextStyle ITALIC_STYLE
        A shared instance of a style that will render italic text. If this instance is modified, everyone using it is also affected.
      • UPRIGHT_STYLE

        public static final TextStyle UPRIGHT_STYLE
      • SUPERSCRIPT_STYLE

        public static final TextStyle SUPERSCRIPT_STYLE
        A shared instance of a style that will render superscript text. If this instance is modified, everyone using it is also affected.
      • SUBSCRIPT_STYLE

        public static final TextStyle SUBSCRIPT_STYLE
        A shared instance of a style that will render subscript text. If this instance is modified, everyone using it is also affected.
      • STRIKETHROUGH_STYLE

        public static final TextStyle STRIKETHROUGH_STYLE
        A shared instance of a style that will render struck out text. If this instance is modified, everyone using it is also affected.
      • UNDERLINE_STYLE

        public static final TextStyle UNDERLINE_STYLE
        A shared instance of a style that will render underlined text. If this instance is modified, everyone using it is also affected.
      • KERNING_ON

        public static final TextStyle KERNING_ON
        A shared instance of a style that will enable kerning of text. If this instance is modified, everyone using it is also affected.
      • KERNING_OFF

        public static final TextStyle KERNING_OFF
        A shared instance of a style that will disable kerning of text. If this instance is modified, everyone using it is also affected.
      • LIGATURES_ON

        public static final TextStyle LIGATURES_ON
        A shared instance of a style that will enable optional ligature replacement. If this instance is modified, everyone using it is also affected.
      • LIGATURES_OFF

        public static final TextStyle LIGATURES_OFF
        A shared instance of a style that will disable optional ligature replacement. If this instance is modified, everyone using it is also affected.
      • JUSTIFY

        public static final TextStyle JUSTIFY
        A shared instance of a style that will enable justification. If this instance is modified, everyone using it is also affected.
      • PLAIN_STYLE

        public static final TextStyle PLAIN_STYLE
        A shared instance of a style that will render "plain" text, removing any italic and bold effects.
      • COLOR_BLACK

        public static final TextStyle COLOR_BLACK
        Standard colours.
      • COLOR_WHITE

        public static final TextStyle COLOR_WHITE
      • COLOR_LTGREY

        public static final TextStyle COLOR_LTGREY
      • COLOR_GREY

        public static final TextStyle COLOR_GREY
      • COLOR_DKGREY

        public static final TextStyle COLOR_DKGREY
      • COLOR_RED

        public static final TextStyle COLOR_RED
      • COLOR_ORANGE

        public static final TextStyle COLOR_ORANGE
      • COLOR_YELLOW

        public static final TextStyle COLOR_YELLOW
      • COLOR_GREEN

        public static final TextStyle COLOR_GREEN
      • COLOR_BLUE

        public static final TextStyle COLOR_BLUE
      • COLOR_PURPLE

        public static final TextStyle COLOR_PURPLE
      • COLOR_BROWN

        public static final TextStyle COLOR_BROWN
    • Constructor Detail

      • TextStyle

        public TextStyle()
        Create a new, empty style.
      • TextStyle

        public TextStyle​(java.lang.Object... listOfAttributesAndStyles)
        Create a new style which initially consists of the specified styles.
      • TextStyle

        public TextStyle​(java.awt.font.TextAttribute attr,
                         java.lang.Object styleValue)
        Create a new style which initially consists of a single style. This may optimize internal storage for a style with only a single member, but does not preclude adding additional members later.
    • Method Detail

      • add

        public void add​(java.awt.font.TextAttribute attr,
                        java.lang.Object styleValue)
        Add a new TextAttribute to this style.
      • add

        public void add​(java.lang.Object... listOfAttributesAndStyles)
        Add an arbitrarily long sequence of styles and values. The sequence of arguments must come in pairs of TextAttributes followed by Object values.
      • add

        public void add​(TextStyle sourceStyle)
        Add all the attributes of the sourceStyle to this style.
      • get

        public java.lang.Object get​(java.awt.font.TextAttribute attr)
        Get the value for a TextAttribute in this style. Returns null if the attribute has not been specified.
      • remove

        public void remove​(java.awt.font.TextAttribute attr)
        Remove a TextAttribute from the style.
      • contains

        public boolean contains​(java.awt.font.TextAttribute attr)
        Returns whether the specified attribute is a member of this style.
      • applyStyle

        public void applyStyle​(java.text.AttributedString s,
                               int beginPos,
                               int endPos)
        Apply this style to a range of characters in an AttributedString.
        Parameters:
        s - the string to the apply the attributes of the style to
        beginPos - the index of the first character in the range
        endPos - the index one past the last character in the range
      • applyStyle

        public void applyStyle​(java.text.AttributedString s)
        Apply a style to all characters in an AttributedString.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object