source: main/trunk/gli/src/org/greenstone/gatherer/gui/MenuBar.java

Last change on this file was 34283, checked in by ak19, 4 years ago

Incorporating Kathy & Dr Bainbridge's improvements to the recently added export to meta CSV features: 1. Move meta to CSV now called Convert meta to CSV launch. 2. Launch Export Meta JChooser dialog in collection dir not import dir, but Convert Meta still launched in importDir as before. Also upload any metadata.csv created in collection dir to remote server if client-GLI, not just if meta.csv was created in importDir. 3. Labels of JChooser confirm button and dialog title corrected. 4. Updates to dictionary string names and values.

  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 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_exportmeta = null;
72 public JMenuItem file_convertmeta = null;
73 public JMenuItem file_new = null;
74 public JMenuItem file_open = null;
75 public JMenuItem file_options = null;
76 public JMenuItem file_save = null;
77 public JMenuItem edit_copy;
78 public JMenuItem edit_cut;
79 public JMenuItem edit_paste;
80 public JMenuItem edit_config;
81 public JMenuItem help_general;
82 public JMenuItem help_download;
83 public JMenuItem help_gather;
84 public JMenuItem help_enrich;
85 public JMenuItem help_design;
86 public JMenuItem help_create;
87 public JMenuItem help_format;
88 public JMenuItem help_about;
89
90
91 public MenuBar(MenuListener menu_listener)
92 {
93 this.setComponentOrientation(Dictionary.getOrientation());
94
95 file = new JMenu();
96 file.setEnabled(false);
97 file.setText(Dictionary.get("Menu.File"));
98 file.setComponentOrientation(Dictionary.getOrientation());
99
100 file_associations = new JMenuItem(Dictionary.get("Menu.File_Associations"));
101 file_associations.addActionListener(Gatherer.g_man);
102 file_associations.setComponentOrientation(Dictionary.getOrientation());
103
104 file_cdimage = new JMenuItem(Dictionary.get("Menu.File_CDimage"));
105 file_cdimage.addActionListener(Gatherer.g_man);
106 file_cdimage.setEnabled(!Gatherer.isGsdlRemote);
107 file_cdimage.setComponentOrientation(Dictionary.getOrientation());
108
109 file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
110 file_close.addActionListener(Gatherer.g_man);
111 file_close.setEnabled(false);
112 file_close.setComponentOrientation(Dictionary.getOrientation());
113
114 file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
115 file_delete.addActionListener(Gatherer.g_man);
116 file_delete.setComponentOrientation(Dictionary.getOrientation());
117
118 file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
119 file_exit.addActionListener(Gatherer.g_man);
120 file_exit.setComponentOrientation(Dictionary.getOrientation());
121
122 file_exportas = new JMenuItem(Dictionary.get("Menu.File_ExportAs"));
123 file_exportas.addActionListener(Gatherer.g_man);
124 file_exportas.setEnabled(!Gatherer.isGsdlRemote);
125 file_exportas.setComponentOrientation(Dictionary.getOrientation());
126
127 file_exportmeta = new JMenuItem(Dictionary.get("Menu.File_ExportMeta"));
128 file_exportmeta.addActionListener(Gatherer.g_man);
129 file_exportmeta.setEnabled(false);
130 file_exportmeta.setComponentOrientation(Dictionary.getOrientation());
131
132 file_convertmeta = new JMenuItem(Dictionary.get("Menu.File_ConvertMetaToCSV"));
133 file_convertmeta.addActionListener(Gatherer.g_man);
134 file_convertmeta.setEnabled(false);
135 file_convertmeta.setComponentOrientation(Dictionary.getOrientation());
136
137 file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
138 file_new.addActionListener(Gatherer.g_man);
139 file_new.setComponentOrientation(Dictionary.getOrientation());
140
141 file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
142 file_open.addActionListener(Gatherer.g_man);
143 file_open.setComponentOrientation(Dictionary.getOrientation());
144
145 file_options = new JMenuItem(Dictionary.get("Menu.File_Options"));
146 file_options.addActionListener(Gatherer.g_man);
147 file_options.setComponentOrientation(Dictionary.getOrientation());
148
149 file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
150 file_save.addActionListener(Gatherer.g_man);
151 file_save.setEnabled(false);
152 file_save.setComponentOrientation(Dictionary.getOrientation());
153
154 // Layout (file menu)
155 file.add(file_new);
156 file.add(file_open);
157 file.add(file_save);
158 file.add(file_close);
159 file.add(new JSeparator());
160 file.add(file_delete);
161 file.add(file_exportas);
162 file.add(file_exportmeta);
163 file.add(file_convertmeta);
164 // these currently don't work. better to just disable them?
165 if (!Gatherer.GS3) {
166 file.add(file_cdimage);
167 }
168 file.add(new JSeparator());
169 file.add(file_associations);
170 file.add(file_options);
171 file.add(new JSeparator());
172 file.add(file_exit);
173
174 // Edit menu
175 edit = new JMenu();
176 edit.setEnabled(false);
177 edit.setText(Dictionary.get("Menu.Edit"));
178 edit.setComponentOrientation(Dictionary.getOrientation());
179 String modkey = "ctrl";
180 if(Utility.isMac()) { // on Mac, we now use the Apple key instead of Ctrl for GLI/GEMS edit shortcuts
181 // http://stackoverflow.com/questions/5585919/creating-unicode-character-from-its-number
182 char appleKeyCodepoint = 0x2318; // applekey symbol unicode codepoint: U+2318 (\u2318)
183 String appleKeySymbol = String.valueOf(appleKeyCodepoint);
184 modkey = appleKeySymbol;
185 }
186
187 edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
188 edit_cut.addActionListener(Gatherer.g_man);
189 edit_cut.setComponentOrientation(Dictionary.getOrientation());
190
191 edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
192 edit_copy.addActionListener(Gatherer.g_man);
193 edit_copy.setComponentOrientation(Dictionary.getOrientation());
194
195 edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
196 edit_paste.addActionListener(Gatherer.g_man);
197 edit_paste.setComponentOrientation(Dictionary.getOrientation());
198
199 // Layout (edit menu)
200 edit.add(edit_cut);
201 edit.add(edit_copy);
202 edit.add(edit_paste);
203
204 // if GS3, then we have a menu item that allows editing of config files
205 if(Gatherer.GS3) {
206
207 edit_config = new JMenuItem(Dictionary.get("Menu.Edit_Config"));
208 // handle the actual Edit > ColConfig.xml menu item
209 edit_config.addActionListener(Gatherer.g_man);
210 edit_config.setComponentOrientation(Dictionary.getOrientation());
211 edit.add(edit_config);
212 // The Edit menu itself now listens, in order to gray out the
213 // Edit > collectionConfig.xml option when no collection is open
214 // (JMenu doesn't work with ActionListener only with MenuListener, see
215 // http://stackoverflow.com/questions/9862165/jmenu-actionlistener)
216 edit.addMenuListener(menu_listener);
217
218 }
219
220 // Help menu
221 help = new JMenu();
222 help.setIcon(HELP_ICON);
223 help.setText(Dictionary.get("Menu.Help"));
224 help.setComponentOrientation(Dictionary.getOrientation());
225
226 help_general = new JMenuItem(Dictionary.get("Source.General"));
227 help_general.addActionListener(Gatherer.g_man);
228 help_general.setComponentOrientation(Dictionary.getOrientation());
229
230 help_download = new JMenuItem(Dictionary.get("GUI.Download"), BLANK_ICON);
231 help_download.addActionListener(Gatherer.g_man);
232 help_download.setComponentOrientation(Dictionary.getOrientation());
233
234 help_gather = new JMenuItem(Dictionary.get("GUI.Gather"), BLANK_ICON);
235 help_gather.addActionListener(Gatherer.g_man);
236 help_gather.setComponentOrientation(Dictionary.getOrientation());
237
238 help_enrich = new JMenuItem(Dictionary.get("GUI.Enrich"), BLANK_ICON);
239 help_enrich.addActionListener(Gatherer.g_man);
240 help_enrich.setComponentOrientation(Dictionary.getOrientation());
241
242 help_design = new JMenuItem(Dictionary.get("GUI.Design"), BLANK_ICON);
243 help_design.addActionListener(Gatherer.g_man);
244 help_design.setComponentOrientation(Dictionary.getOrientation());
245
246 help_create = new JMenuItem(Dictionary.get("GUI.Create"), BLANK_ICON);
247 help_create.addActionListener(Gatherer.g_man);
248 help_create.setComponentOrientation(Dictionary.getOrientation());
249
250 help_format = new JMenuItem(Dictionary.get("GUI.Format"), BLANK_ICON);
251 help_format.addActionListener(Gatherer.g_man);
252 help_format.setComponentOrientation(Dictionary.getOrientation());
253
254 help_about = new JMenuItem(Dictionary.get("Menu.Help_About"));
255 help_about.addActionListener(Gatherer.g_man);
256 help_about.setComponentOrientation(Dictionary.getOrientation());
257
258 // Layout (help menu)
259 help.add(help_general);
260 help.add(new JSeparator());
261 if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
262 help.add(help_download);
263 }
264 if (Configuration.get("workflow.gather", true)) {
265 help.add(help_gather);
266 }
267 if (Configuration.get("workflow.enrich", true)) {
268 help.add(help_enrich);
269 }
270 if (Configuration.get("workflow.design", true)) {
271 help.add(help_design);
272 }
273 if (Configuration.get("workflow.create", true)) {
274 help.add(help_create);
275 }
276 if (Configuration.get("workflow.format", true)) {
277 help.add(help_format);
278 }
279 help.add(new JSeparator());
280 help.add(help_about);
281
282 // Layout (menu bar)
283 this.add(file);
284 this.add(Box.createHorizontalStrut(15));
285 this.add(edit);
286 this.add(Box.createHorizontalGlue());
287 this.add(help);
288 }
289
290 /** Once a quit has been requested by the user, prevent any further menu selections. */
291 public void exit() {
292 file.setEnabled(false);
293 edit.setEnabled(false);
294 help.setEnabled(false);
295 }
296
297 public void refresh(int refresh_reason, boolean ready)
298 {
299 file_close.setEnabled(ready);
300 file_save.setEnabled(ready);
301 file_exportmeta.setEnabled(ready);
302 file_convertmeta.setEnabled(ready);
303 }
304
305
306 /** In order to provide context aware help advice we keep track of which
307 * tab the user has open, and then highlight that help menu item with
308 * separators.
309 * @param tab_index The index of the selected tab (0-7).
310 */
311 public void tabSelected(int tab_index) {
312 JMenuItem selected;
313 if(current_tab != -1) {
314 // Remove the image
315 selected = help.getItem(current_tab);
316 if(selected != null) {
317 selected.setIcon(BLANK_ICON);
318 }
319 }
320 current_tab = tab_index + 2;
321 selected = help.getItem(current_tab);
322 if(selected != null) {
323 selected.setIcon(HELP_ICON);
324 }
325 selected = null;
326 }
327}
Note: See TracBrowser for help on using the repository browser.