diff --git a/src/java/com/samskivert/swing/Controller.java b/src/java/com/samskivert/swing/Controller.java index 65430c2f..28967ec4 100644 --- a/src/java/com/samskivert/swing/Controller.java +++ b/src/java/com/samskivert/swing/Controller.java @@ -27,6 +27,7 @@ import java.awt.event.ActionListener; import java.lang.reflect.Method; +import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JComponent; @@ -99,6 +100,70 @@ public abstract class Controller } }; + /** + * Posts the specified action to the nearest controller in scope. The + * controller search begins with the source component of the action and + * traverses up the component tree looking for a controller to handle the + * action. The controller location and action event processing is + * guaranteed to take place on the AWT thread regardless of what thread + * calls postAction and that processing will not occur + * immediately but is instead appended to the AWT event dispatch queue for + * processing. + */ + public static void postAction (ActionEvent action) + { + // slip things onto the event queue for later + EventQueue.invokeLater(new ActionInvoker(action)); + } + + /** + * Like {@link #postAction(ActionEvent)} except that it constructs the + * action event for you with the supplied source component and string + * command. The id of the event will always be set to + * zero. + */ + public static void postAction (Component source, String command) + { + // slip things onto the event queue for later + ActionEvent event = new ActionEvent(source, 0, command); + EventQueue.invokeLater(new ActionInvoker(event)); + } + + /** + * Like {@link #postAction(ActionEvent)} except that it constructs a + * {@link CommandEvent} with the supplied source component, string + * command and argument. + */ + public static void postAction ( + Component source, String command, Object argument) + { + // slip things onto the event queue for later + CommandEvent event = new CommandEvent(source, command, argument); + EventQueue.invokeLater(new ActionInvoker(event)); + } + + /** + * Creates a button and configures it with the specified label and action + * command and adds {@link #DISPATCHER} as an action listener. + */ + public static JButton createActionButton (String label, String command) + { + JButton button = new JButton(label); + configureAction(button, command); + return button; + } + + /** + * Configures the supplied button with the {@link #DISPATCHER} action + * listener and the specified action command (which, if it is a method name + * will be looked up dynamically on the matching controller). + */ + public static void configureAction (AbstractButton button, String action) + { + button.setActionCommand(action); + button.addActionListener(DISPATCHER); + } + /** * Lets this controller know about the panel that it is controlling. */ @@ -313,60 +378,6 @@ public abstract class Controller return null; } - /** - * Posts the specified action to the nearest controller in scope. The - * controller search begins with the source component of the action and - * traverses up the component tree looking for a controller to handle the - * action. The controller location and action event processing is - * guaranteed to take place on the AWT thread regardless of what thread - * calls postAction and that processing will not occur - * immediately but is instead appended to the AWT event dispatch queue for - * processing. - */ - public static void postAction (ActionEvent action) - { - // slip things onto the event queue for later - EventQueue.invokeLater(new ActionInvoker(action)); - } - - /** - * Like {@link #postAction(ActionEvent)} except that it constructs the - * action event for you with the supplied source component and string - * command. The id of the event will always be set to - * zero. - */ - public static void postAction (Component source, String command) - { - // slip things onto the event queue for later - ActionEvent event = new ActionEvent(source, 0, command); - EventQueue.invokeLater(new ActionInvoker(event)); - } - - /** - * Like {@link #postAction(ActionEvent)} except that it constructs a - * {@link CommandEvent} with the supplied source component, string - * command and argument. - */ - public static void postAction ( - Component source, String command, Object argument) - { - // slip things onto the event queue for later - CommandEvent event = new CommandEvent(source, command, argument); - EventQueue.invokeLater(new ActionInvoker(event)); - } - - /** - * Creates a button and configures it with the specified label and - * action command and adds {@link #DISPATCHER} as an action listener. - */ - public static JButton createActionButton (String label, String command) - { - JButton button = new JButton(label); - button.setActionCommand(command); - button.addActionListener(DISPATCHER); - return button; - } - /** * This class is used to dispatch action events to controllers within * the context of the AWT event dispatch mechanism.