G4P (GUI for Processing)  4.3.8
A set of GUI controls for your Processing sketch.
 All Classes Functions Variables Pages
g4p_controls.StyledString Class Reference
Inheritance diagram for g4p_controls.StyledString:

Classes

class  TextLayoutHitInfo
 
class  TextLayoutInfo
 

Public Member Functions

void addAttribute (Attribute type, Object value)
 
void addAttribute (Attribute type, Object value, int lineNo, int charStart, int charEnd)
 
void addAttribute (Attribute type, Object value, int lineNo)
 
void addAttribute (Attribute type, Object value, int beginIdx, int endIdx)
 
void clearAttributes (int lineNo, int beginIdx, int endIdx)
 
void clearAttributes (int lineNo)
 
void clearAttributes (int beginIdx, int endIdx)
 
void clearAttributes ()
 
StyledString deepCopy () throws Exception
 
boolean deleteCharacters (int fromPos, int nbrToRemove)
 
LinkedList< TextLayoutInfogetLines (Graphics2D g2d)
 
float getMaxLineHeight ()
 
float getMaxLineLength ()
 
int getNbrLines ()
 
String getPlainText ()
 
String getPlainText (int beginIdx, int endIdx)
 
String getPlainText (int lineNo)
 
String[] getPlainTextAsArray ()
 
float getTextAreaHeight ()
 
int getWrapWidth ()
 
int insertCharacters (String chars, int lineNo, int charStart, boolean startNewLine, boolean endNewLine)
 
int insertCharacters (String chars, int insertPos)
 
int insertCharacters (String chars, int insertPos, boolean startNewLine, boolean endNewLine)
 
boolean insertEOL (int insertPos)
 
void invalidateText ()
 
int length ()
 
void setJustify (boolean justify)
 
void setJustifyRatio (float jRatio)
 
void setText (String text)
 
void setText (String text, int wrapWidth)
 
void setWrapWidth (int wrapWidth)
 
 StyledString (String startText)
 
 StyledString (String startText, int wrapWidth)
 

Static Public Member Functions

static StyledString load (PApplet papp, String fname)
 
static void save (PApplet papp, StyledString ss, String fname)
 

Protected Member Functions

void removeConsecutiveBlankLines ()
 

Additional Inherited Members

- Public Attributes inherited from g4p_controls.GConstantsInternal
int ALL_METHOD = 0x0000001f
 
int CLIP_RUN = 512
 
int COMBI_MODES = 768
 
String DEFAULT_SLIDER_STYLE = "grey_blue"
 
int DRAG_CONTROL = 3
 
int DRAW_METHOD = 0x00000001
 
char EOL = '\n'
 
int EXCP_IN_HANDLER = 0xff000005
 
int[][] grid
 
int GROUP_CONTROL_METHOD = DRAW_METHOD | MOUSE_METHOD | KEY_METHOD
 
int I_CL = 4
 
int I_COVERED = 32
 
int I_CR = 8
 
int I_INSIDE = 16
 
int I_MODES = 63
 
int I_NONE = 0
 
int I_TL = 1
 
int I_TR = 2
 
int INVALID_PAPPLET = 0xff000004
 
int INVALID_TYPE = 0xff000003
 
int KEY_METHOD = 0x00000008
 
int MERGE_RUNS = 256
 
int MISSING = 0xff000001
 
int MOUSE_METHOD = 0x00000002
 
int NONEXISTANT = 0xff000002
 
int OFF_CONTROL = 0
 
int OVER_CONTROL = 1
 
BasicStroke pen_1_0 = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
BasicStroke pen_2_0 = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
BasicStroke pen_3_0 = new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
BasicStroke pen_4_0 = new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
int POST_METHOD = 0x00000010
 
int PRE_METHOD = 0x00000004
 
int PRESS_CONTROL = 2
 
int SCROLLBAR_HORIZONTAL = GConstants.SCROLLBARS_HORIZONTAL_ONLY
 
int SCROLLBAR_VERTICAL = GConstants.SCROLLBARS_VERTICAL_ONLY
 
