edu.kzoo.grid.gui
Class GeneratedButtonList

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.ArrayList
                    |
                    +--edu.kzoo.grid.gui.GeneratedButtonList
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.util.RandomAccess, java.io.Serializable

public class GeneratedButtonList
extends java.util.ArrayList

Grid GUI Support Package:
A GeneratedButtonList object creates a group of control buttons based on the methods of another class. When the GeneratedButtonList object is constructed, the client code must specify a target object (the object whose methods are to be associated with control buttons) and a set of arguments to be passed to those methods. The GeneratedButtonList object will generate control buttons for all of the target object's methods that could be passed the given set of arguments and have a void return type.

Version:
29 July 2004
Author:
Alyce Brady
See Also:
Serialized Form

Nested Class Summary
protected  class GeneratedButtonList.GeneratedThreadedControlButton
          GeneratedThreadedControlButton objects represent buttons whose button action is to reflectively invoke the appropriate method in the target object.
 
Field Summary
protected  java.util.Map buttonLabelToMethodObjMap
           
protected  boolean displayGridAfterButtonActions
           
protected  GridAppFrame gui
           
protected  boolean includeOnButtonClickMethodsOnly
           
static java.util.regex.Pattern methNamePattern
           
static java.lang.String methNameRegExpr
           
protected  java.lang.Object[] methodArguments
           
static java.lang.String prefix
           
static java.lang.String suffix
           
protected  java.util.List targetMethods
           
protected  java.lang.Object targetObj
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, boolean displayAfterButtonPresses)
          Constructs a list of control buttons based on methods associated with the given target object.
GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, boolean onButtonClickMethodsOnly, boolean displayAfterButtonPresses)
          Constructs a list of control buttons based on methods associated with the given target object.
GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, java.lang.Object[] arguments, boolean displayAfterButtonPresses)
          Constructs a list of control buttons based on methods associated with the given target object.
GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, java.lang.Object[] arguments, boolean onClickButtonMethodsOnly, boolean displayAfterButtonPresses)
          Constructs a list of control buttons based on methods associated with the given target object.
 
Method Summary
protected  java.lang.String buttonLabelFor(java.lang.reflect.Method method)
          Returns the appropriate button label for the given method.
protected  void createButtons()
          Creates control buttons that, when pressed, will pass a message to the appropriate method in the target object.
protected  void identifyButtonMethods()
          Identifies the target object's methods for which control buttons should be created.
protected  boolean meetsControlMethodCriteria(java.lang.reflect.Method methodToCheck, java.lang.Class targetClass)
          Returns true if the given method was declared in the specified class (not in one of its superclasses) and has the right return type and parameters to be turned into a control button; false otherwise.
protected  boolean meetsMethodNameFormatCriteria(java.lang.String methodName)
          Returns true if the given method was declared in the specified class (not in one of its superclasses) and has the right return type and parameters to be turned into a control button; false otherwise.
 void resetButtonLabel(java.lang.String prevButtonLabel, java.lang.String buttonLabel)
          Resets the specified button label associated with a method in the target object.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Field Detail

prefix

public static final java.lang.String prefix
See Also:
Constant Field Values

suffix

public static final java.lang.String suffix
See Also:
Constant Field Values

methNameRegExpr

public static final java.lang.String methNameRegExpr
See Also:
Constant Field Values

methNamePattern

public static final java.util.regex.Pattern methNamePattern

gui

protected GridAppFrame gui

targetObj

protected java.lang.Object targetObj

includeOnButtonClickMethodsOnly

protected boolean includeOnButtonClickMethodsOnly

targetMethods

protected java.util.List targetMethods

methodArguments

protected java.lang.Object[] methodArguments

buttonLabelToMethodObjMap

protected java.util.Map buttonLabelToMethodObjMap

displayGridAfterButtonActions

protected boolean displayGridAfterButtonActions
Constructor Detail

GeneratedButtonList

public GeneratedButtonList(GridAppFrame gui,
                           java.lang.Object targetObj,
                           boolean displayAfterButtonPresses)
Constructs a list of control buttons based on methods associated with the given target object. Will only include methods that take 0 arguments and have a void return type. The text on each control button will be the associated method name or, if the name matches the on...ButtonClick format, the middle part of the method name. For example, the control button for a doX method would have the label "doX", while the control button for an onDoYButtonClick method would have the label "DoY". When each resulting control button is pressed, it will send the associated message to the target object. It may also display the contents of the grid afterward, depending on the value of displayAfterButtonPresses.

Parameters:
gui - graphical user interface that will contain these buttons
targetObj - an object of the class whose methods should become control buttons; the buttons will forward messages to targetObj in response to button presses
displayAfterButtonPresses - true if the user interface should display the contents of the grid after executing the behaviors associated with control button presses; false otherwise

GeneratedButtonList

public GeneratedButtonList(GridAppFrame gui,
                           java.lang.Object targetObj,
                           boolean onButtonClickMethodsOnly,
                           boolean displayAfterButtonPresses)
