public final class StyledString extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
StyledString.TextLayoutHitInfo
For multi-line text, the TextHitInfo class is not enough.
|
static class |
StyledString.TextLayoutInfo
Class to hold information about a text layout.
|
Modifier and Type | Field and Description |
---|---|
static int |
ALL_METHOD |
static int |
CLIP_RUN |
static int |
COMBI_MODES |
static String |
DEFAULT_SLIDER_STYLE |
static int |
DRAG_CONTROL |
static int |
DRAW_METHOD |
static int |
EXCP_IN_HANDLER |
static int[][] |
grid |
static int |
I_CL |
static int |
I_COVERED |
static int |
I_CR |
static int |
I_INSIDE |
static int |
I_MODES |
static int |
I_NONE |
static int |
I_TL |
static int |
I_TR |
static int |
KEY_METHOD |
static int |
MERGE_RUNS |
static int |
MISSING |
static int |
MOUSE_METHOD |
static int |
NONEXISTANT |
static int |
OFF_CONTROL |
static int |
OVER_CONTROL |
static BasicStroke |
pen_1_0 |
static BasicStroke |
pen_2_0 |
static BasicStroke |
pen_3_0 |
static BasicStroke |
pen_4_0 |
static int |
POST_METHOD |
static int |
PRE_METHOD |
static int |
PRESS_CONTROL |
static int |
RUNTIME_ERROR |
static String |
SLIDER_STYLES |
static int |
TINT_FOR_ALPHA |
Constructor and Description |
---|
StyledString(String startText)
This is assumed to be a single line of text (i.e.
|
StyledString(String startText,
int wrapWidth)
Supports multiple lines of text wrapped on word boundaries.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(AttributedCharacterIterator.Attribute type,
Object value)
Add an attribute that affects the whole length of the string.
|
void |
addAttribute(AttributedCharacterIterator.Attribute type,
Object value,
int charStart,
int charEnd)
Set charStart and charEnd to <0 if full length.
|
void |
clearAllAttributes()
Removes all styling from the string.
|
void |
clearAttributes(int start,
int end)
Clears all attributes from start to end-1
|
boolean |
deleteCharacters(int fromPos,
int nbrToRemove)
Remove a number of characters from the string
|
LinkedList<StyledString.TextLayoutInfo> |
getLines(Graphics2D g2d)
Get the text layouts for display if the string has changed since last call
to this method regenerate them.
|
float |
getMaxLineHeight()
Get the height of the tallest line
|
float |
getMaxLineLength()
Return the length of the longest line.
|
int |
getNbrLines()
Get the number of lines in the layout
|
String |
getPlainText()
Get the plain text as a String.
|
float |
getTextAreaHeight()
Return the height of the text line(s)
|
int |
getWrapWidth()
Get the break width used to create the lines.
|
int |
insertCharacters(int insertPos,
String chars)
Insert 1 or more characters into the string.
|
int |
insertCharacters(int insertPos,
String chars,
boolean startNewLine) |
boolean |
insertEOL(int insertPos)
Use this method to insert an EOL character.
|
int |
length()
Get the number of characters in this styled string
|
static StyledString |
load(PApplet papp,
String fname)
Load and return a StyledString object from the given file.
|
static void |
save(PApplet papp,
StyledString ss,
String fname)
Save the named StyleString in the named file.
|
void |
setFont(Font a_font) |
void |
setJustify(boolean justify)
Text can be either left or fully justified.
|
void |
setJustifyRatio(float jRatio)
Justify only if the line has sufficient text to do so.
|
void |
setWrapWidth(int wrapWidth)
Set the maximum width of a line.
|
public static final String SLIDER_STYLES
public static final String DEFAULT_SLIDER_STYLE
public static final int DRAW_METHOD
public static final int MOUSE_METHOD
public static final int PRE_METHOD
public static final int KEY_METHOD
public static final int POST_METHOD
public static final int ALL_METHOD
public static final int RUNTIME_ERROR
public static final int MISSING
public static final int NONEXISTANT
public static final int EXCP_IN_HANDLER
public static final int OFF_CONTROL
public static final int OVER_CONTROL
public static final int PRESS_CONTROL
public static final int DRAG_CONTROL
public static final int TINT_FOR_ALPHA
public static final int I_NONE
public static final int I_TL
public static final int I_TR
public static final int I_CL
public static final int I_CR
public static final int I_INSIDE
public static final int I_COVERED
public static final int I_MODES
public static final int MERGE_RUNS
public static final int CLIP_RUN
public static final int COMBI_MODES
public static final int[][] grid
public static final BasicStroke pen_1_0
public static final BasicStroke pen_2_0
public static final BasicStroke pen_3_0
public static final BasicStroke pen_4_0
public StyledString(String startText)
startText
- public StyledString(String startText, int wrapWidth)
startText
- wrapWidth
- public String getPlainText()
public int length()
public void setJustify(boolean justify)
justify
- true for full justificationpublic void setJustifyRatio(float jRatio)
jRatio
- ratio of text length to visibleWidthpublic void addAttribute(AttributedCharacterIterator.Attribute type, Object value)
type
- attribute typevalue
- attribute valuepublic void addAttribute(AttributedCharacterIterator.Attribute type, Object value, int charStart, int charEnd)
type
- value
- charStart
- charEnd
- public void clearAttributes(int start, int end)
start
- end
- public void clearAllAttributes()
public int insertCharacters(int insertPos, String chars)
insertEOL(int)method instead.
chars
- insertPos
- the position in the textpublic int insertCharacters(int insertPos, String chars, boolean startNewLine)
public boolean insertEOL(int insertPos)
insertPos
- index position to insert EOLpublic boolean deleteCharacters(int fromPos, int nbrToRemove)
nbrToRemove
- number of characters to removefromPos
- start location for removalpublic void setFont(Font a_font)
public LinkedList<StyledString.TextLayoutInfo> getLines(Graphics2D g2d)
g2d
- Graphics2D display contextpublic int getNbrLines()
public float getTextAreaHeight()
public float getMaxLineLength()
public float getMaxLineHeight()
public int getWrapWidth()
public void setWrapWidth(int wrapWidth)
wrapWidth
- public static void save(PApplet papp, StyledString ss, String fname)
papp
- ss
- the styled stringfname
- public static StyledString load(PApplet papp, String fname)
papp
- fname
- the filename of the StyledStringProcessing library G4P by Peter Lager. (C) 2013