01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.swing.action;
24:
25: import java.awt.event.ActionEvent;
26:
27: import javax.swing.AbstractAction;
28: import javax.swing.Action;
29:
30: /**
31: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
32: * @version 1.0
33: */
34: public class CustomAction extends AbstractAction {
35:
36: private static final long serialVersionUID = -430436376187044613L;
37: public final static String ICON_NAME = "ICON_NAME";
38: public final static String ACTION_ID = "ACTION_ID";
39: public final static String USER_OBJECT = "USER_OBJECT";
40:
41: protected final SwingEventManager eventManager;
42:
43: public CustomAction(String name, int action,
44: SwingEventManager eventManager) {
45:
46: this .eventManager = eventManager;
47: putValue(Action.NAME, name);
48: putValue(ACTION_ID, Integer.toString(action));
49: eventManager.registerAction(name, this );
50: }
51:
52: public void actionPerformed(ActionEvent evt) {
53:
54: if (eventManager != null) {
55: int id = -1;
56: try {
57: id = Integer.parseInt(getValue(ACTION_ID).toString());
58: } catch (Exception ignored) {
59: return;
60: }
61: ActionEvent forwardAction = new ActionEvent(
62: evt.getSource(), id, evt.getActionCommand(), evt
63: .getModifiers());
64: eventManager.actionPerformed(forwardAction);
65: }
66: }
67:
68: }
|