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

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

Removed a comment I accidently left in.

  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 KB
RevLine 
[4293]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
[4367]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 tools_log = null;
81 public JMenuItem tools_size = null;
82 public JMenuItem help_about;
83 public JMenuItem help_browse;
84 public JMenuItem help_build;
85 public JMenuItem help_collect;
86 public JMenuItem help_design;
87 public JMenuItem help_export;
88 public JMenuItem help_general;
89 public JMenuItem help_metaedit;
90 public JMenuItem help_mirror ;
91 public JMenuItem help_preview;
[4514]92 public MagicMenuItem metadata_view = null;
[4293]93
[4367]94 public MenuBar(MenuListener menu_listener) {
[4293]95
[4367]96 file = new JMenu(get("File"));
97 file.setMnemonic(KeyEvent.VK_F);
98 this.add(file);
[4293]99
[4367]100 file_associations = new JMenuItem(get("File_Associations"), KeyEvent.VK_A);
101 file_associations.addActionListener(Gatherer.g_man);
[4293]102
[4367]103 file_close = new JMenuItem(get("File_Close"), KeyEvent.VK_C);
104 file_close.addActionListener(Gatherer.g_man);
105 file_close.setEnabled(false);
[4293]106
[4367]107 file_delete = new JMenuItem(get("File_Delete"), KeyEvent.VK_D);
108 file_delete.addActionListener(Gatherer.g_man);
[4293]109
[4367]110 file_exit = new JMenuItem(get("File_Exit"), KeyEvent.VK_X);
111 file_exit.addActionListener(Gatherer.g_man);
[4293]112
[4367]113 file_new = new JMenuItem(get("File_New"), KeyEvent.VK_N);
114 file_new.addActionListener(Gatherer.g_man);
[4293]115
[4367]116 file_open = new JMenuItem(get("File_Open"), KeyEvent.VK_O);
117 file_open.addActionListener(Gatherer.g_man);
[4293]118
[4367]119 file_options = new JMenuItem(get("File_Options"), KeyEvent.VK_P);
120 file_options.addActionListener(Gatherer.g_man);
[4293]121
[4367]122 file_save = new JMenuItem(get("File_Save"), KeyEvent.VK_S);
123 file_save.addActionListener(Gatherer.g_man);
124 file_save.setEnabled(false);
[4293]125
[4367]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);
[4293]129
[4367]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);
[4293]143
[4367]144 // Edit menu
145 edit = new JMenu(get("Edit"));
146 edit.setMnemonic(KeyEvent.VK_E);
[4461]147 this.add(Box.createHorizontalStrut(15));
[4367]148 this.add(edit);
[4293]149
[4367]150 edit_copy = new JMenuItem(get("Edit_Copy") + " (ctrl-c)", KeyEvent.VK_C);
151 edit_copy.addActionListener(Gatherer.g_man);
[4293]152
[4367]153 edit_cut = new JMenuItem(get("Edit_Cut") + " (ctrl-x)", KeyEvent.VK_X);
154 edit_cut.addActionListener(Gatherer.g_man);
[4293]155
[4367]156 edit_paste = new JMenuItem(get("Edit_Paste") + " (ctrl-v)", KeyEvent.VK_V);
157 edit_paste.addActionListener(Gatherer.g_man);
[4293]158
[4367]159 edit_undo = new JMenuItem(get("Edit_Undo"), KeyEvent.VK_U);
160 edit_undo.setEnabled(false);
[4293]161
[4367]162 edit_redo = new JMenuItem(get("Edit_Redo"), KeyEvent.VK_D);
163 edit_redo.setEnabled(false);
[4293]164
[4367]165 edit_search = new JMenuItem(get("Edit_Search"), KeyEvent.VK_S);
166 edit_search.addActionListener(Gatherer.g_man);
[4293]167
[4367]168 edit_replace = new JMenuItem(get("Edit_Replace"), KeyEvent.VK_R);
169 edit_replace.addActionListener(Gatherer.g_man);
[4293]170
[4367]171 edit.add(edit_copy);
172 edit.add(edit_cut);
173 edit.add(edit_paste);
174 //edit.add(new JSeparator());
175 //edit.add(edit_undo);
176 //edit.add(edit_redo);
[4514]177 //edit.add(new JSeparator());
178 //edit.add(edit_search);
179 //edit.add(edit_replace);
[4293]180
[4367]181 // Metadata menu
182 metadata = new JMenu(get("Metadata"));
183 metadata.setEnabled(false);
184 metadata.setMnemonic(KeyEvent.VK_M);
[4293]185
[4471]186 metadata_add = new JMenuItem(get("Metadata_Add"), KeyEvent.VK_I);
[4367]187 metadata_add.addActionListener(Gatherer.g_man);
[4293]188
[4367]189 metadata_edit = new JMenuItem(get("Metadata_Edit"), KeyEvent.VK_E);
190 metadata_edit.addActionListener(Gatherer.g_man);
[4293]191
[4367]192 metadata_export = new JMenuItem(get("Metadata_Export"), KeyEvent.VK_X);
193 metadata_export.addActionListener(Gatherer.g_man);
[4293]194
[4514]195 metadata_view = new MagicMenuItem(get("Metadata_View") + " " + get("FileActions.No_Selection"), KeyEvent.VK_A);
196 metadata_view.addActionListener(Gatherer.g_man);
[4293]197
[4367]198 metadata.add(metadata_add);
199 metadata.add(metadata_edit);
200 metadata.add(metadata_export);
201 metadata.add(metadata_view);
[4461]202 this.add(Box.createHorizontalStrut(15));
[4367]203 this.add(metadata);
[4293]204
[4367]205 // Tools menu
206 tools = new JMenu(get("Tools"));
[4293]207
[4367]208 tools_log = new JMenuItem(get("Tools_Log"), KeyEvent.VK_L);
209 tools_log.addActionListener(Gatherer.g_man);
[4293]210
[4367]211 tools_size = new JMenuItem("Calculate Record Size", KeyEvent.VK_S);
212 tools_size.addActionListener(Gatherer.g_man);
[4293]213
[4367]214 tools.add(tools_log);
215 tools.add(tools_size);
[4461]216 //this.add(Box.createHorizontalStrut(15));
[4367]217 //this.add(tools);
[4293]218
[4367]219 // Help menu
220 help = new JMenu(get("Help"));
221 //help.addMenuListener(menu_listener);
222 help.setIcon(Utility.HELP_ICON);
[4293]223
[4367]224 help_about = new JMenuItem(get("Help_About"));
225 help_about.addActionListener(Gatherer.g_man);
[4293]226
[4367]227 help_browse = new JMenuItem(get("GUI.Browser"), Utility.BLANK_ICON);
228 help_browse.addActionListener(Gatherer.g_man);
[4293]229
[4367]230 help_build = new JMenuItem(get("GUI.Create"), Utility.BLANK_ICON);
231 help_build.addActionListener(Gatherer.g_man);
[4293]232
[4367]233 help_collect = new JMenuItem(get("GUI.Collection"), Utility.BLANK_ICON);
234 help_collect.addActionListener(Gatherer.g_man);
[4293]235
[4367]236 help_design = new JMenuItem(get("GUI.Build"), Utility.BLANK_ICON);
237 help_design.addActionListener(Gatherer.g_man);
[4293]238
[4367]239 help_export = new JMenuItem(get("GUI.Export"), Utility.BLANK_ICON);
240 help_export.addActionListener(Gatherer.g_man);
[4293]241
[4367]242 help_general = new JMenuItem(get("Source.General"));
243 help_general.addActionListener(Gatherer.g_man);
[4293]244
[4367]245 help_metaedit = new JMenuItem(get("GUI.MetaEdit"), Utility.BLANK_ICON);
246 help_metaedit.addActionListener(Gatherer.g_man);
[4293]247
[4367]248 help_mirror = new JMenuItem(get("GUI.Mirroring"), Utility.BLANK_ICON);
249 help_mirror.addActionListener(Gatherer.g_man);
[4293]250
[4367]251 help_preview = new JMenuItem(get("GUI.Preview"), Utility.BLANK_ICON);
252 help_preview.addActionListener(Gatherer.g_man);
[4293]253
[4367]254 // Layout help
255 help.add(help_general);
256 help.add(new JSeparator());
257 if(Gatherer.config.get("workflow.browse", true)) {
258 help.add(help_browse);
259 }
260 if(Gatherer.config.get("workflow.mirror", true)) {
261 help.add(help_mirror);
262 }
263 if(Gatherer.config.get("workflow.gather", true)) {
264 help.add(help_collect);
265 }
266 if(Gatherer.config.get("workflow.enrich", true)) {
267 help.add(help_metaedit);
268 }
269 if(Gatherer.config.get("workflow.design", true)) {
270 help.add(help_design);
271 }
272 if(Gatherer.config.get("workflow.export", true)) {
273 help.add(help_export);
274 }
275 if(Gatherer.config.get("workflow.create", true)) {
276 help.add(help_build);
277 }
278 if(Gatherer.config.get("workflow.preview", true)) {
279 help.add(help_preview);
280 }
281 help.add(new JSeparator());
282 help.add(help_about);
283 this.add(Box.createHorizontalGlue());
284 this.add(help);
285 }
[4293]286
[4367]287 public void collectionChanged(boolean ready) {
288 file_close.setEnabled(ready);
289 file_save.setEnabled(ready);
290 file_save_as.setEnabled(ready);
291 metadata.setEnabled(ready);
292 tools.setEnabled(ready);
293 if(ready) {
294 Gatherer.c_man.undo.registerRedoSource(edit_redo);
295 Gatherer.c_man.undo.registerUndoSource(edit_undo);
296 }
297 }
[4293]298
[4381]299 /** Once a quit has been requested by the user, prevent any further menu selections. */
300 public void exit() {
301 edit.setEnabled(false);
302 file.setEnabled(false);
303 help.setEnabled(false);
304 metadata.setEnabled(false);
305 }
306
[4367]307 public void setMetaAuditSuffix(String metaaudit_suffix) {
[4529]308 ///ystem.err.println("**** Set suffix: " + metaaudit_suffix);
[4514]309 if(metaaudit_suffix == null) {
310 metadata_view.setText(get("Menu.Metadata_View") + " " + get("FileActions.No_Selection"));
311 metadata_view.setEnabled(false);
312 }
313 else {
314 ///ystem.err.println("Set metadata view suffix: " + metaaudit_suffix);
315 metadata_view.setText(get("Menu.Metadata_View") + " " + metaaudit_suffix);
316 metadata_view.setEnabled(true);
317 }
[4367]318 }
[4293]319
[4367]320 /** 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. */
321 public void tabEnabled(int tab_index, boolean state) {
322 JMenuItem selected = help.getItem(tab_index + 2); // Remember general and separator items
323 selected.setEnabled(state);
324 }
[4293]325
[4367]326 /** In order to provide context aware help advice we keep track of which
[4293]327 * tab the user has open, and then highlight that help menu item with
328 * separators.
329 * @param tab_index The index of the selected tab (0-7).
330 */
[4367]331 public void tabSelected(int tab_index) {
332 JMenuItem selected;
333 if(current_tab != -1) {
[4293]334 // Remove the image
[4367]335 selected = help.getItem(current_tab);
336 if(selected != null) {
337 selected.setIcon(Utility.BLANK_ICON);
338 }
339 }
340 current_tab = tab_index + 2;
341 selected = help.getItem(current_tab);
342 if(selected != null) {
343 selected.setIcon(Utility.HELP_ICON);
344 }
345 selected = null;
346 }
[4293]347
[4367]348 /** Retrieves a key from the Dictionary, using no extra arguments.
[4293]349 * @param key A String which maps to a certain phrase from the Dictionary.
350 * @return The String the matches the key or an error String if no match
351 * found.
352 */
[4367]353 private String get(String key) {
354 return get(key, null);
355 }
[4293]356
[4367]357 /** Retrieves a key from the Dictionary, providing extra arguments to
[4293]358 * be inserted using a String array.
359 * @param key A String which maps to a certain phrase from the Dictionary.
360 * @param args A String array containing further arguments (such as
361 * formatting instructions and variable values) to be taken into account
362 * when Dictionary creates the return String.
363 * @return The String the matches the key or an error String if no match
364 * found.
365 */
[4367]366 private String get(String key, String args[]) {
367 if(key.indexOf('.') == -1) {
368 key = "Menu." + key;
369 }
370 return Gatherer.dictionary.get(key, args);
371 }
[4293]372
[4514]373 public class MagicMenuItem
374 extends JMenuItem {
375
376 private boolean can_enable;
377 private boolean should_enable;
378
379 public MagicMenuItem(String title, int key_event) {
380 super(title, key_event);
381 super.setEnabled(false);
382 can_enable = false;
383 should_enable = false;
384 }
385
386 public void setCanEnable(boolean can_enable) {
387 ///ystem.err.println("can_enable = " + can_enable);
388 this.can_enable = can_enable;
389 if(can_enable && should_enable) {
390 ///ystem.err.println("setEnable(" + should_enable + ")");
391 super.setEnabled(should_enable);
392 }
393 }
394
395 public void setEnabled(boolean should_enable) {
396 ///ystem.err.println("should_enable = " + should_enable);
397 this.should_enable = should_enable;
398 if(can_enable) {
399 ///ystem.err.println("setEnable(" + should_enable + ")");
400 super.setEnabled(should_enable);
401 }
402 }
403 }
404
[4367]405 private class NonFocusMenu
406 extends JMenu {
[4293]407 public NonFocusMenu(String name) {
[4367]408 super(name);
[4293]409 setFocusPainted(false);
410 }
411
412 public boolean isFocusable(){
413 return false;
414 }
415
416 public void requestFocus(){
[4367]417 }
[4293]418
419 public boolean requestFocus(boolean t){
[4367]420 return false;
421 }
[4293]422
[4367]423 public void setFocusable(boolean f) {
424 }
425 }
[4293]426
[4367]427 private class NonFocusMenuItem
428 extends JMenuItem {
[4293]429 public NonFocusMenuItem(String name, int key) {
[4367]430 super(name, key);
[4293]431 setFocusPainted(false);
432 }
433
434 public boolean isFocusable(){
435 return false;
436 }
437
438 public void requestFocus(){
[4367]439 }
[4293]440
441 public boolean requestFocus(boolean t){
[4367]442 return false;
443 }
[4293]444
[4367]445 public void setFocusable(boolean f) {
446 }
[4293]447
[4367]448 }
[4293]449}
Note: See TracBrowser for help on using the repository browser.