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

java.lang.Object
  extended by cdx.scorebot.util.swing.binding.Binding<FROM,TO>

public class Binding<FROM,TO>
extends java.lang.Object

Describes a binding which holds a value of type T as a String

Author:
David Underhill

Constructor Summary
Binding(TypeTranslator<FROM,TO> translator, java.lang.Object boundItem, java.lang.String varName)
          Instantiates a binding
Binding(TypeTranslator<FROM,TO> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          Instantiates a binding
Binding(TypeTranslator<FROM,TO> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName, int indexAt)
          Instantiates a binding
 
Method Summary
 Binding bindToNewIndex(int index)
          bind to a new index on the same object
 Binding bindToNewObject(java.lang.Object newBoundItem)
          bind to a new object (no index)
 Binding bindToNewObject(java.lang.Object newBoundItem, int index)
          bind to a new object and index
 boolean canSetFromTranslatedValue(TO value)
          whether or not this value can be used to set the value of the bound object
 java.lang.Object getBoundItem()
          gets the object this binding is to
 java.lang.String getGetterName()
          gets the getter's name
 int getIndexAt()
          get the index in the bounditem which we are looking at
 java.lang.String getSetterName()
          gets the setter's name
 TO getTranslatedValue()
          gets the translated value from the value stored in the object
 TypeTranslator<FROM,TO> getTranslator()
          gets the translator
 FROM getValue()
          gets the actual value stored in the object
 void setFromTranslatedValue(TO value)
          sets the actual value from the specified value to be translated
 void setValue(FROM value)
          sets the value stored in the object to the specified value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Binding

public Binding(TypeTranslator<FROM,TO> translator,
               java.lang.Object boundItem,
               java.lang.String varName)
Instantiates a binding

Parameters:
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).

Binding

public Binding(TypeTranslator<FROM,TO> translator,
               java.lang.Object boundItem,
               java.lang.String getterName,
               java.lang.String setterName)
Instantiates a binding

Parameters:
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

Binding

public Binding(TypeTranslator<FROM,TO> translator,
               java.lang.Object boundItem,
               java.lang.String getterName,
               java.lang.String setterName,
               int indexAt)
Instantiates a binding

Parameters:
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

bindToNewIndex

public Binding bindToNewIndex(int index)
bind to a new index on the same object


bindToNewObject

public Binding bindToNewObject(java.lang.Object newBoundItem,
                               int index)
bind to a new object and index


bindToNewObject

public Binding bindToNewObject(java.lang.Object newBoundItem)
bind to a new object (no index)


getBoundItem

public java.lang.Object getBoundItem()
gets the object this binding is to


getGetterName

public java.lang.String getGetterName()
gets the getter's name


getSetterName

public java.lang.String getSetterName()
gets the setter's name


getIndexAt

public int getIndexAt()
get the index in the bounditem which we are looking at


getValue

public FROM getValue()
              throws java.lang.IllegalArgumentException
gets the actual value stored in the object

Throws:
java.lang.IllegalArgumentException - thrown if the value could not be set to the specified value because the getter threw an exception

getTranslatedValue

public TO getTranslatedValue()
                      throws java.lang.IllegalArgumentException,
                             TranslationFailedException
gets the translated value from the value stored in the object

Throws:
java.lang.IllegalArgumentException - thrown if the value could not be set to the specified value because the getter threw an exception
TranslationFailedException - thrown if the value cannot be translated

setValue

public void setValue(FROM value)
              throws java.lang.IllegalArgumentException
sets the value stored in the object to the specified value

Throws:
java.lang.IllegalArgumentException - thrown if the value could not be set to the specified value because the setter threw an exception

setFromTranslatedValue

public void setFromTranslatedValue(TO value)
                            throws java.lang.IllegalArgumentException,
                                   TranslationFailedException
sets the actual value from the specified value to be translated

Throws:
java.lang.IllegalArgumentException - thrown if the value could not be set to the specified value because the setter threw an exception
TranslationFailedException - thrown if the value cannot be translated

canSetFromTranslatedValue

public boolean canSetFromTranslatedValue(TO value)
whether or not this value can be used to set the value of the bound object

Returns:
true if the value can be translated

getTranslator

public TypeTranslator<FROM,TO> getTranslator()
gets the translator