001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.ui;
027:
028: import java.awt.event.*;
029:
030: import java.net.*;
031:
032: import javax.swing.*;
033: import javax.swing.event.*;
034:
035: /**
036: *
037: *
038: * @author $author$
039: * @version $Revision: 1.16 $
040: */
041: public abstract class StandardAction extends AbstractAction {
042: /** */
043: public final static String ON_TOOLBAR = "onToolBar";
044:
045: /** */
046: public final static String TOOLBAR_GROUP = "toolBarGroup";
047:
048: /** */
049: public final static String TOOLBAR_WEIGHT = "toolBarWeight";
050:
051: /** */
052: public final static String ON_MENUBAR = "onMenuBar";
053:
054: /** */
055: public final static String MENU_NAME = "menuName";
056:
057: /** */
058: public final static String MENU_ITEM_GROUP = "menuItemGroup";
059:
060: /** */
061: public final static String MENU_ITEM_WEIGHT = "menuItemWeight";
062:
063: /** */
064: public final static String IMAGE_DIR = "/com/sshtools/sshterm/";
065:
066: /** */
067: public final static String HIDE_TOOLBAR_TEXT = "hideToolbarText";
068:
069: /** */
070: public final static String IS_TOGGLE_BUTTON = "isToggleButton";
071:
072: /** */
073: public final static String LARGE_ICON = "LargeIcon";
074:
075: /** */
076: public final static String ON_CONTEXT_MENU = "onContextMenu";
077:
078: /** */
079: public final static String CONTEXT_MENU_GROUP = "contextMenuGroup";
080:
081: /** */
082: public final static String CONTEXT_MENU_WEIGHT = "contextMenuWeight";
083:
084: /** */
085: public final static String MENU_ICON = "menuIcon";
086:
087: // The listener to action events (usually the main UI)
088: private EventListenerList listeners;
089:
090: /**
091: *
092: *
093: * @return
094: */
095: public String getActionCommand() {
096: return (String) getValue(Action.ACTION_COMMAND_KEY);
097: }
098:
099: /**
100: *
101: *
102: * @return
103: */
104: public String getShortDescription() {
105: return (String) getValue(Action.SHORT_DESCRIPTION);
106: }
107:
108: /**
109: *
110: *
111: * @return
112: */
113: public String getLongDescription() {
114: return (String) getValue(Action.LONG_DESCRIPTION);
115: }
116:
117: /**
118: *
119: *
120: * @return
121: */
122: public String getName() {
123: return (String) getValue(Action.NAME);
124: }
125:
126: /**
127: *
128: *
129: * @return
130: */
131: public String getSmallIcon() {
132: return (String) getValue(Action.SMALL_ICON);
133: }
134:
135: /**
136: *
137: *
138: * @param evt
139: */
140: public void actionPerformed(ActionEvent evt) {
141: if (listeners != null) {
142: Object[] listenerList = listeners.getListenerList();
143:
144: // Recreate the ActionEvent and stuff the value of the ACTION_COMMAND_KEY
145: ActionEvent e = new ActionEvent(evt.getSource(), evt
146: .getID(),
147: (String) getValue(Action.ACTION_COMMAND_KEY));
148:
149: for (int i = 0; i <= (listenerList.length - 2); i += 2) {
150: ((ActionListener) listenerList[i + 1])
151: .actionPerformed(e);
152: }
153: }
154: }
155:
156: /**
157: *
158: *
159: * @param l
160: */
161: public void addActionListener(ActionListener l) {
162: if (listeners == null) {
163: listeners = new EventListenerList();
164: }
165:
166: listeners.add(ActionListener.class, l);
167: }
168:
169: /**
170: *
171: *
172: * @param l
173: */
174: public void removeActionListener(ActionListener l) {
175: if (listeners == null) {
176: return;
177: }
178:
179: listeners.remove(ActionListener.class, l);
180: }
181:
182: /**
183: *
184: *
185: * @param name
186: *
187: * @return
188: */
189: public ImageIcon getIcon(String name) {
190: String imagePath = name.startsWith("/") ? name
191: : (IMAGE_DIR + name);
192: URL url = this .getClass().getResource(imagePath);
193:
194: if (url != null) {
195: return new ImageIcon(url);
196: }
197:
198: return null;
199: }
200: }
|