Class StyleRange


  • public class StyleRange
    extends java.lang.Object
    A data structure represents a style for a range of text. There are two categories of styles that currently supports. One is the font style and color which includes bold, italic, superscript, subscript as well as the color of the text. The other one is line color and style. The line style could be straight line, dotted line, waved line or any customized style using Stroke. The line could be used as underline or strikethrough line.

    The name of StyleRange comes from SWT's StyleRange. We borrowed some design idea from it. StyledLabel is actually very similar to SWT's StyledText. Saying that, the features of the two components are not exactly the same since the purpose of the two components are quite different.

    • Constructor Summary

      Constructors 
      Constructor Description
      StyleRange​(int fontStyle)
      Creates a style range with a specified font style.
      StyleRange​(int fontStyle, int additionalStyle)
      Creates a style range with a specified font style and additional style.
      StyleRange​(int fontStyle, int additionalStyle, float fontShrinkRatio)
      Creates a style range with a specified font style and additional style.
      StyleRange​(int start, int length, int fontStyle)
      Creates a style range with a specified font style and a range.
      StyleRange​(int start, int length, int fontStyle, int additionalStyle)
      Creates a style range with a specified font style, additional style and a range.
      StyleRange​(int start, int length, int fontStyle, int additionalStyle, float fontShrinkRatio)
      Creates a style range with a specified font style, additional style and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor)
      Creates a style range with a specified font style, font color and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, int additionalStyle)
      Creates a style range with a specified font style, font color, additional style and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, int additionalStyle, java.awt.Color lineColor)
      Creates a style range with a specified font style, font color, additional style, line color and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, int additionalStyle, java.awt.Color lineColor, java.awt.Stroke lineStroke)
      Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, int additionalStyle, java.awt.Color lineColor, java.awt.Stroke lineStroke, float fontShrinkRatio)
      Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, java.awt.Color backgroundColor, int additionalStyle)
      Creates a style range with a specified font style, font color, additional style and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, java.awt.Color backgroundColor, int additionalStyle, java.awt.Color lineColor)
      Creates a style range with a specified font style, font color, additional style, line color and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, java.awt.Color backgroundColor, int additionalStyle, java.awt.Color lineColor, java.awt.Stroke lineStroke)
      Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
      StyleRange​(int start, int length, int fontStyle, java.awt.Color fontColor, java.awt.Color backgroundColor, int additionalStyle, java.awt.Color lineColor, java.awt.Stroke lineStroke, float fontShrinkRatio)
      Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
      StyleRange​(int start, int length, java.awt.Color fontColor)
      Creates a style range with a specified font color and a range.
      StyleRange​(int fontStyle, java.awt.Color fontColor)
      Creates a style range with a specified font style and font color.
      StyleRange​(int fontStyle, java.awt.Color fontColor, int additionalStyle, java.awt.Color lineColor)
      Creates a style range with a specified font style, font color, and additional style.
      StyleRange​(int fontStyle, java.awt.Color fontColor, int additionalStyle, java.awt.Color lineColor, java.awt.Stroke lineStroke)
      Creates a style range with a specified font style, font color, additional style, and line color.
      StyleRange​(int fontStyle, java.awt.Color fontColor, java.awt.Color backgroundColor, int additionalStyle, java.awt.Color lineColor)
      Creates a style range with a specified font style, font color, and additional style.
      StyleRange​(StyleRange range)
      Creates a style range exactly the same with the existing range.
      StyleRange​(java.awt.Color fontColor)
      Creates a style range with a specified font color.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getAdditionalStyle()
      Gets the additional style.
      java.awt.Color getBackgroundColor()
      Gets the background color.
      java.awt.Color getFontColor()
      Gets the font color.
      float getFontShrinkRatio()
      Gets the font shrink ratio for superscript and subscript.
      int getFontStyle()
      Gets the font style.
      int getLength()
      Gets the length of the range.
      java.awt.Color getLineColor()
      Gets the line color.
      java.awt.Stroke getLineStroke()
      Gets the line stroke.
      int getStart()
      Gets the start index of the range.
      boolean isDotted()
      Checks if the line has dotted style.
      boolean isDoublestrikethrough()
      Checks if the text has double strike through style.
      boolean isStrikethrough()
      Checks if the text has strike through style.
      boolean isSubscript()
      Checks if the text is subscript.
      boolean isSuperscript()
      Checks if the text is superscript.
      boolean isUnderlined()
      Checks if the text has underlined style.
      boolean isWaved()
      Checks if the line has waved style.
      void setLength​(int length)
      Sets the length of the range.
      void setStart​(int start)
      Sets the start index of the range.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StyleRange

        public StyleRange​(int fontStyle)
        Creates a style range with a specified font style.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
      • StyleRange

        public StyleRange​(java.awt.Color fontColor)
        Creates a style range with a specified font color.
        Parameters:
        fontColor - the color of the text
      • StyleRange

        public StyleRange​(int fontStyle,
                          java.awt.Color fontColor)
        Creates a style range with a specified font style and font color.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text
      • StyleRange

        public StyleRange​(int fontStyle,
                          int additionalStyle)
        Creates a style range with a specified font style and additional style.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to connect two or more styles as long as it makes sense.
      • StyleRange

        public StyleRange​(int fontStyle,
                          int additionalStyle,
                          float fontShrinkRatio)
        Creates a style range with a specified font style and additional style.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        fontShrinkRatio - the ratio that regular font size divides by subscript or superscript font size.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle)
        Creates a style range with a specified font style and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor)
        Creates a style range with a specified font style, font color and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          java.awt.Color fontColor)
        Creates a style range with a specified font color and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontColor - the color of the text.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          int additionalStyle)
        Creates a style range with a specified font style, additional style and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          int additionalStyle,
                          float fontShrinkRatio)
        Creates a style range with a specified font style, additional style and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        fontShrinkRatio - the ratio that regular font size divides by subscript or superscript font size.
      • StyleRange

        public StyleRange​(int fontStyle,
                          java.awt.Color fontColor,
                          int additionalStyle,
                          java.awt.Color lineColor)
        Creates a style range with a specified font style, font color, and additional style.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
      • StyleRange

        public StyleRange​(int fontStyle,
                          java.awt.Color fontColor,
                          java.awt.Color backgroundColor,
                          int additionalStyle,
                          java.awt.Color lineColor)
        Creates a style range with a specified font style, font color, and additional style.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        backgroundColor - the background color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          int additionalStyle)
        Creates a style range with a specified font style, font color, additional style and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          java.awt.Color backgroundColor,
                          int additionalStyle)
        Creates a style range with a specified font style, font color, additional style and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        backgroundColor - the background color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
      • StyleRange

        public StyleRange​(int fontStyle,
                          java.awt.Color fontColor,
                          int additionalStyle,
                          java.awt.Color lineColor,
                          java.awt.Stroke lineStroke)
        Creates a style range with a specified font style, font color, additional style, and line color.
        Parameters:
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        lineColor - the color of the line.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          int additionalStyle,
                          java.awt.Color lineColor)
        Creates a style range with a specified font style, font color, additional style, line color and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        lineColor - the color of the line.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          java.awt.Color backgroundColor,
                          int additionalStyle,
                          java.awt.Color lineColor)
        Creates a style range with a specified font style, font color, additional style, line color and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        backgroundColor - the background color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        lineColor - the color of the line.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          int additionalStyle,
                          java.awt.Color lineColor,
                          java.awt.Stroke lineStroke)
        Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        lineColor - the color of the line.
        lineStroke - the stroke of the line.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          java.awt.Color backgroundColor,
                          int additionalStyle,
                          java.awt.Color lineColor,
                          java.awt.Stroke lineStroke)
        Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        backgroundColor - the background color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        lineColor - the color of the line.
        lineStroke - the stroke of the line.
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          int additionalStyle,
                          java.awt.Color lineColor,
                          java.awt.Stroke lineStroke,
                          float fontShrinkRatio)
        Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
        lineColor - the color of the line.
        lineStroke - the stroke of the line.
        fontShrinkRatio - the ratio that regular font size divides by subscript or superscript font size.
      • StyleRange

        public StyleRange​(StyleRange range)
        Creates a style range exactly the same with the existing range.
        Parameters:
        range - the old range
        Since:
        3.2.1
      • StyleRange

        public StyleRange​(int start,
                          int length,
                          int fontStyle,
                          java.awt.Color fontColor,
                          java.awt.Color backgroundColor,
                          int additionalStyle,
                          java.awt.Color lineColor,
                          java.awt.Stroke lineStroke,
                          float fontShrinkRatio)
        Creates a style range with a specified font style, font color, additional style, line color, line stroke and a range.
        Parameters:
        start - the start index of the range in a string
        length - the length of the range.
        fontStyle - Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        fontColor - the color of the text.
        backgroundColor - the background color of the text.
        additionalStyle - Valid additional styles are defined as constants in StyleRange. The names begin with STYLE_. You can also use bitwise OR "|" to concat any two or more styles as long as it makes sense.
        lineColor - the color of the line.
        lineStroke - the stroke of the line.
        fontShrinkRatio - the ratio that regular font size divides by subscript or superscript font size.
    • Method Detail

      • getStart

        public int getStart()
        Gets the start index of the range.
        Returns:
        the start index of the range.
      • setStart

        public void setStart​(int start)
        Sets the start index of the range.
        Parameters:
        start - the start index of the range
      • getLength

        public int getLength()
        Gets the length of the range.
        Returns:
        the length of the range.
      • setLength

        public void setLength​(int length)
        Sets the length of the range.
        Parameters:
        length - the length of the range
      • getFontStyle

        public int getFontStyle()
        Gets the font style. Possible values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
        Returns:
        the font style.
      • getFontColor

        public java.awt.Color getFontColor()
        Gets the font color.
        Returns:
        the font color.
      • getBackgroundColor

        public java.awt.Color getBackgroundColor()
        Gets the background color.
        Returns:
        the background color.
      • getLineColor

        public java.awt.Color getLineColor()
        Gets the line color.
        Returns:
        the line color.
      • getLineStroke

        public java.awt.Stroke getLineStroke()
        Gets the line stroke.
        Returns:
        the line stroke.
      • isStrikethrough

        public boolean isStrikethrough()
        Checks if the text has strike through style.
        Returns:
        true if the text has strike through style.
      • isDoublestrikethrough

        public boolean isDoublestrikethrough()
        Checks if the text has double strike through style.
        Returns:
        true if the text has double strike through style.
      • isWaved

        public boolean isWaved()
        Checks if the line has waved style.
        Returns:
        true if the line has waved style.
      • isUnderlined

        public boolean isUnderlined()
        Checks if the text has underlined style.
        Returns:
        true if the text has underlined style.
      • isDotted

        public boolean isDotted()
        Checks if the line has dotted style.
        Returns:
        true if the line has dotted style.
      • isSuperscript

        public boolean isSuperscript()
        Checks if the text is superscript.
        Returns:
        true if the text is superscript.
      • isSubscript

        public boolean isSubscript()
        Checks if the text is subscript.
        Returns:
        true if the text is subscript.
      • getFontShrinkRatio

        public float getFontShrinkRatio()
        Gets the font shrink ratio for superscript and subscript.
        Returns:
        the shrink ratio.