GUI Commands User GuideVersion 2.1 |
||
Creating CommandsThere are three steps to creating an ActionCommand:
1. Command ConfigurationAll configuration in GUI Commands is loaded from ResourceBundles. The property keys
consists of the command id, an For example, let's add the following to
hello-world@face.text=_Hello World!!!@control H
hello-world@face.icon=classpath:images/hello-world.png
hello-world@face.description=Says hello ($accelerator).
# create a user defined property
hello-world@properties.greeting=Hello World!!!
The above examples configures the text, icon and description of the "hello-world" command. The text property specifies that 'H' is the mnemonic and "Control H" is the accelerator. The description contains the command accelerator in parenthesis. We also configure a custom user property called 2. Load the configurationThe next step is to load the configuration. GUI Commands allows you to provide just the
resource bundle name using the same syntax as Now we load the configuration file
// load our configuration file
GuiCommands.load("MyCommands");
3. Create the CommandFinally all you need to do is extend ActionCommand and implement handleExecute(). You can then create as many buttons and menus as you like. /** * A command with the id "hello-world" that displays * a greeting over the current frame. */ public class HelloWorldCommand extends ActionCommand { public HelloWorldCommand() { super("hello-world"); } /** * Say hello */ public void handleExecute() { Window window = getInvokerWindow(); // get the user property we defined in the configuration String greeting = getProperty("greeting"); // show the greeting JOptionPane.showMessageDialog(window, greeting); } } // now create the command. HelloWorldCommand helloWorldCommand = new HelloWorldCommand(); // and ask it for a button. AbstractButton button = helloWorldCommand.createButton(); |
||