1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 package com.sshtools.common.ui;
27
28 import java.awt.event;
29
30 import java.net;
31
32 import javax.swing;
33 import javax.swing.event;
34
35
36 /**
37 *
38 *
39 * @author $author$
40 * @version $Revision: 1.16 $
41 */
42 public abstract class StandardAction extends AbstractAction {
43 /** */
44 public final static String ON_TOOLBAR = "onToolBar";
45
46 /** */
47 public final static String TOOLBAR_GROUP = "toolBarGroup";
48
49 /** */
50 public final static String TOOLBAR_WEIGHT = "toolBarWeight";
51
52 /** */
53 public final static String ON_MENUBAR = "onMenuBar";
54
55 /** */
56 public final static String MENU_NAME = "menuName";
57
58 /** */
59 public final static String MENU_ITEM_GROUP = "menuItemGroup";
60
61 /** */
62 public final static String MENU_ITEM_WEIGHT = "menuItemWeight";
63
64 /** */
65 public final static String IMAGE_DIR = "/com/sshtools/sshterm/";
66
67 /** */
68 public final static String HIDE_TOOLBAR_TEXT = "hideToolbarText";
69
70 /** */
71 public final static String IS_TOGGLE_BUTTON = "isToggleButton";
72
73 /** */
74 public final static String LARGE_ICON = "LargeIcon";
75
76 /** */
77 public final static String ON_CONTEXT_MENU = "onContextMenu";
78
79 /** */
80 public final static String CONTEXT_MENU_GROUP = "contextMenuGroup";
81
82 /** */
83 public final static String CONTEXT_MENU_WEIGHT = "contextMenuWeight";
84
85 /** */
86 public final static String MENU_ICON = "menuIcon";
87
88 // The listener to action events (usually the main UI)
89 private EventListenerList listeners;
90
91 /**
92 *
93 *
94 * @return
95 */
96 public String getActionCommand() {
97 return (String) getValue(Action.ACTION_COMMAND_KEY);
98 }
99
100 /**
101 *
102 *
103 * @return
104 */
105 public String getShortDescription() {
106 return (String) getValue(Action.SHORT_DESCRIPTION);
107 }
108
109 /**
110 *
111 *
112 * @return
113 */
114 public String getLongDescription() {
115 return (String) getValue(Action.LONG_DESCRIPTION);
116 }
117
118 /**
119 *
120 *
121 * @return
122 */
123 public String getName() {
124 return (String) getValue(Action.NAME);
125 }
126
127 /**
128 *
129 *
130 * @return
131 */
132 public String getSmallIcon() {
133 return (String) getValue(Action.SMALL_ICON);
134 }
135
136 /**
137 *
138 *
139 * @param evt
140 */
141 public void actionPerformed(ActionEvent evt) {
142 if (listeners != null) {
143 Object[] listenerList = listeners.getListenerList();
144
145 // Recreate the ActionEvent and stuff the value of the ACTION_COMMAND_KEY
146 ActionEvent e = new ActionEvent(evt.getSource(), evt.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]).actionPerformed(e);
151 }
152 }
153 }
154
155 /**
156 *
157 *
158 * @param l
159 */
160 public void addActionListener(ActionListener l) {
161 if (listeners == null) {
162 listeners = new EventListenerList();
163 }
164
165 listeners.add(ActionListener.class, l);
166 }
167
168 /**
169 *
170 *
171 * @param l
172 */
173 public void removeActionListener(ActionListener l) {
174 if (listeners == null) {
175 return;
176 }
177
178 listeners.remove(ActionListener.class, l);
179 }
180
181 /**
182 *
183 *
184 * @param name
185 *
186 * @return
187 */
188 public ImageIcon getIcon(String name) {
189 String imagePath = name.startsWith("/") ? name : (IMAGE_DIR + name);
190 URL url = this.getClass().getResource(imagePath);
191
192 if (url != null) {
193 return new ImageIcon(url);
194 }
195
196 return null;
197 }
198 }