public class StyledString extends Object
StyledString.Styler
to
compute the result of getStyleRanges()
.
The styled string can be built in the following two ways:
This class may be instantiated; it is not intended to be subclassed.
Modifier and Type | Class and Description |
---|---|
static class |
StyledString.Styler
A styler will be asked to apply its styles to one ore more ranges in the
StyledString . |
Modifier and Type | Field and Description |
---|---|
static StyledString.Styler |
COUNTER_STYLER
A built-in styler using the
JFacePreferences.COUNTER_COLOR
managed in the JFace color registry (See
JFaceResources.getColorRegistry() ). |
static StyledString.Styler |
DECORATIONS_STYLER
A built-in styler using the
JFacePreferences.DECORATIONS_COLOR
managed in the JFace color registry (See
JFaceResources.getColorRegistry() ). |
static StyledString.Styler |
QUALIFIER_STYLER
A built-in styler using the
JFacePreferences.QUALIFIER_COLOR
managed in the JFace color registry (See
JFaceResources.getColorRegistry() ). |
Constructor and Description |
---|
StyledString()
Creates an empty
StyledString . |
StyledString(String string)
Creates an
StyledString initialized with a string without
a style associated. |
StyledString(String string,
StyledString.Styler styler)
Creates an
StyledString initialized with a string and a
style. |
Modifier and Type | Method and Description |
---|---|
StyledString |
append(char ch)
Appends the string representation of the given character
to the
StyledString . |
StyledString |
append(char[] chars)
Appends the string representation of the given character array
to the
StyledString . |
StyledString |
append(char[] chars,
StyledString.Styler styler)
Appends the string representation of the given character array
with a style to the
StyledString . |
StyledString |
append(char ch,
StyledString.Styler styler)
Appends the string representation of the given character
with a style to the
StyledString . |
StyledString |
append(String string)
Appends a string to the
StyledString . |
StyledString |
append(String string,
StyledString.Styler styler)
Appends a string with a style to the
StyledString . |
StyledString |
append(StyledString string)
Appends a string with styles to the
StyledString . |
static StyledString.Styler |
createColorRegistryStyler(String foregroundColorName,
String backgroundColorName)
Creates a styler that takes the given foreground and background colors
from the JFace color registry.
|
String |
getString()
Returns the string of this
StyledString . |
StyleRange[] |
getStyleRanges()
Returns an array of
StyleRange resulting from applying all
associated stylers for this string builder. |
StyledString |
insert(char ch,
int offset)
Inserts the character at the given offset.
|
int |
length()
Returns the length of the string of this
StyledString . |
void |
setStyle(int offset,
int length,
StyledString.Styler styler)
Sets a styler to use for the given source range.
|
String |
toString()
Returns the string of this
StyledString . |
public static final StyledString.Styler QUALIFIER_STYLER
JFacePreferences.QUALIFIER_COLOR
managed in the JFace color registry (See
JFaceResources.getColorRegistry()
).public static final StyledString.Styler COUNTER_STYLER
JFacePreferences.COUNTER_COLOR
managed in the JFace color registry (See
JFaceResources.getColorRegistry()
).public static final StyledString.Styler DECORATIONS_STYLER
JFacePreferences.DECORATIONS_COLOR
managed in the JFace color registry (See
JFaceResources.getColorRegistry()
).public StyledString()
StyledString
.public StyledString(String string)
StyledString
initialized with a string without
a style associated.string
- the stringpublic StyledString(String string, StyledString.Styler styler)
StyledString
initialized with a string and a
style.string
- the stringstyler
- the styler for the string or null
to not
associated a styler.public static StyledString.Styler createColorRegistryStyler(String foregroundColorName, String backgroundColorName)
foregroundColorName
- the color name for the foreground colorbackgroundColorName
- the color name for the background colorpublic String getString()
StyledString
.StyledString
.public String toString()
StyledString
.toString
in class Object
StyledString
.public int length()
StyledString
.public StyledString append(String string)
StyledString
. The appended string
will have no associated styler.string
- the string to appendpublic StyledString append(char[] chars)
StyledString
. The appended
character array will have no associated styler.chars
- the character array to appendpublic StyledString append(char ch)
StyledString
. The appended
character will have no associated styler.ch
- the character to appendpublic StyledString append(StyledString string)
StyledString
.string
- the string to appendpublic StyledString append(char ch, StyledString.Styler styler)
StyledString
. The
appended character will have the given style associated.ch
- the character to appendstyler
- the styler to use for styling the character to append or
null
if no styler should be associated with the
appended characterpublic StyledString append(String string, StyledString.Styler styler)
StyledString
. The
appended string will be styled using the given styler.string
- the string to appendstyler
- the styler to use for styling the string to append or
null
if no styler should be associated with the
appended string.public StyledString append(char[] chars, StyledString.Styler styler)
StyledString
. The
appended character array will be styled using the given styler.chars
- the character array to appendstyler
- the styler to use for styling the character array to append or
null
if no styler should be associated with the
appended character arraypublic StyledString insert(char ch, int offset) throws StringIndexOutOfBoundsException
ch
- the character to insertoffset
- the insertion indexStringIndexOutOfBoundsException
- if offset
is less than zero, or if offset
is greater than the length of this objectpublic void setStyle(int offset, int length, StyledString.Styler styler) throws StringIndexOutOfBoundsException
StyledString
. Stylers
previously set for that range will be overwritten.offset
- the start offset of the rangelength
- the length of the rangestyler
- the styler to setStringIndexOutOfBoundsException
- if start
is less than zero, or if offset plus
length is greater than the length of this object.public StyleRange[] getStyleRanges()
StyleRange
resulting from applying all
associated stylers for this string builder.StyleRange
resulting from applying the
stored stylers to this string.
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.