Top Fields Constructors Methods
org.eclipse.swt.custom

pack-priv Class DefaultContent

extends Object
implements StyledTextContent
Class Inheritance
All Implemented Interfaces
org.eclipse.swt.custom.StyledTextContent
Imports
java.util.*, .List, org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.widgets.*

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
private static final String
pack-priv int[][]
pack-priv int
pack-priv int
pack-priv List<StyledTextListener>
pack-priv char[]

Constructor Summary

AccessConstructor and Description
pack-priv
DefaultContent()

Creates a new DefaultContent and initializes it.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addLineIndex(int
the start of the line
start
,
int
the length of the line
length
)

Adds a line to the end of the line indexes array.

pack-priv int[][]

Returns:

a new array of line indexes
addLineIndex
(int
the start of the line
start
,
int
the length of the line
length
,
int[][]
the array to which to add the line index
linesArray
,
int
the position at which to add the line
count
)

Adds a line index to the end of linesArray.

public void
addTextChangeListener(TextChangeListener
the listener
listener
)

Implements org.eclipse.swt.custom.StyledTextContent.addTextChangeListener.

Adds a TextChangeListener listening for TextChangingEvent and TextChangedEvent.
pack-priv void
adjustGap(int
the position at which a change is occurring
position
,
int
the size of the change
sizeHint
,
int
the line where the gap will go
line
)

Adjusts the gap to accommodate a text change that is occurring.

pack-priv void
delete(int
the position at which the text to delete starts
position
,
int
the length of the text to delete
length
,
int
the number of lines that are being deleted
numLines
)

Deletes text.

pack-priv void
error(int
the error code
code
)

Reports an SWT error.

pack-priv void
expandLinesBy(int
the number to increase the array by
numLines
)

Increases the line indexes array to accommodate more lines.

pack-priv boolean

Returns:

true if gap exists, false otherwise
gapExists
()

Returns whether or not a gap exists in the text store.

public int

Returns:

the logical length of the text store
getCharCount
()

Implements org.eclipse.swt.custom.StyledTextContent.getCharCount.

Return the number of characters in the content.
pack-priv String

Returns:

the logical line text (i.e., without the gap) with delimiters
getFullLine
(int
the index of the line to return
index
)

Returns the line at the given index with delimiters.

public String

Returns:

the logical line text (i.e., without the gap)
getLine
(int
the index of the line to return
index
)

Implements org.eclipse.swt.custom.StyledTextContent.getLine.

Returns the line at index without delimiters.
public int

Returns:

the line index
getLineAtOffset
(int
logical character offset (i.e., does not include gap)
charPosition
)

Implements org.eclipse.swt.custom.StyledTextContent.getLineAtOffset.

Returns the line at the given offset.
pack-priv int

Returns:

the line index
getLineAtPhysicalOffset
(int
physical character offset (i.e., includes gap)
position
)

Returns the line index at the given physical offset.

public int

Returns:

the number of lines in the text store
getLineCount
()

Implements org.eclipse.swt.custom.StyledTextContent.getLineCount.

Return the number of lines.
public String

Returns:

the platform line delimiter as specified in the line.separator system property.
getLineDelimiter
()

Implements org.eclipse.swt.custom.StyledTextContent.getLineDelimiter.

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

Returns:

the logical starting offset of the line. When there are not any lines, getOffsetAtLine(0) is a valid call that should answer 0.
getOffsetAtLine
(int
index of line
lineIndex
)

Implements org.eclipse.swt.custom.StyledTextContent.getOffsetAtLine.

Returns the logical offset of the given line.
pack-priv String

Returns:

the physical line
getPhysicalLine
(int
the line index
index
)

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

pack-priv String

Returns:

the text
getPhysicalText
(int
the physical start offset of the text to return
start
,
int
the physical length of the text to return
length
)

Returns a string representing the continuous content of the text store.

public String

Returns:

the text
getTextRange
(int
the logical start offset of the text to return
start
,
int
the logical length of the text to return
length
)

Implements org.eclipse.swt.custom.StyledTextContent.getTextRange.

Returns a string representing the logical content of the text store (i.e., gap stripped out).
pack-priv void
indexLines()

Calculates the indexes of each line in the text store.

pack-priv int[][]

Returns:

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

Calculates the indexes of each line of text in the given range.

pack-priv void
insert(int
the position at which to insert the text
position
,
String
the text to insert
text
)

Inserts text.

pack-priv boolean

Returns:

true if ch is a delimiter, false otherwise
isDelimiter
(char
the character to test
ch
)

Returns whether or not the given character is a line delimiter.

private boolean
isInsideCRLF(int pos)

pack-priv int

Returns:

number of lines
lineCount
(int
the start of the text to lineate
startOffset
,
int
the length of the text to lineate
length
)

