Class DefaultContent
java.lang.Object
org.eclipse.swt.custom.DefaultContent
- All Implemented Interfaces:
StyledTextContent
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) int(package private) int(package private) int(package private) int(package private) intprivate static final String(package private) int[][](package private) int(package private) int(package private) List<StyledTextListener> (package private) char[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddLineIndex(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 oflinesArray.voidaddTextChangeListener(TextChangeListener listener) Adds aTextChangeListenerlistening forTextChangingEventandTextChangedEvent.(package private) voidadjustGap(int position, int sizeHint, int line) Adjusts the gap to accommodate a text change that is occurring.(package private) voiddelete(int position, int length, int numLines) Deletes text.(package private) voiderror(int code) Reports an SWT error.(package private) voidexpandLinesBy(int numLines) Increases the line indexes array to accommodate more lines.(package private) booleanReturns whether or not a gap exists in the text store.intReturn the number of characters in the content.(package private) StringgetFullLine(int index) Returns the line at the given index with delimiters.getLine(int index) Returns the line atindexwithout delimiters.intgetLineAtOffset(int charPosition) Returns the line at the given offset.(package private) intgetLineAtPhysicalOffset(int position) Returns the line index at the given physical offset.intReturn the number of lines.Returns the line delimiter that should be used by the StyledText widget when inserting new lines.intgetOffsetAtLine(int lineIndex) Returns the logical offset of the given line.(package private) StringgetPhysicalLine(int index) Returns the physical line at the given index (i.e., with delimiters and the gap).(package private) StringgetPhysicalText(int start, int length) Returns a string representing the continuous content of the text store.getTextRange(int start, int length) Returns a string representing the logical content of the text store (i.e., gap stripped out).(package private) voidCalculates 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) voidInserts text.(package private) booleanisDelimiter(char ch) Returns whether or not the given character is a line delimiter.private booleanisInsideCRLF(int pos) (package private) intlineCount(int startOffset, int length) Returns the number of lines that are in the specified text.(package private) intReturns the number of lines that are in the specified text.(package private) voidmoveAndResizeGap(int position, int size, int newGapLine) Moves the gap and adjusts its size in anticipation of a text change.voidremoveTextChangeListener(TextChangeListener listener) Removes the specifiedTextChangeListener.voidreplaceTextRange(int start, int replaceLength, String newText) Replaces the text withnewTextstarting at positionstartfor a length ofreplaceLength.(package private) voidsendTextEvent(StyledTextEvent event) Sends the text listeners the TextChanged event.voidSets the content to text and removes the gap since there are no sensible predictions about where the next change will occur.private voidvalidateReplace(int start, int replaceLength) Validates the replace operation.
-
Field Details
-
LineDelimiter
-
textListeners
List<StyledTextListener> 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 Details
-
DefaultContent
DefaultContent()Creates a new DefaultContent and initializes it. AStyledTextContentwill always have at least one empty line.
-
-
Method Details
-
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.lineCountis updated to reflect the new entry.- Parameters:
start- the start of the linelength- the length of the line
-
addLineIndex
int[][] addLineIndex(int start, int length, int[][] linesArray, int count) Adds a line index to the end oflinesArray. Increases the size of the array if necessary and returns a new array.- Parameters:
start- the start of the linelength- the length of the linelinesArray- the array to which to add the line indexcount- the position at which to add the line- Returns:
- a new array of line indexes
-
addTextChangeListener
Adds aTextChangeListenerlistening forTextChangingEventandTextChangedEvent. ATextChangingEventis sent before changes to the text occur. ATextChangedEventis sent after changes to the text occurred.- Specified by:
addTextChangeListenerin interfaceStyledTextContent- Parameters:
listener- the listener- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT when listener is null
-
adjustGap
void adjustGap(int position, int sizeHint, int line) Adjusts the gap to accommodate a text change that is occurring.- Parameters:
position- the position at which a change is occurringsizeHint- the size of the changeline- 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
-
isInsideCRLF
private boolean isInsideCRLF(int pos) -
validateReplace
private void validateReplace(int start, int replaceLength) Validates the replace operation. DefaultContent will not allow the \r\n line delimiter to be split or partially deleted.- Parameters:
start- start offset of text to replacereplaceLength- 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 lineatelength- the length of the text to lineate, includes gapnumLines- 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
Inserts text.- Parameters:
position- the position at which to insert the texttext- the text to insert
-
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 occurringsize- the size of the changenewGapLine- the line where the gap should be put
-
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 lineatelength- the length of the text to lineate- Returns:
- number of lines
-
lineCount
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:StyledTextContentReturn the number of characters in the content.- Specified by:
getCharCountin interfaceStyledTextContent- Returns:
- the logical length of the text store
-
getLine
Returns the line atindexwithout delimiters.- Specified by:
getLinein interfaceStyledTextContent- Parameters:
index- the index of the line to return- Returns:
- the logical line text (i.e., without the gap)
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT when index is out of range
-
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 theStyledTextContentinterface.- Specified by:
getLineDelimiterin interfaceStyledTextContent- Returns:
- the platform line delimiter as specified in the line.separator system property.
-
getFullLine
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
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:StyledTextContentReturn 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:
getLineCountin interfaceStyledTextContent- Returns:
- the number of lines in the text store
-
getLineAtOffset
public int getLineAtOffset(int charPosition) Returns the line at the given offset.- Specified by:
getLineAtOffsetin interfaceStyledTextContent- Parameters:
charPosition- logical character offset (i.e., does not include gap)- Returns:
- the line index
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT when charPosition is out of range
-
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:
getOffsetAtLinein interfaceStyledTextContent- 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.
- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT when lineIndex is out of range
-
expandLinesBy
void expandLinesBy(int numLines) Increases the line indexes array to accommodate 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
Returns a string representing the continuous content of the text store.- Parameters:
start- the physical start offset of the text to returnlength- the physical length of the text to return- Returns:
- the text
-
getTextRange
Returns a string representing the logical content of the text store (i.e., gap stripped out).- Specified by:
getTextRangein interfaceStyledTextContent- Parameters:
start- the logical start offset of the text to returnlength- the logical length of the text to return- Returns:
- the text
-
removeTextChangeListener
Removes the specifiedTextChangeListener.- Specified by:
removeTextChangeListenerin interfaceStyledTextContent- Parameters:
listener- the listener which should no longer be notified- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT when listener is null
-
replaceTextRange
Replaces the text withnewTextstarting at positionstartfor a length ofreplaceLength. Notifies the appropriate listeners.When sending the TextChangingEvent,
newLineCountis the number of lines that are going to be inserted andreplaceLineCountis 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:
replaceTextRangein interfaceStyledTextContent- Parameters:
start- start offset of text to replacereplaceLength- start offset of text to replacenewText- start offset of text to replace- Throws:
SWTException-- ERROR_INVALID_ARGUMENT when the text change results in a multi byte line delimiter being split or partially deleted. Splitting a line delimiter by inserting text between the CR and LF characters of the \r\n delimiter or deleting part of this line delimiter is not supported
- See Also:
-
sendTextEvent
Sends the text listeners the TextChanged event. -
setText
Sets the content to text and removes the gap since there are no sensible predictions about where the next change will occur.- Specified by:
setTextin interfaceStyledTextContent- Parameters:
text- the text- See Also:
-
delete
void delete(int position, int length, int numLines) Deletes text.- Parameters:
position- the position at which the text to delete startslength- the length of the text to deletenumLines- the number of lines that are being deleted
-