org.zaval.data
Class Text

java.lang.Object
  |
  +--org.zaval.data.Text
All Implemented Interfaces:
TextModel

public class Text
extends java.lang.Object
implements TextModel

This class is an implementation of TextModel interface. It uses simple text representation - a line is considered to be terminated by a line feed ('\n').


Constructor Summary
Text(java.lang.String s)
          Constructs a new text with the given text.
 
Method Summary
 void addTextListener(TextListener l)
          Adds the specified text listener.
 int getExtraChar(int i)
          Gets special extra char that is used to store extra information by the specified index.
 java.lang.String getLine(int line)
          Returns the line at the specified line number.
 int getSize()
          Returns the line number of the text.
 java.lang.String getText()
          Returns the original text data that have been set with setText method.
 int getTextLength()
          Returns the text length.
protected  java.util.Vector parse(char[] buffer)
          Parses the specified text buffer and returns a vector of the text lines.
 void remove(int offset, int size)
          Removes a text at the specified offset with the size.
 void removeTextListener(TextListener l)
          Removes the specified text listener.
 void setExtraChar(int i, int ch)
          Sets special extra char that is used to store extra information by the specified index.
 void setText(java.lang.String text)
          Sets the specified text data.
 void write(char ch, int offset)
          Inserts the specified character at the given offset.
 void write(java.lang.String s, int offset)
          Inserts the specified text at the given offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Text

public Text(java.lang.String s)
Constructs a new text with the given text.
Parameters:
s - the initial value of the text.
Method Detail

getLine

public java.lang.String getLine(int line)
Returns the line at the specified line number.
Specified by:
getLine in interface TextModel
Parameters:
line - the specified line number.
Returns:
a line at the specified line number.

setText

public void setText(java.lang.String text)
Sets the specified text data. The method performs the text data parsing process. The process decides how the text data have to be divided into lines, the implementation uses "\n" character as the text line separator.
Specified by:
setText in interface TextModel
Parameters:
text - the text data.

getText

public java.lang.String getText()
Returns the original text data that have been set with setText method.
Specified by:
getText in interface TextModel
Returns:
an original text data.

getSize

public int getSize()
Returns the line number of the text.
Specified by:
getSize in interface TextModel
Returns:
a line number.

write

public void write(java.lang.String s,
                  int offset)
Inserts the specified text at the given offset. The offset has to be less than the text length. The method performs re-parsing of the text.
Specified by:
write in interface TextModel
Parameters:
s - the text to be inserted.
offset - the offset where the text will be inserted.

write

public void write(char ch,
                  int offset)
Inserts the specified character at the given offset. The offset has to be less than the text length. The method performs re-parsing of the text.
Specified by:
write in interface TextModel
Parameters:
ch - the character to be inserted.
offset - the offset where the character will be inserted.

remove

public void remove(int offset,
                   int size)
Removes a text at the specified offset with the size. The offset and the offset plus the size have to be less than the text length.
Specified by:
remove in interface TextModel
Parameters:
offset - the offset where the text will be removed.
size - the size of the part that is going to be removed.

parse

protected java.util.Vector parse(char[] buffer)
Parses the specified text buffer and returns a vector of the text lines. The method determines how the text has to be divided to the string lines.
Parameters:
buffer - the specified text buffer.
Returns:
a vector of the strings that are represented as character arrays.

addTextListener

public void addTextListener(TextListener l)
Adds the specified text listener.
Specified by:
addTextListener in interface TextModel
Parameters:
l - the text listener.

removeTextListener

public void removeTextListener(TextListener l)
Removes the specified text listener.
Specified by:
removeTextListener in interface TextModel
Parameters:
l - the text listener.
See Also:
TextListener, TextEvent

getTextLength

public int getTextLength()
Returns the text length.
Specified by:
getTextLength in interface TextModel
Returns:
a text length.

getExtraChar

public int getExtraChar(int i)
Description copied from interface: TextModel
Gets special extra char that is used to store extra information by the specified index. The method is depricated to be used, because it will be probably re-designed in the future.
Specified by:
getExtraChar in interface TextModel
Following copied from interface: org.zaval.data.TextModel
Parameters:
i - the specified extra char index.
Returns:
an extra char value.

setExtraChar

public void setExtraChar(int i,
                         int ch)
Description copied from interface: TextModel
Sets special extra char that is used to store extra information by the specified index. The method is depricated to be used, because it will probably be re-designed in the future.
Specified by:
setExtraChar in interface TextModel
Following copied from interface: org.zaval.data.TextModel
Parameters:
i - the specified extra char index.
val - the specified extra char value.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org