Class StyleRange

java.lang.Object
com.jidesoft.swing.StyleRange

public class StyleRange extends 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.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • 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, Color fontColor)
    Creates a style range with a specified font style, font color and a range.
    StyleRange(int start, int length, int fontStyle, 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, Color fontColor, int additionalStyle, 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, Color fontColor, int additionalStyle, Color lineColor, 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, Color fontColor, int additionalStyle, Color lineColor, 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, Color fontColor, 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, Color fontColor, Color backgroundColor, int additionalStyle, 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, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor, 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, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor, 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, Color fontColor)
    Creates a style range with a specified font color and a range.
    StyleRange(int fontStyle, Color fontColor)
    Creates a style range with a specified font style and font color.
    StyleRange(int fontStyle, Color fontColor, int additionalStyle, Color lineColor)
    Creates a style range with a specified font style, font color, and additional style.
    StyleRange(int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke)
    Creates a style range with a specified font style, font color, additional style, and line color.
    StyleRange(int fontStyle, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor)
    Creates a style range with a specified font style, font color, and additional style.
    Creates a style range exactly the same with the existing range.
    StyleRange(Color fontColor)
    Creates a style range with a specified font color.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the additional style.
    Gets the background color.
    Gets the font color.
    float
    Gets the font shrink ratio for superscript and subscript.
    int
    Gets the font style.
    int
    Gets the length of the range.
    Gets the line color.
    Gets the line stroke.
    int
    Gets the start index of the range.
    boolean
    Checks if the line has dotted style.
    boolean
    Checks if the text has double strike through style.
    boolean
    Checks if the text has strike through style.
    boolean
    Checks if the text is subscript.
    boolean
    Checks if the text is superscript.
    boolean
    Checks if the text has underlined style.
    boolean
    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
  • Field Details

  • Constructor Details

    • 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(Color fontColor)
      Creates a style range with a specified font color.
      Parameters:
      fontColor - the color of the text
    • StyleRange

      public StyleRange(int fontStyle, 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, 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, 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, Color fontColor, int additionalStyle, 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, Color fontColor, Color backgroundColor, int additionalStyle, 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, 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, Color fontColor, 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, Color fontColor, int additionalStyle, Color lineColor, 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, Color fontColor, int additionalStyle, 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, Color fontColor, Color backgroundColor, int additionalStyle, 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, Color fontColor, int additionalStyle, Color lineColor, 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, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor, 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, Color fontColor, int additionalStyle, Color lineColor, 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, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor, 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 Details

    • 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 Color getFontColor()
      Gets the font color.
      Returns:
      the font color.
    • getBackgroundColor

      public Color getBackgroundColor()
      Gets the background color.
      Returns:
      the background color.
    • getAdditionalStyle

      public int getAdditionalStyle()
      Gets the additional style. Possible additional styles are defined as constants in StyleRange. The names begin with STYLE_. The value could also be two or more styles concatenated by | as long as it makes sense. It could be more convenient to use methods isStrikethrough(), isDoublestrikethrough(), isDotted(), isWaved(), isUnderlined(), isSubscript(), isSuperscript() to see what's the additional style.
      Returns:
      the additional style.
    • getLineColor

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

      public 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.