Returns the number of lines that are in the specified text.

pack-priv int

Returns:

number of lines in the text
lineCount
(String
the text to lineate
text
)

Returns the number of lines that are in the specified text.

pack-priv void
moveAndResizeGap(int
the position at which a change is occurring
position
,
int
the size of the change
size
,
int
the line where the gap should be put
newGapLine
)

Moves the gap and adjusts its size in anticipation of a text change.

public void
removeTextChangeListener(TextChangeListener
the listener which should no longer be notified
listener
)

Implements org.eclipse.swt.custom.StyledTextContent.removeTextChangeListener.

Removes the specified TextChangeListener.
public void
replaceTextRange(int
start offset of text to replace
start
,
int
start offset of text to replace
replaceLength
,
String
start offset of text to replace
newText
)

Implements org.eclipse.swt.custom.StyledTextContent.replaceTextRange.

Replaces the text with newText starting at position start for a length of replaceLength.
pack-priv void
sendTextEvent(StyledTextEvent event)

Sends the text listeners the TextChanged event.

public void
setText(String
the text
text
)

Implements org.eclipse.swt.custom.StyledTextContent.setText.

Sets the content to text and removes the gap since there are no sensible predictions about where the next change will occur.
private void
validateReplace(int
start offset of text to replace
start
,
int
start offset of text to replace
replaceLength
)

Validates the replace operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

expandExpback to summary
pack-priv int expandExp
gapEndback to summary
pack-priv int gapEnd
gapLineback to summary
pack-priv int gapLine
gapStartback to summary
pack-priv int gapStart
highWatermarkback to summary
pack-priv int highWatermark
lineCountback to summary
pack-priv int lineCount
LineDelimiterback to summary
private static final String LineDelimiter
linesback to summary
pack-priv int[][] lines
lowWatermarkback to summary
pack-priv int lowWatermark
replaceExpandExpback to summary
pack-priv int replaceExpandExp
textListenersback to summary
pack-priv List<StyledTextListener> textListeners
textStoreback to summary
pack-priv char[] textStore

Constructor Detail

DefaultContentback to summary
pack-priv DefaultContent()

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

Method Detail

addLineIndexback to summary
pack-priv 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:int

the start of the line

length:int

the length of the line

addLineIndexback to summary
pack-priv 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:int

the start of the line

length:int

the length of the line

linesArray:int[][]

the array to which to add the line index

count:int

the position at which to add the line

Returns:int[][]

a new array of line indexes

addTextChangeListenerback to summary
public void addTextChangeListener(TextChangeListener listener)

Implements org.eclipse.swt.custom.StyledTextContent.addTextChangeListener.

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 occurred.

Parameters
listener:TextChangeListener

the listener

Annotations
@Override
Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT when listener is null
adjustGapback to summary
pack-priv void adjustGap(int position, int sizeHint, int line)

Adjusts the gap to accommodate a text change that is occurring.

Parameters
position:int

the position at which a change is occurring

sizeHint:int

the size of the change

line:int

the line where the gap will go

deleteback to summary
pack-priv void delete(int position, int length, int numLines)

Deletes text.

Parameters
position:int

the position at which the text to delete starts

length:int

the length of the text to delete

numLines:int

the number of lines that are being deleted

errorback to summary
pack-priv void error(int code)

Reports an SWT error.

Parameters
code:int

the error code

expandLinesByback to summary
pack-priv void expandLinesBy(int numLines)

Increases the line indexes array to accommodate more lines.

Parameters
numLines:int

the number to increase the array by

gapExistsback to summary
pack-priv boolean gapExists()

Returns whether or not a gap exists in the text store.

Returns:boolean

true if gap exists, false otherwise

getCharCountback to summary
public int getCharCount()

Implements org.eclipse.swt.custom.StyledTextContent.getCharCount.

Doc from org.eclipse.swt.custom.StyledTextContent.getCharCount.

Return the number of characters in the content.

Returns:int

the logical length of the text store

Annotations
@Override
getFullLineback to summary
pack-priv String getFullLine(int index)

Returns the line at the given index with delimiters.

Parameters
index:int

the index of the line to return

Returns:String

the logical line text (i.e., without the gap) with delimiters

getLineback to summary
public String getLine(int index)

Implements org.eclipse.swt.custom.StyledTextContent.getLine.

Returns the line at index without delimiters.

Parameters
index:int

the index of the line to return

Returns:String

the logical line text (i.e., without the gap)

Annotations
@Override
Exceptions
IllegalArgumentException:
  • ERROR_INVALID_ARGUMENT when index is out of range
getLineAtOffsetback to summary
public int getLineAtOffset(int charPosition)

Implements org.eclipse.swt.custom.StyledTextContent.getLineAtOffset.

