|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
org.eclipse.swt.custom.StyledText
public class StyledText
A StyledText is an editable user interface object that displays lines of text. The following style attributes can be defined for the text:
In addition to text style attributes, the background color of a line may be specified.
There are two ways to use this widget when specifying text style information. You may use the API that is defined for StyledText or you may define your own LineStyleListener. If you define your own listener, you will be responsible for maintaining the text style information for the widget. IMPORTANT: You may not define your own listener and use the StyledText API. The following StyledText API is not supported if you have defined a LineStyleListener:
There are two ways to use this widget when specifying line background colors. You may use the API that is defined for StyledText or you may define your own LineBackgroundListener. If you define your own listener, you will be responsible for maintaining the line background color information for the widget. IMPORTANT: You may not define your own listener and use the StyledText API. The following StyledText API is not supported if you have defined a LineBackgroundListener:
The content implementation for this widget may also be user-defined. To do so, you must implement the StyledTextContent interface and use the StyledText API setContent(StyledTextContent) to initialize the widget.
IMPORTANT: This class is not intended to be subclassed.
Field Summary |
---|
Fields inherited from class org.eclipse.swt.widgets.Composite |
---|
embeddedHandle |
Fields inherited from class org.eclipse.swt.widgets.Widget |
---|
handle |
Constructor Summary | |
---|---|
StyledText(Composite parent,
int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. |
Method Summary | |
---|---|
void |
addBidiSegmentListener(BidiSegmentListener listener)
Adds a bidirectional segment listener. |
void |
addCaretListener(CaretListener listener)
Adds a caret listener. |
void |
addExtendedModifyListener(ExtendedModifyListener extendedModifyListener)
Adds an extended modify listener. |
void |
addLineBackgroundListener(LineBackgroundListener listener)
Adds a line background listener. |
void |
addLineStyleListener(LineStyleListener listener)
Adds a line style listener. |
void |
addModifyListener(ModifyListener modifyListener)
Adds a modify listener. |
void |
addPaintObjectListener(PaintObjectListener listener)
Adds a paint object listener. |
void |
addSelectionListener(SelectionListener listener)
Adds a selection listener. |
void |
addVerifyKeyListener(VerifyKeyListener listener)
Adds a verify key listener. |
void |
addVerifyListener(VerifyListener verifyListener)
Adds a verify listener. |
void |
addWordMovementListener(MovementListener movementListener)
Adds a word movement listener. |
void |
append(java.lang.String string)
Appends a string to the text at the end of the widget. |
Point |
computeSize(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver. |
void |
copy()
Copies the selected text to the DND.CLIPBOARD clipboard. |
void |
copy(int clipboardType)
Copies the selected text to the specified clipboard. |
void |
cut()
Moves the selected text to the clipboard. |
int |
getAlignment()
Returns the alignment of the widget. |
Color |
getBackground()
Returns the receiver's background color. |
int |
getBaseline()
Returns the baseline, in pixels. |
int |
getBaseline(int offset)
Returns the baseline at the given offset, in pixels. |
boolean |
getBidiColoring()
Deprecated. use BidiSegmentListener instead. |
boolean |
getBlockSelection()
TEMPORARY CODE - API SUBJECT TO CHANGE Returns whether the widget is in block selection mode. |
int |
getCaretOffset()
Returns the caret position relative to the start of the text. |
int |
getCharCount()
Gets the number of characters. |
StyledTextContent |
getContent()
Returns the content implementation that is used for text storage. |
boolean |
getDoubleClickEnabled()
Returns whether the widget implements double click mouse behavior. |
boolean |
getDragDetect()
Returns true if the receiver is detecting
drag gestures, and false otherwise. |
boolean |
getEditable()
Returns whether the widget content can be edited. |
Color |
getForeground()
Returns the foreground color that the receiver will use to draw. |
int |
getHorizontalIndex()
Returns the horizontal scroll offset relative to the start of the line. |
int |
getHorizontalPixel()
Returns the horizontal scroll offset relative to the start of the line. |
int |
getIndent()
Returns the line indentation of the widget. |
boolean |
getJustify()
Returns whether the widget justifies lines. |
int |
getKeyBinding(int key)
Returns the action assigned to the key. |
java.lang.String |
getLine(int lineIndex)
Returns the line at the given line index without delimiters. |
int |
getLineAlignment(int index)
Returns the alignment of the line at the given index. |
int |
getLineAtOffset(int offset)
Returns the line at the specified offset in the text where 0 < offset < getCharCount() so that getLineAtOffset(getCharCount()) returns the line of the insert location. |
Color |
getLineBackground(int index)
Returns the background color of the line at the given index. |
Bullet |
getLineBullet(int index)
Returns the bullet of the line at the given index. |
int |
getLineCount()
Gets the number of text lines. |
java.lang.String |
getLineDelimiter()
Returns the line delimiter used for entering new lines by key down or paste operation. |
int |
getLineHeight()
Returns the line height. |
int |
getLineHeight(int offset)
Returns the line height at the given offset. |
int |
getLineIndent(int index)
Returns the indentation of the line at the given index. |
int |
getLineIndex(int y)
Returns the line index for a y, relative to the client area. |
boolean |
getLineJustify(int index)
Returns whether the line at the given index is justified. |
int |
getLinePixel(int lineIndex)
Returns the top pixel, relative to the client area, of a given line. |
int |
getLineSpacing()
Returns the line spacing of the widget. |
Point |
getLocationAtOffset(int offset)
Returns the x, y location of the upper left corner of the character bounding box at the specified offset in the text. |
int |
getOffsetAtLine(int lineIndex)
Returns the character offset of the first character of the given line. |
int |
getOffsetAtLocation(Point point)
Returns the offset of the character at the given location relative to the first character in the document. |
int |
getOrientation()
Returns the orientation of the receiver. |
int[] |
getRanges()
Returns all the ranges of text that have an associated StyleRange. |
int[] |
getRanges(int start,
int length)
Returns the ranges of text that have an associated StyleRange. |
Point |
getSelection()
Returns the selection. |
Color |
getSelectionBackground()
Returns the receiver's selection background color. |
int |
getSelectionCount()
Gets the number of selected characters. |
Color |
getSelectionForeground()
Returns the receiver's selection foreground color. |
Point |
getSelectionRange()
Returns the selection. |
int[] |
getSelectionRanges()
TEMPORARY CODE - API SUBJECT TO CHANGE Returns the ranges of text that are inside the block selection rectangle. |
java.lang.String |
getSelectionText()
Returns the selected text. |
int |
getStyle()
Returns the receiver's style information. |
StyleRange |
getStyleRangeAtOffset(int offset)
Returns the style range at the given offset. |
StyleRange[] |
getStyleRanges()
Returns the styles. |
StyleRange[] |
getStyleRanges(boolean includeRanges)
Returns the styles. |
StyleRange[] |
getStyleRanges(int start,
int length)
Returns the styles for the given text range. |
StyleRange[] |
getStyleRanges(int start,
int length,
boolean includeRanges)
Returns the styles for the given text range. |
int |
getTabs()
Returns the tab width measured in characters. |
java.lang.String |
getText()
Returns a copy of the widget content. |
java.lang.String |
getText(int start,
int end)
Returns the widget content between the two offsets. |
Rectangle |
getTextBounds(int start,
int end)
Returns the smallest bounding rectangle that includes the characters between two offsets. |
int |
getTextLimit()
Returns the maximum number of characters that the receiver is capable of holding. |
java.lang.String |
getTextRange(int start,
int length)
Returns the widget content starting at start for length characters. |
int |
getTopIndex()
Gets the top index. |
int |
getTopPixel()
Gets the top pixel. |
boolean |
getWordWrap()
Returns whether the widget wraps lines. |
void |
insert(java.lang.String string)
Inserts a string. |
void |
invokeAction(int action)
Executes the action. |
void |
paste()
Replaces the selection with the text on the DND.CLIPBOARD
clipboard or, if there is no selection, inserts the text at the current
caret offset. |
void |
print()
Prints the widget's text to the default printer. |
java.lang.Runnable |
print(Printer printer)
Returns a runnable that will print the widget's text to the specified printer. |
java.lang.Runnable |
print(Printer printer,
StyledTextPrintOptions options)
Returns a runnable that will print the widget's text to the specified printer. |
void |
redraw()
Causes the entire bounds of the receiver to be marked as needing to be redrawn. |
void |
redraw(int x,
int y,
int width,
int height,
boolean all)
Causes the rectangular area of the receiver specified by the arguments to be marked as needing to be redrawn. |
void |
redrawRange(int start,
int length,
boolean clearBackground)
Redraws the specified text range. |
void |
removeBidiSegmentListener(BidiSegmentListener listener)
Removes the specified bidirectional segment listener. |
void |
removeCaretListener(CaretListener listener)
Removes the specified caret listener. |
void |
removeExtendedModifyListener(ExtendedModifyListener extendedModifyListener)
Removes the specified extended modify listener. |
void |
removeLineBackgroundListener(LineBackgroundListener listener)
Removes the specified line background listener. |
void |
removeLineStyleListener(LineStyleListener listener)
Removes the specified line style listener. |
void |
removeModifyListener(ModifyListener modifyListener)
Removes the specified modify listener. |
void |
removePaintObjectListener(PaintObjectListener listener)
Removes the specified listener. |
void |
removeSelectionListener(SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection. |
void |
removeVerifyKeyListener(VerifyKeyListener listener)
Removes the specified key verify listener. |
void |
removeVerifyListener(VerifyListener verifyListener)
Removes the specified verify listener. |
void |
removeWordMovementListener(MovementListener listener)
Removes the specified word movement listener. |
void |
replaceStyleRanges(int start,
int length,
StyleRange[] ranges)
Replaces the styles in the given range with new styles. |
void |
replaceTextRange(int start,
int length,
java.lang.String text)
Replaces the given text range with new text. |
void |
scroll(int destX,
int destY,
int x,
int y,
int width,
int height,
boolean all)
Scrolls a rectangular area of the receiver by first copying the source area to the destination and then causing the area of the source which is not covered by the destination to be repainted. |
void |
selectAll()
Selects all the text. |
void |
setAlignment(int alignment)
Sets the alignment of the widget. |
void |
setBackground(Color color)
Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null. |
void |
setBidiColoring(boolean mode)
Deprecated. use BidiSegmentListener instead. |
void |
setBlockSelection(boolean blockSelection)
TEMPORARY CODE - API SUBJECT TO CHANGE Sets the block selection mode. |
void |
setCaret(Caret caret)
Sets the receiver's caret. |
void |
setCaretOffset(int offset)
Sets the caret offset. |
void |
setContent(StyledTextContent newContent)
Sets the content implementation to use for text storage. |
void |
setCursor(Cursor cursor)
Sets the receiver's cursor to the cursor specified by the argument. |
void |
setDoubleClickEnabled(boolean enable)
Sets whether the widget implements double click mouse behavior. |
void |
setDragDetect(boolean dragDetect)
Sets the receiver's drag detect state. |
void |
setEditable(boolean editable)
Sets whether the widget content can be edited. |
void |
setFont(Font font)
Sets a new font to render text with. |
void |
setForeground(Color color)
Sets the receiver's foreground color to the color specified by the argument, or to the default system color for the control if the argument is null. |
void |
setHorizontalIndex(int offset)
Sets the horizontal scroll offset relative to the start of the line. |
void |
setHorizontalPixel(int pixel)
Sets the horizontal pixel offset relative to the start of the line. |
void |
setIndent(int indent)
Sets the line indentation of the widget. |
void |
setJustify(boolean justify)
Sets whether the widget should justify lines. |
void |
setKeyBinding(int key,
int action)
Maps a key to an action. |
void |
setLineAlignment(int startLine,
int lineCount,
int alignment)
Sets the alignment of the specified lines. |
void |
setLineBackground(int startLine,
int lineCount,
Color background)
Sets the background color of the specified lines. |
void |
setLineBullet(int startLine,
int lineCount,
Bullet bullet)
Sets the bullet of the specified lines. |
void |
setLineIndent(int startLine,
int lineCount,
int indent)
Sets the indent of the specified lines. |
void |
setLineJustify(int startLine,
int lineCount,
boolean justify)
Sets the justify of the specified lines. |
void |
setLineSpacing(int lineSpacing)
Sets the line spacing of the widget. |
void |
setOrientation(int orientation)
Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT . |
void |
setSelection(int start)
Sets the selection to the given position and scrolls it into view. |
void |
setSelection(int start,
int end)
Sets the selection and scrolls it into view. |
void |
setSelection(Point point)
Sets the selection and scrolls it into view. |
void |
setSelectionBackground(Color color)
Sets the receiver's selection background color to the color specified by the argument, or to the default system color for the control if the argument is null. |
void |
setSelectionForeground(Color color)
Sets the receiver's selection foreground color to the color specified by the argument, or to the default system color for the control if the argument is null. |
void |
setSelectionRange(int start,
int length)
Sets the selection. |
void |
setStyleRange(StyleRange range)
Adds the specified style. |
void |
setStyleRanges(int[] ranges,
StyleRange[] styles)
Sets styles to be used for rendering the widget content. |
void |
setStyleRanges(int start,
int length,
int[] ranges,
StyleRange[] styles)
Clears the styles in the range specified by start and
length and adds the new styles. |
void |
setStyleRanges(StyleRange[] ranges)
Sets styles to be used for rendering the widget content. |
void |
setTabs(int tabs)
Sets the tab width. |
void |
setText(java.lang.String text)
Sets the widget content. |
void |
setTextLimit(int limit)
Sets the text limit to the specified number of characters. |
void |
setTopIndex(int topIndex)
Sets the top index. |
void |
setTopPixel(int pixel)
Sets the top pixel offset. |
void |
setWordWrap(boolean wrap)
Sets whether the widget wraps lines. |
void |
showSelection()
Scrolls the selection into view. |
Methods inherited from class org.eclipse.swt.widgets.Canvas |
---|
drawBackground, getCaret, getIME, setIME |
Methods inherited from class org.eclipse.swt.widgets.Composite |
---|
changed, checkSubclass, getBackgroundMode, getChildren, getClientArea, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
---|
computeTrim, getBorderWidth, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Widget |
---|
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public StyledText(Composite parent, int style)
The style value is either one of the style constants defined in
class SWT
which is applicable to instances of this
class, or must be built by bitwise OR'ing together
(that is, using the int
"|" operator) two or more
of those SWT
style constants. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct
java.lang.IllegalArgumentException
- SWTException
- SWT.FULL_SELECTION
,
SWT.MULTI
,
SWT.READ_ONLY
,
SWT.SINGLE
,
SWT.WRAP
,
getStyle()
Method Detail |
---|
public void addExtendedModifyListener(ExtendedModifyListener extendedModifyListener)
extendedModifyListener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addBidiSegmentListener(BidiSegmentListener listener)
A BidiSegmentEvent is sent whenever a line of text is measured or rendered. The user can specify text ranges in the line that should be treated as if they had a different direction than the surrounding text. This may be used when adjacent segments of right-to-left text should not be reordered relative to each other. E.g., Multiple Java string literals in a right-to-left language should generally remain in logical order to each other, that is, the way they are stored.
listener
- the listener
SWTException
- java.lang.IllegalArgumentException
- BidiSegmentEvent
public void addCaretListener(CaretListener listener)
listener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addLineBackgroundListener(LineBackgroundListener listener)
listener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addLineStyleListener(LineStyleListener listener)
listener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addModifyListener(ModifyListener modifyListener)
modifyListener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addPaintObjectListener(PaintObjectListener listener)
listener
- the listener
SWTException
- java.lang.IllegalArgumentException
- PaintObjectListener
,
PaintObjectEvent
public void addSelectionListener(SelectionListener listener)
When widgetSelected
is called, the event x and y fields contain
the start and end caret indices of the selection.
widgetDefaultSelected
is not called for StyledTexts.
listener
- the listener which should be notified when the user changes the receiver's selection
java.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
public void addVerifyKeyListener(VerifyKeyListener listener)
listener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addVerifyListener(VerifyListener verifyListener)
verifyListener
- the listener
SWTException
- java.lang.IllegalArgumentException
- public void addWordMovementListener(MovementListener movementListener)
movementListener
- the listener
SWTException
- java.lang.IllegalArgumentException
- MovementEvent
,
MovementListener
,
removeWordMovementListener(org.eclipse.swt.custom.MovementListener)
public void append(java.lang.String string)
string
- the string to be appended
SWTException
- java.lang.IllegalArgumentException
- replaceTextRange(int,int,String)
public Point computeSize(int wHint, int hHint, boolean changed)
Control
The preferred size of a control is the size that it would
best be displayed at. The width hint and height hint arguments
allow the caller to ask a control questions such as "Given a particular
width, how high does the control need to be to show all of the contents?"
To indicate that the caller does not wish to constrain a particular
dimension, the constant SWT.DEFAULT
is passed for the hint.
If the changed flag is true
, it indicates that the receiver's
contents have changed, therefore any caches that a layout manager
containing the control may have been keeping need to be flushed. When the
control is resized, the changed flag will be false
, so layout
manager caches can be retained.
computeSize
in class Composite
wHint
- the width hint (can be SWT.DEFAULT
)hHint
- the height hint (can be SWT.DEFAULT
)changed
- true
if the control's contents have changed, and false
otherwise
Layout
,
Control.getBorderWidth()
,
Control.getBounds()
,
Control.getSize()
,
Control.pack(boolean)
,
"computeTrim, getClientArea for controls that implement them"public void copy()
DND.CLIPBOARD
clipboard.
The text will be put on the clipboard in plain text format and RTF format.
The DND.CLIPBOARD
clipboard is used for data that is
transferred by keyboard accelerator (such as Ctrl+C/Ctrl+V) or
by menu action.
SWTException
- public void copy(int clipboardType)
The clipboardType is one of the clipboard constants defined in class
DND
. The DND.CLIPBOARD
clipboard is
used for data that is transferred by keyboard accelerator (such as Ctrl+C/Ctrl+V)
or by menu action. The DND.SELECTION_CLIPBOARD
clipboard is used for data that is transferred by selecting text and pasting
with the middle mouse button.
clipboardType
- indicates the type of clipboard
SWTException
- public int getAlignment()
SWTException
- getLineAlignment(int)
public void cut()
SWTException
- public Color getBackground()
Control
getBackground
in class Control
public int getBaseline()
SWTException
- getBaseline(int)
public int getBaseline(int offset)
offset
- the offset
SWTException
- java.lang.IllegalArgumentException
- public boolean getBidiColoring()
SWTException
- public boolean getBlockSelection()
SWTException
- public int getCaretOffset()
SWTException
- public StyledTextContent getContent()
SWTException
- public boolean getDragDetect()
Control
true
if the receiver is detecting
drag gestures, and false
otherwise.
getDragDetect
in class Control
public boolean getDoubleClickEnabled()
SWTException
- public boolean getEditable()
SWTException
- public Color getForeground()
Control
getForeground
in class Control
public int getHorizontalIndex()
SWTException
- public int getHorizontalPixel()
SWTException
- public int getIndent()
SWTException
- getLineIndent(int)
public boolean getJustify()
SWTException
- getLineJustify(int)
public int getKeyBinding(int key)
key
- a key code defined in SWT.java or a character.
Optionally ORd with a state mask. Preferred state masks are one or more of
SWT.MOD1, SWT.MOD2, SWT.MOD3, since these masks account for modifier platform
differences. However, there may be cases where using the specific state masks
(i.e., SWT.CTRL, SWT.SHIFT, SWT.ALT, SWT.COMMAND) makes sense.
SWTException
- public int getCharCount()
SWTException
- public java.lang.String getLine(int lineIndex)
lineIndex
- index of the line to return.
SWTException
- java.lang.IllegalArgumentException
- public int getLineAlignment(int index)
index
- the index of the line
SWTException
- java.lang.IllegalArgumentException
- getAlignment()
public int getLineAtOffset(int offset)
offset
- offset relative to the start of the content.
0 <= offset <= getCharCount()
SWTException
- java.lang.IllegalArgumentException
- public Color getLineBackground(int index)
index
- the index of the line
SWTException
- java.lang.IllegalArgumentException
- public Bullet getLineBullet(int index)
index
- the index of the line
SWTException
- java.lang.IllegalArgumentException
- public int getLineCount()
SWTException
- public java.lang.String getLineDelimiter()
SWTException
- public int getLineHeight()
Note: this API should not be used if a StyleRange attribute causes lines to have different heights (i.e. different fonts, rise, etc).
SWTException
- getLineHeight(int)
public int getLineHeight(int offset)
offset
- the offset
SWTException
- java.lang.IllegalArgumentException
- public int getLineIndent(int index)
index
- the index of the line
SWTException
- java.lang.IllegalArgumentException
- getIndent()
public boolean getLineJustify(int index)
index
- the index of the line
SWTException
- java.lang.IllegalArgumentException
- getJustify()
public int getLineSpacing()
SWTException
- public int getLinePixel(int lineIndex)
lineIndex
- the line index, the max value is lineCount. If
lineIndex == lineCount it returns the bottom pixel of the last line.
It means this function can be used to retrieve the bottom pixel of any line.
public int getLineIndex(int y)
y
- the y-coordinate pixel
public Point getLocationAtOffset(int offset)
offset
- offset relative to the start of the content.
0 <= offset <= getCharCount()
SWTException
- java.lang.IllegalArgumentException
- public int getOffsetAtLine(int lineIndex)
lineIndex
- index of the line, 0 based relative to the first
line in the content. 0 <= lineIndex < getLineCount(), except
lineIndex may always be 0
SWTException
- java.lang.IllegalArgumentException
- public int getOffsetAtLocation(Point point)
The return value reflects the character offset that the caret will be placed at if a mouse click occurred at the specified location. If the x coordinate of the location is beyond the center of a character the returned offset will be behind the character.
point
- the origin of character bounding box relative to
the origin of the widget client area.
SWTException
- java.lang.IllegalArgumentException
- public int getOrientation()
SWTException
- public int[] getRanges()
The ranges array contains start and length pairs. Each pair refers to
the corresponding style in the styles array. For example, the pair
that starts at ranges[n] with length ranges[n+1] uses the style
at styles[n/2] returned by getStyleRanges(int, int, boolean)
.
SWTException
- getStyleRanges(boolean)
public int[] getRanges(int start, int length)
The ranges array contains start and length pairs. Each pair refers to
the corresponding style in the styles array. For example, the pair
that starts at ranges[n] with length ranges[n+1] uses the style
at styles[n/2] returned by getStyleRanges(int, int, boolean)
.
start
- the start offset of the style ranges to returnlength
- the number of style ranges to return
SWTException
- java.lang.IllegalArgumentException
- getStyleRanges(int, int, boolean)
public Point getSelection()
Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N
SWTException
- getSelectionRange()
public Point getSelectionRange()
SWTException
- public int[] getSelectionRanges()
The ranges array contains start and length pairs. When the receiver is not in block selection mode the return arrays contains the start and length of the regular selection.
SWTException
- public Color getSelectionBackground()
SWTException
- public int getSelectionCount()
SWTException
- public Color getSelectionForeground()
SWTException
- public java.lang.String getSelectionText()
SWTException
- public int getStyle()
Widget
Note that the value which is returned by this method may
not match the value which was provided to the constructor
when the receiver was created. This can occur when the underlying
operating system does not support a particular combination of
requested styles. For example, if the platform widget used to
implement a particular SWT widget always has scroll bars, the
result of calling this method would always have the
SWT.H_SCROLL
and SWT.V_SCROLL
bits set.
getStyle
in class Widget
public StyleRange getStyleRangeAtOffset(int offset)
Returns null if a LineStyleListener has been set or if a style is not set for the offset. Should not be called if a LineStyleListener has been set since the listener maintains the styles.
offset
- the offset to return the style for.
0 <= offset < getCharCount() must be true.
SWTException
- java.lang.IllegalArgumentException
- public StyleRange[] getStyleRanges()
Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles.
Note: Because a StyleRange includes the start and length, the same instance cannot occur multiple times in the array of styles. If the same style attributes, such as font and color, occur in multiple StyleRanges,getStyleRanges(boolean)
can be used to get the styles without the ranges.
SWTException
- getStyleRanges(boolean)
public StyleRange[] getStyleRanges(boolean includeRanges)
Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles.
Note: When includeRanges
is true, the start and length
fields of each StyleRange will be valid, however the StyleRange
objects may need to be cloned. When includeRanges
is
false, getRanges(int, int)
can be used to get the
associated ranges.
includeRanges
- whether the start and length field of the StyleRanges should be set.
SWTException
- getRanges(int, int)
,
setStyleRanges(int[], StyleRange[])
public StyleRange[] getStyleRanges(int start, int length)
Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles.
Note: Because the StyleRange includes the start and length, the
same instance cannot occur multiple times in the array of styles.
If the same style attributes, such as font and color, occur in
multiple StyleRanges, getStyleRanges(int, int, boolean)
can be used to get the styles without the ranges.
start
- the start offset of the style ranges to returnlength
- the number of style ranges to return
StyleRange
will have a starting offset >= start
and the last returned StyleRange
will have an ending
offset <= start + length - 1
SWTException
- java.lang.IllegalArgumentException
- getStyleRanges(int, int, boolean)
public StyleRange[] getStyleRanges(int start, int length, boolean includeRanges)
Returns an empty array if a LineStyleListener has been set. Should not be called if a LineStyleListener has been set since the listener maintains the styles.
Note: When includeRanges
is true, the start and length
fields of each StyleRange will be valid, however the StyleRange
objects may need to be cloned. When includeRanges
is
false, getRanges(int, int)
can be used to get the
associated ranges.
start
- the start offset of the style ranges to returnlength
- the number of style ranges to returnincludeRanges
- whether the start and length field of the StyleRanges should be set.
StyleRange
will have a starting offset >= start
and the last returned StyleRange
will have an ending
offset <= start + length - 1
SWTException
- java.lang.IllegalArgumentException
- getRanges(int, int)
,
setStyleRanges(int[], StyleRange[])
public int getTabs()
SWTException
- public java.lang.String getText()
SWTException
- public java.lang.String getText(int start, int end)
start
- offset of the first character in the returned Stringend
- offset of the last character in the returned String
SWTException
- java.lang.IllegalArgumentException
- getTextRange(int,int)
public Rectangle getTextBounds(int start, int end)
start
- offset of the first character included in the bounding boxend
- offset of the last character included in the bounding box
SWTException
- java.lang.IllegalArgumentException
- public java.lang.String getTextRange(int start, int length)
start
- offset of the first character in the returned Stringlength
- number of characters to return
SWTException
- java.lang.IllegalArgumentException
- public int getTextLimit()
SWTException
- public int getTopIndex()
The top index is the index of the fully visible line that is currently at the top of the widget or the topmost partially visible line if no line is fully visible. The top index changes when the widget is scrolled. Indexing is zero based.
SWTException
- public int getTopPixel()
The top pixel is the pixel position of the line that is currently at the top of the widget. The text widget can be scrolled by pixels by dragging the scroll thumb so that a partial line may be displayed at the top the widget. The top pixel changes when the widget is scrolled. The top pixel does not include the widget trimming.
SWTException
- public boolean getWordWrap()
public void insert(java.lang.String string)
string
- the string
SWTException
- java.lang.IllegalArgumentException
- replaceTextRange(int,int,String)
public void invokeAction(int action)
action
- one of the actions defined in ST.javapublic void paste()
DND.CLIPBOARD
clipboard or, if there is no selection, inserts the text at the current
caret offset. If the widget has the SWT.SINGLE style and the
clipboard text contains more than one line, only the first line without
line delimiters is inserted in the widget.
SWTException
- public void print()
SWTException
- public java.lang.Runnable print(Printer printer)
The runnable may be run in a non-UI thread.
printer
- the printer to print to
Runnable
for printing the receiver's text
SWTException
- java.lang.IllegalArgumentException
- public java.lang.Runnable print(Printer printer, StyledTextPrintOptions options)
The runnable may be run in a non-UI thread.
printer
- the printer to print tooptions
- print options to use during printing
Runnable
for printing the receiver's text
SWTException
- java.lang.IllegalArgumentException
- public void redraw()
Recalculates the content width for all lines in the bounds.
When a LineStyleListener
is used a redraw call
is the only notification to the widget that styles have changed
and that the content width may have changed.
redraw
in class Control
SWTException
- Control.update()
public void redraw(int x, int y, int width, int height, boolean all)
all
flag
is true
, any children of the receiver which
intersect with the specified area will also paint their
intersecting areas. If the all
flag is
false
, the children will not be painted.
Marks the content width of all lines in the specified rectangle
as unknown. Recalculates the content width of all visible lines.
When a LineStyleListener
is used a redraw call
is the only notification to the widget that styles have changed
and that the content width may have changed.
redraw
in class Control
x
- the x coordinate of the area to drawy
- the y coordinate of the area to drawwidth
- the width of the area to drawheight
- the height of the area to drawall
- true
if children should redraw, and false
otherwise
SWTException
- Control.update()
public void redrawRange(int start, int length, boolean clearBackground)
start
- offset of the first character to redrawlength
- number of characters to redrawclearBackground
- true if the background should be cleared as
part of the redraw operation. If true, the entire redraw range will
be cleared before anything is redrawn. If the redraw range includes
the last character of a line (i.e., the entire line is redrawn) the
line is cleared all the way to the right border of the widget.
The redraw operation will be faster and smoother if clearBackground
is set to false. Whether or not the flag can be set to false depends
on the type of change that has taken place. If font styles or
background colors for the redraw range have changed, clearBackground
should be set to true. If only foreground colors have changed for
the redraw range, clearBackground can be set to false.
SWTException
- java.lang.IllegalArgumentException
- public void removeBidiSegmentListener(BidiSegmentListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeCaretListener(CaretListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeExtendedModifyListener(ExtendedModifyListener extendedModifyListener)
extendedModifyListener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeLineBackgroundListener(LineBackgroundListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeLineStyleListener(LineStyleListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeModifyListener(ModifyListener modifyListener)
modifyListener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removePaintObjectListener(PaintObjectListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeSelectionListener(SelectionListener listener)
listener
- the listener which should no longer be notified
java.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
public void removeVerifyListener(VerifyListener verifyListener)
verifyListener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeVerifyKeyListener(VerifyKeyListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- public void removeWordMovementListener(MovementListener listener)
listener
- the listener which should no longer be notified
SWTException
- java.lang.IllegalArgumentException
- MovementEvent
,
MovementListener
,
addWordMovementListener(org.eclipse.swt.custom.MovementListener)
public void replaceStyleRanges(int start, int length, StyleRange[] ranges)
Note: Because a StyleRange includes the start and length, the
same instance cannot occur multiple times in the array of styles.
If the same style attributes, such as font and color, occur in
multiple StyleRanges, setStyleRanges(int, int, int[], StyleRange[])
can be used to share styles and reduce memory usage.
Should not be called if a LineStyleListener has been set since the listener maintains the styles.
start
- offset of first character where styles will be deletedlength
- length of the range to delete styles inranges
- StyleRange objects containing the new style information.
The ranges should not overlap and should be within the specified start
and length. The style rendering is undefined if the ranges do overlap
or are ill-defined. Must not be null.
SWTException
- java.lang.IllegalArgumentException
- setStyleRanges(int, int, int[], StyleRange[])
public void replaceTextRange(int start, int length, java.lang.String text)
NOTE: During the replace operation the current selection is changed as follows:
start
- offset of first character to replacelength
- number of characters to replace. Use 0 to insert texttext
- new text. May be empty to delete text.
SWTException
- java.lang.IllegalArgumentException
- public void scroll(int destX, int destY, int x, int y, int width, int height, boolean all)
Canvas
scroll
in class Canvas
destX
- the x coordinate of the destinationdestY
- the y coordinate of the destinationx
- the x coordinate of the sourcey
- the y coordinate of the sourcewidth
- the width of the areaheight
- the height of the areaall
- true
if children should be scrolled, and false
otherwisepublic void selectAll()
SWTException
- public void setAlignment(int alignment)
SWT.LEFT
,
SWT.CENTER
or SWT.RIGHT
. The alignment applies for all lines.
Note that if SWT.MULTI
is set, then SWT.WRAP
must also be set
in order to stabilize the right edge before setting alignment.
alignment
- the new alignment
SWTException
- setLineAlignment(int, int, int)
public void setBackground(Color color)
Control
Note: This operation is a hint and may be overridden by the platform. For example, on Windows the background of a Button cannot be changed.
setBackground
in class Control
color
- the new color (or null)Control.setBackground(Color)
public void setBlockSelection(boolean blockSelection)
blockSelection
- true=enable block selection, false=disable block selectionpublic void setCaret(Caret caret)
setCaret
in class Canvas
caret
- the new caret for the receiver
SWTException
- public void setBidiColoring(boolean mode)
mode
- the new coloring mode
SWTException
- public void setCaretOffset(int offset)
offset
- caret offset, relative to the first character in the text.
SWTException
- java.lang.IllegalArgumentException
- public void setContent(StyledTextContent newContent)
newContent
- StyledTextContent implementation to use for text storage.
SWTException
- java.lang.IllegalArgumentException
- public void setCursor(Cursor cursor)
setCursor
in class Control
cursor
- the new cursor (or null)Control.setCursor(Cursor)
public void setDoubleClickEnabled(boolean enable)
enable
- if true double clicking a word selects the word, if false
double clicks have the same effect as regular mouse clicks.
SWTException
- public void setDragDetect(boolean dragDetect)
Control
true
, the receiver will detect drag gestures,
otherwise these gestures will be ignored.
setDragDetect
in class Control
dragDetect
- the new drag detect statepublic void setEditable(boolean editable)
editable
- if true content can be edited, if false content can not be
edited
SWTException
- public void setFont(Font font)
NOTE: Italic fonts are not supported unless they have no overhang and the same baseline as regular fonts.
setFont
in class Canvas
font
- new font
SWTException
- public void setForeground(Color color)
Control
Note: This operation is a hint and may be overridden by the platform.
setForeground
in class Control
color
- the new color (or null)public void setHorizontalIndex(int offset)
NOTE: The horizontal index is reset to 0 when new text is set in the widget.
offset
- horizontal scroll offset relative to the start
of the line, measured in character increments starting at 0, if
equal to 0 the content is not scrolled, if > 0 = the content is scrolled.
SWTException
- public void setHorizontalPixel(int pixel)
NOTE: The horizontal pixel offset is reset to 0 when new text is set in the widget.
pixel
- horizontal pixel offset relative to the start
of the line.
SWTException
- public void setIndent(int indent)
It is the amount of blank space, in pixels, at the beginning of each line. When a line wraps in several lines only the first one is indented.
indent
- the new indent
SWTException
- setLineIndent(int, int, int)
public void setJustify(boolean justify)
justify
- whether lines should be justified
SWTException
- setLineJustify(int, int, boolean)
public void setKeyBinding(int key, int action)
One action can be associated with N keys. However, each key can only have one action (key:action is N:1 relation).
key
- a key code defined in SWT.java or a character.
Optionally ORd with a state mask. Preferred state masks are one or more of
SWT.MOD1, SWT.MOD2, SWT.MOD3, since these masks account for modifier platform
differences. However, there may be cases where using the specific state masks
(i.e., SWT.CTRL, SWT.SHIFT, SWT.ALT, SWT.COMMAND) makes sense.action
- one of the predefined actions defined in ST.java.
Use SWT.NULL to remove a key binding.
SWTException
- public void setLineAlignment(int startLine, int lineCount, int alignment)
SWT.LEFT
,
SWT.CENTER
or SWT.RIGHT
.
Note that if SWT.MULTI
is set, then SWT.WRAP
must also be set
in order to stabilize the right edge before setting alignment.
All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter.
When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged.
startLine
- first line the alignment is applied to, 0 basedlineCount
- number of lines the alignment applies to.alignment
- line alignment
SWTException
- java.lang.IllegalArgumentException
- setAlignment(int)
public void setLineBackground(int startLine, int lineCount, Color background)
The background color is drawn for the width of the widget. All line background colors are discarded when setText is called. The text background color if defined in a StyleRange overlays the line background color.
Should not be called if a LineBackgroundListener has been set since the listener maintains the line backgrounds.
All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter.
When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged.
startLine
- first line the color is applied to, 0 basedlineCount
- number of lines the color applies to.background
- line background color
SWTException
- java.lang.IllegalArgumentException
- public void setLineBullet(int startLine, int lineCount, Bullet bullet)
Should not be called if a LineStyleListener has been set since the listener maintains the line attributes.
All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter.
When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged.
startLine
- first line the bullet is applied to, 0 basedlineCount
- number of lines the bullet applies to.bullet
- line bullet
SWTException
- java.lang.IllegalArgumentException
- public void setLineIndent(int startLine, int lineCount, int indent)
Should not be called if a LineStyleListener has been set since the listener maintains the line attributes.
All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter.
When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged.
startLine
- first line the indent is applied to, 0 basedlineCount
- number of lines the indent applies to.indent
- line indent
SWTException
- java.lang.IllegalArgumentException
- setIndent(int)
public void setLineJustify(int startLine, int lineCount, boolean justify)
Should not be called if a LineStyleListener has been set since the listener maintains the line attributes.
All line attributes are maintained relative to the line text, not the line index that is specified in this method call. During text changes, when entire lines are inserted or removed, the line attributes that are associated with the lines after the change will "move" with their respective text. An entire line is defined as extending from the first character on a line to the last and including the line delimiter.
When two lines are joined by deleting a line delimiter, the top line attributes take precedence and the attributes of the bottom line are deleted. For all other text changes line attributes will remain unchanged.
startLine
- first line the justify is applied to, 0 basedlineCount
- number of lines the justify applies to.justify
- true if lines should be justified
SWTException
- java.lang.IllegalArgumentException
- setJustify(boolean)
public void setLineSpacing(int lineSpacing)
lineSpacing
- the line spacing
SWTException
- public void setOrientation(int orientation)
SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.
orientation
- new orientation style
SWTException
- public void setSelection(int start)
start
- new caret position
SWTException
- java.lang.IllegalArgumentException
- setSelection(int,int)
public void setSelection(Point point)
Indexing is zero based. Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N
point
- x=selection start offset, y=selection end offset
The caret will be placed at the selection start when x > y.
SWTException
- java.lang.IllegalArgumentException
- setSelection(int,int)
public void setSelectionBackground(Color color)
color
- the new color (or null)
java.lang.IllegalArgumentException
- SWTException
- public void setSelectionForeground(Color color)
Note that this is a HINT. Some platforms do not allow the application to change the selection foreground color.
color
- the new color (or null)
java.lang.IllegalArgumentException
- SWTException
- public void setSelection(int start, int end)
Indexing is zero based. Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N
start
- selection start offset. The caret will be placed at the
selection start when start > end.end
- selection end offset
SWTException
- java.lang.IllegalArgumentException
- setSelectionRange(int,int)
public void setSelectionRange(int start, int length)
The new selection may not be visible. Call showSelection to scroll the selection into view. A negative length places the caret at the visual start of the selection.
start
- offset of the first selected characterlength
- number of characters to select
SWTException
- java.lang.IllegalArgumentException
- public void setStyleRange(StyleRange range)
The new style overwrites existing styles for the specified range. Existing style ranges are adjusted if they partially overlap with the new style. To clear an individual style, call setStyleRange with a StyleRange that has null attributes.
Should not be called if a LineStyleListener has been set since the listener maintains the styles.
range
- StyleRange object containing the style information.
Overwrites the old style in the given range. May be null to delete
all styles.
SWTException
- java.lang.IllegalArgumentException
- public void setStyleRanges(int start, int length, int[] ranges, StyleRange[] styles)
start
and
length
and adds the new styles.
The ranges array contains start and length pairs. Each pair refers to the corresponding style in the styles array. For example, the pair that starts at ranges[n] with length ranges[n+1] uses the style at styles[n/2]. The range fields within each StyleRange are ignored. If ranges or styles is null, the specified range is cleared.
Note: It is expected that the same instance of a StyleRange will occur multiple times within the styles array, reducing memory usage.
Should not be called if a LineStyleListener has been set since the listener maintains the styles.
start
- offset of first character where styles will be deletedlength
- length of the range to delete styles inranges
- the array of ranges. The ranges must not overlap and must be in order.styles
- the array of StyleRanges. The range fields within the StyleRange are unused.
SWTException
- java.lang.IllegalArgumentException
- public void setStyleRanges(int[] ranges, StyleRange[] styles)
All styles in the widget will be replaced with the given set of ranges and styles. The ranges array contains start and length pairs. Each pair refers to the corresponding style in the styles array. For example, the pair that starts at ranges[n] with length ranges[n+1] uses the style at styles[n/2]. The range fields within each StyleRange are ignored. If either argument is null, the styles are cleared.
Note: It is expected that the same instance of a StyleRange will occur multiple times within the styles array, reducing memory usage.
Should not be called if a LineStyleListener has been set since the listener maintains the styles.
ranges
- the array of ranges. The ranges must not overlap and must be in order.styles
- the array of StyleRanges. The range fields within the StyleRange are unused.
SWTException
- java.lang.IllegalArgumentException
- public void setStyleRanges(StyleRange[] ranges)
Note: Because a StyleRange includes the start and length, the
same instance cannot occur multiple times in the array of styles.
If the same style attributes, such as font and color, occur in
multiple StyleRanges, setStyleRanges(int[], StyleRange[])
can be used to share styles and reduce memory usage.
Should not be called if a LineStyleListener has been set since the listener maintains the styles.
ranges
- StyleRange objects containing the style information.
The ranges should not overlap. The style rendering is undefined if
the ranges do overlap. Must not be null. The styles need to be in order.
SWTException
- java.lang.IllegalArgumentException
- setStyleRanges(int[], StyleRange[])
public void setTabs(int tabs)
tabs
- tab width measured in characters.
SWTException
- public void setText(java.lang.String text)
Note: Only a single line of text should be set when the SWT.SINGLE style is used.
text
- new widget content. Replaces existing content. Line styles
that were set using StyledText API are discarded. The
current selection is also discarded.
SWTException
- java.lang.IllegalArgumentException
- public void setTextLimit(int limit)
The text limit specifies the amount of text that the user can type into the widget.
limit
- the new text limit.
SWTException
- java.lang.IllegalArgumentException
- public void setTopIndex(int topIndex)
The top index is the index of the line that is currently at the top of the widget. The top index changes when the widget is scrolled. Indexing starts from zero. Note: The top index is reset to 0 when new text is set in the widget.
topIndex
- new top index. Must be between 0 and
getLineCount() - fully visible lines per page. If no lines are fully
visible the maximum value is getLineCount() - 1. An out of range
index will be adjusted accordingly.
SWTException
- public void setTopPixel(int pixel)
The top pixel offset is the vertical pixel offset of the widget. The widget is scrolled so that the given pixel position is at the top. The top index is adjusted to the corresponding top line. Note: The top pixel is reset to 0 when new text is set in the widget.
pixel
- new top pixel offset. Must be between 0 and
(getLineCount() - visible lines per page) / getLineHeight()). An out
of range offset will be adjusted accordingly.
SWTException
- public void setWordWrap(boolean wrap)
This overrides the creation style bit SWT.WRAP.
wrap
- true=widget wraps lines, false=widget does not wrap linespublic void showSelection()
The end of the selection will be scrolled into view. Note that if a right-to-left selection exists, the end of the selection is the visual beginning of the selection (i.e., where the caret is located).
SWTException
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |