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

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

GLI and GEMS Edit menu refers to Apple key on Macs instead of the Ctrl key, since Professor Witten and Jenny discovered that the Apple key now works on Mac machines in GLI (and the Ctrl doesn't work anymore).

  • Property svn:keywords set to Author Date Id Revision
File size: 10.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 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 String modkey = Utility.isMac() ? "apple" : "ctrl";
165 edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
166 edit_cut.addActionListener(Gatherer.g_man);
167 edit_cut.setComponentOrientation(Dictionary.getOrientation());
168
169 edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
170 edit_copy.addActionListener(Gatherer.g_man);
171 edit_copy.setComponentOrientation(Dictionary.getOrientation());
172
173 edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
174 edit_paste.addActionListener(Gatherer.g_man);
175 edit_paste.setComponentOrientation(Dictionary.getOrientation());
176 // Layout (edit menu)
177 edit.add(edit_cut);
178 edit.add(edit_copy);
179 edit.add(edit_paste);
180
181 // Help menu
182 help = new JMenu();
183 help.setIcon(HELP_ICON);
184 help.setText(Dictionary.get("Menu.Help"));
185 help.setComponentOrientation(Dictionary.getOrientation());
186
187 help_general = new JMenuItem(Dictionary.get("Source.General"));
188 help_general.addActionListener(Gatherer.g_man);
189 help_general.setComponentOrientation(Dictionary.getOrientation());
190
191 help_download = new JMenuItem(Dictionary.get("GUI.Download"), BLANK_ICON);
192 help_download.addActionListener(Gatherer.g_man);
193 help_download.setComponentOrientation(Dictionary.getOrientation());
194
195 help_gather = new JMenuItem(Dictionary.get("GUI.Gather"), BLANK_ICON);
196 help_gather.addActionListener(Gatherer.g_man);
197 help_gather.setComponentOrientation(Dictionary.getOrientation());
198
199 help_enrich = new JMenuItem(Dictionary.get("GUI.Enrich"), BLANK_ICON);
200 help_enrich.addActionListener(Gatherer.g_man);
201 help_enrich.setComponentOrientation(Dictionary.getOrientation());
202
203 help_design = new JMenuItem(Dictionary.get("GUI.Design"), BLANK_ICON);
204 help_design.addActionListener(Gatherer.g_man);
205 help_design.setComponentOrientation(Dictionary.getOrientation());
206
207 help_create = new JMenuItem(Dictionary.get("GUI.Create"), BLANK_ICON);
208 help_create.addActionListener(Gatherer.g_man);
209 help_create.setComponentOrientation(Dictionary.getOrientation());
210
211 help_format = new JMenuItem(Dictionary.get("GUI.Format"), BLANK_ICON);
212 help_format.addActionListener(Gatherer.g_man);
213 help_format.setComponentOrientation(Dictionary.getOrientation());
214
215 help_about = new JMenuItem(Dictionary.get("Menu.Help_About"));
216 help_about.addActionListener(Gatherer.g_man);
217 help_about.setComponentOrientation(Dictionary.getOrientation());
218
219 // Layout (help menu)
220 help.add(help_general);
221 help.add(new JSeparator());
222 if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
223 help.add(help_download);
224 }
225 if (Configuration.get("workflow.gather", true)) {
226 help.add(help_gather);
227 }
228 if (Configuration.get("workflow.enrich", true)) {
229 help.add(help_enrich);
230 }
231 if (Configuration.get("workflow.design", true)) {
232 help.add(help_design);
233 }
234 if (Configuration.get("workflow.create", true)) {
235 help.add(help_create);
236 }
237 if (Configuration.get("workflow.format", true)) {
238 help.add(help_format);
239 }
240 help.add(new JSeparator());
241 help.add(help_about);
242
243 // Layout (menu bar)
244 this.add(file);
245 this.add(Box.createHorizontalStrut(15));
246 this.add(edit);
247 this.add(Box.createHorizontalGlue());
248 this.add(help);
249 }
250
251 /** Once a quit has been requested by the user, prevent any further menu selections. */
252 public void exit() {
253 file.setEnabled(false);
254 edit.setEnabled(false);
255 help.setEnabled(false);
256 }
257
258 public void refresh(int refresh_reason, boolean ready)
259 {
260 file_close.setEnabled(ready);
261 file_save.setEnabled(ready);
262 }
263
264
265 /** In order to provide context aware help advice we keep track of which
266 * tab the user has open, and then highlight that help menu item with
267 * separators.
268 * @param tab_index The index of the selected tab (0-7).
269 */
270 public void tabSelected(int tab_index) {
271 JMenuItem selected;
272 if(current_tab != -1) {
273 // Remove the image
274 selected = help.getItem(current_tab);
275 if(selected != null) {
276 selected.setIcon(BLANK_ICON);
277 }
278 }
279 current_tab = tab_index + 2;
280 selected = help.getItem(current_tab);
281 if(selected != null) {
282 selected.setIcon(HELP_ICON);
283 }
284 selected = null;
285 }
286}
Note: See TracBrowser for help on using the repository browser.