|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Button
com.ccg.awt.TriggerButton
public class TriggerButton
An easy way to create localized buttons and link callbacks. Often one needs to create GUI button objects that the user can "press". When the user "presses" the button, typically the programmer would like to have one or more methods called on particular objects. This class simplifies the process. It does this in the following manner:
create buttons which are
localized based on the contents of a resource bundle.
trigger the
invocation of any method of one or more objects when the user
"presses" the button.
This allows one to write much "cleaner" looking GUI classes as demonstrated in the demo applet.
create(com.ccg.util.Lookup, java.lang.String),
addTrigger(java.lang.Object, java.lang.String),
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.awt.Button |
|---|
Button.AccessibleAWTButton |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
TriggerButton()
Construct the button without an initial label. |
|
TriggerButton(String label)
Construct the button with an initial label. |
|
| Method Summary | |
|---|---|
void |
actionPerformed(ActionEvent aevent)
Handle the condition when the users presses the button. |
Exception |
addTrigger(Object o,
String methodName)
Add a method to be invoked when button action occurs. |
void |
addTriggerMethod(Object o,
Method m,
Object[] params)
Add a method to be invoked when button action occurs. |
Exception |
addTriggerPopupMenu(PopupMenu pm)
Add a PopupMenu to display when button pressed. |
static TriggerButton |
create(Lookup lookup,
String tag)
The easy way to create localizable trigger buttons. |
| Methods inherited from class java.awt.Button |
|---|
addActionListener, addNotify, getAccessibleContext, getActionCommand, getActionListeners, getLabel, getListeners, paramString, processActionEvent, processEvent, removeActionListener, setActionCommand, setLabel |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TriggerButton()
addTriggerMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) and addTrigger(java.lang.Object, java.lang.String) methods to
register methods to be invoked when the button action is invoked.
public TriggerButton(String label)
addTriggerMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) and addTrigger(java.lang.Object, java.lang.String) methods to
register methods to be invoked when the button action is invoked.
| Method Detail |
|---|
public static TriggerButton create(Lookup lookup, String tag)
TriggerButton object based on the
contents of a Lookup table. This has two nice
advantages. One, it simplifies the process of localizing your
application. Two, it removes the decision of how the button
should be labeld from the code. Using this method, you can use
standard Java property files to:
Consider the following example resource file:
# Player start button, comment out if you want to remove from # what is displayed the the user. Player.Start.label=Start
If we were to load the above resource file using the TagLookup class with a initial tag of "Player", a ResourceBundle (say is was "myproject.MyStrings"
resource (don't forget the ".poperties" extension). The following
code fragment could be used:
TagLookup lookup = new TagLookup(myGui,"Player");
TriggerButton tb = TriggerButton.create(rb,".Start");
if (tb) add(tb); // add to GUI if it was configured
That's all there is to it, you would have created and added the button to your panel if it was configured, and the label would be "Start".
lookup - Used to lookup the ".label" to associate with the button (if
the ".label" isn't found, then no button is created).tag - Since your lookup table may contain definitions for many GUI
objects, set this to the "Tag" associated with your label (may
".Start" for Start button resources, ".Stop" for Stop button
resources etc.)
addTrigger(java.lang.Object, java.lang.String),
TagLookup.TagLookup(Class,String)public void addTriggerMethod(Object o, Method m, Object[] params)
o - Object to invoke the method on (must not be null).m - Method to invoke on object (must not be null).args - Optional arguments to pass to method when it is invoked (may
be null).addTrigger(java.lang.Object, java.lang.String)public Exception addTrigger(Object o, String methodName)
Object and name of the method to be invoked. It
assumes that the method doesn't require any parameters.
This version looks up the Method
object for you. If this lookup throws an Exception, then the desired trigger action will not be
registered and the exception thrown will be returned. This method
does not throw any exceptions itself since it assumes that you
will only pass valid values to it.
o - Object to invoke the method on (must not be null).methodName - Name of method to invoke (must not be null). It is used to
lookup the Method for the object
passed.
Exception
is thrown, it will be returned (and your trigger method
probably won't work as expected).addTriggerMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])public Exception addTriggerPopupMenu(PopupMenu pm)
PopupMenu to display when button pressed.
This method links a PopupMenu item to the button
that will be displayed when the user clicks on the button.
pm - {java.awt.PopupMenu} to associate with the button.
Exception
is thrown, it will be returned (and your trigger method
probably won't work as expected).addTriggerMethod(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])public void actionPerformed(ActionEvent aevent)
actionPerformed in interface ActionListeneraevent - ActionEvent which we are processing
(typically generated by the GUI when the user presses the
button.addTrigger(java.lang.Object, java.lang.String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||