org.jminor.common.ui.valuemap
Class TextValueLink<K>

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.jminor.common.ui.control.Control
          extended by org.jminor.common.ui.control.AbstractValueLink<ValueChangeMapEditModel<K,V>,V>
              extended by org.jminor.common.ui.valuemap.AbstractValueMapLink<K,Object>
                  extended by org.jminor.common.ui.valuemap.TextValueLink<K>
All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action
Direct Known Subclasses:
DoubleValueLink, FormattedValueLink, IntValueLink

public class TextValueLink<K>
extends AbstractValueMapLink<K,Object>

A class for linking a text component to a ValueChangeMapEditModel text property value.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
TextValueLink(JTextComponent textComponent, ValueChangeMapEditModel<K,Object> editModel, K key, boolean immediateUpdate)
          Instantiates a new TextValueLink
TextValueLink(JTextComponent textComponent, ValueChangeMapEditModel<K,Object> editModel, K key, boolean immediateUpdate, LinkType linkType)
          Instantiates a new TextValueLink
 
Method Summary
protected  String getText()
           
protected  Object getUIValue()
          
protected  String getValueAsText(Object value)
          Returns a String representation of the given value object, null is returned in case of a null value
protected  Object getValueFromText(String text)
          Returns a property value based on the given text, if the text can not be parsed into a valid value, null is returned
 boolean isImmediateUpdate()
           
protected  void setUIValue(Object value)
          Sets the value in the UI
protected  String translate(String text)
          Provides a hook into the value setting mechanism.
 
Methods inherited from class org.jminor.common.ui.valuemap.AbstractValueMapLink
getEditModel, getKey, getModelValue, getValidationMessage, isModelValueNull, isNullable, setModelValue
 
Methods inherited from class org.jminor.common.ui.control.AbstractValueLink
actionPerformed, getLinkType, getValueOwner, updateModel, updateUI
 
Methods inherited from class org.jminor.common.ui.control.Control
getDescription, getEnabledState, getIcon, getMnemonic, getName, isEnabled, setDescription, setEnabled, setIcon, setKeyStroke, setMnemonic, setName
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, putValue, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextValueLink

public TextValueLink(JTextComponent textComponent,
                     ValueChangeMapEditModel<K,Object> editModel,
                     K key,
                     boolean immediateUpdate)
Instantiates a new TextValueLink

Parameters:
textComponent - the text component to link
editModel - the ValueChangeMapEditModel instance
key - the key to link
immediateUpdate - if true then the underlying model value is updated on each keystroke,

TextValueLink

public TextValueLink(JTextComponent textComponent,
                     ValueChangeMapEditModel<K,Object> editModel,
                     K key,
                     boolean immediateUpdate,
                     LinkType linkType)
Instantiates a new TextValueLink

Parameters:
textComponent - the text component to link
editModel - the ValueChangeMapEditModel instance
key - the key to link
immediateUpdate - if true then the underlying model value is updated on each keystroke, otherwise it is updated on actionPerformed or focusLost
linkType - the link type
Method Detail

isImmediateUpdate

public final boolean isImmediateUpdate()
Returns:
true if the underlying property should be updated on each keystroke

getUIValue

protected final Object getUIValue()

Specified by:
getUIValue in class AbstractValueLink<ValueChangeMapEditModel<K,Object>,Object>
Returns:
the value according to the UI

setUIValue

protected final void setUIValue(Object value)
Sets the value in the UI

Specified by:
setUIValue in class AbstractValueLink<ValueChangeMapEditModel<K,Object>,Object>
Parameters:
value - the value to represent in the UI

getText

protected final String getText()
Returns:
the text from the linked text component

translate

protected String translate(String text)
Provides a hook into the value setting mechanism.

Parameters:
text - the value returned from the UI component
Returns:
the translated value

getValueFromText

protected Object getValueFromText(String text)
                           throws ParseException
Returns a property value based on the given text, if the text can not be parsed into a valid value, null is returned

Parameters:
text - the text from which to parse a value
Returns:
a value, null if the input text has zero length or if it does not yield a valid value
Throws:
ParseException - in case the value could not be parsed from the text

getValueAsText

protected String getValueAsText(Object value)
Returns a String representation of the given value object, null is returned in case of a null value

Parameters:
value - the value to return as String
Returns:
a String representation of the given value, null if the value is null