public class FormattedText
extends java.lang.Object
Text
widget of SWT. This control works on the same principle than the JFace
viewers. The embedded text widget is accessible by the getControl() method,
allowing to apply to it all necessary behaviors (layout, listeners...).
Formatting is delegated to formatter objects implementing the ITextFormatter
interface. Each formatter class manages a base class of values (date, number...).
Formatters are associated by 2 different means :
setFormatter()
method.setValue()
is called and there is currently no formatter,
a new one is automatically created based on the class of the value.CENTER, LEFT, RIGHT, READ_ONLY
Modifier and Type | Field and Description |
---|---|
protected static boolean |
beepSound
Flag to activate or not beep sound on input errors
|
protected int |
caretPos
Save position of cursor when the focus is lost
|
protected static int |
count |
protected ITextFormatter |
formatter
Formatter
|
protected int |
id |
protected org.eclipse.swt.layout.GridLayout |
layout
Layout
|
protected org.eclipse.swt.widgets.Listener |
modifyFilter
Filter for modify events
|
protected org.eclipse.swt.widgets.Text |
text
Encapsulated Text widget
|
static java.lang.String |
TEXT_DATA_KEY
The key used to register the FormattedText in its Text widget data
|
Constructor and Description |
---|
FormattedText(org.eclipse.swt.widgets.Composite parent)
Creates a formatted text on a newly-created text control under the given
parent.
|
FormattedText(org.eclipse.swt.widgets.Composite parent,
int style)
Creates a formatted text on a newly-created text control under the given
parent.
|
FormattedText(org.eclipse.swt.widgets.Text t)
Creates a formatted text on the given text control.
|
Modifier and Type | Method and Description |
---|---|
org.eclipse.swt.widgets.Text |
getControl()
Returns the primary
Text control associated with this viewer. |
ITextFormatter |
getFormatter()
Returns the formatter associated to the
Text widget. |
java.lang.Object |
getValue()
Returns the current value of the widget.
|
java.lang.Class<?> |
getValueType()
Returns the type of value the
ITextFormatter associated with this
FormattedText handles,
i.e. |
static boolean |
isBeepSound()
Returns true if beep sound must be produced on input errors, else false.
|
boolean |
isEmpty()
Returns
true if the current value is empty, else
false .An empty value depends of the formatter applied on the Text widget and is not just an empty String in the widget. |
boolean |
isValid()
Returns
true if the current value is valid, else false . |
static void |
setBeepSound(boolean beepSound)
Set the beep sound to ON or OFF for all the FormattedText fields.
|
void |
setFormatter(ITextFormatter formatter)
Associates a formatter to the widget.
Parameter can not be null. |
void |
setValue(java.lang.Object value)
Sets a new value.
|
public static final java.lang.String TEXT_DATA_KEY
protected org.eclipse.swt.widgets.Text text
protected ITextFormatter formatter
protected int caretPos
protected org.eclipse.swt.layout.GridLayout layout
protected org.eclipse.swt.widgets.Listener modifyFilter
protected static boolean beepSound
protected static int count
protected int id
public FormattedText(org.eclipse.swt.widgets.Composite parent)
BORDER
.parent
- the parent controlpublic FormattedText(org.eclipse.swt.widgets.Composite parent, int style)
parent
- the parent controlstyle
- the SWT style bits used to create the textpublic FormattedText(org.eclipse.swt.widgets.Text t)
t
- the text controlpublic org.eclipse.swt.widgets.Text getControl()
Text
control associated with this viewer.public ITextFormatter getFormatter()
Text
widget.null
if no formatter is currently associatedpublic java.lang.Object getValue()
The returned value is provided by the formatter and is of the type managed
by the formatter. For example a DateFormatter
will return a
Date
value.
If no formatter is associated, the String
contained in the
Text
widget is returned.
public java.lang.Class<?> getValueType()
ITextFormatter
associated with this
FormattedText handles,
i.e. returns in getValue()
.public static boolean isBeepSound()
public boolean isEmpty()
true
if the current value is empty, else
false
.true
if empty.public boolean isValid()
true
if the current value is valid, else false
.true
if valid.public static void setBeepSound(boolean beepSound)
beepSound
- true to emit beep sound on errors, else falsepublic void setFormatter(ITextFormatter formatter)
formatter
- formatterpublic void setValue(java.lang.Object value)
If no formatter is currently associated to he widget, a new one is created
by the factory based on the value's class.
If the value is incompatible with the formatter, an IllegalArgumentException
is returned.
value
- new value