Returns the line at the given offset.

Parameters
charPosition:int

logical character offset (i.e., does not include gap)

Returns:int

the line index

Annotations
@Override
Exceptions
IllegalArgumentException:
  • ERROR_INVALID_ARGUMENT when charPosition is out of range
getLineAtPhysicalOffsetback to summary
pack-priv int getLineAtPhysicalOffset(int position)

Returns the line index at the given physical offset.

Parameters
position:int

physical character offset (i.e., includes gap)

Returns:int

the line index

getLineCountback to summary
public int getLineCount()

Implements org.eclipse.swt.custom.StyledTextContent.getLineCount.

Doc from org.eclipse.swt.custom.StyledTextContent.getLineCount.

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:int

the number of lines in the text store

Annotations
@Override
getLineDelimiterback to summary
public String getLineDelimiter()

Implements org.eclipse.swt.custom.StyledTextContent.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.

Returns:String

the platform line delimiter as specified in the line.separator system property.

Annotations
@Override
getOffsetAtLineback to summary
public int getOffsetAtLine(int lineIndex)

Implements org.eclipse.swt.custom.StyledTextContent.getOffsetAtLine.

Returns the logical offset of the given line.

Parameters
lineIndex:int

index of line

Returns:int

the logical starting offset of the line. When there are not any lines, getOffsetAtLine(0) is a valid call that should answer 0.

Annotations
@Override
Exceptions
IllegalArgumentException:
  • ERROR_INVALID_ARGUMENT when lineIndex is out of range
getPhysicalLineback to summary
pack-priv String getPhysicalLine(int index)

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

Parameters
index:int

the line index

Returns:String

the physical line

getPhysicalTextback to summary
pack-priv String getPhysicalText(int start, int length)

Returns a string representing the continuous content of the text store.

Parameters
start:int

the physical start offset of the text to return

length:int

the physical length of the text to return

Returns:String

the text

getTextRangeback to summary
public String getTextRange(int start, int length)

Implements org.eclipse.swt.custom.StyledTextContent.getTextRange.

Returns a string representing the logical content of the text store (i.e., gap stripped out).

Parameters
start:int

the logical start offset of the text to return

length:int

the logical length of the text to return

Returns:String

the text

Annotations
@Override
indexLinesback to summary
pack-priv void indexLines()

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

indexLinesback to summary
pack-priv int[][] indexLines(int offset, int length, int numLines)

Calculates the indexes of each line of text in the given range.

Parameters
offset:int

the logical start offset of the text lineate

length:int

the length of the text to lineate, includes gap

numLines:int

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:int[][]

a line indexes array where each line is identified by a start offset and a length

insertback to summary
pack-priv void insert(int position, String text)

Inserts text.

Parameters
position:int

the position at which to insert the text

text:String

the text to insert

isDelimiterback to summary
pack-priv 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:char

the character to test

Returns:boolean

true if ch is a delimiter, false otherwise

isInsideCRLFback to summary
private boolean isInsideCRLF(int pos)
lineCountback to summary
pack-priv int lineCount(int startOffset, int length)

Returns the number of lines that are in the specified text.

Parameters
startOffset:int

the start of the text to lineate

length:int

the length of the text to lineate

Returns:int

number of lines

lineCountback to summary
pack-priv int lineCount(String text)

Returns the number of lines that are in the specified text.

Parameters
text:String

the text to lineate

Returns:int

number of lines in the text

moveAndResizeGapback to summary
pack-priv 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:int

the position at which a change is occurring

size:int

the size of the change

newGapLine:int

the line where the gap should be put

removeTextChangeListenerback to summary
public void removeTextChangeListener(TextChangeListener listener)

Implements org.eclipse.swt.custom.StyledTextContent.removeTextChangeListener.

Removes the specified TextChangeListener.

Parameters
listener:TextChangeListener

the listener which should no longer be notified

Annotations
@Override
Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT when listener is null
replaceTextRangeback to summary
public void replaceTextRange(int start, int replaceLength, String newText)

Implements org.eclipse.swt.custom.StyledTextContent.replaceTextRange.

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)
Parameters
start:int

start offset of text to replace

replaceLength:int

start offset of text to replace

newText:String

start offset of text to replace

Annotations
@Override
Exceptions
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
sendTextEventback to summary
pack-priv void sendTextEvent(StyledTextEvent event)

Sends the text listeners the TextChanged event.

setTextback to summary
public void setText(String text)

Implements org.eclipse.swt.custom.StyledTextContent.setText.

Sets the content to text and removes the gap since there are no sensible predictions about where the next change will occur.

Parameters
text:String

the text

Annotations
@Override
validateReplaceback to summary
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:int

start offset of text to replace

replaceLength:int

start offset of text to replace