Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
com.jgoodies.binding.adapter.BasicComponentFactory
public class BasicComponentFactory
extends java.lang.Object
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 | |
Method Summary | |
static JCheckBox |
|
static JColorChooser |
|
static JColorChooser |
|
static JComboBox |
|
static JComboBox |
|
static JComboBox |
|
static JComboBox |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JLabel |
|
static JLabel |
|
static JList |
|
static JList |
|
static JList |
|
static JList |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JFormattedTextField |
|
static JPasswordField |
|
static JPasswordField |
|
static JRadioButton |
|
static JTextArea |
|
static JTextArea |
|
static JTextField |
|
static JTextField |
|
public static JCheckBox createCheckBox(ValueModel valueModel, String text)
Creates and returns a check box with the specified text label that is bound to the given ValueModel. The check box is selected if and only if the model's value equalsBoolean.TRUE
. The model is converted to the required ToggleButtonModel using a ToggleButtonAdapter.
- Parameters:
valueModel
- the model that provides a Boolean valuetext
- the check boxes' text label
- Returns:
- a check box with the specified text bound to the given model, selected if the model's value equals Boolean.TRUE
public static JColorChooser createColorChooser(ValueModel valueModel)
Creates and returns a JColorChooser that has the color selection bound to the given ValueModel. The ValueModel must be of type Color and must allow read-access to its value, and the initial value must not benull
. 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 fornull
values and it may have unpredictable results. To avoid these problems, you may create the ColorChooser with a default color usingcreateColorChooser(ValueModel,Color)
.
- Parameters:
valueModel
- a Color-typed ValueModel
- Returns:
- a color chooser with the selected color bound to the given model
- Since:
- 1.0.3
- See Also:
createColorChooser(ValueModel,Color)
public static JColorChooser createColorChooser(ValueModel valueModel, Color defaultColor)
Creates and returns a JColorChooser that has the color selection bound to the given ValueModel. The ValueModel must be of type Color and must allow read-access to its value. If the valueModel returnsnull
, the given default color is used instead. This avoids problems with the ColorSelectionModel that may have unpredictable result fornull
values.
- Parameters:
valueModel
- a Color-typed ValueModeldefaultColor
- the color used if the valueModel returns null
- Returns:
- a color chooser with the selected color bound to the given model
- Since:
- 1.1
public static JComboBox createComboBox(SelectionInList selectionInList)
Creates and returns a non-editable JComboBox that is bound to the given SelectionInList. The SelectionInList's ListModel is the list data provider and the selection index holder is used for the combo box model's selected item. There are a couple of other possibilities to bind a JComboBox. See the constructors and the class comment of theComboBoxAdapter
.
- Parameters:
selectionInList
- provides the list and selection
- Returns:
- a non-editable JComboBox that is bound to the SelectionInList
- Since:
- 1.0.1
- See Also:
ComboBoxAdapter
public static JComboBox createComboBox(SelectionInList selectionInList, ListCellRenderer cellRenderer)
Creates and returns a non-editable JComboBox that is bound to the given SelectionInList using the given cell renderer. The SelectionInList provides the list data and the selection index holder is used for the combo box model's selected item. There are a couple of other possibilities to bind a JComboBox. See the constructors and the class comment of theComboBoxAdapter
.
- Parameters:
selectionInList
- provides the list and selectioncellRenderer
- an optional ListCellRenderer, can benull
- Returns:
- a non-editable JComboBox that is bound to the SelectionInList and uses the given renderer - if non-
null
- Since:
- 1.0.1
- See Also:
ComboBoxAdapter
public static JComboBox createComboBox(SelectionInListModel selectionInListModel)
Creates and returns a non-editable JComboBox that is bound to the given SelectionInListModel. The SelectionInListModel provides the list data and the selection index holder is used for the combo box model's selected item. There are a couple of other possibilities to bind a JComboBox. See the constructors and the class comment of theComboBoxAdapter
.
- Parameters:
selectionInListModel
- provides the list and selection
- Returns:
- a non-editable JComboBox that is bound to the SelectionInListModel
- Since:
- 1.5
- See Also:
ComboBoxAdapter
public static JComboBox createComboBox(SelectionInListModel selectionInListModel, ListCellRenderer cellRenderer)
Creates and returns a non-editable JComboBox that is bound to the given SelectionInListModel using the given cell renderer. The SelectionInListModel provides the list data and the selection index holder is used for the combo box model's selected item. There are a couple of other possibilities to bind a JComboBox. See the constructors and the class comment of theComboBoxAdapter
.
- Parameters:
selectionInListModel
- provides the list and selectioncellRenderer
- an optional ListCellRenderer, can benull
- Returns:
- a non-editable JComboBox that is bound to the SelectionInListModel and uses the given renderer - if non-
null
- Since:
- 1.5
- See Also:
ComboBoxAdapter
public static JFormattedTextField createDateField(ValueModel valueModel)
Creates and returns a formatted text field that is bound to the Date value of the given ValueModel. The JFormattedTextField is configured with an AbstractFormatter that uses two different DateFormats to edit and display the Date. ASHORT
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 casesnull
Dates are mapped to the empty String.
- Parameters:
valueModel
- the model that holds the value to be edited
- Returns:
- a formatted text field for Date instances that is bound to the given value model
public static JFormattedTextField createFormattedTextField(ValueModel valueModel, 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.
- Parameters:
valueModel
- the model that provides the valueformat
- theFormat
used to convert values into a text representation and vice versa via#format
and#parse
- Returns:
- a formatted text field that is bound to the given value model
public static JFormattedTextField createFormattedTextField(ValueModel valueModel, 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.
- Parameters:
valueModel
- the model that provides the valueformatter
- the Formatter used to convert values to a text representation and vice versa via#valueToString
and#stringToValue
- Returns:
- a formatted text field that is bound to the given value model
public static JFormattedTextField createFormattedTextField(ValueModel valueModel, 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.
- Parameters:
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
- Returns:
- a formatted text field that is bound to the given value model
public static JFormattedTextField createFormattedTextField(ValueModel valueModel, 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.
- Parameters:
valueModel
- the model that provides the valuemask
- the mask pattern used to create an instance ofMaskFormatter
that in turn converts values to Strings and vice versa
- Returns:
- a bound formatted text field using a MaskFormatter
public static JFormattedTextField createIntegerField(ValueModel valueModel)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. Empty strings are converted tonull
and vice versa. The Format used to convert numbers to strings and vice versa isNumberFormat.getIntegerInstance()
.
- Parameters:
valueModel
- the model that holds the value to be edited
- Returns:
- a formatted text field for Integer instances that is bound to the specified valueModel
public static JFormattedTextField createIntegerField(ValueModel valueModel, NumberFormat numberFormat)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. Empty strings are converted tonull
and vice versa.
- Parameters:
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versa
- Returns:
- a formatted text field for Integer instances that is bound to the specified valueModel
public static JFormattedTextField createIntegerField(ValueModel valueModel, NumberFormat numberFormat, Integer emptyNumber)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. Empty strings are converted to the specified empty number.
- Parameters:
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
- Returns:
- a formatted text field for Integer instances that is bound to the specified valueModel
public static JFormattedTextField createIntegerField(ValueModel valueModel, NumberFormat numberFormat, int emptyNumber)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. Empty strings are converted to the specified empty number.
- Parameters:
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
- Returns:
- a formatted text field for Integer instances that is bound to the specified valueModel
public static JFormattedTextField createIntegerField(ValueModel valueModel, int emptyNumber)
Creates and returns a formatted text field that is bound to the Integer value of the given ValueModel. Empty strings are converted to the specified empty number. The Format used to convert numbers to strings and vice versa isNumberFormat.getIntegerInstance()
.
- Parameters:
valueModel
- the model that holds the value to be editedemptyNumber
- an Integer that represents the empty string
- Returns:
- a formatted text field for Integer instances that is bound to the specified valueModel
public static JLabel createLabel(ValueModel valueModel)
Creates and returns a text label that is bound to the given ValueModel.
- Parameters:
valueModel
- the model that provides the value
- Returns:
- a text label that is bound to the given value model
public static JLabel createLabel(ValueModel valueModel, Format format)
Creates and returns a text label that is bound to the given ValueModel that is wrapped by aStringConverter
. The conversion to Strings uses the specified Format.
- Parameters:
valueModel
- the model that provides the valueformat
- the format used to create the StringConverter
- Returns:
- a text label that is bound to the given value model
- See Also:
ConverterFactory
public static JList createList(SelectionInList selectionInList)
Creates and returns a JList for the given SelectionInList.
- Parameters:
selectionInList
- provides the list and selection
- Returns:
- a JList bound to the given SelectionInList
public static JList createList(SelectionInList selectionInList, ListCellRenderer cellRenderer)
Creates and returns a JList for the given SelectionInList using the specified optional ListCellRenderer to render cells.
- Parameters:
selectionInList
- provides the list and selectioncellRenderer
- an optional ListCellRenderer, can benull
- Returns:
- a JList bound to the given SelectionInList
public static JList createList(SelectionInListModel selectionInListModel)
Creates and returns a JList for the given SelectionInListModel.
- Parameters:
selectionInListModel
- provides the list and selection
- Returns:
- a JList bound to the given SelectionInListModel
- Since:
- 1.5
public static JList createList(SelectionInListModel selectionInListModel, ListCellRenderer cellRenderer)
Creates and returns a JList for the given SelectionInListModel using the specified optional ListCellRenderer to render cells.
- Parameters:
selectionInListModel
- provides the list and selectioncellRenderer
- an optional ListCellRenderer, can benull
- Returns:
- a JList bound to the given SelectionInListModel
- Since:
- 1.5
public static JFormattedTextField createLongField(ValueModel valueModel)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. Empty strings are converted tonull
and vice versa. The Format used to convert numbers to strings and vice versa isNumberFormat.getIntegerInstance()
.
- Parameters:
valueModel
- the model that holds the value to be edited
- Returns:
- a formatted text field for Long instances that is bound to the specified valueModel
public static JFormattedTextField createLongField(ValueModel valueModel, NumberFormat numberFormat)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. Empty strings are converted tonull
and vice versa.
- Parameters:
valueModel
- the model that holds the value to be editednumberFormat
- used to convert numbers to strings and vice versa
- Returns:
- a formatted text field for Long instances that is bound to the specified valueModel
public static JFormattedTextField createLongField(ValueModel valueModel, NumberFormat numberFormat, Long emptyNumber)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. Empty strings are converted to the specified empty number.
- Parameters:
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
- Returns:
- a formatted text field for Long instances that is bound to the specified valueModel
public static JFormattedTextField createLongField(ValueModel valueModel, NumberFormat numberFormat, long emptyNumber)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. Empty strings are converted to the specified empty number.
- Parameters:
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
- Returns:
- a formatted text field for Long instances that is bound to the specified valueModel
public static JFormattedTextField createLongField(ValueModel valueModel, long emptyNumber)
Creates and returns a formatted text field that is bound to the Long value of the given ValueModel. Empty strings are converted to the specified empty number. The Format used to convert numbers to strings and vice versa isNumberFormat.getIntegerInstance()
.
- Parameters:
valueModel
- the model that holds the value to be editedemptyNumber
- a Long that represents the empty string
- Returns:
- a formatted text field for Long instances that is bound to the specified valueModel
public static JPasswordField createPasswordField(ValueModel valueModel)
Creates and returns a JPasswordField with the content bound to the given ValueModel. Text changes are committed to the model on focus lost. 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. MethodJPasswordField.getPassword()
return's the field's password as a character array.
- Parameters:
valueModel
- the model that provides the value
- Returns:
- a text field that is bound to the given value model
- See Also:
createPasswordField(ValueModel,boolean)
,JPasswordField.getPassword()
public static JPasswordField createPasswordField(ValueModel valueModel, boolean commitOnFocusLost)
Creates and returns a JPasswordField with the content bound to the given ValueModel. Text changes can be committed to the model on focus lost or on every character typed. 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. MethodJPasswordField.getPassword()
return's the field's password as a character array.
- Parameters:
valueModel
- the model that provides the valuecommitOnFocusLost
- true to commit text changes on focus lost, false to commit text changes on every character typed
- Returns:
- a text field that is bound to the given value model
- See Also:
createPasswordField(ValueModel)
,JPasswordField.getPassword()
public static JRadioButton createRadioButton(ValueModel model, Object choice, String text)
Creates and returns a radio button with the specified text label that is bound to the given ValueModel. The radio button is selected if and only if the model's value equals the specified choice. The model is converted to the required ToggleButton using a RadioButtonAdapter.
- Parameters:
model
- the model that provides the current choicechoice
- this button's valuetext
- the radio buttons' text label
- Returns:
- a radio button with the specified text bound to the given model, selected if the model's value equals the specified choice
public static JTextArea createTextArea(ValueModel valueModel)
Creates and returns a text area with the content bound to the given ValueModel. Text changes are committed to the model on focus lost.
- Parameters:
valueModel
- the model that provides the value
- Returns:
- a text area that is bound to the given value model
- See Also:
createTextArea(ValueModel,boolean)
public static JTextArea createTextArea(ValueModel valueModel, boolean commitOnFocusLost)
Creates and returns a text area with the content bound to the given ValueModel. Text changes can be committed to the model on focus lost or on every character typed.
- Parameters:
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
- Returns:
- a text area that is bound to the given value model
- See Also:
createTextArea(ValueModel)
public static JTextField createTextField(ValueModel valueModel)
Creates and returns a text field with the content bound to the given ValueModel. Text changes are comitted to the model on focus lost.
- Parameters:
valueModel
- the model that provides the value
- Returns:
- a text field that is bound to the given value model
- See Also:
createTextField(ValueModel,boolean)
public static JTextField createTextField(ValueModel valueModel, boolean commitOnFocusLost)
Creates and returns a text field with the content bound to the given ValueModel. Text changes can be committed to the model on focus lost or on every character typed.
- Parameters:
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
- Returns:
- a text field that is bound to the given value model
- See Also:
createTextField(ValueModel)