String SLIDER_STYLES = "|grey_blue|blue18px|green_red20px|purple18px|red_yellow18px|"
 
int TINT_FOR_ALPHA = 255
 
int TPAD2 = 2
 
int TPAD4 = 4
 
int TPAD6 = 6
 
int TPAD8 = 8
 
float WHEEL_DELTA = 0.01f
 
float WHEEL_STICK_FACTOR = 0.51f
 
int Z_PANEL = 1024
 
int Z_SLIPPY = 24
 
int Z_SLIPPY_EXPANDS = 48
 
int Z_STICKY = 0
 

Detailed Description

This class is used to represent text with attributes.
It means that you don't have to have the same style of font or even the same font face over the whole length of the text.

Most font features can be modified all except the text background which is transparent. There is a feature to highlight part of the string by having a different background colour but this is used for highlighting selected text in GTextField and GTextArea components.

It is also used for all controls that use text.

Author
Peter Lager

Constructor & Destructor Documentation

g4p_controls.StyledString.StyledString ( String  startText)

This is assumed to be a single line of text (i.e. no wrap). EOL characters will be stripped from the text before use.

Parameters
startTextthe initial text for this instance
g4p_controls.StyledString.StyledString ( String  startText,
int  wrapWidth 
)

Supports multiple lines of text wrapped on word boundaries.

Parameters
startTextthe text to use
wrapWidththe wrap width

Member Function Documentation

void g4p_controls.StyledString.addAttribute ( Attribute  type,
Object  value 
)

Add an attribute that affects the whole length of the string.

Parameters
typeattribute type
valueattribute value
void g4p_controls.StyledString.addAttribute ( Attribute  type,
Object  value,
int  lineNo,
int  charStart,
int  charEnd 
)

Add a text attribute (style) to the specifies range of characters

Parameters
typeattribute type
valueattribute value
lineNothe line of test affected
charStartthe first character affected
charEndthe character position after the last character affected.
void g4p_controls.StyledString.addAttribute ( Attribute  type,
Object  value,
int  lineNo 
)

Add a text attribute (style) to an entire display line