Constructs a list of control buttons based on methods associated with the given target object. Will only include methods that take 0 arguments, have a void return type, and, if onButtonClickMethodsOnly is true, whose names match the on...ButtonClick format (e.g., onXYZButtonClick). The text on each control button will be the associated method name or, if the name matches the on...ButtonClick format, the middle part of the method name. For example, the control button for a doX method would have the label "doX", while the control button for an onDoYButtonClick method would have the label "DoY". When each resulting control button is pressed, it will send the associated message to the target object. It may also display the contents of the grid afterward, depending on the value of displayAfterButtonPresses.

Parameters:
gui - graphical user interface that will contain these buttons
targetObj - an object of the class whose methods should become control buttons; the buttons will forward messages to targetObj in response to button presses
onButtonClickMethodsOnly - true if only on...ButtonClick methods should be included; false otherwise
displayAfterButtonPresses - true if the user interface should display the contents of the grid after executing the behaviors associated with control button presses; false otherwise

GeneratedButtonList

public GeneratedButtonList(GridAppFrame gui,
                           java.lang.Object targetObj,
                           java.lang.Object[] arguments,
                           boolean displayAfterButtonPresses)
Constructs a list of control buttons based on methods associated with the given target object. Will only include methods that could be passed the given set of arguments and that have a void return type. The text on each control button will be the associated method name or, if the name matches the on...ButtonClick format, the middle part of the method name. For example, the control button for a doX method would have the label "doX", while the control button for an onDoYButtonClick method would have the label "DoY". When each resulting control button is pressed, it will send the associated message to the target object, passing as arguments the objects provided to this constructor. It may also display the contents of the grid afterward, depending on the value of displayAfterButtonPresses.

Parameters:
gui - graphical user interface that will contain these buttons
targetObj - an object of the class whose methods should become control buttons; the buttons will forward messages to targetObj in response to button presses
arguments - the arguments to pass to methods associated with control buttons
displayAfterButtonPresses - true if the user interface should display the contents of the grid after executing the behaviors associated with control button presses; false otherwise

GeneratedButtonList

public GeneratedButtonList(GridAppFrame gui,
                           java.lang.Object targetObj,
                           java.lang.Object[] arguments,
                           boolean onClickButtonMethodsOnly,
                           boolean displayAfterButtonPresses)
Constructs a list of control buttons based on methods associated with the given target object. Will only include methods that could be passed the given set of arguments, that have a void return type, and, if onButtonClickMethodsOnly is true, whose names match the on...ButtonClick format (e.g., onXYZButtonClick). The text on each control button will be the associated method name or, if the name matches the on...ButtonClick format, the middle part of the method name. For example, the control button for a doX method would have the label "doX", while the control button for an onDoYButtonClick method would have the label "DoY". When each resulting control button is pressed, it will send the associated message to the target object, passing as arguments the objects provided to this constructor. It may also display the contents of the grid afterward, depending on the value of displayAfterButtonPresses.

Parameters:
gui - graphical user interface that will contain these buttons
targetObj - an object of the class whose methods should become control buttons; the buttons will forward messages to targetObj in response to button presses
arguments - the arguments to pass to methods associated with control buttons
displayAfterButtonPresses - true if the user interface should display the contents of the grid after executing the behaviors associated with control button presses; false otherwise
Method Detail

identifyButtonMethods

protected void identifyButtonMethods()
Identifies the target object's methods for which control buttons should be created.


meetsControlMethodCriteria

protected boolean meetsControlMethodCriteria(java.lang.reflect.Method methodToCheck,
                                             java.lang.Class targetClass)
Returns true if the given method was declared in the specified class (not in one of its superclasses) and has the right return type and parameters to be turned into a control button; false otherwise.


meetsMethodNameFormatCriteria

protected boolean meetsMethodNameFormatCriteria(java.lang.String methodName)
Returns true if the given method was declared in the specified class (not in one of its superclasses) and has the right return type and parameters to be turned into a control button; false otherwise.


buttonLabelFor

protected java.lang.String buttonLabelFor(java.lang.reflect.Method method)
Returns the appropriate button label for the given method.


createButtons

protected void createButtons()
Creates control buttons that, when pressed, will pass a message to the appropriate method in the target object.


resetButtonLabel

public void resetButtonLabel(java.lang.String prevButtonLabel,
                             java.lang.String buttonLabel)
Resets the specified button label associated with a method in the target object. The prevButtonLabel parameter should be the previous button label. (The default button label is the name of the associated method or, if the method name matches the onXYZButtonClick format, is the name of the method without the on...ButtonClick prefix and suffix, e.g., XYZ). This method should be called before the constructWindowContents method of the graphical user interface. This method does nothing if the list of generated control buttons does not include a button whose current label is prevButtonLabel.

Parameters:
prevButtonLabel - previous button label
buttonLabel - label to place on button