G4P (GUI for Processing) 4.3.9
A set of GUI controls for your Processing sketch.
Loading...
Searching...
No Matches
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 beginIdx, int endIdx)
 
void addAttribute (Attribute type, Object value, int lineNo)
 
void addAttribute (Attribute type, Object value, int lineNo, int charStart, int charEnd)
 
void clearAttributes ()
 
void clearAttributes (int beginIdx, int endIdx)
 
void clearAttributes (int lineNo)
 
void clearAttributes (int lineNo, int beginIdx, int endIdx)
 
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 insertPos)
 
int insertCharacters (String chars, int insertPos, boolean startNewLine, boolean endNewLine)
 
int insertCharacters (String chars, int lineNo, int charStart, 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 ()
 

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

◆ StyledString() [1/2]

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

◆ StyledString() [2/2]

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

◆ addAttribute() [1/4]

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

◆ addAttribute() [2/4]

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)

◆ addAttribute() [3/4]

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

◆ addAttribute() [4/4]

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.

◆ clearAttributes() [1/4]

void g4p_controls.StyledString.clearAttributes ( )

Removes all styling from the string.

◆ clearAttributes() [2/4]

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)

◆ clearAttributes() [3/4]

void g4p_controls.StyledString.clearAttributes ( int  lineNo)

Clear the attributes from a given line

Parameters
lineNothe line to use

◆ clearAttributes() [4/4]

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)

◆ deleteCharacters()

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

◆ getLines()

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

◆ getMaxLineHeight()

float g4p_controls.StyledString.getMaxLineHeight ( )
Returns
the height of the tallest line

◆ getMaxLineLength()

float g4p_controls.StyledString.getMaxLineLength ( )
Returns
the length of the longest line.

◆ getNbrLines()

int g4p_controls.StyledString.getNbrLines ( )
Returns
the number of lines in the layout

◆ getPlainText() [1/3]

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

◆ getPlainText() [2/3]

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

◆ getPlainText() [3/3]

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.

◆ getPlainTextAsArray()

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

◆ getTextAreaHeight()

float g4p_controls.StyledString.getTextAreaHeight ( )
Returns
the height of the text line(s)

◆ getWrapWidth()

int g4p_controls.StyledString.getWrapWidth ( )
Returns
the break width used to create the lines.

◆ insertCharacters() [1/3]

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

◆ insertCharacters() [2/3]

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

◆ insertCharacters() [3/3]

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

◆ insertEOL()

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

◆ length()

int g4p_controls.StyledString.length ( )
Returns
the number of characters in this styled string

◆ load()

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

◆ removeConsecutiveBlankLines()

void g4p_controls.StyledString.removeConsecutiveBlankLines ( )
protected

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

◆ save()

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

◆ setJustify()

void g4p_controls.StyledString.setJustify ( boolean  justify)

Text can be either left or fully justified.

Parameters
justifytrue for full justification

◆ setJustifyRatio()

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

◆ setText() [1/2]

void g4p_controls.StyledString.setText ( String  text)

Change the text for single line styled string

Parameters
textthe text to use

◆ setText() [2/2]

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

◆ setWrapWidth()

void g4p_controls.StyledString.setWrapWidth ( int  wrapWidth)

Set the maximum width of a line.

Parameters
wrapWidththe maximum line length in pixels