GUI Commands User GuideVersion 2.1 |
||||||||||||||||||
Using AnnotationsUsing annotated methods in GUI Commands is a two step process.
The following shows an example of annotating methods with both the ActionCommand and SwingWorkerCommand annotations.
public class AnnotatedClass
{
@ActionCommand_("open")
public void doOpen()
{
// do the same operation.
}
@SwingWorkerCommand_("save")
public void doSave()
{
// do the save operation on a background thread.
}
}
The value of the annotation is used to define the command id, thus in the above
example the "open" command will invoke the In order to make the commands available they need to be created and bound to a
container. This is achieved by calling AnnotatedClass annotatedClass = ...; CommandContainer container = ...; // create commands from the annotated methods and bind them // to the conatiner. GuiCommands.bindAnnotatedCommands(container, annotatedClass); In the above example the container will then be populated with both the "open" and "save" commands generated from the annotated class. Method ParametersAnnotated methods can also specify a single parameter a type of either
The following example shows an annotated method that will be passed the commands invoking window.
@ActionCommand_("hello-world")
public void helloWorld(Window invokerWindow)
{
JOptionPane.showMessageDialog(invokerWindow, "Hello World!!!");
}
SwingWorkerCommand AnnotationThe
Methods annotated with // we've had to use the fully qualified class name of the command as it // clashes with the name of the @SwingWorkerCommand_ annotation. @SwingWorkerCommand_(id="save", glassPane="true") public void doSave(com.pietschy.command.worker.SwingWorkerCommand command) { while (...) { command.setProgress(...); } } |
||||||||||||||||||