01: /*--
02: Copyright (C) 2003-2007 Wolf Paulus.
03: All rights reserved.
04:
05: Redistribution and use in source and binary forms, with or without
06: modification, are permitted provided that the following conditions
07: are met:
08:
09: 1. Redistributions of source code must retain the above copyright
10: notice, this list of conditions, and the following disclaimer.
11:
12: 2. Redistributions in binary form must reproduce the above copyright
13: notice, this list of conditions, and the disclaimer that follows
14: these conditions in the documentation and/or other materials provided
15: with the distribution.
16:
17: 3. The end-user documentation included with the redistribution,
18: if any, must include the following acknowledgment:
19: "This product includes software developed by the
20: SWIXML Project (http://www.swixml.org/)."
21: Alternately, this acknowledgment may appear in the software itself,
22: if and wherever such third-party acknowledgments normally appear.
23:
24: 4. The name "Swixml" must not be used to endorse or promote products
25: derived from this software without prior written permission. For
26: written permission, please contact <info_AT_swixml_DOT_org>
27:
28: 5. Products derived from this software may not be called "Swixml",
29: nor may "Swixml" appear in their name, without prior written
30: permission from the Swixml Project Management.
31:
32: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
33: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35: DISCLAIMED. IN NO EVENT SHALL THE SWIXML PROJECT OR ITS
36: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39: USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40: ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41: OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42: OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43: SUCH DAMAGE.
44: ====================================================================
45:
46: This software consists of voluntary contributions made by many
47: individuals on behalf of the Swixml Project and was originally
48: created by Wolf Paulus <wolf_AT_swixml_DOT_org>. For more information
49: on the Swixml Project, please see <http://www.swixml.org/>.
50: */
51: package org.swixml;
52:
53: import javax.swing.*;
54: import java.awt.event.ActionEvent;
55: import java.lang.reflect.Method;
56: import java.lang.reflect.InvocationTargetException;
57:
58: /**
59: * XAction, Action Wrapper to generate Actions on the fly.
60: * @author <a href="mailto:wolf@wolfpaulus.com">Wolf Paulus</a>
61: */
62:
63: public class XAction extends AbstractAction {
64: Method method;
65: Object client;
66:
67: public XAction(Object client, String methodName)
68: throws NoSuchMethodException {
69: this .client = client;
70: if (client != null) {
71: method = client.getClass().getMethod(methodName);
72: }
73:
74: }
75:
76: public void actionPerformed(ActionEvent e) {
77: try {
78: this .method.invoke(client);
79: } catch (IllegalAccessException e1) {
80: e1.printStackTrace();
81: } catch (InvocationTargetException e1) {
82: e1.printStackTrace();
83: }
84: }
85: }
|