Class FxText
public class FxText
{
// Fields
public char buffer[];
public int nBuffSize;
public int nChars;
// Constructors
public FxText();
public FxText(String newBuff);
public FxText(char newBuff[]);
public FxText(char newBuff[], int offset, int length);
// Methods
public void append(char key);
public void append(char key[]);
public void append(char key[], int offs, int len);
public void ensureResize(int amountNeeded);
public char getChar(int idx);
public int getLength();
public int getWordBreak( int iChar );
public void insert(char key, int iPos);
public void insert(char key[], int offs, int keyLen, int iPos);
public void insert(char key[], int iPos);
public boolean isDelimiter(int iPos);
public boolean isWhite(int i);
public boolean isWhite(int i, boolean treatLFasWhite);
public void remove(int iPos, int numberToRemove);
public void setText(char newBuff[]);
public void setText(String s);
public void setText(char newBuff[], int offset, int nCharsNew);
}
This class performs basic insertion and deletion operations on a text buffer. The FxText class is similar to the java.lang.StringBuffer class, but there is no synchronization on the buffer in the FxText class, which makes it much more efficient. FxText buffers, which are designed to be plugged into UI components, are the basis for FxFormattedText.
As with the StringBuffer class, append and insert are the principle operations of the FxText class, and the setText method allows buffer substitution.
Warning Because the FxTextclass has no synchronization, it is not thread safe and should not be used in multithreaded applications. To avoid a possible conflict with multiple threads, synchronize the FxFormattedTextobject.
public FxText();
Creates an empty text buffer.
public FxText(String newBuff);
Creates a text buffer based on a string.
Parameter | Description |
newBuff
| The string that the new text buffer is based on.
|
public FxText(char newBuff[]);
Creates a text buffer based on a character array.
Parameter | Description |
newBuff
| The array of characters that the new text buffer is based on.
|
public FxText(char newBuff[], int offset, int length);
Creates a text buffer based on a portion of a character array.
Parameter | Description |
newBuff
| The array of characters that the new text buffer is based on.
|
offset
| The offset to use.
|
length
| The length of the array to be used.
|
public void append(char key);
Appends a character to the end of the buffer.
Return Value:
No return value.
Parameter | Description |
key
| The character to append.
|
public void append(char key[]);
Appends an array of characters to the end of the buffer.
Return Value:
No return value.
Parameter | Description |
key
| The array of characters to append.
|
public void append(char key[], int offs, int len);
Appends an array of characters, or a subsection of an array, to the end of the buffer.
Return Value:
No return value.
Parameter | Description |
key
| The array of characters to append.
|
offs
| The offset of the array to copy from.
|
len
| The length of the array or length of the array subsection to copy.
|
public void ensureResize(int amountNeeded);
Ensures that the current text buffer has enough room to handle any changes. If the buffer is too small, a larger text buffer is created by using the amountNeeded parameter. Use this method before insert, append, and setText operations to check bounds on a text buffer.
Return Value:
No return value.
Parameter | Description |
amountNeeded
| The number of characters needed for expanded text buffer operations.
|
public char getChar(int idx);
Retrieves the character at the given location.
Return Value:
Returns the character at position idx.
Parameter | Description |
idx
| The index of the character in an array.
|
public int getLength();
Retrieves the number of characters in the buffer.
Return Value:
Returns the number of characters in the buffer.
public int getWordBreak( int iChar );
Retrieves the number of characters in the next word.
Return Value:
Returns the number of characters in the next word.
Parameter | Description |
iChar
| The location to start searching for the next word.
|
Remarks:
The next word includes leading white space, but not trailing white space.
public void insert(char key, int iPos);
Inserts a single character into the buffer.
Return Value:
No return value.
Parameter | Description |
key
| The character to insert.
|
iPos
| The position in the buffer to insert the character.
|
public void insert(char key[], int offs, int keyLen, int iPos);
Inserts an array of characters or an array fragment into the buffer.
Return Value:
No return value.
Parameter | Description |
key
| The array of characters to insert.
|
offs
| The offset in the array or array fragment to start from.
|
keyLen
| The length of the character array fragment.
|
iPos
| The position in the buffer to insert the character.
|
public void insert(char key[], int iPos);
Inserts an array of characters into the buffer.
Return Value:
No return value.
Parameter | Description |
key
| The array of characters to insert.
|
iPos
| The position in the buffer to insert the characters.
|
public boolean isDelimiter(int iPos);
Checks if the character is a delimiter.
Return Value:
Returns true if it is a delimiter; otherwise, returns false.
Parameter | Description |
iPos
| The character position to check.
|
public boolean isWhite(int i);
Determines if a character is a white space.
Return Value:
Returns true if it is a white space; otherwise, returns false.
Parameter | Description |
i
| The offset in buffer.
|
public boolean isWhite(int i, boolean treatLFasWhite);
Determines if a character is a white space and whether to treat line feed characters as white spaces.
Return Value:
Returns true if it is considered white space; otherwise, returns false.
Parameter | Description |
i
| The offset in buffer.
|
treatLFasWhite
| Set this value to true if a line feed character should be treated as a white space.
|
Remarks:
This method is useful for marking the end of a line of text.
public void remove(int iPos, int numberToRemove);
Deletes one or more characters in the text buffer.
Return Value:
No return value.
Parameter | Description |
iPos
| The position at which to start the deletion.
|
numberToRemove
| The number of characters to remove.
|
public void setText(char newBuff[]);
Replaces the text in the sentence with that of a character array.
Return Value:
No return value.
Parameter | Description |
newBuff[]
| A character array.
|
public void setText(String s);
Replaces the text in the sentence with that of a specified string.
Return Value:
No return value.
Parameter | Description |
s
| The string that replaces the text buffer.
|
public void setText(char newBuff[], int offset, int nCharsNew);
Replaces the text in the sentence with that of a character array, starting at a specified offset.
Return Value:
No return value.
Parameter | Description |
newBuff
| A character array.
|
offset
| The specified starting offset.
|
nCharsNew
| The length of the new character array.
|
- buffer[]
- The buffer containing the sentence.
- nBuffSize
- The current maximum size of the buffer (in characters).
- nChars
- The number of characters in the buffer.