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

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.JMenuComponentDelegate
All Implemented Interfaces:
BoundDelegateComponent, BoundDelegateContainer

public class JMenuComponentDelegate
extends ListBasedComponentDelegate

A delegate for a JMenu 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 submenu in the JMenu 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
JMenuComponentDelegate(BoundComponent owner, JMenuBound compon)
          Instantiates an unbound JMenu Delegate
JMenuComponentDelegate(BoundComponent owner, JMenuBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String varName)
          Instantiates a bound JMenu Delegate
JMenuComponentDelegate(BoundComponent owner, JMenuBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.Object boundItem, java.lang.String getterName, java.lang.String setterName)
          Instantiates a bound JMenu Delegate
JMenuComponentDelegate(BoundComponent owner, JMenuBound 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 JMenu Delegate
JMenuComponentDelegate(BoundComponent owner, JMenuBound compon, TypeTranslator<java.util.AbstractList,java.util.AbstractList> translator, java.lang.String varName)
          Instantiates a bound JMenu Delegate
 
Method Summary
 void addMenuAtBottom(javax.swing.JMenuItem ti)
          Adds a JMenuItem to the bottom of this menu
 void addMenuAtTop(javax.swing.JMenuItem ti)
          Adds a JMenuItem to the top of this menu
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.JMenuItem getMenuAtBottom(int index)
          Gets the specified JMenuItem from the bottom of this menu
 javax.swing.JMenuItem getMenuAtTop(int index)
          Gets the specified JMenuItem from the top of this menu
 java.util.Vector<javax.swing.JMenuItem> getMenusAtBottom()
          gets the JMenuItems being added at the bottom of the JMenu
 java.util.Vector<javax.swing.JMenuItem> getMenusAtTop()
          gets the JMenuItems being added at the top of the JMenu
 int getSelectedIndex()
          Returns the index of the menu item which is selected, or -1 if there is no selected item.
 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 removeItem(int index)
          removes the specified item from the list (do nothing if the index is invalid)
 void removeMenuAtBottom(int index)
          Removes the JMenuItem from the bottom of this menu
 void removeMenuAtTop(int index)
          Removes the JMenuItem from the top of this menu
 void selectItem(int index)
          selects the item at the specified index (if the index does not exist, this is ignored)
protected  void setOrAddToModel(javax.swing.JMenu menu, int index, java.lang.String text)
          sets the specified element in the model to the specified text
 void setSelectedIndex(int index)
          Sets a single menu item as selected (deselects any other menu items)
 
Methods inherited from class cdx.scorebot.util.swing.binding.delegate.ListBasedComponentDelegate
addBoundComponent, addItem, getBoundComponents, getPrimaryComponent, moveItemDown, moveItemUp, moveSelectedItemDown, moveSelectedItemUp, 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

JMenuComponentDelegate

public JMenuComponentDelegate(BoundComponent owner,
                              JMenuBound compon)
Instantiates an unbound JMenu Delegate

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

JMenuComponentDelegate

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

JMenuComponentDelegate

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

JMenuComponentDelegate

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

JMenuComponentDelegate

public JMenuComponentDelegate(BoundComponent owner,
                              JMenuBound 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 JMenu 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>

addMenuAtTop

public void addMenuAtTop(javax.swing.JMenuItem ti)
Adds a JMenuItem to the top of this menu

Parameters:
ti - the JMenuItem to add to this JMenu

removeMenuAtTop

public void removeMenuAtTop(int index)
                     throws java.lang.ArrayIndexOutOfBoundsException
Removes the JMenuItem from the top of this menu

Parameters:
index - remove the MenuAtTop at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getMenuAtTop

public javax.swing.JMenuItem getMenuAtTop(int index)
                                   throws java.lang.ArrayIndexOutOfBoundsException
Gets the specified JMenuItem from the top of this menu

Returns:
the JMenuItem at the specified index in the top of this menu
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getMenusAtTop

public java.util.Vector<javax.swing.JMenuItem> getMenusAtTop()
gets the JMenuItems being added at the top of the JMenu


addMenuAtBottom

public void addMenuAtBottom(javax.swing.JMenuItem ti)
Adds a JMenuItem to the bottom of this menu

Parameters:
ti - the JMenuItem to add to this JMenu

removeMenuAtBottom

public void removeMenuAtBottom(int index)
                        throws java.lang.ArrayIndexOutOfBoundsException
Removes the JMenuItem from the bottom of this menu

Parameters:
index - remove the MenuAtBottom at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getMenuAtBottom

public javax.swing.JMenuItem getMenuAtBottom(int index)
                                      throws java.lang.ArrayIndexOutOfBoundsException
Gets the specified JMenuItem from the bottom of this menu

Returns:
the JMenuItem at the specified index in the bottom of this menu
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getMenusAtBottom

public java.util.Vector<javax.swing.JMenuItem> getMenusAtBottom()
gets the JMenuItems being added at the bottom of the JMenu


getSelectedIndex

public int getSelectedIndex()
Returns the index of the menu item which is selected, or -1 if there is no selected item.

Specified by:
getSelectedIndex in class ListBasedComponentDelegate

setSelectedIndex

public void setSelectedIndex(int index)
Sets a single menu item as selected (deselects any other menu items)

Specified by:
setSelectedIndex in class ListBasedComponentDelegate

removeItem

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

Overrides:
removeItem in class ListBasedComponentDelegate

setOrAddToModel

protected final void setOrAddToModel(javax.swing.JMenu menu,
                                     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)