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

Last change on this file since 28627 was 28627, checked in by ak19, 10 years ago

Related to the previous commit. Displaying the apple symbol instead of the word apple for the Mac modifier key for editing cmd shortcuts.

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