public abstract class Field
extends java.lang.Object
Each Field has a name, a JLabel and a JComponent for user editing/input. The name must be unique within the PersistenceManager and/or PrefPanel. A Field can optionally have a tooltip, and can be enabled/disabled from allowing editing.
Each Field has a current "valid value" object. The JComponent has an "edit value", which may be invalid. When the field loses focus, or accept() is called, the value is validated and transferred to the validValue. If not valid, the user cannot leave the field. The edit value is thus not visible until it has been accepted. If the new value is different from the previously valid value, a PropertyChangeEvent is thrown, and the canonical form is written back to the edit value.
Each Field optionally has a PersistenceManager, which may contain the "stored value" of the field. If it exists, it is used as the starting value, otherwise, the "default value" is used. The default value may be null.
When accept() is called, validate() is called on the edit value to ensure the field has a valid format. If so, the value is compared to the previously accepted value, and if different, a PropertyChangeEvent is sent, and the store is updated.
The specialized set/get like setText() or setDouble() set both the edit value and the store value. The setters throw an event if the new value is different from previous.
When the PersistenceManager sends a PreferenceChangeEvent, the field gets the new value and displays it. If different from previous value, a PropertyChangeEvent is sent. Thus the PersistenceManager object is the "model" and the Field is the "view", and they automatically stay in synch.
A PreferencesExt object is optionally used to save state about the Field UI.
PrefPanel
Modifier and Type | Class and Description |
---|---|
static class |
Field.BeanTableField
This uses a BeanTable to display a list of beans.
|
static class |
Field.CheckBox
A boolean input box using a checkbox.
|
static class |
Field.Date
Data input for Date
|
static class |
Field.Double
Data input for double.
|
static class |
Field.EnumCombo
This allows user to make a choice from a collection of "type-safe enumeration" objects.
|
static class |
Field.Int
Data input for double.
|
static class |
Field.Password
A text input field which doesnt echo the input, for passwords.
|
static class |
Field.Text
String input field.
|
static class |
Field.TextArea
String input field using a TextArea.
|
static class |
Field.TextCombo
A text input field which keeps track of recent choices in a combobox.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
label |
protected javax.swing.event.EventListenerList |
listenerList |
protected java.lang.String |
name |
protected javax.swing.JPopupMenu |
popupMenu |
protected java.lang.Object |
previousValue |
protected PersistenceManager |
storeData |
protected java.lang.Object |
validValue |
Modifier | Constructor and Description |
---|---|
protected |
Field(java.lang.String name,
java.lang.String label,
PersistenceManager storeData)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
_validate(java.lang.StringBuffer buff)
See if edit value is valid, put error message in buff.
|
protected boolean |
accept(java.lang.StringBuffer buff)
Get current value from editComponent, save to store.
|
protected boolean |
acceptIfDifferent(java.lang.Object newValue)
See if this value is different from current accepted value (using equals());
If so, set old value to accepted value, then accepted value to this value.
|
void |
addPopupMenuAction(java.lang.String name,
javax.swing.AbstractAction action) |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Register for PropertyChange events when the value of the Field changes.
|
protected void |
addStandardPopups() |
void |
addValidator(FieldValidator v)
Add a validator to this field.
|
static java.lang.String |
dfrac(double d,
int fixed_decimals)
Double value formatting with fixed number of digits to the right of the decimal point.
|
protected void |
finish() |
javax.swing.JComponent |
getDeepEditComponent() |
abstract javax.swing.JComponent |
getEditComponent()
Return the editing JComponent
|
protected abstract java.lang.Object |
getEditValue()
Get current value from editComponent
|
java.lang.String |
getLabel()
Return the JLabel component
|
java.lang.String |
getName()
Return the name of the field
|
PersistenceManager |
getPersistenceManager()
Return the PersistenceManager component
|
protected abstract java.lang.Object |
getStoreValue(java.lang.Object defValue)
Get value from Store.
|
java.lang.String |
getToolTipText()
Get the tooltip
|
java.lang.Object |
getValue()
Get valid value as String, Double, Integer, etc.
|
boolean |
isEditable()
Return whether the field is editable, default == enabled
|
boolean |
isEnabled()
Return whether the field is enabled
|
protected void |
next() |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Deregister for when the value changes
|
protected void |
restoreValue(java.lang.Object defValue) |
protected void |
sendEvent() |
void |
setEditable(boolean editable)
Set whether the field is editable, default == enabled
|
protected abstract void |
setEditValue(java.lang.Object value)
Set current value of editComponent
|
void |
setEnabled(boolean enable)
Set whether the field is enabled
|
protected void |
setNewValueFromStore()
The value in the store has changed: update the edit component
send event if its different from previous
|
protected abstract void |
setStoreValue(java.lang.Object newValue)
Put new value into Store.
|
void |
setToolTipText(java.lang.String tip)
Set the tooltip
|
void |
setValue(java.lang.Object newValue)
Set the current valid and edit value.
|
protected boolean |
validate(java.lang.StringBuffer buff)
See if edit value is valid, put error message in buff.
|
protected java.lang.String name
protected PersistenceManager storeData
protected javax.swing.event.EventListenerList listenerList
protected java.lang.String label
protected java.lang.Object validValue
protected java.lang.Object previousValue
protected javax.swing.JPopupMenu popupMenu
protected Field(java.lang.String name, java.lang.String label, PersistenceManager storeData)
name
- of the field; must be unique within the storelabel
- to display to the userstoreData
- store/fetch data from here, may be null.protected void finish()
public java.lang.String getName()
public java.lang.String getLabel()
public PersistenceManager getPersistenceManager()
public boolean isEnabled()
public void setEnabled(boolean enable)
public boolean isEditable()
public void setEditable(boolean editable)
public void setToolTipText(java.lang.String tip)
public java.lang.String getToolTipText()
public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
public abstract javax.swing.JComponent getEditComponent()
protected abstract boolean _validate(java.lang.StringBuffer buff)
protected abstract java.lang.Object getEditValue()
protected abstract void setEditValue(java.lang.Object value)
protected abstract java.lang.Object getStoreValue(java.lang.Object defValue)
protected abstract void setStoreValue(java.lang.Object newValue)
public javax.swing.JComponent getDeepEditComponent()
public java.lang.Object getValue()
public void setValue(java.lang.Object newValue)
public void addValidator(FieldValidator v)
v
- an implementation of FieldValidator.protected boolean validate(java.lang.StringBuffer buff)
protected boolean accept(java.lang.StringBuffer buff)
protected boolean acceptIfDifferent(java.lang.Object newValue)
protected void restoreValue(java.lang.Object defValue)
protected void setNewValueFromStore()
protected void sendEvent()
protected void next()
protected void addStandardPopups()
public void addPopupMenuAction(java.lang.String name, javax.swing.AbstractAction action)
public static java.lang.String dfrac(double d, int fixed_decimals)
d
- the number to format.fixed_decimals
- number of digits to the right of the decimal point