|
Eclipse Platform Release 3.4 |
||||||||||
| 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
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.Control |
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 |
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(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. |
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. |
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. |
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. |
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. |
String |
getText()
Returns a copy of the widget content. |
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. |
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(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. |
Runnable |
print(Printer printer)
Returns a runnable that will print the widget's text to the specified printer. |
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 |
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,
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 |
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(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, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList |
| Methods inherited from class org.eclipse.swt.widgets.Scrollable |
computeTrim, getClientArea, 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
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 - 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 - IllegalArgumentException - BidiSegmentEventpublic void addLineBackgroundListener(LineBackgroundListener listener)
listener - the listener
SWTException - IllegalArgumentException - public void addLineStyleListener(LineStyleListener listener)
listener - the listener
SWTException - IllegalArgumentException - public void addModifyListener(ModifyListener modifyListener)
modifyListener - the listener
SWTException - IllegalArgumentException - public void addPaintObjectListener(PaintObjectListener listener)
listener - the listener
SWTException - IllegalArgumentException - PaintObjectListener,
PaintObjectEventpublic 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
IllegalArgumentException - SWTException - SelectionListener,
removeSelectionListener(org.eclipse.swt.events.SelectionListener),
SelectionEventpublic void addVerifyKeyListener(VerifyKeyListener listener)
listener - the listener
SWTException - IllegalArgumentException - public void addVerifyListener(VerifyListener verifyListener)
verifyListener - the listener
SWTException - IllegalArgumentException - public void addWordMovementListener(MovementListener movementListener)
movementListener - the listener
SWTException - IllegalArgumentException - MovementEvent,
MovementListener,
removeWordMovementListener(org.eclipse.swt.custom.MovementListener)public void append(String string)
string - the string to be appended
SWTException - 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 Compositepublic 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 Controlpublic int getBaseline()
SWTException - getBaseline(int)public int getBaseline(int offset)
offset - the offset
SWTException - IllegalArgumentException - public boolean getBidiColoring()
SWTException - public int getCaretOffset()
SWTException - public StyledTextContent getContent()
SWTException - public boolean getDragDetect()
Controltrue if the receiver is detecting
drag gestures, and false otherwise.
getDragDetect in class Controlpublic boolean getDoubleClickEnabled()
SWTException - public boolean getEditable()
SWTException - public Color getForeground()
Control
getForeground in class Controlpublic 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 String getLine(int lineIndex)
lineIndex - index of the line to return.
SWTException - IllegalArgumentException - public int getLineAlignment(int index)