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

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
All Implemented Interfaces:
BoundDelegateComponent, BoundDelegateContainer
Direct Known Subclasses:
JComboBoxComponentDelegate, JListComponentDelegate, JMenuComponentDelegate

public abstract class ListBasedComponentDelegate
extends GenericJComponentDelegate<java.util.AbstractList,java.util.AbstractList>
implements BoundDelegateContainer

A delegate for a JList, JComboBox, or other type 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 JList is selected, the relateed bound components will be refreshed with the values from the corresponding Object in the AbstractList.

Author:
David Underhill

Field Summary
protected  java.util.Vector<BoundComponent> components
          components whose bindings are contained within the objects contained in this list
protected  java.util.AbstractList myList
           
protected  int primaryComponentIndex
          the index of the subcomponent which determines the names of the entries in the list (-1 [default] => number them instead)
 
Constructor Summary
ListBasedComponentDelegate(BoundComponent owner, BoundComponent compon)
          Instantiates an unbound JList Delegate
ListBasedComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String varName)
          Instantiates a bound JList Delegate
ListBasedComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          Instantiates a bound JList Delegate
ListBasedComponentDelegate(BoundComponent owner, BoundComponent 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 JList Delegate
ListBasedComponentDelegate(BoundComponent owner, BoundComponent compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.String varName)
          Instantiates a bound JList Delegate
 
Method Summary
 void addBoundComponent(BoundComponent b)
          add bound component to this (b's parent will be set to this)
 void addItem(java.lang.Object o)
          adds a new item to the list
 java.util.Vector<BoundComponent> getBoundComponents()
          get bound components this contains
 int getPrimaryComponent()
          gets the index of the component which whose string value is used as the value to represent that collection, or -1 to just number the sets
abstract  int getSelectedIndex()
          Returns the smallest selected cell index; the selection when only a single item is selected in the list.
 void moveItemDown(int index)
          moves the specified item down one (if the index is invalid or is the last item, this does nothing)
 void moveItemUp(int index)
          moves the specified item up one (if the index is invalid or is the first item, this does nothing)
 void moveSelectedItemDown()
          moves the selected item down one (if it is the last item, this does nothing)
 void moveSelectedItemUp()
          moves the selected item up one (if it is the first item, this does nothing)
 void removeItem(int index)
          removes the specified item from the list (do nothing if the index is invalid)
 void removeSelectedItem()
          removes the currently selected item from the list (do nothing if nothing is selected)
 void save()
          tells the boundObject about changes to the AbstractList
 void setPrimaryComponent(int primComponIndex)
          sets the index of the component which whose string value is used as the value to represent that collection, or -1 to just number the sets
abstract  void setSelectedIndex(int index)
          Selects a single cell.
 boolean swapItems(int index1, int index2)
          swaps two items in the list (if either index is invalid this returns false and does nothing)
 void swapItems(int index1, int index2, int selectIndex)
          swaps two items in the list (if either index is invalid, this does nothing) and selects the specified item
protected  java.lang.String updateItemText(int numOn)
           
 void updateSubcomponentBindings()
          update all components within this component
 
Methods inherited from class cdx.scorebot.util.swing.binding.delegate.GenericJComponentDelegate
completeInit, 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, load, 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.BoundDelegateContainer
notifyBoundComponentChange, selectItem
 
Methods inherited from interface cdx.scorebot.util.swing.binding.delegate.BoundDelegateComponent
addBindingListener, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, changeBinding, getBinding, getBoundParent, highlightOnError, isContainer, isValidated, load, notifyListenersOfBindingChanged, notifyListenersOfBindingChanging, removeBindingListener, setBoundParent, setHighlightOnError
 

Field Detail

components

protected java.util.Vector<BoundComponent> components
components whose bindings are contained within the objects contained in this list


primaryComponentIndex

protected int primaryComponentIndex
the index of the subcomponent which determines the names of the entries in the list (-1 [default] => number them instead)


myList

protected java.util.AbstractList myList
Constructor Detail

ListBasedComponentDelegate

public ListBasedComponentDelegate(BoundComponent owner,
                                  BoundComponent compon)
Instantiates an unbound JList Delegate

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

ListBasedComponentDelegate

public ListBasedComponentDelegate(BoundComponent owner,
                                  BoundComponent compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.String varName)
Instantiates a bound JList 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).

ListBasedComponentDelegate

public ListBasedComponentDelegate(BoundComponent owner,
                                  BoundComponent compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.Object boundItem,
                                  java.lang.String varName)
Instantiates a bound JList 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).

ListBasedComponentDelegate

public ListBasedComponentDelegate(BoundComponent owner,
                                  BoundComponent compon,
                                  TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator,
                                  java.lang.Object boundItem,
                                  java.lang.String getterName,
                                  java.lang.String setterName)
Instantiates a bound JList 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

ListBasedComponentDelegate

public ListBasedComponentDelegate(BoundComponent owner,
                                  BoundComponent 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 JList 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

save

public final void save()
tells the boundObject about changes to the AbstractList

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

updateItemText

protected java.lang.String updateItemText(int numOn)

getSelectedIndex

public abstract 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.


setSelectedIndex

public abstract 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.


addItem

public final void addItem(java.lang.Object o)
adds a new item to the list


moveSelectedItemDown

public final void moveSelectedItemDown()
moves the selected item down one (if it is the last item, this does nothing)


moveItemDown

public final void moveItemDown(int index)
moves the specified item down one (if the index is invalid or is the last item, this does nothing)


moveSelectedItemUp

public final void moveSelectedItemUp()
moves the selected item up one (if it is the first item, this does nothing)


moveItemUp

public final void moveItemUp(int index)
moves the specified item up one (if the index is invalid or is the first item, this does nothing)


swapItems

public final boolean swapItems(int index1,
                               int index2)
swaps two items in the list (if either index is invalid this returns false and does nothing)


swapItems

public final void swapItems(int index1,
                            int index2,
                            int selectIndex)
swaps two items in the list (if either index is invalid, this does nothing) and selects the specified item


removeSelectedItem

public final void removeSelectedItem()
removes the currently selected item from the list (do nothing if nothing is selected)


removeItem

public void removeItem(int index)
removes the specified item from the list (do nothing if the index is invalid)


addBoundComponent

public final void addBoundComponent(BoundComponent b)
add bound component to this (b's parent will be set to this)

Specified by:
addBoundComponent in interface BoundDelegateContainer

getBoundComponents

public final java.util.Vector<BoundComponent> getBoundComponents()
get bound components this contains

Specified by:
getBoundComponents in interface BoundDelegateContainer

getPrimaryComponent

public final int getPrimaryComponent()
gets the index of the component which whose string value is used as the value to represent that collection, or -1 to just number the sets

Specified by:
getPrimaryComponent in interface BoundDelegateContainer

setPrimaryComponent

public final void setPrimaryComponent(int primComponIndex)
sets the index of the component which whose string value is used as the value to represent that collection, or -1 to just number the sets

Specified by:
setPrimaryComponent in interface BoundDelegateContainer
Parameters:
primComponIndex - index of the BoundComponent which is the primary component in the getBoundComponents() vector.

updateSubcomponentBindings

public final void updateSubcomponentBindings()
update all components within this component

Specified by:
updateSubcomponentBindings in interface BoundDelegateContainer