org.eclipse.swt.custom
Class DefaultContent

java.lang.Object
  |
  +--org.eclipse.swt.custom.DefaultContent
All Implemented Interfaces:
StyledTextContent

class DefaultContent
extends Object
implements StyledTextContent


Field Summary
(package private)  int expandExp
           
(package private)  int gapEnd
           
(package private)  int gapLine
           
(package private)  int gapStart
           
(package private)  int highWatermark
           
(package private)  int lineCount
           
private static String LineDelimiter
           
(package private)  int[][] lines
           
(package private)  int lowWatermark
           
(package private)  int replaceExpandExp
           
(package private)  Vector textListeners
           
(package private)  char[] textStore
           
 
Constructor Summary
(package private) DefaultContent()
          Creates a new DefaultContent and initializes it.
 
Method Summary
(package private)  void addLineIndex(int start, int length)
          Adds a line to the end of the line indexes array.
(package private)  int[][] addLineIndex(int start, int length, int[][] linesArray, int count)
          Adds a line index to the end of linesArray.
 void addTextChangeListener(TextChangeListener listener)
          Adds a TextChangeListener listening for TextChangingEvent and TextChangedEvent.
(package private)  void adjustGap(int position, int sizeHint, int line)
          Adjusts the gap to accomodate a text change that is occurring.
(package private)  void delete(int position, int length, int numLines)
          Deletes text.
(package private)  void error(int code)
          Reports an SWT error.
(package private)  void expandLinesBy(int numLines)
          Increases the line indexes array to accomodate more lines.
(package private)  boolean gapExists()
          Returns whether or not a gap exists in the text store.
 int getCharCount()
          Enabled: Return the number of characters in the content.
(package private)  String getFullLine(int index)
          Returns the line at the given index with delimiters.
 String getLine(int index)
          Returns the line at index without delimiters.
 int getLineAtOffset(int charPosition)
          Returns the line at the given offset.
(package private)  int getLineAtPhysicalOffset(int position)
          Returns the line index at the given physical offset.
 int getLineCount()
          Enabled: Return the number of lines.
 String getLineDelimiter()
          Returns the line delimiter that should be used by the StyledText widget when inserting new lines.
 int getOffsetAtLine(int lineIndex)
          Returns the logical offset of the given line.
(package private)  String getPhysicalLine(int index)
          Returns the physical line at the given index (i.e., with delimiters and the gap).
(package private)  String getPhysicalText(int start, int length)
          Returns a string representing the continous content of the text store.
 String getTextRange(int start, int length)
          Returns a string representing the logical content of the text store (i.e., gap stripped out).
(package private)  void indexLines()
          Calculates the indexes of each line in the text store.
(package private)  int[][] indexLines(int offset, int length, int numLines)
          Calculates the indexes of each line of text in the given range.
(package private)  void insert(int position, String text)
          Inserts text.
(package private)  boolean isDelimiter(char ch)
          Returns whether or not the given character is a line delimiter.
protected  boolean isValidReplace(int start, int replaceLength, String newText)
          Determine whether or not the replace operation is valid.
(package private)  int lineCount(int startOffset, int length)
          Returns the number of lines that are in the specified text.
(package private)  int lineCount(String text)
          Returns the number of lines that are in the specified text.
(package private)  void moveAndResizeGap(int position, int size, int newGapLine)
          Moves the gap and adjusts its size in anticipation of a text change.
 void removeTextChangeListener(TextChangeListener listener)
          Removes the specified TextChangeListener.
 void replaceTextRange(int start, int replaceLength, String newText)
          Replaces the text with newText starting at position start for a length of replaceLength.
(package private)  void sendTextEvent(StyledTextEvent event)
          Sends the text listeners the TextChanged event.
 void setText(String text)
          Sets the content to text and removes the gap since there are no sensible predictions about where the next change will occur.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LineDelimiter

private static final String LineDelimiter

textListeners

Vector textListeners

textStore

char[] textStore

gapStart

