Package com.jidesoft.swing
Class StyleRange
java.lang.Object
com.jidesoft.swing.StyleRange
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
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionStyleRange
(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.StyleRange
(StyleRange range) 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 TypeMethodDescriptionint
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
getStart()
Gets the start index of the range.boolean
isDotted()
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
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.
-
Field Details
-
STYLE_STRIKE_THROUGH
public static final int STYLE_STRIKE_THROUGH- See Also:
-
STYLE_DOUBLE_STRIKE_THROUGH
public static final int STYLE_DOUBLE_STRIKE_THROUGH- See Also:
-
STYLE_WAVED
public static final int STYLE_WAVED- See Also:
-
STYLE_UNDERLINED
public static final int STYLE_UNDERLINED- See Also:
-
STYLE_DOTTED
public static final int STYLE_DOTTED- See Also:
-
STYLE_SUPERSCRIPT
public static final int STYLE_SUPERSCRIPT- See Also:
-
STYLE_SUBSCRIPT
public static final int STYLE_SUBSCRIPT- See Also:
-
-
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
Creates a style range with a specified font color.- Parameters:
fontColor
- the color of the text
-
StyleRange
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 inStyleRange
. 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 inStyleRange
. 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 stringlength
- the length of the range.fontStyle
- Valid values are Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC.
-
StyleRange
Creates a style range with a specified font style, font color and a range.- Parameters:
start
- the start index of the range in a stringlength
- 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
Creates a style range with a specified font color and a range.- Parameters:
start
- the start index of the range in a stringlength
- 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 stringlength
- 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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
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 inStyleRange
. 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 inStyleRange
. The names begin with STYLE_. You can also use any | to concat two or more styles as long as it makes sense.
-
StyleRange
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 stringlength
- 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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 stringlength
- 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 inStyleRange
. 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
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 stringlength
- 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 inStyleRange
. 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
Gets the font color.- Returns:
- the font 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 inStyleRange
. 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 methodsisStrikethrough()
,isDoublestrikethrough()
,isDotted()
,isWaved()
,isUnderlined()
,isSubscript()
,isSuperscript()
to see what's the additional style.- Returns:
- the additional style.
-
getLineColor
Gets the line color.- Returns:
- the line color.
-
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.
-