public class GeneratedButtonList extends java.util.ArrayList<ThreadedControlButton>
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.Modifier and Type | Class and Description |
---|---|
protected class |
GeneratedButtonList.GeneratedThreadedControlButton
GeneratedThreadedControlButton objects represent buttons whose
button action is to reflectively invoke the appropriate method
in the target object.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.reflect.Method> |
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<java.lang.reflect.Method> |
targetMethods |
protected java.lang.Object |
targetObj |
Constructor and Description |
---|
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 onButtonClickMethodsOnly,
boolean displayAfterButtonPresses)
Constructs a list of control buttons based on methods associated
with the given target object.
|
Modifier and Type | Method and Description |
---|---|
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.
|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
public static final java.lang.String prefix
public static final java.lang.String suffix
public static final java.lang.String methNameRegExpr
public static final java.util.regex.Pattern methNamePattern
protected GridAppFrame gui
protected java.lang.Object targetObj
protected boolean includeOnButtonClickMethodsOnly
protected java.util.List<java.lang.reflect.Method> targetMethods
protected java.lang.Object[] methodArguments
protected java.util.Map<java.lang.String,java.lang.reflect.Method> buttonLabelToMethodObjMap
protected boolean displayGridAfterButtonActions
public GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, boolean displayAfterButtonPresses)
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
.gui
- graphical user interface that will contain these
buttonstargetObj
- an object of the class whose methods should become
control buttons; the buttons will forward
messages to targetObj in response to button pressesdisplayAfterButtonPresses
- true if the user interface should
display the contents of the grid after executing
the behaviors associated with control button
presses; false otherwisepublic GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, boolean onButtonClickMethodsOnly, boolean displayAfterButtonPresses)
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
.gui
- graphical user interface that will contain these
buttonstargetObj
- an object of the class whose methods should become
control buttons; the buttons will forward
messages to targetObj in response to button pressesonButtonClickMethodsOnly
- true if only on...ButtonClick
methods should be included; false otherwisedisplayAfterButtonPresses
- true if the user interface should
display the contents of the grid after executing
the behaviors associated with control button
presses; false otherwisepublic GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, java.lang.Object[] arguments, boolean displayAfterButtonPresses)
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
.gui
- graphical user interface that will contain these
buttonstargetObj
- an object of the class whose methods should become
control buttons; the buttons will forward
messages to targetObj in response to button pressesarguments
- the arguments to pass to methods associated with
control buttonsdisplayAfterButtonPresses
- true if the user interface should
display the contents of the grid after executing
the behaviors associated with control button
presses; false otherwisepublic GeneratedButtonList(GridAppFrame gui, java.lang.Object targetObj, java.lang.Object[] arguments, boolean onButtonClickMethodsOnly, boolean displayAfterButtonPresses)
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
.gui
- graphical user interface that will contain these
buttonstargetObj
- an object of the class whose methods should become
control buttons; the buttons will forward
messages to targetObj in response to button pressesarguments
- the arguments to pass to methods associated with
control buttonsonButtonClickMethodsOnly
- true if only on...ButtonClick
methods should be included; false otherwisedisplayAfterButtonPresses
- true if the user interface should
display the contents of the grid after executing
the behaviors associated with control button
presses; false otherwiseprotected void identifyButtonMethods()
protected boolean meetsControlMethodCriteria(java.lang.reflect.Method methodToCheck, java.lang.Class targetClass)
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)
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 java.lang.String buttonLabelFor(java.lang.reflect.Method method)
protected void createButtons()
public void resetButtonLabel(java.lang.String prevButtonLabel, java.lang.String buttonLabel)
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
.prevButtonLabel
- previous button labelbuttonLabel
- label to place on button