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

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

Option in GLI file menu to Export collection meta to CSV (new CSV file or add to existing). Uses apache commons CSV, so had to include the csv subfolder of commons into apache.jar, where all other apache jars used by GLI are bundled into. Updated the gli/lib/README about this.

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