|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jgoodies.binding.adapter.BasicComponentFactory
public class BasicComponentFactory
Consists only of static methods that create and vend frequently used
Swing components that are then bound to a given ValueModel.
This class is one of two helper classes that help you establish a binding:
1) the Bindings class binds components that have been created before;
it wraps ValueModels with the adapters from package
com.jgoodies.binding.adapter
.
2) this BasicComponentFactory creates Swing components that are then
tied to ValueModels using the the different #bind
methods
in the Bindings class.
If you have an existing factory that vends Swing components, you can use Bindings to bind them to ValueModels. If you don't have such a factory, you can use this BasicComponentFactory to create and bind Swing components.
This class is intended to be used or extended by custom ComponentFactory classes. Such a factory can create a broader variety of component types, may use different default configurations, and can use your favorite Formatters, FormatterFactories, etc.
ValueModel
,
Bindings
Constructor Summary | |
---|---|
protected |
BasicComponentFactory()
|
Method Summary | ||
---|---|---|
static javax.swing.JCheckBox |
createCheckBox(ValueModel valueModel,
java.lang.String text)
Creates and returns a check box with the specified text label that is bound to the given ValueModel. |
|
static javax.swing.JColorChooser |
createColorChooser(ValueModel valueModel)
Creates and returns a JColorChooser that has the color selection bound to the given ValueModel. |
|
static javax.swing.JColorChooser |
createColorChooser(ValueModel valueModel,
java.awt.Color defaultColor)
Creates and returns a JColorChooser that has the color selection bound to the given ValueModel. |
|
static
|
createComboBox(SelectionInList<E> selectionInList)
Creates and returns a non-editable JComboBox that is bound to the given SelectionInList. |
|
static
|
createComboBox(SelectionInList<E> selectionInList,
javax.swing.ListCellRenderer cellRenderer)
Creates and returns a non-editable JComboBox that is bound to the given SelectionInList using the given cell renderer. |
|
static javax.swing.JFormattedTextField |
createDateField(ValueModel valueModel)
Creates and returns a formatted text field that is bound to the Date value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createFormattedTextField(ValueModel valueModel,
java.text.Format format)
Creates and returns a formatted text field that binds its value to the given model and converts Strings to values using the given Format. |
|
static javax.swing.JFormattedTextField |
createFormattedTextField(ValueModel valueModel,
javax.swing.JFormattedTextField.AbstractFormatter formatter)
Creates and returns a formatted text field that binds its value to the given model and converts Strings to values using the given Formatter. |
|
static javax.swing.JFormattedTextField |
createFormattedTextField(ValueModel valueModel,
javax.swing.JFormattedTextField.AbstractFormatterFactory formatterFactory)
Creates and returns a formatted text field that binds its value to the given model and converts Strings to values using Formatters provided by the given AbstractFormatterFactory. |
|
static javax.swing.JFormattedTextField |
createFormattedTextField(ValueModel valueModel,
java.lang.String mask)
Creates and returns a formatted text field that binds its value to the given model and converts Strings to values using a MaskFormatter that is based on the given mask. |
|
static javax.swing.JFormattedTextField |
createIntegerField(ValueModel valueModel)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createIntegerField(ValueModel valueModel,
int emptyNumber)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createIntegerField(ValueModel valueModel,
java.text.NumberFormat numberFormat)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createIntegerField(ValueModel valueModel,
java.text.NumberFormat numberFormat,
int emptyNumber)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createIntegerField(ValueModel valueModel,
java.text.NumberFormat numberFormat,
java.lang.Integer emptyNumber)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. |
|
static javax.swing.JLabel |
createLabel(ValueModel valueModel)
Creates and returns a text label that is bound to the given ValueModel. |
|
static javax.swing.JLabel |
createLabel(ValueModel valueModel,
java.text.Format format)
Creates and returns a text label that is bound to the given ValueModel that is wrapped by a StringConverter . |
|
static
|
createList(SelectionInList<E> selectionInList)
Creates and returns a JList for the given SelectionInList. |
|
static
|
createList(SelectionInList<E> selectionInList,
javax.swing.ListCellRenderer cellRenderer)
Creates and returns a JList for the given SelectionInList using the specified optional ListCellRenderer to render cells. |
|
static javax.swing.JFormattedTextField |
createLongField(ValueModel valueModel)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createLongField(ValueModel valueModel,
long emptyNumber)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createLongField(ValueModel valueModel,
java.text.NumberFormat numberFormat)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createLongField(ValueModel valueModel,
java.text.NumberFormat numberFormat,
long emptyNumber)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. |
|
static javax.swing.JFormattedTextField |
createLongField(ValueModel valueModel,
java.text.NumberFormat numberFormat,
java.lang.Long emptyNumber)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. |
|
static javax.swing.JPasswordField |
createPasswordField(ValueModel valueModel)
Creates and returns a JPasswordField with the content bound to the given ValueModel. |
|
static javax.swing.JPasswordField |
createPasswordField(ValueModel valueModel,
boolean commitOnFocusLost)
Creates and returns a JPasswordField with the content bound to the given ValueModel. |
|
static javax.swing.JRadioButton |
createRadioButton(ValueModel model,
java.lang.Object choice,
java.lang.String text)
Creates and returns a radio button with the specified text label that is bound to the given ValueModel. |
|
static javax.swing.JTextArea |
createTextArea(ValueModel valueModel)
Creates and returns a text area with the content bound to the given ValueModel. |
|
static javax.swing.JTextArea |
createTextArea(ValueModel valueModel,
boolean commitOnFocusLost)
Creates and returns a text area with the content bound to the given ValueModel. |
|
static javax.swing.JTextField |
createTextField(ValueModel valueModel)
Creates and returns a text field with the content bound to the given ValueModel. |
|
static javax.swing.JTextField |
createTextField(ValueModel valueModel,
boolean commitOnFocusLost)
Creates and returns a text field with the content bound to the given ValueModel. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected BasicComponentFactory()
Method Detail |
---|
public static javax.swing.JCheckBox createCheckBox(ValueModel valueModel, java.lang.String text)
Boolean.TRUE
.The model is converted to the required ToggleButtonModel using a ToggleButtonAdapter.
valueModel
- the model that provides a Boolean valuetext
- the check boxes' text label
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JColorChooser createColorChooser(ValueModel valueModel)
null
.
It is strongly recommended (though not required)
that the underlying ValueModel provides only non-null values.
This is so because the ColorSelectionModel behavior is undefined
for null
values and it may have unpredictable results.
To avoid these problems, you may create the ColorChooser with
a default color using createColorChooser(ValueModel, Color)
.
valueModel
- a Color-typed ValueModel
java.lang.NullPointerException
- if the valueModel is null
,
or if its initial value is null
createColorChooser(ValueModel, Color)
public static javax.swing.JColorChooser createColorChooser(ValueModel valueModel, java.awt.Color defaultColor)
null
, the given default color is used instead.
This avoids problems with the ColorSelectionModel that may have
unpredictable result for null
values.
valueModel
- a Color-typed ValueModeldefaultColor
- the color used if the valueModel returns null
java.lang.NullPointerException
- if the valueModel or the default color
is null
,public static <E> javax.swing.JComboBox createComboBox(SelectionInList<E> selectionInList)
If the selectionInList's selection holder is a ComponentValueModel
it is synchronized with the visible and enabled state of the returned
combo box.
There are a couple of other possibilities to bind a JComboBox.
See the constructors and the class comment of the
ComboBoxAdapter
.
E
- the type of the combo box items and the selectionselectionInList
- provides the list and selection
java.lang.NullPointerException
- if the selectionInList
is null
ComboBoxAdapter
public static <E> javax.swing.JComboBox createComboBox(SelectionInList<E> selectionInList, javax.swing.ListCellRenderer cellRenderer)
If the selectionInList's selection holder is a ComponentValueModel
it is synchronized with the visible and enabled state of the returned
combo box.
There are a couple of other possibilities to bind a JComboBox.
See the constructors and the class comment of the
ComboBoxAdapter
.
E
- the type of the combo box items and the selectionselectionInList
- provides the list and selectioncellRenderer
- an optional ListCellRenderer,
can be null
null
java.lang.NullPointerException
- if the selectionInList
is null
ComboBoxAdapter
public static javax.swing.JFormattedTextField createDateField(ValueModel valueModel)
SHORT
DateFormat with strict checking is used to edit
(parse) a date; the DateFormatter's default DateFormat is used to
display (format) a date. In both cases null
Dates are
mapped to the empty String.
valueModel
- the model that holds the value to be edited
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createFormattedTextField(ValueModel valueModel, java.text.Format format)
valueModel
- the model that provides the valueformat
- the Format
used to convert values
into a text representation and vice versa via #format
and #parse
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createFormattedTextField(ValueModel valueModel, javax.swing.JFormattedTextField.AbstractFormatter formatter)
valueModel
- the model that provides the valueformatter
- the Formatter used to convert values to
a text representation and vice versa via #valueToString
and #stringToValue
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createFormattedTextField(ValueModel valueModel, javax.swing.JFormattedTextField.AbstractFormatterFactory formatterFactory)
valueModel
- the model that provides the valueformatterFactory
- provides formatters for different field states
that in turn are used to convert values to a text representation and
vice versa via #valueToString
and #stringToValue
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createFormattedTextField(ValueModel valueModel, java.lang.String mask)
valueModel
- the model that provides the valuemask
- the mask pattern used to create an instance of
MaskFormatter
that in turn converts values to Strings
and vice versa
java.lang.NullPointerException
- if the valueModel is null
java.lang.IllegalArgumentException
- if the mask is invalidpublic static javax.swing.JFormattedTextField createIntegerField(ValueModel valueModel)
null
and vice versa.
The Format used to convert numbers to strings and vice versa
is NumberFormat.getIntegerInstance()
.
valueModel
- the model that holds the value to be edited
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createIntegerField(ValueModel valueModel, int emptyNumber)
The Format used to convert numbers to strings and vice versa
is NumberFormat.getIntegerInstance()
.
valueModel
- the model that holds the value to be editedemptyNumber
- an Integer that represents the empty string
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createIntegerField(ValueModel valueModel, java.text.NumberFormat numberFormat)
null
and vice versa.
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versa
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createIntegerField(ValueModel valueModel, java.text.NumberFormat numberFormat, int emptyNumber)
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versaemptyNumber
- an Integer that represents the empty string
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createIntegerField(ValueModel valueModel, java.text.NumberFormat numberFormat, java.lang.Integer emptyNumber)
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versaemptyNumber
- an Integer that represents the empty string
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JFormattedTextField createLongField(ValueModel valueModel)
null
and vice versa.
The Format used to convert numbers to strings and vice versa is
NumberFormat.getIntegerInstance()
.
valueModel
- the model that holds the value to be edited
java.lang.NullPointerException
- if the model is null
public static javax.swing.JFormattedTextField createLongField(ValueModel valueModel, long emptyNumber)
The Format used to convert numbers to strings and vice versa is
NumberFormat.getIntegerInstance()
.
valueModel
- the model that holds the value to be editedemptyNumber
- a Long that represents the empty string
java.lang.NullPointerException
- if the model is null
public static javax.swing.JFormattedTextField createLongField(ValueModel valueModel, java.text.NumberFormat numberFormat)
null
and vice versa.
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versa
java.lang.NullPointerException
- if the model is null
public static javax.swing.JFormattedTextField createLongField(ValueModel valueModel, java.text.NumberFormat numberFormat, long emptyNumber)
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versaemptyNumber
- a Long that represents the empty string
java.lang.NullPointerException
- if the model is null
public static javax.swing.JFormattedTextField createLongField(ValueModel valueModel, java.text.NumberFormat numberFormat, java.lang.Long emptyNumber)
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versaemptyNumber
- a Long that represents the empty string
java.lang.NullPointerException
- if the model is null
public static javax.swing.JLabel createLabel(ValueModel valueModel)
valueModel
- the model that provides the value
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JLabel createLabel(ValueModel valueModel, java.text.Format format)
StringConverter
.
The conversion to Strings uses the specified Format.
valueModel
- the model that provides the valueformat
- the format used to create the StringConverter
java.lang.NullPointerException
- if the valueModel is null
ConverterFactory
public static <E> javax.swing.JList createList(SelectionInList<E> selectionInList)
If the selectionInList's selection holder is a ComponentValueModel
it is synchronized with the visible and enabled state of the returned
list.
E
- the type of the list items and the selectionselectionInList
- provides the list and selection
java.lang.NullPointerException
- if selectionInList is null
public static <E> javax.swing.JList createList(SelectionInList<E> selectionInList, javax.swing.ListCellRenderer cellRenderer)
If the selectionInList's selection holder is a ComponentValueModel
it is synchronized with the visible and enabled state of the returned
list.
E
- the type of the list items and the selectionselectionInList
- provides the list and selectioncellRenderer
- an optional ListCellRenderer,
can be null
java.lang.NullPointerException
- if selectionInList is null
public static javax.swing.JPasswordField createPasswordField(ValueModel valueModel)
Security Note: The binding created by this method
uses Strings as values of the given ValueModel. The String-typed
passwords could potentially be observed in a security fraud.
For stronger security it is recommended to request a character array
from the JPasswordField and clear the array after use by setting
each character to zero. Method JPasswordField.getPassword()
return's the field's password as a character array.
valueModel
- the model that provides the value
java.lang.NullPointerException
- if the valueModel is null
createPasswordField(ValueModel, boolean)
,
JPasswordField.getPassword()
public static javax.swing.JPasswordField createPasswordField(ValueModel valueModel, boolean commitOnFocusLost)
Security Note: The binding created by this method
uses Strings as values of the given ValueModel. The String-typed
passwords could potentially be observed in a security fraud.
For stronger security it is recommended to request a character array
from the JPasswordField and clear the array after use by setting
each character to zero. Method JPasswordField.getPassword()
return's the field's password as a character array.
valueModel
- the model that provides the valuecommitOnFocusLost
- true to commit text changes on focus lost,
false to commit text changes on every character typed
java.lang.NullPointerException
- if the valueModel is null
createPasswordField(ValueModel)
,
JPasswordField.getPassword()
public static javax.swing.JRadioButton createRadioButton(ValueModel model, java.lang.Object choice, java.lang.String text)
The model is converted to the required ToggleButton using a RadioButtonAdapter.
model
- the model that provides the current choicechoice
- this button's valuetext
- the radio buttons' text label
java.lang.NullPointerException
- if the valueModel is null
public static javax.swing.JTextArea createTextArea(ValueModel valueModel)
valueModel
- the model that provides the value
java.lang.NullPointerException
- if the valueModel is null
createTextArea(ValueModel, boolean)
public static javax.swing.JTextArea createTextArea(ValueModel valueModel, boolean commitOnFocusLost)
valueModel
- the model that provides the text valuecommitOnFocusLost
- true to commit text changes on focus lost,
false to commit text changes on every character typed
java.lang.NullPointerException
- if the valueModel is null
createTextArea(ValueModel)
public static javax.swing.JTextField createTextField(ValueModel valueModel)
valueModel
- the model that provides the value
java.lang.NullPointerException
- if the valueModel is null
createTextField(ValueModel, boolean)
public static javax.swing.JTextField createTextField(ValueModel valueModel, boolean commitOnFocusLost)
valueModel
- the model that provides the text valuecommitOnFocusLost
- true to commit text changes on focus lost,
false to commit text changes on every character typed
java.lang.NullPointerException
- if the valueModel is null
createTextField(ValueModel)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |