01: /*
02: * ActionPanel.java
03: *
04: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package org.underworldlabs.swing;
23:
24: import java.awt.LayoutManager;
25: import java.awt.event.ActionEvent;
26: import java.awt.event.ActionListener;
27: import java.lang.reflect.Method;
28: import javax.swing.JPanel;
29:
30: /* ----------------------------------------------------------
31: * CVS NOTE: Changes to the CVS repository prior to the
32: * release of version 3.0.0beta1 has meant a
33: * resetting of CVS revision numbers.
34: * ----------------------------------------------------------
35: */
36:
37: /**
38: * Base panel with default action listener implementation using reflection.
39: *
40: * @author Takis Diakoumis
41: * @version $Revision: 1.4 $
42: * @date $Date: 2006/05/14 06:56:07 $
43: */
44: public class ActionPanel extends JPanel implements ActionListener {
45:
46: private static Object[] args;
47: private static Class[] argTypes;
48:
49: public ActionPanel() {
50: super ();
51: }
52:
53: public ActionPanel(boolean isDoubleBuffered) {
54: super (isDoubleBuffered);
55: }
56:
57: public ActionPanel(LayoutManager layout) {
58: super (layout);
59: }
60:
61: public ActionPanel(LayoutManager layout, boolean isDoubleBuffered) {
62: super (layout, isDoubleBuffered);
63: }
64:
65: public void actionPerformed(ActionEvent e) {
66: String command = e.getActionCommand();
67: try {
68:
69: if (argTypes == null) {
70: argTypes = new Class[0];
71: }
72:
73: Method method = getClass().getMethod(command, argTypes);
74:
75: if (args == null) {
76: args = new Object[0];
77: }
78:
79: method.invoke(this , args);
80: } catch (Exception ex) {
81: ex.printStackTrace();
82: }
83: }
84:
85: }
|