Added convenience method for creating buttons and wiring them up with
actions. git-svn-id: https://samskivert.googlecode.com/svn/trunk@712 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Controller.java,v 1.13 2002/04/08 17:40:31 mdb Exp $
|
// $Id: Controller.java,v 1.14 2002/04/26 02:31:32 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -27,6 +27,7 @@ import java.awt.event.ActionListener;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.event.AncestorEvent;
|
import javax.swing.event.AncestorEvent;
|
||||||
|
|
||||||
@@ -81,6 +82,13 @@ public abstract class Controller
|
|||||||
* button.addActionListener(Controller.DISPATCHER);
|
* button.addActionListener(Controller.DISPATCHER);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* or, use the provided convenience function:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* JButton button =
|
||||||
|
* Controller.createActionButton("Do thing", "dothing");
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
* The controllers in scope would then be requested (in order) to
|
* The controllers in scope would then be requested (in order) to
|
||||||
* process the <code>dothing</code> action whenever the button was
|
* process the <code>dothing</code> action whenever the button was
|
||||||
* clicked.
|
* clicked.
|
||||||
@@ -296,6 +304,18 @@ public abstract class Controller
|
|||||||
EventQueue.invokeLater(new ActionInvoker(event));
|
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
|
* This class is used to dispatch action events to controllers within
|
||||||
* the context of the AWT event dispatch mechanism.
|
* the context of the AWT event dispatch mechanism.
|
||||||
|
|||||||
Reference in New Issue
Block a user