cdx.scorebot.util.swing.binding.delegate
Class GenericDelegate<FROM,TO>

java.lang.Object
  extended by cdx.scorebot.util.swing.binding.delegate.GenericDelegate<FROM,TO>
All Implemented Interfaces:
BoundDelegateComponent
Direct Known Subclasses:
ButtonGroupDelegate, GenericJComponentDelegate, IntermediateFieldDelegate

public abstract class GenericDelegate<FROM,TO>
extends java.lang.Object
implements BoundDelegateComponent

Binds some Object of type FROM to a component which requires type TO

Author:
David Underhill

Constructor Summary
GenericDelegate(boolean isContainer, BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,TO> translator, java.lang.Object boundItem, java.lang.String varName)
          Instantiates a bound Object Delegate
GenericDelegate(boolean isContainer, BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,TO> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          Instantiates a bound Object Delegate
GenericDelegate(boolean isContainer, BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,TO> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName, int indexAt)
          Instantiates a bound Object Delegate
GenericDelegate(boolean isContainer, BoundComponent owner, BoundComponent compon, TypeTranslator<FROM,TO> translator, java.lang.String varName)
          Instantiates an unbound Object Delegate
GenericDelegate(BoundComponent owner, BoundComponent compon)
          Instantiates an unbound Object Delegate
 
Method Summary
 void addBindingListener(BindingListener listener)
          Register a listener for this object
 void changeBinding(Binding b)
          change what this object is bound to (will save the current value to its currently bound object)
 void changeBinding(int index)
          change what this object is bound to (will save the current value to its currently bound object)
 void changeBinding(java.lang.Object newBoundItem)
          change what this object is bound to (will save the current value to its currently bound object)
 void changeBinding(java.lang.Object newBoundItem, int index)
          change what this object is bound to (will save the current value to its currently bound object)
 void changeBinding(java.lang.Object boundItem, java.lang.String varName)
          change what this object is bound to (will save the current value to its currently bound object)
 void changeBinding(java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          change what this object is bound to (will save the current value to its currently bound object)
 void changeBinding(java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName, int indexAt)
          change what this object is bound to (will save the current value to its currently bound object)
protected abstract  void completeInit()
          suggested that this is used to load the component with its initial values after the constructor is done
 Binding<FROM,TO> getBinding()
          gets the binding for this component
 BoundDelegateContainer getBoundParent()
          gets the parent container for this component
protected  java.lang.String getFormattedValidationErrorMsg()
          gets the validation error message prefaced by "\nError: " if there is an error message.
 BoundComponent getMe()
          gets a reference to the Object this works for
 BoundComponent getOwner()
          gets a reference to the BoundComponent this works for
protected  java.lang.String getValidationErrorMsg()
          gets the validation error message
protected abstract  void handleValidationState()
          draw the border to reflect the specified validation state
 boolean highlightOnError()
          whether or not to highlight with a red border on error
 boolean isContainer()
          whether or not this bound component is a container of other bound components
 boolean isValidated()
          whether or not a validation error has occurred
abstract  void load()
          load the current text for this component from the bound object
 void notifyListenersOfBindingChanged()
          Notifies all listeners that the binding has changed
 void notifyListenersOfBindingChanging()
          Notifies all listeners that the binding is about to change
 void notifyListenersOfBindingLoaded()
          Notifies all listeners that the binding has changed and been loaded
 void removeBindingListener(BindingListener listener)
          Remove a registered listener from this object
abstract  void save()
          save the current text in this component to the bound object
 void setBoundParent(BoundDelegateContainer c)
          sets the parent container for this component
 void setHighlightOnError(boolean highlightOnError)
          whether or not to highlight with a red border on error
protected  void setValidationError(boolean validationError)
          sets whether or not a validation error has occurred and clears the validation error message
protected  void setValidationError(boolean validationError, java.lang.String validationErrorMsg)
          sets whether or not a validation error has occurred (also sets a validation error message too)
 boolean validationError()
          gets whether or not a validation error has occurred
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDelegate

public GenericDelegate(BoundComponent owner,
                       BoundComponent compon)
Instantiates an unbound Object Delegate

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

GenericDelegate

public GenericDelegate(boolean isContainer,
                       BoundComponent owner,
                       BoundComponent compon,
                       TypeTranslator<FROM,TO> translator,
                       java.lang.String varName)
Instantiates an unbound Object Delegate

Parameters:
owner - the BoundComponent which this belongs to
isContainer - whether or not this component can contain others
compon - the component that this works for
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).

GenericDelegate

public GenericDelegate(boolean isContainer,
                       BoundComponent owner,
                       BoundComponent compon,
                       TypeTranslator<FROM,TO> translator,
                       java.lang.Object boundItem,
                       java.lang.String varName)
Instantiates a bound Object Delegate

Parameters:
owner - the BoundComponent which this belongs to
isContainer - whether or not this component can contain others
compon - the component that this works for
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).