Parameters
typeattribute type
valueattribute value
lineNothe line of test affected
void g4p_controls.StyledString.addAttribute ( Attribute  type,
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.

Parameters
typeattribute type
valueattribute value
beginIdxthe index of the first character (inclusive)
endIdxthe index of the last character (exclusive)
void g4p_controls.StyledString.clearAttributes ( int  lineNo,
int  beginIdx,
int  endIdx 
)

Remove text attributes (style) to the specified line and range of characters.

Parameters
lineNothe line of test affected
beginIdxthe index of the first character (inclusive)
endIdxthe index of the last character (exclusive)
void g4p_controls.StyledString.clearAttributes ( int  lineNo)

Clear the attributes from a given line

Parameters
lineNothe line to use
void g4p_controls.StyledString.clearAttributes ( int  beginIdx,
int  endIdx 
)

Remove text attributes (style) to the specified range of characters.

Parameters
beginIdxthe index of the first character (inclusive)
endIdxthe index of the last character (exclusive)
void g4p_controls.StyledString.clearAttributes ( )

Removes all styling from the string.

boolean g4p_controls.StyledString.deleteCharacters ( int  fromPos,
int  nbrToRemove 
)

Remove a number of characters from the string

Parameters
nbrToRemovenumber of characters to remove
fromPosstart location for removal
Returns
true if the deletion was successful else false
LinkedList<TextLayoutInfo> g4p_controls.StyledString.getLines ( Graphics2D  g2d)

Get the text layouts for display if the string has changed since last call to this method regenerate them.

Parameters
g2dGraphics2D display context
Returns
a list of text layouts for rendering
float g4p_controls.StyledString.getMaxLineHeight ( )
Returns
the height of the tallest line
float g4p_controls.StyledString.getMaxLineLength ( )
Returns
the length of the longest line.
int g4p_controls.StyledString.getNbrLines ( )
Returns
the number of lines in the layout
String g4p_controls.StyledString.getPlainText ( )

Get the plain text as a String. Any line breaks will kept and will be represented by the character 'backslash n'

Returns
the associated plain text
String g4p_controls.StyledString.getPlainText ( int  beginIdx,
int  endIdx 
)

Get the plain text as a String. Any line breaks will kept and will be represented by the character 'backslash n'

Parameters
beginIdxthe beginning index inclusive
endIdxthe ending index exclusive
Returns
the substring starting at beginIdx to endIdx-1
String g4p_controls.StyledString.getPlainText ( int  lineNo)

Get a line of text from the plain text. Lines are separated by End-of-line (EOL) characters.

Parameters
lineNothe line number we want the text for
Returns
the line of text or an empty string if the line number is invalid.
String [] g4p_controls.StyledString.getPlainTextAsArray ( )

Get the plain text as a String array. (splitting on line breaks)

Returns
the associated plain text as a String array split on line breaks
float g4p_controls.StyledString.getTextAreaHeight ( )
Returns
the height of the text line(s)
int g4p_controls.StyledString.getWrapWidth ( )
Returns
the break width used to create the lines.
int g4p_controls.StyledString.insertCharacters ( String  chars,
int  lineNo,
int  charStart,
boolean  startNewLine,
boolean  endNewLine 
)

Insert some text into the position indicated.

Parameters
lineNoa valid line number
charStartthe position in the line ≥ 0
charsthe characters to insert
startNewLineprefix the chars with a EOL
endNewLinepostfix the chars with a EOL
Returns
the number of characters inserted
int g4p_controls.StyledString.insertCharacters ( String  chars,
int  insertPos 
)

Insert 1 or more characters into the string. The inserted text will first be made safe by removing any inappropriate EOL characters.
Do not use this method to insert EOL characters, use the

insertEOL(int)

method instead.

Parameters
insertPosposition in string to insert characters
charsthe characters to insert
Returns
the number of characters inserted
int g4p_controls.StyledString.insertCharacters ( String  chars,
int  insertPos,
boolean  startNewLine,
boolean  endNewLine 
)

Insert 1 or more characters into the string. The inserted text will first be made safe by removing any inappropriate EOL characters.
Do not use this method to insert EOL characters, use the

insertEOL(int)

method instead.

Parameters
insertPosposition in string to insert characters
charsthe characters to insert
startNewLineif true insert a new line before the chars to insert
endNewLineif true append a new line after the chars to insert
Returns
the number of characters inserted
boolean g4p_controls.StyledString.insertEOL ( int  insertPos)

Use this method to insert an EOL character.

Parameters
insertPosindex position to insert EOL
Returns
true if an EOL was inserted into the string
int g4p_controls.StyledString.length ( )
Returns
the number of characters in this styled string
static StyledString g4p_controls.StyledString.load ( PApplet  papp,
String  fname 
)
static

Load and return a StyledString object from the given file.

Parameters
pappthe main sketch PApplet instance
fnamethe filename of the StyledString
Returns
the styled string instance loaded from the file
void g4p_controls.StyledString.removeConsecutiveBlankLines ( )
protected

Ensure we do not have more than 2consecutive blank lines. This can happen when manually deleting a line adjacent to a blank line.

static void g4p_controls.StyledString.save ( PApplet  papp,
StyledString  ss,
String  fname 
)
static

Save the named StyleString in the named file.

Parameters
pappthe main sketch PApplet instance
ssthe styled string
fnamethe filename to use
void g4p_controls.StyledString.setJustify ( boolean  justify)

Text can be either left or fully justified.

Parameters
justifytrue for full justification
void g4p_controls.StyledString.setJustifyRatio ( float  jRatio)

Justify only if the line has sufficient text to do so.

Parameters
jRatioratio of text length to visibleWidth
void g4p_controls.StyledString.setText ( String  text)

Change the text for single line styled string

Parameters
textthe text to use
void g4p_controls.StyledString.setText ( String  text,
int  wrapWidth 
)

Change the text for single line styled string

Parameters
textthe text to use
wrapWidththe wrap width
void g4p_controls.StyledString.setWrapWidth ( int  wrapWidth)

Set the maximum width of a line.

Parameters
wrapWidththe maximum line length in pixels