Class FormattedText
java.lang.Object
org.eclipse.nebula.widgets.formattedtext.FormattedText
public class FormattedText
extends java.lang.Object
Formatted text viewer. Adds formatting capabilities to the
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 :
- By the
setFormatter()
method. - When
setValue()
is called and there is currently no formatter, a new one is automatically created based on the class of the value.
Styles:
CENTER, LEFT, RIGHT, READ_ONLY
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
beepSound
Flag to activate or not beep sound on input errorsprotected int
caretPos
Save position of cursor when the focus is lostprotected static int
count
protected ITextFormatter
formatter
Formatterprotected int
id
protected org.eclipse.swt.layout.GridLayout
layout
Layoutprotected org.eclipse.swt.widgets.Listener
modifyFilter
Filter for modify eventsprotected org.eclipse.swt.widgets.Text
text
Encapsulated Text widgetstatic java.lang.String
TEXT_DATA_KEY
The key used to register the FormattedText in its Text widget data -
Constructor Summary
Constructors Constructor 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. -
Method Summary
Modifier and Type Method Description org.eclipse.swt.widgets.Text
getControl()
Returns the primaryText
control associated with this viewer.ITextFormatter
getFormatter()
Returns the formatter associated to theText
widget.java.lang.Object
getValue()
Returns the current value of the widget.java.lang.Class<?>
getValueType()
Returns the type of value theITextFormatter
associated with this FormattedText handles, i.e. returns ingetValue()
.static boolean
isBeepSound()
Returns true if beep sound must be produced on input errors, else false.boolean
isEmpty()
Returnstrue
if the current value is empty, elsefalse
.
An empty value depends of the formatter applied on the Text widget and is not just an empty String in the widget.boolean
isValid()
Returnstrue
if the current value is valid, elsefalse
.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.
-
Field Details
-
TEXT_DATA_KEY
public static final java.lang.String TEXT_DATA_KEYThe key used to register the FormattedText in its Text widget data- See Also:
- Constant Field Values
-
text
protected org.eclipse.swt.widgets.Text textEncapsulated Text widget -
formatter
Formatter -
caretPos
protected int caretPosSave position of cursor when the focus is lost -
layout
protected org.eclipse.swt.layout.GridLayout layoutLayout -
modifyFilter
protected org.eclipse.swt.widgets.Listener modifyFilterFilter for modify events -
beepSound
protected static boolean beepSoundFlag to activate or not beep sound on input errors -
count
protected static int count -
id
protected int id
-
-
Constructor Details
-
FormattedText
public FormattedText(org.eclipse.swt.widgets.Composite parent)Creates a formatted text on a newly-created text control under the given parent. The text control is created using the SWT style bitsBORDER
.- Parameters:
parent
- the parent control
-
FormattedText
public FormattedText(org.eclipse.swt.widgets.Composite parent, int style)Creates a formatted text on a newly-created text control under the given parent. The text control is created using the given SWT style bits.- Parameters:
parent
- the parent controlstyle
- the SWT style bits used to create the text
-
FormattedText
public FormattedText(org.eclipse.swt.widgets.Text t)Creates a formatted text on the given text control.- Parameters:
t
- the text control
-
-
Method Details
-
getControl
public org.eclipse.swt.widgets.Text getControl()Returns the primaryText
control associated with this viewer.- Returns:
- the SWT text control which displays this viewer's content
-
getFormatter
Returns the formatter associated to theText
widget.- Returns:
- Formatter, or
null
if no formatter is currently associated
-
getValue
public java.lang.Object getValue()Returns the current value of the widget.The returned value is provided by the formatter and is of the type managed by the formatter. For example a
DateFormatter
will return aDate
value.
If no formatter is associated, theString
contained in theText
widget is returned.- Returns:
- Current value
-
getValueType
public java.lang.Class<?> getValueType()Returns the type of value theITextFormatter
associated with this FormattedText handles, i.e. returns ingetValue()
.- Returns:
- The value type.
-
isBeepSound
public static boolean isBeepSound()Returns true if beep sound must be produced on input errors, else false.- Returns:
- true / false
-
isEmpty
public boolean isEmpty()Returnstrue
if the current value is empty, elsefalse
.
An empty value depends of the formatter applied on the Text widget and is not just an empty String in the widget. Formatters can use special formatting characters to format the value. These characters are not always considered as part of the value. For example, in a DateFormatter the pattern uses "/" separator and always displays it in the input field.- Returns:
true
if empty.
-
isValid
public boolean isValid()Returnstrue
if the current value is valid, elsefalse
.- Returns:
true
if valid.
-
setBeepSound
public static void setBeepSound(boolean beepSound)Set the beep sound to ON or OFF for all the FormattedText fields. Beep sound are produced by formatters on every input error. Formatter implementation must check this flag on before to emit a beep sound.- Parameters:
beepSound
- true to emit beep sound on errors, else false
-
setFormatter
Associates a formatter to the widget.
Parameter can not be null. In some situations, the FormattedText component must not do formatting (eg. when reusing the same object for editing of different types of values). In this case, use a StringFormatter. This formatter do no formatting.- Parameters:
formatter
- formatter
-
setValue
public void setValue(java.lang.Object value)Sets a new 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, anIllegalArgumentException
is returned.- Parameters:
value
- new value
-