|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.eclipse.swt.custom.WrappedContent
An instance of class WrappedContent
is used by
StyledText to display wrapped lines. Lines are wrapped at word
breaks which are marked by a space character. Trailing space
behind words is kept on the current line.
If the last remaining word on a line can not be fully displayed
the line is wrapped character by character.
WrappedContent wraps a StyledTextContent which provides the line
data. The start offset and length of wrapped lines is calculated
and updated based on recalculation requests and text changes.
All public methods in this class implement the
StyledTextContent
interface. Package visible
methods are internal API for use by StyledText
.
Field Summary | |
(package private) static int |
LINE_LENGTH
|
(package private) static int |
LINE_OFFSET
|
(package private) StyledTextContent |
logicalContent
|
(package private) StyledTextRenderer |
renderer
|
(package private) int |
visualLineCount
|
(package private) int[][] |
visualLines
|
(package private) static int |
WRAP_LINE_LENGTH
|
(package private) static int |
WRAP_LINE_WIDTH
|
Constructor Summary | |
(package private) |
WrappedContent(StyledTextRenderer renderer,
StyledTextContent logicalContent)
Create a new instance. |
Method Summary | |
void |
addTextChangeListener(TextChangeListener listener)
Enabled: Called by StyledText to add itself as an Observer to content changes. |
private void |
ensureSize(int numLines)
Grow the lines array to at least the specified size. |
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)
Returns the visual (wrapped) line at given 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. |
private int |
getTextWidth(String line,
int logicalLineOffset,
int visualLineOffset,
int visualLineLength,
StyleRange[] styles,
int startX,
GC gc)
Measure the width of a segment in the specified logical line. |
(package private) int |
getVisualLineCount()
Returns the number of visual (wrapped) lines. |
private int |
getWordEnd(String line,
int startOffset,
int offset)
Returns the offset of the character after the word at the specified offset. |
private int |
getWordStart(String line,
int startOffset,
int offset)
Returns the start offset of the word at the specified offset. |
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". |
(package private) void |
reset(int startLine,
int lineCount)
Reset the visual (wrapped) lines in the specified range. |
private int |
reset(int startLine,
int lineCount,
boolean wrap)
Reset the visual (wrapped) lines in the specified range. |
private void |
resetVisualLines(int startLine,
int lineCount)
Reset the visual (wrapped) lines in the specified range. |
void |
setText(String text)
Enabled: Set text to "text". |
private void |
setVisualLine(int visualLineIndex,
int visualLineOffset,
int visualLineLength)
Set the line wrap data for the specified visual (wrapped) line. |
(package private) void |
textChanged(int startOffset,
int newLineCount,
int replaceLineCount,
int newCharCount,
int replaceCharCount)
Recalculates the line wrap for the lines affected by the text change. |
private int[] |
wrapLine(String line,
int logicalLineOffset,
int visualLineOffset,
int startX,
int width,
int numChars,
StyleRange[] styles,
GC gc)
Wrap the given logical line at the specified offset. |
private int |
wrapLineRange(int startLine,
int endLine,
int visualLineIndex)
Wrap the logical lines in the given range at the current client area width of the StyledText widget |
private int |
wrapLineRange(int startLine,
int endLine,
int visualLineIndex,
int width)
Wrap the lines in the given range. |
(package private) void |
wrapLines()
Wrap all logical lines at the current client area width of the StyledText widget |
(package private) void |
wrapLines(int width)
Wrap all logical lines at the given width. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
static final int LINE_OFFSET
static final int LINE_LENGTH
static final int WRAP_LINE_LENGTH
static final int WRAP_LINE_WIDTH
StyledTextRenderer renderer
StyledTextContent logicalContent
int[][] visualLines
int visualLineCount
Constructor Detail |
WrappedContent(StyledTextRenderer renderer, StyledTextContent logicalContent)
renderer
- logicalContent
- StyledTextContent that provides the line
data.Method Detail |
public void addTextChangeListener(TextChangeListener listener)
StyledTextContent
addTextChangeListener
in interface StyledTextContent
listener
- the listenerStyledTextContent.addTextChangeListener(TextChangeListener)
private void ensureSize(int numLines)
numLines
- number of elements that the array should have
at a minimumpublic int getCharCount()
StyledTextContent
getCharCount
in interface StyledTextContent
StyledTextContent.getCharCount()
public String getLine(int lineIndex)
StyledTextContent
getLine
in interface StyledTextContent
lineIndex
- index of the line to return. Does not include
delimiters of preceeding lines. Index 0 is the first line of the
content.
StyledTextContent.getLine(int)
public int getLineAtOffset(int offset)
The offset is ambiguous if it identifies the end of a visual line and there is another visual line below. In this case the end of the visual line has the same offset as the beginning of the next visual line since the visual line break is not represented by any character in the logical line. In this ambiguous case the offset is assumed to represent the end of a visual line and the index of the first visual line is returned.
getLineAtOffset
in interface StyledTextContent
offset
- offset of the desired line.
StyledTextContent.getLineAtOffset(int)
public int getLineCount()
StyledTextContent
getLineCount
in interface StyledTextContent
StyledTextContent.getLineCount()
public String getLineDelimiter()
StyledTextContent
getLineDelimiter
in interface StyledTextContent
StyledTextContent.getLineDelimiter()
public int getOffsetAtLine(int lineIndex)
StyledTextContent
NOTE: When there is no text (i.e., no lines), getOffsetAtLine(0) is a valid call that should return 0.
getOffsetAtLine
in interface StyledTextContent
lineIndex
- index of the line. The first line is at index 0.
StyledTextContent.getOffsetAtLine(int)
public String getTextRange(int start, int length)
StyledTextContent
getTextRange
in interface StyledTextContent
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
StyledTextContent.getTextRange(int, int)
int getVisualLineCount()
private int getWordEnd(String line, int startOffset, int offset)
Words are separated by spaces. Trailing spaces are considered part of the word.
line
- logical line the word is instartOffset
- start offset of the line, relative to the start
of the logical line.offset
- offset of the word to return the end of, relative to
the start of the visual line.
private int getWordStart(String line, int startOffset, int offset)
Words are separated by spaces. Trailing spaces are considered part of the word.
line
- logical line the word is instartOffset
- start offset of the line, relative to the start
of the logical line.offset
- offset of the word to return the start of, relative to
the start of the visual line.
public void removeTextChangeListener(TextChangeListener listener)
StyledTextContent
removeTextChangeListener
in interface StyledTextContent
listener
- the listenerStyledTextContent.removeTextChangeListener(TextChangeListener)
void reset(int startLine, int lineCount)
startLine
- index of the first visual linelineCount
- number of visual linesprivate int reset(int startLine, int lineCount, boolean wrap)
startLine
- index of the first visual linelineCount
- number of visual lineswrap
- true=rewrap the logical lines in the reset visual range
false=don't rewrap lines. Visual lines will be left in an inconsistent
state since there will be a range of unwrapped and unknown lines.
private void resetVisualLines(int startLine, int lineCount)
startLine
- index of the first visual linelineCount
- number of visual linespublic void replaceTextRange(int start, int replaceLength, String text)
StyledTextContent
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:
replaceTextRange
in interface StyledTextContent
start
- start offset of text to replace, none of the offsets include
delimiters of preceeding lines, offset 0 is the first character of the
documentreplaceLength
- start offset of text to replaceStyledTextContent.replaceTextRange(int, int, String)
public void setText(String text)
StyledTextContent
TextChangedEvent
to the
textSet method of the TextChangeListeners that were added using
addTextChangeListener
.
setText
in interface StyledTextContent
text
- the new textStyledTextContent.setText(String)
private void setVisualLine(int visualLineIndex, int visualLineOffset, int visualLineLength)
visualLineIndex
- index of the visual linevisualLineOffset
- start offset of the visual line, relative
to the start of the documentvisualLineLength
- length of the visual linevoid textChanged(int startOffset, int newLineCount, int replaceLineCount, int newCharCount, int replaceCharCount)
startOffset
- the start offset of the text changenewLineCount
- the number of inserted linesreplaceLineCount
- the number of deleted linesnewCharCount
- the number of new charactersreplaceCharCount
- the number of deleted charactersprivate int getTextWidth(String line, int logicalLineOffset, int visualLineOffset, int visualLineLength, StyleRange[] styles, int startX, GC gc)
line
- the logical linelogicalLineOffset
- start offset of the logical line, relative
to the start of the documentvisualLineOffset
- offset to start measuring at/start offset
of the visual linevisualLineLength
- length of the segment to measure/the visual
linestyles
- StyleRanges to use during measuringstartX
- x position of the visual line relative to the start
of the logical linegc
- GC to use for measuringprivate int[] wrapLine(String line, int logicalLineOffset, int visualLineOffset, int startX, int width, int numChars, StyleRange[] styles, GC gc)
line
- the logical linelogicalLineOffset
- offset of the logical line, relative to the
beginning of the contentvisualLineOffset
- start offset of the new visual line, relative
to the start of the logical line.startX
- x position of visualLineOffset, relative to the beginning
of the logical linewidth
- width to wrap the line tonumChars
- average number of characters that fit into widthstyles
- StyleRanges to use for measuring the wrapped linegc
- GC to use for measuring
private int wrapLineRange(int startLine, int endLine, int visualLineIndex)
startLine
- first logical line to wrapendLine
- line after last logical linevisualLineIndex
- visual (wrapped) line index that startLine
corresponds to.
private int wrapLineRange(int startLine, int endLine, int visualLineIndex, int width)
startLine
- first logical line to wrapendLine
- line after last logical linevisualLineIndex
- visual (wrapped) line index that startLine
corresponds to.width
- line width to wrap at
void wrapLines()
void wrapLines(int width)
width
- width to wrap lines at
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |