source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/gui/MenuBar.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 11.0 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import javax.swing.*;
42import javax.swing.event.*;
43import org.greenstone.gatherer.Configuration;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.Gatherer;
46import org.greenstone.gatherer.util.JarTools;
47import org.greenstone.gatherer.util.Utility;
48
49/** The menu bar for the Gatherer main GUI.
50 * @author John Thompson, Greenstone Digital Library, University of Waikato
51 * @version 2.2
52 */
53public class MenuBar
54 extends JMenuBar
55{
56 static public ImageIcon BLANK_ICON = JarTools.getImage("blank.gif");
57 static public ImageIcon HELP_ICON = JarTools.getImage("help.png");
58
59 /** The icon to be displayed alongside the context choosen help file. */
60 private int current_tab = -1;
61
62 public JMenu file = null;
63 public JMenu edit = null;
64 public JMenu help = null;
65 public JMenuItem file_associations;
66 public JMenuItem file_cdimage = null;
67 public JMenuItem file_close = null;
68 public JMenuItem file_delete = null;
69 public JMenuItem file_exit = null;
70 public JMenuItem file_exportas = null;
71 public JMenuItem file_new = null;
72 public JMenuItem file_open = null;
73 public JMenuItem file_options = null;
74 public JMenuItem file_save = null;
75 public JMenuItem edit_copy;
76 public JMenuItem edit_cut;
77 public JMenuItem edit_paste;
78 public JMenuItem edit_config;
79 public JMenuItem help_general;
80 public JMenuItem help_download;
81 public JMenuItem help_gather;
82 public JMenuItem help_enrich;
83 public JMenuItem help_design;
84 public JMenuItem help_create;
85 public JMenuItem help_format;
86 public JMenuItem help_about;
87
88
89 public MenuBar(MenuListener menu_listener)
90 {
91 this.setComponentOrientation(Dictionary.getOrientation());
92
93 file = new JMenu();
94 file.setEnabled(false);
95 file.setText(Dictionary.get("Menu.File"));
96 file.setComponentOrientation(Dictionary.getOrientation());
97
98 file_associations = new JMenuItem(Dictionary.get("Menu.File_Associations"));
99 file_associations.addActionListener(Gatherer.g_man);
100 file_associations.setComponentOrientation(Dictionary.getOrientation());
101
102 file_cdimage = new JMenuItem(Dictionary.get("Menu.File_CDimage"));
103 file_cdimage.addActionListener(Gatherer.g_man);
104 file_cdimage.setEnabled(!Gatherer.isGsdlRemote);
105 file_cdimage.setComponentOrientation(Dictionary.getOrientation());
106
107 file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
108 file_close.addActionListener(Gatherer.g_man);
109 file_close.setEnabled(false);
110 file_close.setComponentOrientation(Dictionary.getOrientation());
111
112 file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
113 file_delete.addActionListener(Gatherer.g_man);
114 file_delete.setComponentOrientation(Dictionary.getOrientation());
115
116 file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
117 file_exit.addActionListener(Gatherer.g_man);
118 file_exit.setComponentOrientation(Dictionary.getOrientation());
119
120 file_exportas = new JMenuItem(Dictionary.get("Menu.File_ExportAs"));
121 file_exportas.addActionListener(Gatherer.g_man);
122 file_exportas.setEnabled(!Gatherer.isGsdlRemote);
123 file_exportas.setComponentOrientation(Dictionary.getOrientation());
124
125 file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
126 file_new.addActionListener(Gatherer.g_man);
127 file_new.setComponentOrientation(Dictionary.getOrientation());
128
129 file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
130 file_open.addActionListener(Gatherer.g_man);
131 file_open.setComponentOrientation(Dictionary.getOrientation());
132
133 file_options = new JMenuItem(Dictionary.get("Menu.File_Options"));
134 file_options.addActionListener(Gatherer.g_man);
135 file_options.setComponentOrientation(Dictionary.getOrientation());
136
137 file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
138 file_save.addActionListener(Gatherer.g_man);
139 file_save.setEnabled(false);
140 file_save.setComponentOrientation(Dictionary.getOrientation());
141
142 // Layout (file menu)
143 file.add(file_new);
144 file.add(file_open);
145 file.add(file_save);
146 file.add(file_close);
147 file.add(new JSeparator());
148 file.add(file_delete);
149 file.add(file_exportas);
150 // these currently don't work. better to just disable them?
151 if (!Gatherer.GS3) {
152 file.add(file_cdimage);
153 }
154 file.add(new JSeparator());
155 file.add(file_associations);
156 file.add(file_options);
157 file.add(new JSeparator());
158 file.add(file_exit);
159
160 // Edit menu
161 edit = new JMenu();
162 edit.setEnabled(false);
163 edit.setText(Dictionary.get("Menu.Edit"));
164 edit.setComponentOrientation(Dictionary.getOrientation());
165 String modkey = "ctrl";
166 if(Utility.isMac()) { // on Mac, we now use the Apple key instead of Ctrl for GLI/GEMS edit shortcuts
167 // http://stackoverflow.com/questions/5585919/creating-unicode-character-from-its-number
168 char appleKeyCodepoint = 0x2318; // applekey symbol unicode codepoint: U+2318 (\u2318)
169 String appleKeySymbol = String.valueOf(appleKeyCodepoint);
170 modkey = appleKeySymbol;
171 }
172
173 edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
174 edit_cut.addActionListener(Gatherer.g_man);
175 edit_cut.setComponentOrientation(Dictionary.getOrientation());
176
177 edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
178 edit_copy.addActionListener(Gatherer.g_man);
179 edit_copy.setComponentOrientation(Dictionary.getOrientation());
180
181 edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
182 edit_paste.addActionListener(Gatherer.g_man);
183 edit_paste.setComponentOrientation(Dictionary.getOrientation());
184
185 // Layout (edit menu)
186 edit.add(edit_cut);
187 edit.add(edit_copy);
188 edit.add(edit_paste);
189
190 // if GS3, then we have a menu item that allows editing of config files
191 if(Gatherer.GS3) {
192
193 edit_config = new JMenuItem(Dictionary.get("Menu.Edit_Config"));
194 // handle the actual Edit > ColConfig.xml menu item
195 edit_config.addActionListener(Gatherer.g_man);
196 edit_config.setComponentOrientation(Dictionary.getOrientation());
197 edit.add(edit_config);
198 // The Edit menu itself now listens, in order to gray out the
199 // Edit > collectionConfig.xml option when no collection is open
200 // (JMenu doesn't work with ActionListener only with MenuListener, see
201 // http://stackoverflow.com/questions/9862165/jmenu-actionlistener)
202 edit.addMenuListener(menu_listener);
203
204 }
205
206 // Help menu
207 help = new JMenu();
208 help.setIcon(HELP_ICON);
209 help.setText(Dictionary.get("Menu.Help"));
210 help.setComponentOrientation(Dictionary.getOrientation());
211
212 help_general = new JMenuItem(Dictionary.get("Source.General"));
213 help_general.addActionListener(Gatherer.g_man);
214 help_general.setComponentOrientation(Dictionary.getOrientation());
215
216 help_download = new JMenuItem(Dictionary.get("GUI.Download"), BLANK_ICON);
217 help_download.addActionListener(Gatherer.g_man);
218 help_download.setComponentOrientation(Dictionary.getOrientation());
219
220 help_gather = new JMenuItem(Dictionary.get("GUI.Gather"), BLANK_ICON);
221 help_gather.addActionListener(Gatherer.g_man);
222 help_gather.setComponentOrientation(Dictionary.getOrientation());
223
224 help_enrich = new JMenuItem(Dictionary.get("GUI.Enrich"), BLANK_ICON);
225 help_enrich.addActionListener(Gatherer.g_man);
226 help_enrich.setComponentOrientation(Dictionary.getOrientation());
227
228 help_design = new JMenuItem(Dictionary.get("GUI.Design"), BLANK_ICON);
229 help_design.addActionListener(Gatherer.g_man);
230 help_design.setComponentOrientation(Dictionary.getOrientation());
231
232 help_create = new JMenuItem(Dictionary.get("GUI.Create"), BLANK_ICON);
233 help_create.addActionListener(Gatherer.g_man);
234 help_create.setComponentOrientation(Dictionary.getOrientation());
235
236 help_format = new JMenuItem(Dictionary.get("GUI.Format"), BLANK_ICON);
237 help_format.addActionListener(Gatherer.g_man);
238 help_format.setComponentOrientation(Dictionary.getOrientation());
239
240 help_about = new JMenuItem(Dictionary.get("Menu.Help_About"));
241 help_about.addActionListener(Gatherer.g_man);
242 help_about.setComponentOrientation(Dictionary.getOrientation());
243
244 // Layout (help menu)
245 help.add(help_general);
246 help.add(new JSeparator());
247 if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
248 help.add(help_download);
249 }
250 if (Configuration.get("workflow.gather", true)) {
251 help.add(help_gather);
252 }
253 if (Configuration.get("workflow.enrich", true)) {
254 help.add(help_enrich);
255 }
256 if (Configuration.get("workflow.design", true)) {
257 help.add(help_design);
258 }
259 if (Configuration.get("workflow.create", true)) {
260 help.add(help_create);
261 }
262 if (Configuration.get("workflow.format", true)) {
263 help.add(help_format);
264 }
265 help.add(new JSeparator());
266 help.add(help_about);
267
268 // Layout (menu bar)
269 this.add(file);
270 this.add(Box.createHorizontalStrut(15));
271 this.add(edit);
272 this.add(Box.createHorizontalGlue());
273 this.add(help);
274 }
275
276 /** Once a quit has been requested by the user, prevent any further menu selections. */
277 public void exit() {
278 file.setEnabled(false);
279 edit.setEnabled(false);
280 help.setEnabled(false);
281 }
282
283 public void refresh(int refresh_reason, boolean ready)
284 {
285 file_close.setEnabled(ready);
286 file_save.setEnabled(ready);
287 }
288
289
290 /** In order to provide context aware help advice we keep track of which
291 * tab the user has open, and then highlight that help menu item with
292 * separators.
293 * @param tab_index The index of the selected tab (0-7).
294 */
295 public void tabSelected(int tab_index) {
296 JMenuItem selected;
297 if(current_tab != -1) {
298 // Remove the image
299 selected = help.getItem(current_tab);
300 if(selected != null) {
301 selected.setIcon(BLANK_ICON);
302 }
303 }
304 current_tab = tab_index + 2;
305 selected = help.getItem(current_tab);
306 if(selected != null) {
307 selected.setIcon(HELP_ICON);
308 }
309 selected = null;
310 }
311}
Note: See TracBrowser for help on using the repository browser.