cdx.scorebot.util.swing.binding.delegate
Class JComboBoxComponentDelegate

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

public class JComboBoxComponentDelegate
extends ListBasedComponentDelegate

A delegate for a JComboBox which is bound to an AbstractList. Other related bound components may be bound to this ListBasedComponentDelegate. Such related components would be member variables of the Objects in the AbstractList. When a particular item in the JComboBox is selected, the relateed bound components will be refreshed with the values from the corresponding Object in the AbstractList.

Author:
David Underhill

Field Summary
 
Fields inherited from class cdx.scorebot.util.swing.binding.delegate.ListBasedComponentDelegate
components, myList, primaryComponentIndex
 
Constructor Summary
JComboBoxComponentDelegate(BoundComponent owner, JComboBoxBound compon)
          Instantiates an unbound JComboBox Delegate
JComboBoxComponentDelegate(BoundComponent owner, JComboBoxBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String varName)
          Instantiates a bound JComboBox Delegate
JComboBoxComponentDelegate(BoundComponent owner, JComboBoxBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          Instantiates a bound JComboBox Delegate
JComboBoxComponentDelegate(BoundComponent owner, JComboBoxBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName, int indexAt)
          Instantiates a bound JComboBox Delegate
JComboBoxComponentDelegate(BoundComponent owner, JComboBoxBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.String varName)
          Instantiates a bound JComboBox 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
 javax.swing.ListModel getModel()
          Returns the data model that holds the list of items displayed by the JComboBox component.
 int getSelectedIndex()
          Returns the smallest selected cell index; the selection when only a single item is selected in the list.
 void load()
          load the current contents for this component from the bound object
 void notifyBoundComponentChange(BoundComponent c)
          notify the parent of a bound component change in value
 void selectItem(int index)
          selects the item at the specified index (if the index does not exist, this is ignored)
 void setModel(javax.swing.ListModel model)
          Sets the model that represents the contents or "value" of the list, notifies property change listeners, and then clears the list's selection.
protected  void setOrAddToModel(javax.swing.DefaultComboBoxModel model, int index, java.lang.String text)
          sets the specified element in the model to the specified text
 void setSelectedIndex(int index)
          Selects a single cell.
 
Methods inherited from class cdx.scorebot.util.swing.binding.delegate.ListBasedComponentDelegate
addBoundComponent, addItem, getBoundComponents, getPrimaryComponent, moveItemDown, moveItemUp, moveSelectedItemDown, moveSelectedItemUp, removeItem, removeSelectedItem, save, setPrimaryComponent, swapItems, swapItems, updateItemText, updateSubcomponentBindings
 
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

JComboBoxComponentDelegate

public JComboBoxComponentDelegate(BoundComponent owner,
                                  JComboBoxBound compon)
Instantiates an unbound JComboBox Delegate

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

JComboBoxComponentDelegate

public JComboBoxComponentDelegate(BoundComponent owner,
                                  JComboBoxBound compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.String varName)
Instantiates a bound JComboBox Delegate

Parameters:
owner - the BoundComponent which this belongs to
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).

JComboBoxComponentDelegate

public JComboBoxComponentDelegate(BoundComponent owner,
                                  JComboBoxBound compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.Object boundItem,
                                  java.lang.String varName)
Instantiates a bound JComboBox Delegate

Parameters:
owner - the BoundComponent which this belongs to
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).

JComboBoxComponentDelegate

public JComboBoxComponentDelegate(BoundComponent owner,
                                  JComboBoxBound compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.Object boundItem,
                                  java.lang.String getterName,
                                  java.lang.String setterName)
Instantiates a bound JComboBox Delegate

Parameters:
owner - the BoundComponent which this belongs to
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

JComboBoxComponentDelegate

public JComboBoxComponentDelegate(BoundComponent owner,
                                  JComboBoxBound compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.Object boundItem,
                                  java.lang.String getterName,
                                  java.lang.String setterName,
                                  int indexAt)
Instantiates a bound JComboBox Delegate

Parameters:
owner - the BoundComponent which this belongs to
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 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<java.util.AbstractList,java.util.AbstractList>

load

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

Specified by:
load in interface BoundDelegateComponent
Specified by:
load in class GenericDelegate<java.util.AbstractList,java.util.AbstractList>

getModel

public final javax.swing.ListModel getModel()
Returns the data model that holds the list of items displayed by the JComboBox component.

Returns:
the ListModel that provides the displayed list of items

setModel

public void setModel(javax.swing.ListModel model)
Sets the model that represents the contents or "value" of the list, notifies property change listeners, and then clears the list's selection.

Parameters:
model - the ListModel that provides the list of items for display

getSelectedIndex

public final int getSelectedIndex()
Returns the smallest selected cell index; the selection when only a single item is selected in the list. When multiple items are selected, it is simply the smallest selected index. Returns -1 if there is no selection.

Specified by:
getSelectedIndex in class ListBasedComponentDelegate

setSelectedIndex

public final void setSelectedIndex(int index)
Selects a single cell. Does nothing if the given index is greater than or equal to the model size. This is a convenience method that uses setSelectionInterval on the selection model. Refer to the documentation for the selection model class being used for details on how values less than 0 are handled.

Specified by:
setSelectedIndex in class ListBasedComponentDelegate

setOrAddToModel

protected final void setOrAddToModel(javax.swing.DefaultComboBoxModel model,
                                     int index,
                                     java.lang.String text)
sets the specified element in the model to the specified text


notifyBoundComponentChange

public final void notifyBoundComponentChange(BoundComponent c)
notify the parent of a bound component change in value


selectItem

public final void selectItem(int index)
selects the item at the specified index (if the index does not exist, this is ignored)