cdx.scorebot.util.swing.binding.delegate
Class JTextComponentDelegate<FROM>

java.lang.Object
  extended by cdx.scorebot.util.swing.binding.delegate.GenericDelegate<FROM,TO>
      extended by cdx.scorebot.util.swing.binding.delegate.GenericJComponentDelegate<FROM,java.lang.String>
          extended by cdx.scorebot.util.swing.binding.delegate.JTextComponentDelegate<FROM>
All Implemented Interfaces:
BoundDelegateComponent

public class JTextComponentDelegate<FROM>
extends GenericJComponentDelegate<FROM,java.lang.String>
implements BoundDelegateComponent

A delegate for a JTextComponent which is bound to a value of type FROM which can be represented as a String.

Author:
David Underhill

Constructor Summary
JTextComponentDelegate(BoundComponent owner, BoundComponent compon)
          Instantiates an unbound JTextComponent Delegate
JTextComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,java.lang.String> translator, java.lang.Object boundItem, java.lang.String varName)
          Instantiates a bound JTextComponent Delegate
JTextComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,java.lang.String> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          Instantiates a bound JTextComponent Delegate
JTextComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,java.lang.String> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName, int indexAt)
          Instantiates a bound JTextComponent Delegate
JTextComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,java.lang.String> translator, java.lang.String varName)
          Instantiates a bound JTextComponent Delegate
 
Method Summary
protected  void completeInit()
          adds a focus listener which binds any changes in the component to the object it is bound to when focus is lost
 void load()
          load the current text for this component from the bound object
 void save()
          save the current text in this component to the bound object
 void setText(java.lang.String t)
          Sets the bound item with the translation of the specified text.
 
Methods inherited from class cdx.scorebot.util.swing.binding.delegate.GenericJComponentDelegate
handleValidationState
 
Methods inherited from class cdx.scorebot.util.swing.binding.delegate.GenericDelegate
addBindingListener, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, getBinding, getBoundParent, getFormattedValidationErrorMsg, getMe, getOwner, getValidationErrorMsg, highlightOnError, isContainer, isValidated, notifyListenersOfBindingChanged, notifyListenersOfBindingChanging, notifyListenersOfBindingLoaded, removeBindingListener, setBoundParent, setHighlightOnError, setValidationError, setValidationError, validationError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cdx.scorebot.util.swing.binding.delegate.BoundDelegateComponent
addBindingListener, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, getBinding, getBoundParent, highlightOnError, isContainer, isValidated, notifyListenersOfBindingChanged, notifyListenersOfBindingChanging, removeBindingListener, setBoundParent, setHighlightOnError
 

Constructor Detail

JTextComponentDelegate

public JTextComponentDelegate(BoundComponent owner,
                              BoundComponent compon)
Instantiates an unbound JTextComponent Delegate

Parameters:
owner - the BoundComponent which this belongs to
compon - the component that this works for

JTextComponentDelegate

public JTextComponentDelegate(BoundComponent owner,
                              BoundComponent compon,
                              TypeTranslator<FROM,java.lang.String> translator,
                              java.lang.String varName)
Instantiates a bound JTextComponent Delegate

Parameters:
owner - the BoundComponent which this belongs to
compon - the component that this works for; must be a JTextComponent
translator - how to translate between the value in the boundItem (type FROM) a another value of type TO
varName - the name of the variable; assumes the getter and setter name will be get and set followed by varName with its first letter capitalized (ex: if varName is "value" then the getter will be getValue).

JTextComponentDelegate

public JTextComponentDelegate(BoundComponent owner,
                              BoundComponent compon,
                              TypeTranslator<FROM,java.lang.String> translator,
                              java.lang.Object boundItem,
                              java.lang.String varName)
Instantiates a bound JTextComponent Delegate

Parameters:
owner - the BoundComponent which this belongs to
compon - the component that this works for; must be a JTextComponent
translator - how to translate between the value in the boundItem (type FROM) a another value of type TO
boundItem - the object this is bound to (contains the value to be modified as specified by varName)
varName - the name of the variable; assumes the getter and setter name will be get and set followed by varName with its first letter capitalized (ex: if varName is "value" then the getter will be getValue).

JTextComponentDelegate

public JTextComponentDelegate(BoundComponent owner,
                              BoundComponent compon,
                              TypeTranslator<FROM,java.lang.String> translator,
                              java.lang.Object boundItem,
                              java.lang.String getterName,
                              java.lang.String setterName)
Instantiates a bound JTextComponent Delegate

Parameters:
owner - the BoundComponent which this belongs to
compon - the component that this works for; must be a JTextComponent
translator - how to translate between the value in the boundItem (type FROM) a another value of type TO
boundItem - the object this is bound to (contains the value to be modified as specified by the getter and setter name)
getterName - how to get the bound value from the bound object
setterName - how to set the bound value from the bound object

JTextComponentDelegate

public JTextComponentDelegate(BoundComponent owner,
                              BoundComponent compon,
                              TypeTranslator<FROM,java.lang.String> translator,
                              java.lang.Object boundItem,
                              java.lang.String getterName,
                              java.lang.String setterName,
                              int indexAt)
Instantiates a bound JTextComponent Delegate

Parameters:
owner - the BoundComponent which this belongs to
compon - the component that this works for; must be a JTextComponent
translator - how to translate between the value in the boundItem (type FROM) a another value of type TO
boundItem - the object this is bound to (contains the value to be modified as specified by the getter and setter name)
getterName - how to get the bound value from the bound object
setterName - how to set the bound value from the bound object
indexAt - if bound value is stored within a container with get(index) and set(index, Object) methods, then indexAt should be the index to use; otherwise, indexAt should be -1
Method Detail

completeInit

protected void completeInit()
adds a focus listener which binds any changes in the component to the object it is bound to when focus is lost

Specified by:
completeInit in class GenericJComponentDelegate<FROM,java.lang.String>

load

public void load()
load the current text for this component from the bound object

Specified by:
load in interface BoundDelegateComponent
Specified by:
load in class GenericDelegate<FROM,java.lang.String>

save

public void save()
save the current text in this component to the bound object

Specified by:
save in interface BoundDelegateComponent
Specified by:
save in class GenericDelegate<FROM,java.lang.String>

setText

public void setText(java.lang.String t)
Sets the bound item with the translation of the specified text. The text which appears in this component will be the translation back from the bound item. If the text cannot be translated, this a validation error will be flagged and the text will be set but the bound object's value will not change!

Parameters:
t - the new text to be set