int gapStart

gapEnd

int gapEnd

gapLine

int gapLine

highWatermark

int highWatermark

lowWatermark

int lowWatermark

lines

int[][] lines

lineCount

int lineCount

expandExp

int expandExp

replaceExpandExp

int replaceExpandExp
Constructor Detail

DefaultContent

DefaultContent()
Creates a new DefaultContent and initializes it. A StyledTextContent will always have at least one empty line.

Method Detail

addLineIndex

void addLineIndex(int start,
                  int length)
Adds a line to the end of the line indexes array. Increases the size of the array if necessary. lineCount is updated to reflect the new entry.

Parameters:
start - the start of the line
length - the length of the line

addLineIndex

int[][] addLineIndex(int start,
                     int length,
                     int[][] linesArray,
                     int count)
Adds a line index to the end of linesArray. Increases the size of the array if necessary and returns a new array.

Parameters:
start - the start of the line
length - the length of the line
linesArray - the array to which to add the line index
count - the position at which to add the line
Returns:
a new array of line indexes

addTextChangeListener

public void addTextChangeListener(TextChangeListener listener)
Adds a TextChangeListener listening for TextChangingEvent and TextChangedEvent. A TextChangingEvent is sent before changes to the text occur. A TextChangedEvent is sent after changes to the text occured.

Specified by:
addTextChangeListener in interface StyledTextContent
Parameters:
listener - the listener

adjustGap

void adjustGap(int position,
               int sizeHint,
               int line)
Adjusts the gap to accomodate a text change that is occurring.

Parameters:
position - the position at which a change is occurring
sizeHint - the size of the change
line - the line where the gap will go

indexLines

void indexLines()
Calculates the indexes of each line in the text store. Assumes no gap exists. Optimized to do less checking.


isDelimiter

boolean isDelimiter(char ch)
Returns whether or not the given character is a line delimiter. Both CR and LF are valid line delimiters.

Parameters:
ch - the character to test
Returns:
true if ch is a delimiter, false otherwise

isValidReplace

protected boolean isValidReplace(int start,
                                 int replaceLength,
                                 String newText)
Determine whether or not the replace operation is valid. DefaultContent will not allow the /r/n line delimiter to be split or partially deleted.

Parameters:
start - start offset of text to replace
replaceLength - start offset of text to replace
newText - start offset of text to replace

indexLines

int[][] indexLines(int offset,
                   int length,
                   int numLines)
Calculates the indexes of each line of text in the given range.

Parameters:
offset - the logical start offset of the text lineate
length - the length of the text to lineate, includes gap
numLines - the number of lines to initially allocate for the line index array, passed in for efficiency (the exact number of lines may be known)
Returns:
a line indexes array where each line is identified by a start offset and a length

insert

void insert(int position,
            String text)
Inserts text.

Parameters:
position - the position at which to insert the text

moveAndResizeGap

void moveAndResizeGap(int position,
                      int size,
                      int newGapLine)
Moves the gap and adjusts its size in anticipation of a text change. The gap is resized to actual size + the specified size and moved to the given position.

Parameters:
position - the position at which a change is occurring

lineCount

int lineCount(int startOffset,
              int length)
Returns the number of lines that are in the specified text.

Parameters:
startOffset - the start of the text to lineate
length - the length of the text to lineate
Returns:
number of lines

lineCount

int lineCount(String text)
Returns the number of lines that are in the specified text.

Parameters:
text - the text to lineate
Returns:
number of lines in the text

getCharCount

public int getCharCount()
Description copied from interface: StyledTextContent
Enabled: Return the number of characters in the content.

Specified by:
getCharCount in interface StyledTextContent
Returns:
the logical length of the text store

getLine

public String getLine(int index)
Returns the line at index without delimiters.

Specified by:
getLine in interface StyledTextContent
Parameters:
index - the index of the line to return
Returns:
the logical line text (i.e., without the gap)

getLineDelimiter