GenericDelegate

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

Parameters:
owner - the BoundComponent which this belongs to
isContainer - whether or not this component can contain others
compon - the component that this works for
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

GenericDelegate

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

Parameters:
owner - the BoundComponent which this belongs to
isContainer - whether or not this component can contain others
compon - the component that this works for
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 abstract void completeInit()
suggested that this is used to load the component with its initial values after the constructor is done


addBindingListener

public void addBindingListener(BindingListener listener)
Register a listener for this object

Specified by:
addBindingListener in interface BoundDelegateComponent
Parameters:
listener - the object which is listening

notifyListenersOfBindingChanging

public void notifyListenersOfBindingChanging()
Notifies all listeners that the binding is about to change

Specified by:
notifyListenersOfBindingChanging in interface BoundDelegateComponent

notifyListenersOfBindingChanged

public void notifyListenersOfBindingChanged()
Notifies all listeners that the binding has changed

Specified by:
notifyListenersOfBindingChanged in interface BoundDelegateComponent

notifyListenersOfBindingLoaded

public void notifyListenersOfBindingLoaded()
Notifies all listeners that the binding has changed and been loaded


removeBindingListener

public void removeBindingListener(BindingListener listener)
Remove a registered listener from this object

Specified by:
removeBindingListener in interface BoundDelegateComponent
Parameters:
listener - the object which is listening to be removed

changeBinding

public final void changeBinding(Binding b)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
b - the new binding

changeBinding

public void changeBinding(java.lang.Object newBoundItem)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
newBoundItem - the object this is bound to (contains the value to be modified as specified by varName)

changeBinding

public final void changeBinding(java.lang.Object newBoundItem,
                                int index)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
newBoundItem - the object this is bound to (contains the value to be modified as specified by varName)
index - the new index to bind to

changeBinding

public final void changeBinding(int index)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
index - the new index to bind to

changeBinding

public final void changeBinding(java.lang.Object boundItem,
                                java.lang.String varName)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
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).

changeBinding

public final void changeBinding(java.lang.Object boundItem,
                                java.lang.String getterName,
                                java.lang.String setterName)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
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

changeBinding

public final void changeBinding(java.lang.Object boundItem,
                                java.lang.String getterName,
                                java.lang.String setterName,
                                int indexAt)
change what this object is bound to (will save the current value to its currently bound object)

Specified by:
changeBinding in interface BoundDelegateComponent
Parameters:
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

load

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

Specified by:
load in interface BoundDelegateComponent

save

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

Specified by:
save in interface BoundDelegateComponent

getOwner

public final BoundComponent getOwner()
gets a reference to the BoundComponent this works for


getMe

public BoundComponent getMe()
gets a reference to the Object this works for


getBinding

public final Binding<FROM,TO> getBinding()
gets the binding for this component

Specified by:
getBinding in interface BoundDelegateComponent

getBoundParent

public final BoundDelegateContainer getBoundParent()
gets the parent container for this component

Specified by:
getBoundParent in interface BoundDelegateComponent

setBoundParent

public final void setBoundParent(BoundDelegateContainer c)
sets the parent container for this component

Specified by:
setBoundParent in interface BoundDelegateComponent

isContainer

public final boolean isContainer()
whether or not this bound component is a container of other bound components

Specified by:
isContainer in interface BoundDelegateComponent

isValidated

public final boolean isValidated()
whether or not a validation error has occurred

Specified by:
isValidated in interface BoundDelegateComponent

handleValidationState

protected abstract void handleValidationState()
draw the border to reflect the specified validation state


highlightOnError

public final boolean highlightOnError()
whether or not to highlight with a red border on error

Specified by:
highlightOnError in interface BoundDelegateComponent

setHighlightOnError

public final void setHighlightOnError(boolean highlightOnError)
whether or not to highlight with a red border on error

Specified by:
setHighlightOnError in interface BoundDelegateComponent

validationError

public final boolean validationError()
gets whether or not a validation error has occurred


setValidationError

protected final void setValidationError(boolean validationError)
sets whether or not a validation error has occurred and clears the validation error message


setValidationError

protected final void setValidationError(boolean validationError,
                                        java.lang.String validationErrorMsg)
sets whether or not a validation error has occurred (also sets a validation error message too)


getValidationErrorMsg

protected final java.lang.String getValidationErrorMsg()
gets the validation error message


getFormattedValidationErrorMsg

protected final java.lang.String getFormattedValidationErrorMsg()
gets the validation error message prefaced by "\nError: " if there is an error message. The message is also broken into lines which are no more than 80 characters in length.