|
Eclipse Rich Ajax Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.swt.widgets.Widget org.eclipse.swt.widgets.Control org.eclipse.swt.widgets.Scrollable org.eclipse.swt.widgets.Text
public class Text
Instances of this class are selectable user interface objects that allow the user to enter and modify text.
Note: Only one of the styles MULTI and SINGLE may be specified.
Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH. When the platform supports the hint, the text control shows these icons. When an icon is selected, a default selection event is sent with the detail field set to one of ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the detail. In the case of ICON_CANCEL, the text is cleared before the default selection event is sent causing the application to search for an empty string.
IMPORTANT: This class is not intended to be subclassed.
Due to limitations of the JavaScript library, the current WRAP behavior of a MULI line text is always as if WRAP was set.
Field Summary | |
---|---|
static java.lang.String |
DELIMITER
The delimiter used by multi-line text widgets. |
static int |
LIMIT
The maximum number of characters that can be entered into a text widget. |
Constructor Summary | |
---|---|
Text(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 |
addModifyListener(ModifyListener listener)
Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in the ModifyListener
interface. |
|
void |
addSelectionListener(SelectionListener listener)
Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the SelectionListener
interface. |
|
void |
addVerifyListener(VerifyListener verifyListener)
Adds the listener to the collection of listeners who will be notified when the receiver's text is verified, by sending it one of the messages defined in the VerifyListener
interface. |
|
void |
append(java.lang.String string)
Appends a string. |
|
void |
clearSelection()
Clears the selection. |
|
Point |
computeSize(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver. |
|
Rectangle |
computeTrim(int x,
int y,
int width,
int height)
Given a desired client area for the receiver (as described by the arguments), returns the bounding rectangle which would be required to produce that client area. |
|
|
getAdapter(java.lang.Class<T> adapter)
Implementation of the Adaptable interface. |
|
int |
getCaretPosition()
Returns the character position of the caret. |
|
int |
getCharCount()
Returns the number of characters. |
|
char |
getEchoChar()
Returns the echo character. |
|
boolean |
getEditable()
Returns the editable state. |
|
java.lang.String |
getLineDelimiter()
Returns the line delimiter. |
|
int |
getLineHeight()
Returns the height of a line. |
|
java.lang.String |
getMessage()
Returns the widget message. |
|
Point |
getSelection()
Returns a Point whose x coordinate is the
character position representing the start of the selected
text, and whose y coordinate is the character position
representing the end of the selection. |
|
int |
getSelectionCount()
Returns the number of selected characters. |
|
java.lang.String |
getSelectionText()
Gets the selected text, or an empty string if there is no current selection. |
|
java.lang.String |
getText()
Returns the widget text. |
|
java.lang.String |
getText(int start,
int end)
Returns a range of text. |
|
char[] |
getTextChars()
Returns the widget's text as a character array. |
|
int |
getTextLimit()
Returns the maximum number of characters that the receiver is capable of holding. |
|
void |
insert(java.lang.String string)
Inserts a string. |
|
void |
removeModifyListener(ModifyListener listener)
Removes the listener from the collection of listeners who will be notified when the receiver's text is modified. |
|
void |
removeSelectionListener(SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when the control is selected. |
|
void |
removeVerifyListener(VerifyListener verifyListener)
Removes the listener from the collection of listeners who will be notified when the control is verified. |
|
void |
selectAll()
Selects all the text in the receiver. |
|
void |
setEchoChar(char echo)
Sets the echo character. |
|
void |
setEditable(boolean editable)
Sets the editable state. |
|
void |
setMessage(java.lang.String message)
Sets the widget message. |
|
void |
setSelection(int start)
Sets the selection. |
|
void |
setSelection(int start,
int end)
Sets the selection to the range specified by the given start and end indices. |
|
void |
setSelection(Point selection)
Sets the selection to the range specified by the given point, where the x coordinate represents the start index and the y coordinate represents the end index. |
|
void |
setText(java.lang.String text)
Sets the contents of the receiver to the given string. |
|
void |
setTextChars(char[] text)
Sets the contents of the receiver to the characters in the array. |
|
void |
setTextLimit(int textLimit)
Sets the maximum number of characters that the receiver is capable of holding to be the argument. |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
---|
getClientArea, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Widget |
---|
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, reskin, setData, setData, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int LIMIT
Note that this value is platform dependent, based upon the native widget implementation.
public static final java.lang.String DELIMITER
Constructor Detail |
---|
public Text(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 composite control which will be the parent of the new instance (cannot be null)style
- the style of control to construct
java.lang.IllegalArgumentException
- SWTException
- SWT.SINGLE
,
SWT.MULTI
,
SWT.READ_ONLY
,
SWT.WRAP
,
SWT.PASSWORD
,
SWT.SEARCH
,
SWT.ICON_SEARCH
,
SWT.ICON_CANCEL
,
Widget.checkSubclass()
,
Widget.getStyle()
Method Detail |
---|
public <T> T getAdapter(java.lang.Class<T> adapter)
Widget
Adaptable
interface.
IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
getAdapter
in interface Adaptable
getAdapter
in class Control
adapter
- the lookup class
null
if
there is no adapter associated with the given class.public void setText(java.lang.String text)
text
- the new text
java.lang.IllegalArgumentException
- SWTException
- public java.lang.String getText()
The text for a text widget is the characters in the widget, or an empty string if this has never been set.
SWTException
- public void setTextChars(char[] text)
text
- a character array that contains the new text
java.lang.IllegalArgumentException
- SWTException
- getTextChars()
public char[] getTextChars()
The text for a text widget is the characters in the widget, or a zero length array if this has never been set.
SWTException
- setTextChars(char[])
public java.lang.String getText(int start, int end)
Indexing is zero based. The range of a selection is from 0..N-1 where N is the number of characters in the widget.
start
- the start of the rangeend
- the end of the range
SWTException
- public void append(java.lang.String string)
The new text is appended to the text at the end of the widget.
string
- the string to be appended
java.lang.IllegalArgumentException
- SWTException
- public java.lang.String getLineDelimiter()
SWTException
- DELIMITER
public int getLineHeight()
SWTException
- public void setMessage(java.lang.String message)
Typically this is used in conjunction with SWT.SEARCH
.
message
- the new message
java.lang.IllegalArgumentException
- SWTException
- public java.lang.String getMessage()
Typically this is used in conjunction with SWT.SEARCH
.
SWTException
- public void setEchoChar(char echo)
The echo character is the character that is displayed when the user enters text or the text is changed by the programmer. Setting the echo character to '\0' clears the echo character and redraws the original text. If for any reason the echo character is invalid, or if the platform does not allow modification of the echo character, the default echo character for the platform is used.
echo
- the new echo character
SWTException
- public char getEchoChar()
The echo character is the character that is displayed when the user enters text or the text is changed by the programmer.
SWTException
- setEchoChar(char)
public void setTextLimit(int textLimit)
Instead of trying to set the text limit to zero, consider creating a read-only text widget.
To reset this value to the default, use setTextLimit(Text.LIMIT)
.
Specifying a limit value larger than Text.LIMIT
sets the
receiver's limit to Text.LIMIT
.
textLimit
- new text limit
java.lang.IllegalArgumentException
- SWTException
- LIMIT
public int getTextLimit()
If this has not been changed by setTextLimit()
,
it will be the constant Text.LIMIT
.
SWTException
- LIMIT
public int getCharCount()
SWTException
- public void setSelection(int start)
Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
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. This differs from other functions that address character position such as getText () that use the regular array indexing rules.
start
- new caret position
SWTException
- public void setSelection(int start, int end)
Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
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. This differs from other functions that address character position such as getText () that use the usual array indexing rules.
start
- the start of the rangeend
- the end of the range
SWTException
- public void setSelection(Point selection)
Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
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. This differs from other functions that address character position such as getText () that use the usual array indexing rules.
selection
- the point
java.lang.IllegalArgumentException
- SWTException
- public Point getSelection()
Point
whose x coordinate is the
character position representing the start of the selected
text, and whose y coordinate is the character position
representing the end of the selection. An "empty" selection
is indicated by the x and y coordinates having the same value.
Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
SWTException
- public int getSelectionCount()
SWTException
- public java.lang.String getSelectionText()
SWTException
- public void clearSelection()
SWTException
- public void selectAll()
SWTException
- public int getCaretPosition()
Indexing is zero based.
SWTException
- public void setEditable(boolean editable)
editable
- the new editable state
SWTException
- public boolean getEditable()
SWTException
- public void insert(java.lang.String string)
The old selection is replaced with the new text.
string
- the string
java.lang.IllegalArgumentException
- null
SWTException
- 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 Control
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 Rectangle computeTrim(int x, int y, int width, int height)
Scrollable
In other words, it returns a rectangle such that, if the receiver's bounds were set to that rectangle, the area of the receiver which is capable of displaying data (that is, not covered by the "trimmings") would be the rectangle described by the arguments (relative to the receiver's parent).
computeTrim
in class Scrollable
x
- the desired x coordinate of the client areay
- the desired y coordinate of the client areawidth
- the desired width of the client areaheight
- the desired height of the client area
Scrollable.getClientArea()
public void addSelectionListener(SelectionListener listener)
SelectionListener
interface.
widgetSelected
is not called for texts.
widgetDefaultSelected
is typically called when ENTER is pressed in a single-line text,
or when ENTER is pressed in a search text. If the receiver has the SWT.SEARCH | SWT.ICON_CANCEL
style
and the user cancels the search, the event object detail field contains the value SWT.ICON_CANCEL
.
Likewise, if the receiver has the SWT.ICON_SEARCH
style and the icon search is selected, the
event object detail field contains the value SWT.ICON_SEARCH
.
listener
- the listener which should be notified when the control is selected by the user
java.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
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 addModifyListener(ModifyListener listener)
ModifyListener
interface.
listener
- the listener which should be notified
java.lang.IllegalArgumentException
- SWTException
- ModifyListener
,
removeModifyListener(org.eclipse.swt.events.ModifyListener)
public void removeModifyListener(ModifyListener listener)
listener
- the listener which should no longer be notified
java.lang.IllegalArgumentException
- SWTException
- ModifyListener
,
addModifyListener(org.eclipse.swt.events.ModifyListener)
public void addVerifyListener(VerifyListener verifyListener)
VerifyListener
interface.
verifyListener
- the listener which should be notified
java.lang.IllegalArgumentException
- SWTException
- VerifyListener
,
removeVerifyListener(org.eclipse.swt.events.VerifyListener)
public void removeVerifyListener(VerifyListener verifyListener)
verifyListener
- the listener which should no longer be notified
java.lang.IllegalArgumentException
- SWTException
- VerifyListener
,
addVerifyListener(org.eclipse.swt.events.VerifyListener)
|
Eclipse Rich Ajax Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) EclipseSource and others 2002, 2012. All rights reserved.