org.eclipse.swt.custom
Interface StyledTextContent

All Known Implementing Classes:
DefaultContent, WrappedContent

public interface StyledTextContent

Safe:


Method Summary
 void addTextChangeListener(TextChangeListener listener)
          Enabled: Called by StyledText to add itself as an Observer to content changes.
 int getCharCount()
          Enabled: Return the number of characters in the content.
 String getLine(int lineIndex)
          Enabled: Return the line at the given line index without delimiters.
 int getLineAtOffset(int offset)
          Enabled: Return the line index at the given character offset.
 int getLineCount()
          Enabled: Return the number of lines.
 String getLineDelimiter()
          Enabled: Return the line delimiter that should be used by the StyledText widget when inserting new lines.
 int getOffsetAtLine(int lineIndex)
          Enabled: Return the character offset of the first character of the given line.
 String getTextRange(int start, int length)
          Enabled: Returns a string representing the content at the given range.
 void removeTextChangeListener(TextChangeListener listener)
          Enabled: Remove the specified text changed listener.
 void replaceTextRange(int start, int replaceLength, String text)
          Enabled: Replace the text with "newText" starting at position "start" for a length of "replaceLength".
 void setText(String text)
          Enabled: Set text to "text".
 

Method Detail

addTextChangeListener

public void addTextChangeListener(TextChangeListener listener)
Enabled: Called by StyledText to add itself as an Observer to content changes. See TextChangeListener for a description of the listener methods that are called when text changes occur.

Parameters:
listener - the listener

getCharCount

public int getCharCount()
Enabled: Return the number of characters in the content.

Returns:
the number of characters in the content.

getLine

public String getLine(int lineIndex)
Enabled: Return the line at the given line index without delimiters.

Parameters:
lineIndex - index of the line to return. Does not include delimiters of preceeding lines. Index 0 is the first line of the content.
Returns:
the line text without delimiters

getLineAtOffset

public int getLineAtOffset(int offset)
Enabled: Return the line index at the given character offset.

Parameters:
offset - offset of the line to return. The first character of the document is at offset 0. An offset of getLength() is valid and should answer the number of lines.
Returns:
the line index. The first line is at index 0. If the character at offset is a delimiter character, answer the line index of the line that is delimited. For example, if text = "\r\n\r\n", and delimiter = "\r\n", then:
  • getLineAtOffset(0) == 0
  • getLineAtOffset(1) == 0
  • getLineAtOffset(2) == 1
  • getLineAtOffset(3) == 1
  • getLineAtOffset(4) == 2

getLineCount

public int getLineCount()
Enabled: Return the number of lines. Should answer 1 when no text is specified. The StyledText widget relies on this behavior for drawing the cursor.

Returns:
the number of lines. For example:
  • text value ==> getLineCount
  • null ==> 1
  • "" ==> 1
  • "a\n" ==> 2
  • "\n\n" ==> 3

getLineDelimiter

public String getLineDelimiter()
Enabled: Return the line delimiter that should be used by the StyledText widget when inserting new lines. New lines entered using key strokes and paste operations use this line delimiter. Implementors may use System.getProperty("line.separator") to return the platform line delimiter.

Returns:
the line delimiter that should be used by the StyledText widget when inserting new lines.

getOffsetAtLine

public int getOffsetAtLine(int lineIndex)
Enabled: Return the character offset of the first character of the given line.

NOTE: When there is no text (i.e., no lines), getOffsetAtLine(0) is a valid call that should return 0.

Parameters:
lineIndex - index of the line. The first line is at index 0.
Returns:
offset offset of the first character of the line. The first character of the document is at offset 0. The return value should include line delimiters. For example, if text = "\r\ntest\r\n" and delimiter = "\r\n", then:
  • getOffsetAtLine(0) == 0
  • getOffsetAtLine(1) == 2
  • getOffsetAtLine(2) == 8

getTextRange

public String getTextRange(int start,
                           int length)
Enabled: Returns a string representing the content at the given range.

Parameters:
start - the start offset of the text to return. Offset 0 is the first character of the document.
length - the length of the text to return
Returns:
the text at the given range

removeTextChangeListener

public void removeTextChangeListener(TextChangeListener listener)
Enabled: Remove the specified text changed listener.

Parameters:
listener - the listener

replaceTextRange

public void replaceTextRange(int start,
                             int replaceLength,
                             String text)
Enabled: Replace the text with "newText" starting at position "start" for a length of "replaceLength".

Implementors have to notify the TextChangeListeners that were added using addTextChangeListener before and after the content is changed. A TextChangingEvent has to be sent to the textChanging method before the content is changed and a TextChangedEvent has to be sent to the textChanged method after the content has changed. The text change that occurs after the TextChangingEvent has been sent has to be consistent with the data provided in the TextChangingEvent. This data will be cached by the widget and will be used when the TextChangedEvent is received.

The TextChangingEvent should be set as follows:

NOTE: newLineCount is the number of inserted lines and replaceLineCount is the number of deleted lines based on the change that occurs visually. For example:

Parameters:
start - start offset of text to replace, none of the offsets include delimiters of preceeding lines, offset 0 is the first character of the document
replaceLength - start offset of text to replace
See Also:
TextChangeListener

setText

public void setText(String text)
Enabled: Set text to "text". Implementors have to send a TextChangedEvent to the textSet method of the TextChangeListeners that were added using addTextChangeListener.

Parameters:
text - the new text
See Also:
TextChangeListener


comments?