Package org.eclipse.jface.viewers
Class StyledString
java.lang.Object
org.eclipse.jface.viewers.StyledString
- All Implemented Interfaces:
- CharSequence
A mutable string with styled ranges. All ranges mark substrings of the string
 and do not overlap. Styles are applied using instances of 
StyledString.Styler to
 compute the result of getStyleRanges().
 The styled string can be built in the following two ways:
 - new strings with stylers can be appended
- stylers can by applied to ranges of the existing string
This class may be instantiated; it is not intended to be subclassed.
- Since:
- 3.4
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA styler will be asked to apply its styles to one ore more ranges in theStyledString.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StyledString.StylerA built-in styler using theJFacePreferences.COUNTER_COLORmanaged in the JFace color registry (SeeJFaceResources.getColorRegistry()).static final StyledString.StylerA built-in styler using theJFacePreferences.DECORATIONS_COLORmanaged in the JFace color registry (SeeJFaceResources.getColorRegistry()).static final StyledString.StylerA built-in styler using theJFacePreferences.QUALIFIER_COLORmanaged in the JFace color registry (SeeJFaceResources.getColorRegistry()).
- 
Constructor SummaryConstructorsConstructorDescriptionCreates an emptyStyledString.StyledString(String string) Creates anStyledStringinitialized with a string without a style associated.StyledString(String string, StyledString.Styler styler) Creates anStyledStringinitialized with a string and a style.
- 
Method SummaryModifier and TypeMethodDescriptionappend(char ch) Appends the string representation of the given character to theStyledString.append(char[] chars) Appends the string representation of the given character array to theStyledString.append(char[] chars, StyledString.Styler styler) Appends the string representation of the given character array with a style to theStyledString.append(char ch, StyledString.Styler styler) Appends the string representation of the given character with a style to theStyledString.Appends a string to theStyledString.append(String string, StyledString.Styler styler) Appends a string with a style to theStyledString.append(StyledString string) Appends a string with styles to theStyledString.charcharAt(int index) static StyledString.StylercreateColorRegistryStyler(String foregroundColorName, String backgroundColorName) Creates a styler that takes the given foreground and background colors from the JFace color registry.Returns the string of thisStyledString.Returns an array ofStyleRangeresulting from applying all associated stylers for this string builder.insert(char ch, int offset) Inserts the character at the given offset.intlength()Returns the length of the string of thisStyledString.voidsetStyle(int offset, int length, StyledString.Styler styler) Sets a styler to use for the given source range.subSequence(int start, int end) toString()Returns the string of thisStyledString.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequencechars, codePoints, isEmpty
- 
Field Details- 
QUALIFIER_STYLERA built-in styler using theJFacePreferences.QUALIFIER_COLORmanaged in the JFace color registry (SeeJFaceResources.getColorRegistry()).
- 
COUNTER_STYLERA built-in styler using theJFacePreferences.COUNTER_COLORmanaged in the JFace color registry (SeeJFaceResources.getColorRegistry()).
- 
DECORATIONS_STYLERA built-in styler using theJFacePreferences.DECORATIONS_COLORmanaged in the JFace color registry (SeeJFaceResources.getColorRegistry()).
 
- 
- 
Constructor Details- 
StyledStringpublic StyledString()Creates an emptyStyledString.
- 
StyledStringCreates anStyledStringinitialized with a string without a style associated.- Parameters:
- string- the string
 
- 
StyledStringCreates anStyledStringinitialized with a string and a style.- Parameters:
- string- the string
- styler- the styler for the string or- nullto not associated a styler.
 
 
- 
- 
Method Details- 
createColorRegistryStylerpublic static StyledString.Styler createColorRegistryStyler(String foregroundColorName, String backgroundColorName) Creates a styler that takes the given foreground and background colors from the JFace color registry.- Parameters:
- foregroundColorName- the color name for the foreground color
- backgroundColorName- the color name for the background color
- Returns:
- the created style
 
- 
getStringReturns the string of thisStyledString.- Returns:
- the current string of this StyledString.
 
- 
toStringReturns the string of thisStyledString.- Specified by:
- toStringin interface- CharSequence
- Overrides:
- toStringin class- Object
- Returns:
- the current string of this StyledString.
 
- 
lengthpublic int length()Returns the length of the string of thisStyledString.- Specified by:
- lengthin interface- CharSequence
- Returns:
- the length of the current string
 
- 
subSequence- Specified by:
- subSequencein interface- CharSequence
- Since:
- 3.12
 
- 
charAtpublic char charAt(int index) - Specified by:
- charAtin interface- CharSequence
- Since:
- 3.12
 
- 
appendAppends a string to theStyledString. The appended string will have no associated styler.- Parameters:
- string- the string to append
- Returns:
- returns a reference to this object
 
- 
appendAppends the string representation of the given character array to theStyledString. The appended character array will have no associated styler.- Parameters:
- chars- the character array to append
- Returns:
- returns a reference to this object
 
- 
appendAppends the string representation of the given character to theStyledString. The appended character will have no associated styler.- Parameters:
- ch- the character to append
- Returns:
- returns a reference to this object
 
- 
appendAppends a string with styles to theStyledString.- Parameters:
- string- the string to append
- Returns:
- returns a reference to this object
 
- 
appendAppends the string representation of the given character with a style to theStyledString. The appended character will have the given style associated.- Parameters:
- ch- the character to append
- styler- the styler to use for styling the character to append or- nullif no styler should be associated with the appended character
- Returns:
- returns a reference to this object
 
- 
appendAppends a string with a style to theStyledString. The appended string will be styled using the given styler.- Parameters:
- string- the string to append
- styler- the styler to use for styling the string to append or- nullif no styler should be associated with the appended string.
- Returns:
- returns a reference to this object
 
- 
appendAppends the string representation of the given character array with a style to theStyledString. The appended character array will be styled using the given styler.- Parameters:
- chars- the character array to append
- styler- the styler to use for styling the character array to append or- nullif no styler should be associated with the appended character array
- Returns:
- returns a reference to this object
 
- 
insertInserts the character at the given offset. The inserted character will get the styler that is already at the given offset.- Parameters:
- ch- the character to insert
- offset- the insertion index
- Returns:
- returns a reference to this object
- Throws:
- StringIndexOutOfBoundsException- if- offsetis less than zero, or if- offsetis greater than the length of this object
- Since:
- 3.5
 
- 
setStylepublic void setStyle(int offset, int length, StyledString.Styler styler) throws StringIndexOutOfBoundsException Sets a styler to use for the given source range. The range must be subrange of actual string of thisStyledString. Stylers previously set for that range will be overwritten.- Parameters:
- offset- the start offset of the range
- length- the length of the range
- styler- the styler to set
- Throws:
- StringIndexOutOfBoundsException- if- startis less than zero, or if offset plus length is greater than the length of this object.
 
- 
getStyleRangesReturns an array ofStyleRangeresulting from applying all associated stylers for this string builder.- Returns:
- an array of all StyleRangeresulting from applying the stored stylers to this string.
 
 
-