public final class StyledString
extends java.lang.Object
implements java.io.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 java.lang.String |
DEFAULT_SLIDER_STYLE |
static int |
DRAG_CONTROL |
static int |
DRAW_METHOD |
static int |
EXCP_IN_HANDLER |
static int[][] |
grid |
static int |
GROUP_CONTROL_METHOD |
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 |
INVALID_PAPPLET |
static int |
INVALID_TYPE |
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 java.awt.BasicStroke |
pen_1_0 |
static java.awt.BasicStroke |
pen_2_0 |
static java.awt.BasicStroke |
pen_3_0 |
static java.awt.BasicStroke |
pen_4_0 |
static int |
POST_METHOD |
static int |
PRE_METHOD |
static int |
PRESS_CONTROL |
static int |
SCROLLBAR_HORIZONTAL |
static int |
SCROLLBAR_VERTICAL |
static java.lang.String |
SLIDER_STYLES |
static int |
TINT_FOR_ALPHA |
static int |
TPAD2 |
static int |
TPAD4 |
static int |
TPAD6 |
static int |
TPAD8 |
static float |
WHEEL_DELTA |
static float |
WHEEL_STICK_FACTOR |
static int |
Z_PANEL |
static int |
Z_SLIPPY |
static int |
Z_SLIPPY_EXPANDS |
static int |
Z_STICKY |
Constructor and Description |
---|
StyledString(java.lang.String startText)
This is assumed to be a single line of text (i.e.
|
StyledString(java.lang.String startText,
int wrapWidth)
Supports multiple lines of text wrapped on word boundaries.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.text.AttributedCharacterIterator.Attribute type,
java.lang.Object value)
Add an attribute that affects the whole length of the string.
|
void |
addAttribute(java.text.AttributedCharacterIterator.Attribute type,
java.lang.Object value,
int lineNo)
Add a text attribute (style) to an entire display line
|
void |
addAttribute(java.text.AttributedCharacterIterator.Attribute type,
java.lang.Object value,
int beginIdx,
int endIdx)
Set the attribute to be applied to a range of characters starting at
beginIdx and ending with endIdx-1.
|
void |
addAttribute(java.text.AttributedCharacterIterator.Attribute type,
java.lang.Object value,
int lineNo,
int charStart,
int charEnd)
Add a text attribute (style) to the specifies range of characters
|
void |
clearAttributes()
Removes all styling from the string.
|
void |
clearAttributes(int lineNo) |
void |
clearAttributes(int beginIdx,
int endIdx)
Remove text attributes (style) to the specified range of characters.
|
void |
clearAttributes(int lineNo,
int beginIdx,
int endIdx)
Remove text attributes (style) to the specified line and range of characters.
|
boolean |
deleteCharacters(int fromPos,
int nbrToRemove)
Remove a number of characters from the string
|
java.util.LinkedList<StyledString.TextLayoutInfo> |
getLines(java.awt.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
|
java.lang.String |
getPlainText()
Get the plain text as a String.
|
java.lang.String |
getPlainText(int lineNo)
Get a line of text from the plain text.
|
java.lang.String |
getPlainText(int beginIdx,
int endIdx)
Get the plain text as a String.
|
java.lang.String[] |
getPlainTextAsArray()
Get the plain text as a String array.
|
float |
getTextAreaHeight()
Return the height of the text line(s)
|
int |
getWrapWidth()
Get the break width used to create the lines.
|
int |
insertCharacters(java.lang.String chars,
int insertPos)
Insert 1 or more characters into the string.
|
int |
insertCharacters(java.lang.String chars,
int insertPos,
boolean startNewLine,
boolean endNewLine)
Insert 1 or more characters into the string.
|
int |
insertCharacters(java.lang.String chars,
int lineNo,
int charStart,
boolean startNewLine,
boolean endNewLine)
Insert some text into the position indicated.
|
boolean |
insertEOL(int insertPos)
Use this method to insert an EOL character.
|
void |
invalidateText() |
int |
length()
Get the number of characters in this styled string
|
static StyledString |
load(processing.core.PApplet papp,
java.lang.String fname)
Load and return a StyledString object from the given file.
|
static void |
save(processing.core.PApplet papp,
StyledString ss,
java.lang.String fname)
Save the named StyleString in the named file.
|
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 |
setText(java.lang.String text)
Change the text for single line styled string
|
void |
setText(java.lang.String text,
int wrapWidth)
Change the text for single line styled string
|
void |
setWrapWidth(int wrapWidth)
Set the maximum width of a line.
|
public static final java.lang.String SLIDER_STYLES
public static final java.lang.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 GROUP_CONTROL_METHOD
public static final int MISSING
public static final int NONEXISTANT
public static final int INVALID_TYPE
public static final int INVALID_PAPPLET
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 java.awt.BasicStroke pen_1_0
public static final java.awt.BasicStroke pen_2_0
public static final java.awt.BasicStroke pen_3_0
public static final java.awt.BasicStroke pen_4_0
public static final int TPAD2
public static final int TPAD4
public static final int TPAD6
public static final int TPAD8
public static final int SCROLLBAR_VERTICAL
public static final int SCROLLBAR_HORIZONTAL
public static final float WHEEL_DELTA
public static final float WHEEL_STICK_FACTOR
public static final int Z_STICKY
public static final int Z_SLIPPY
public static final int Z_SLIPPY_EXPANDS
public static final int Z_PANEL
public StyledString(java.lang.String startText)
startText
- public StyledString(java.lang.String startText, int wrapWidth)
startText
- the text to usewrapWidth
- the wrap widthpublic void setText(java.lang.String text)
text
- the text to usepublic void setText(java.lang.String text, int wrapWidth)
text
- the text to usewrapWidth
- the wrap widthpublic java.lang.String getPlainText()
public java.lang.String getPlainText(int beginIdx, int endIdx)
beginIdx
- the beginning index inclusiveendIdx
- the ending index exclusivepublic java.lang.String getPlainText(int lineNo)
lineNo
- the line number we want the text forpublic java.lang.String[] getPlainTextAsArray()
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(java.text.AttributedCharacterIterator.Attribute type, java.lang.Object value)
type
- attribute typevalue
- attribute valuepublic void addAttribute(java.text.AttributedCharacterIterator.Attribute type, java.lang.Object value, int lineNo, int charStart, int charEnd)
type
- attribute typevalue
- attribute valuelineNo
- the line of test affectedcharStart
- the first character affectedcharEnd
- the character position after the last character affected.public void addAttribute(java.text.AttributedCharacterIterator.Attribute type, java.lang.Object value, int lineNo)
type
- attribute typevalue
- attribute valuelineNo
- the line of test affectedpublic void addAttribute(java.text.AttributedCharacterIterator.Attribute type, java.lang.Object value, int beginIdx, int endIdx)
type
- attribute typevalue
- attribute valuebeginIdx
- the index of the first character (inclusive)endIdx
- the index of the last character (exclusive)public void clearAttributes(int lineNo, int beginIdx, int endIdx)
lineNo
- the line of test affectedbeginIdx
- the index of the first character (inclusive)endIdx
- the index of the last character (exclusive)public void clearAttributes(int lineNo)
lineNo
- public void clearAttributes(int beginIdx, int endIdx)
beginIdx
- the index of the first character (inclusive)endIdx
- the index of the last character (exclusive)public void clearAttributes()
public int insertCharacters(java.lang.String chars, int lineNo, int charStart, boolean startNewLine, boolean endNewLine)
lineNo
- a valid line numbercharStart
- the position in the line >= 0chars
- the characters to insertstartNewLine
- prefix the chars with a EOLendNewLine
- postfix the chars with a EOLpublic int insertCharacters(java.lang.String chars, int insertPos)
insertEOL(int)method instead.
insertPos
- position in string to insert characterschars
- the characters to insertpublic int insertCharacters(java.lang.String chars, int insertPos, boolean startNewLine, boolean endNewLine)
insertEOL(int)method instead.
insertPos
- position in string to insert characterschars
- the characters to insertstartNewLine
- if true insert onto a new linepublic 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 invalidateText()
public java.util.LinkedList<StyledString.TextLayoutInfo> getLines(java.awt.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(processing.core.PApplet papp, StyledString ss, java.lang.String fname)
papp
- ss
- the styled stringfname
- public static StyledString load(processing.core.PApplet papp, java.lang.String fname)
papp
- fname
- the filename of the StyledStringProcessing library G4P by Peter Lager. (c) 2017