public final class StyledString extends Object implements GConstantsInternal, Serializable
ALL_METHOD, CLIP_RUN, COMBI_MODES, DRAW_METHOD, EXCP_IN_HANDLER, grid, I_CL, I_COVERED, I_CR, I_INSIDE, I_MODES, I_NONE, I_TL, I_TR, KEY_METHOD, MERGE_RUNS, MISSING, MOUSE_METHOD, NONEXISTANT, OFF_CONTROL, OVER_CONTROL, pen_1_0, pen_2_0, pen_3_0, pen_4_0, POST_METHOD, PRE_METHOD, PRESS_CONTROL, RUNTIME_ERROR, 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() |
void |
clearAttributes(int start,
int end) |
boolean |
deleteCharacters(int fromPos,
int nbrToRemove)
Remove a number of characters from the string
|
LinkedList<g4p_controls.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()
Return 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.
|
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) |
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)
public void clearAllAttributes()
public int insertCharacters(int insertPos, String chars)
insertEOL(int)method instead.
chars
- insertPos
- the position in the textpublic boolean insertEOL(int insertPos)
insertPos
- public boolean deleteCharacters(int fromPos, int nbrToRemove)
nbrToRemove
- number of characters to removefromPos
- start location for removalpublic void setFont(Font a_font)
public void setWrapWidth(int wrapWidth)
public LinkedList<g4p_controls.StyledString.TextLayoutInfo> getLines(Graphics2D g2d)
g2d
- Graphics2D display contextpublic int getNbrLines()
public float getTextAreaHeight()
public float getMaxLineLength()
public float getMaxLineHeight()
public int getWrapWidth()
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) 2012