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

Last change on this file since 4448 was 4381, checked in by jmt12, 21 years ago

Disabled all menu bar menus after File->Quit selected - John

  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.event.*;
40import javax.swing.*;
41import javax.swing.event.*;
42import org.greenstone.gatherer.Gatherer;
43import org.greenstone.gatherer.util.Utility;
44/** The menu bar for the Gatherer main GUI.
45 * @author John Thompson, Greenstone Digital Library, University of Waikato
46 * @version 2.2
47 */
48public class MenuBar
49 extends JMenuBar {
50 /** The icon to be displayed alongside the context choosen help file. */
51 private int current_tab = -1;
52 private JMenu file = null;
53 private JMenu edit = null;
54 private JMenu metadata = null;
55 private JMenu tools = null;
56 private JMenu log = null;
57 private JMenu window = null;
58 private JMenu source = null;
59 private JMenu level = null;
60 public JMenu help = null;
61 public JMenuItem file_associations;
62 public JMenuItem file_close = null;
63 public JMenuItem file_delete = null;
64 public JMenuItem file_exit = null;
65 public JMenuItem file_new = null;
66 public JMenuItem file_open = null;
67 public JMenuItem file_options = null;
68 public JMenuItem file_save = null;
69 public JMenuItem file_save_as;
70 public JMenuItem edit_copy;
71 public JMenuItem edit_cut;
72 public JMenuItem edit_paste;
73 public JMenuItem edit_undo = null;
74 public JMenuItem edit_redo = null;
75 public JMenuItem edit_replace = null;
76 public JMenuItem edit_search = null;
77 public JMenuItem metadata_add = null;
78 public JMenuItem metadata_edit = null;
79 public JMenuItem metadata_export = null;
80 public JMenuItem metadata_view = null;
81 public JMenuItem tools_log = null;
82 public JMenuItem tools_size = null;
83 public JMenuItem help_about;
84 public JMenuItem help_browse;
85 public JMenuItem help_build;
86 public JMenuItem help_collect;
87 public JMenuItem help_design;
88 public JMenuItem help_export;
89 public JMenuItem help_general;
90 public JMenuItem help_metaedit;
91 public JMenuItem help_mirror ;
92 public JMenuItem help_preview;
93
94 public MenuBar(MenuListener menu_listener) {
95
96 file = new JMenu(get("File"));
97 file.setMnemonic(KeyEvent.VK_F);
98 this.add(file);
99
100 file_associations = new JMenuItem(get("File_Associations"), KeyEvent.VK_A);
101 file_associations.addActionListener(Gatherer.g_man);
102
103 file_close = new JMenuItem(get("File_Close"), KeyEvent.VK_C);
104 file_close.addActionListener(Gatherer.g_man);
105 file_close.setEnabled(false);
106
107 file_delete = new JMenuItem(get("File_Delete"), KeyEvent.VK_D);
108 file_delete.addActionListener(Gatherer.g_man);
109
110 file_exit = new JMenuItem(get("File_Exit"), KeyEvent.VK_X);
111 file_exit.addActionListener(Gatherer.g_man);
112
113 file_new = new JMenuItem(get("File_New"), KeyEvent.VK_N);
114 file_new.addActionListener(Gatherer.g_man);
115
116 file_open = new JMenuItem(get("File_Open"), KeyEvent.VK_O);
117 file_open.addActionListener(Gatherer.g_man);
118
119 file_options = new JMenuItem(get("File_Options"), KeyEvent.VK_P);
120 file_options.addActionListener(Gatherer.g_man);
121
122 file_save = new JMenuItem(get("File_Save"), KeyEvent.VK_S);
123 file_save.addActionListener(Gatherer.g_man);
124 file_save.setEnabled(false);
125
126 file_save_as = new JMenuItem(get("File_Save_As"), KeyEvent.VK_A);
127 //file_save_as.addActionListener(Gatherer.g_man);
128 file_save_as.setEnabled(false);
129
130 // Layout file menu
131 file.add(file_new);
132 file.add(file_open);
133 file.add(file_save);
134 //file.add(file_save_as);
135 file.add(file_close);
136 //file.add(new JSeparator());
137 //file.add(file_delete);
138 file.add(new JSeparator());
139 file.add(file_associations);
140 file.add(file_options);
141 file.add(new JSeparator());
142 file.add(file_exit);
143
144 // Edit menu
145 edit = new JMenu(get("Edit"));
146 edit.setMnemonic(KeyEvent.VK_E);
147 this.add(edit);
148
149 edit_copy = new JMenuItem(get("Edit_Copy") + " (ctrl-c)", KeyEvent.VK_C);
150 edit_copy.addActionListener(Gatherer.g_man);
151
152 edit_cut = new JMenuItem(get("Edit_Cut") + " (ctrl-x)", KeyEvent.VK_X);
153 edit_cut.addActionListener(Gatherer.g_man);
154
155 edit_paste = new JMenuItem(get("Edit_Paste") + " (ctrl-v)", KeyEvent.VK_V);
156 edit_paste.addActionListener(Gatherer.g_man);
157
158 edit_undo = new JMenuItem(get("Edit_Undo"), KeyEvent.VK_U);
159 edit_undo.setEnabled(false);
160
161 edit_redo = new JMenuItem(get("Edit_Redo"), KeyEvent.VK_D);
162 edit_redo.setEnabled(false);
163
164 edit_search = new JMenuItem(get("Edit_Search"), KeyEvent.VK_S);
165 edit_search.addActionListener(Gatherer.g_man);
166
167 edit_replace = new JMenuItem(get("Edit_Replace"), KeyEvent.VK_R);
168 edit_replace.addActionListener(Gatherer.g_man);
169
170 edit.add(edit_copy);
171 edit.add(edit_cut);
172 edit.add(edit_paste);
173 //edit.add(new JSeparator());
174 //edit.add(edit_undo);
175 //edit.add(edit_redo);
176 edit.add(new JSeparator());
177 edit.add(edit_search);
178 edit.add(edit_replace);
179
180 // Metadata menu
181 metadata = new JMenu(get("Metadata"));
182 metadata.setEnabled(false);
183 metadata.setMnemonic(KeyEvent.VK_M);
184
185 metadata_add = new JMenuItem(get("Metadata_Add"), KeyEvent.VK_A);
186 metadata_add.addActionListener(Gatherer.g_man);
187
188 metadata_edit = new JMenuItem(get("Metadata_Edit"), KeyEvent.VK_E);
189 metadata_edit.addActionListener(Gatherer.g_man);
190
191 metadata_export = new JMenuItem(get("Metadata_Export"), KeyEvent.VK_X);
192 metadata_export.addActionListener(Gatherer.g_man);
193
194 metadata_view = new JMenuItem(get("Metadata_View") + " " + get("FileActions.No_Selection"), KeyEvent.VK_V);
195 metadata_view.addActionListener(Gatherer.g_man);
196
197 metadata.add(metadata_add);
198 metadata.add(metadata_edit);
199 metadata.add(metadata_export);
200 metadata.add(metadata_view);
201 this.add(metadata);
202
203 // Tools menu
204 tools = new JMenu(get("Tools"));
205
206 tools_log = new JMenuItem(get("Tools_Log"), KeyEvent.VK_L);
207 tools_log.addActionListener(Gatherer.g_man);
208
209 tools_size = new JMenuItem("Calculate Record Size", KeyEvent.VK_S);
210 tools_size.addActionListener(Gatherer.g_man);
211
212 tools.add(tools_log);
213 tools.add(tools_size);
214 //this.add(tools);
215
216 // Help menu
217 help = new JMenu(get("Help"));
218 //help.addMenuListener(menu_listener);
219 help.setIcon(Utility.HELP_ICON);
220
221 help_about = new JMenuItem(get("Help_About"));
222 help_about.addActionListener(Gatherer.g_man);
223
224 help_browse = new JMenuItem(get("GUI.Browser"), Utility.BLANK_ICON);
225 help_browse.addActionListener(Gatherer.g_man);
226
227 help_build = new JMenuItem(get("GUI.Create"), Utility.BLANK_ICON);
228 help_build.addActionListener(Gatherer.g_man);
229
230 help_collect = new JMenuItem(get("GUI.Collection"), Utility.BLANK_ICON);
231 help_collect.addActionListener(Gatherer.g_man);
232
233 help_design = new JMenuItem(get("GUI.Build"), Utility.BLANK_ICON);
234 help_design.addActionListener(Gatherer.g_man);
235
236 help_export = new JMenuItem(get("GUI.Export"), Utility.BLANK_ICON);
237 help_export.addActionListener(Gatherer.g_man);
238
239 help_general = new JMenuItem(get("Source.General"));
240 help_general.addActionListener(Gatherer.g_man);
241
242 help_metaedit = new JMenuItem(get("GUI.MetaEdit"), Utility.BLANK_ICON);
243 help_metaedit.addActionListener(Gatherer.g_man);
244
245 help_mirror = new JMenuItem(get("GUI.Mirroring"), Utility.BLANK_ICON);
246 help_mirror.addActionListener(Gatherer.g_man);
247
248 help_preview = new JMenuItem(get("GUI.Preview"), Utility.BLANK_ICON);
249 help_preview.addActionListener(Gatherer.g_man);
250
251 // Layout help
252 help.add(help_general);
253 help.add(new JSeparator());
254 if(Gatherer.config.get("workflow.browse", true)) {
255 help.add(help_browse);
256 }
257 if(Gatherer.config.get("workflow.mirror", true)) {
258 help.add(help_mirror);
259 }
260 if(Gatherer.config.get("workflow.gather", true)) {
261 help.add(help_collect);
262 }
263 if(Gatherer.config.get("workflow.enrich", true)) {
264 help.add(help_metaedit);
265 }
266 if(Gatherer.config.get("workflow.design", true)) {
267 help.add(help_design);
268 }
269 if(Gatherer.config.get("workflow.export", true)) {
270 help.add(help_export);
271 }
272 if(Gatherer.config.get("workflow.create", true)) {
273 help.add(help_build);
274 }
275 if(Gatherer.config.get("workflow.preview", true)) {
276 help.add(help_preview);
277 }
278 help.add(new JSeparator());
279 help.add(help_about);
280 this.add(Box.createHorizontalGlue());
281 this.add(help);
282 }
283
284 public void collectionChanged(boolean ready) {
285 file_close.setEnabled(ready);
286 file_save.setEnabled(ready);
287 file_save_as.setEnabled(ready);
288 metadata.setEnabled(ready);
289 tools.setEnabled(ready);
290 if(ready) {
291 Gatherer.c_man.undo.registerRedoSource(edit_redo);
292 Gatherer.c_man.undo.registerUndoSource(edit_undo);
293 }
294 }
295
296 /** Once a quit has been requested by the user, prevent any further menu selections. */
297 public void exit() {
298 edit.setEnabled(false);
299 file.setEnabled(false);
300 help.setEnabled(false);
301 metadata.setEnabled(false);
302 }
303
304 public void setMetaAuditSuffix(String metaaudit_suffix) {
305 ///ystem.err.println("Set metadata view suffix: " + metaaudit_suffix);
306 metadata_view.setText(get("Menu.Metadata_View") + " " + metaaudit_suffix);
307 }
308
309 /** Set the enabled state of one of the help menu items, based on its 'tabs' current state. Note that this method should only be called from the AWTEvent thread. */
310 public void tabEnabled(int tab_index, boolean state) {
311 JMenuItem selected = help.getItem(tab_index + 2); // Remember general and separator items
312 selected.setEnabled(state);
313 }
314
315 /** In order to provide context aware help advice we keep track of which
316 * tab the user has open, and then highlight that help menu item with
317 * separators.
318 * @param tab_index The index of the selected tab (0-7).
319 */
320 public void tabSelected(int tab_index) {
321 JMenuItem selected;
322 if(current_tab != -1) {
323 // Remove the image
324 selected = help.getItem(current_tab);
325 if(selected != null) {
326 selected.setIcon(Utility.BLANK_ICON);
327 }
328 }
329 current_tab = tab_index + 2;
330 selected = help.getItem(current_tab);
331 if(selected != null) {
332 selected.setIcon(Utility.HELP_ICON);
333 }
334 selected = null;
335 }
336
337 /** Retrieves a key from the Dictionary, using no extra arguments.
338 * @param key A String which maps to a certain phrase from the Dictionary.
339 * @return The String the matches the key or an error String if no match
340 * found.
341 */
342 private String get(String key) {
343 return get(key, null);
344 }
345
346 /** Retrieves a key from the Dictionary, providing extra arguments to
347 * be inserted using a String array.
348 * @param key A String which maps to a certain phrase from the Dictionary.
349 * @param args A String array containing further arguments (such as
350 * formatting instructions and variable values) to be taken into account
351 * when Dictionary creates the return String.
352 * @return The String the matches the key or an error String if no match
353 * found.
354 */
355 private String get(String key, String args[]) {
356 if(key.indexOf('.') == -1) {
357 key = "Menu." + key;
358 }
359 return Gatherer.dictionary.get(key, args);
360 }
361
362 private class NonFocusMenu
363 extends JMenu {
364 public NonFocusMenu(String name) {
365 super(name);
366 setFocusPainted(false);
367 }
368
369 public boolean isFocusable(){
370 return false;
371 }
372
373 public void requestFocus(){
374 }
375
376 public boolean requestFocus(boolean t){
377 return false;
378 }
379
380 public void setFocusable(boolean f) {
381 }
382 }
383
384 private class NonFocusMenuItem
385 extends JMenuItem {
386 public NonFocusMenuItem(String name, int key) {
387 super(name, key);
388 setFocusPainted(false);
389 }
390
391 public boolean isFocusable(){
392 return false;
393 }
394
395 public void requestFocus(){
396 }
397
398 public boolean requestFocus(boolean t){
399 return false;
400 }
401
402 public void setFocusable(boolean f) {
403 }
404
405 }
406}
Note: See TracBrowser for help on using the repository browser.