public String getLineDelimiter()
Returns the line delimiter that should be used by the StyledText widget when inserting new lines. This delimiter may be different than the delimiter that is used by the StyledTextContent interface.

Specified by:
getLineDelimiter in interface StyledTextContent
Returns:
the platform line delimiter as specified in the line.separator system property.

getFullLine

String getFullLine(int index)
Returns the line at the given index with delimiters.

Parameters:
index - the index of the line to return
Returns:
the logical line text (i.e., without the gap) with delimiters

getPhysicalLine

String getPhysicalLine(int index)
Returns the physical line at the given index (i.e., with delimiters and the gap).

Parameters:
index - the line index
Returns:
the physical line

getLineCount

public int getLineCount()
Description copied from interface: StyledTextContent
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.

Specified by:
getLineCount in interface StyledTextContent
Returns:
the number of lines in the text store

getLineAtOffset

public int getLineAtOffset(int charPosition)
Returns the line at the given offset.

Specified by:
getLineAtOffset in interface StyledTextContent
Parameters:
charPosition - logical character offset (i.e., does not include gap)
Returns:
the line index

getLineAtPhysicalOffset

int getLineAtPhysicalOffset(int position)
Returns the line index at the given physical offset.

Parameters:
position - physical character offset (i.e., includes gap)
Returns:
the line index

getOffsetAtLine

public int getOffsetAtLine(int lineIndex)
Returns the logical offset of the given line.

Specified by:
getOffsetAtLine in interface StyledTextContent
Parameters:
lineIndex - index of line
Returns:
the logical starting offset of the line. When there are not any lines, getOffsetAtLine(0) is a valid call that should answer 0.

expandLinesBy

void expandLinesBy(int numLines)
Increases the line indexes array to accomodate more lines.

Parameters:
numLines - the number to increase the array by

error

void error(int code)
Reports an SWT error.

Parameters:
code - the error code

gapExists

boolean gapExists()
Returns whether or not a gap exists in the text store.

Returns:
true if gap exists, false otherwise

getPhysicalText

String getPhysicalText(int start,
                       int length)
Returns a string representing the continous content of the text store.

Parameters:
start - the physical start offset of the text to return
length - the physical length of the text to return
Returns:
the text

getTextRange

public String getTextRange(int start,
                           int length)
Returns a string representing the logical content of the text store (i.e., gap stripped out).

Specified by:
getTextRange in interface StyledTextContent
Parameters:
start - the logical start offset of the text to return
length - the logical length of the text to return
Returns:
the text

removeTextChangeListener

public void removeTextChangeListener(TextChangeListener listener)
Removes the specified TextChangeListener.

Specified by:
removeTextChangeListener in interface StyledTextContent
Parameters:
listener - the listener

replaceTextRange

public void replaceTextRange(int start,
                             int replaceLength,
                             String newText)
Replaces the text with newText starting at position start for a length of replaceLength. Notifies the appropriate listeners.

When sending the TextChangingEvent, newLineCount is the number of lines that are going to be inserted and replaceLineCount is the number of lines that are going to be deleted, based on the change that occurs visually. For example:

  • (replaceText,newText) ==> (replaceLineCount,newLineCount)
  • ("","\n") ==> (0,1)
  • ("\n\n","a") ==> (2,0)

Specified by:
replaceTextRange in interface StyledTextContent
Parameters:
start - start offset of text to replace
replaceLength - start offset of text to replace
newText - start offset of text to replace
See Also:
TextChangeListener

sendTextEvent

void sendTextEvent(StyledTextEvent event)
Sends the text listeners the TextChanged event.


setText

public void setText(String text)
Sets the content to text and removes the gap since there are no sensible predictions about where the next change will occur.

Specified by:
setText in interface StyledTextContent
Parameters:
text - the text
See Also:
TextChangeListener

delete

void delete(int position,
            int length,
            int numLines)
Deletes text.

Parameters:
position - the position at which the text to delete starts
length - the length of the text to delete
numLines - the number of lines that are being deleted


comments?