Class TextWriter
java.lang.Object
org.eclipse.swt.custom.TextWriter
- Direct Known Subclasses:
StyledTextWriterBase
The
TextWriter class is used to write widget content to
a string. Whole and partial lines and line breaks can be written. To write
partial lines, specify the start and length of the desired segment
during object creation.
NOTE: toString() is guaranteed to return a valid string only after close()
has been called.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTextWriter(int start, int length) Creates a writer that writes content starting at offset "start" in the document. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the writer.intReturns the number of characters to write.intgetStart()Returns the offset where writing starts.booleanisClosed()Returns whether the writer is closed.toString()Returns the string.(package private) voidwrite(char i) Appends the given character to the data.(package private) voidwrite(int i) Appends the given int to the data.(package private) voidAppends the given string to the data.(package private) voidInserts the given string to the data at the specified offset.voidAppends the specified line text to the data.voidwriteLineDelimiter(String lineDelimiter) Appends the specified line delimiter to the data.
-
Field Details
-
buffer
-
startOffset
private int startOffset -
endOffset
private int endOffset -
isClosed
private boolean isClosed
-
-
Constructor Details
-
TextWriter
public TextWriter(int start, int length) Creates a writer that writes content starting at offset "start" in the document.startandlengthcan be set to specify partial lines.- Parameters:
start- start offset of content to write, 0 based from beginning of documentlength- length of content to write
-
-
Method Details
-
close
public void close()Closes the writer. Once closed no more content can be written. NOTE:toString()is not guaranteed to return a valid string unless the writer is closed. -
getCharCount
public int getCharCount()Returns the number of characters to write.- Returns:
- the integer number of characters to write
-
getStart
public int getStart()Returns the offset where writing starts. 0 based from the start of the widget text. Used to write partial lines.- Returns:
- the integer offset where writing starts
-
isClosed
public boolean isClosed()Returns whether the writer is closed.- Returns:
- a boolean specifying whether or not the writer is closed
-
toString
-
write
Appends the given string to the data. -
write
Inserts the given string to the data at the specified offset.Do nothing if "offset" is < 0 or > getCharCount()
- Parameters:
string- text to insertoffset- offset in the existing data to insert "string" at.
-
write
void write(int i) Appends the given int to the data. -
write
void write(char i) Appends the given character to the data. -
writeLine
Appends the specified line text to the data.- Parameters:
line- line text to write. Must not contain line breaks Line breaks should be written using writeLineDelimiter()lineOffset- offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.- Throws:
SWTException-- ERROR_IO when the writer is closed.
-
writeLineDelimiter
Appends the specified line delimiter to the data.- Parameters:
lineDelimiter- line delimiter to write- Throws:
SWTException-- ERROR_IO when the writer is closed.
-