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

Last change on this file since 6540 was 5851, checked in by kjdon, 21 years ago

added a separator in the File menu

  • Property svn:keywords set to Author Date Id Revision
File size: 14.7 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.Dictionary;
44import org.greenstone.gatherer.Gatherer;
45import org.greenstone.gatherer.util.Utility;
46
47/** The menu bar for the Gatherer main GUI.
48 * @author John Thompson, Greenstone Digital Library, University of Waikato
49 * @version 2.2
50 */
51public class MenuBar
52 extends JMenuBar {
53 /** The icon to be displayed alongside the context choosen help file. */
54 private int current_tab = -1;
55
56 private JMenu file = null;
57 private JMenu edit = null;
58 private JMenu metadata = null;
59 private JMenu tools = 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_export = null;
66 public JMenuItem file_new = null;
67 public JMenuItem file_open = null;
68 public JMenuItem file_options = null;
69 public JMenuItem file_save = null;
70 public JMenuItem file_save_as;
71 public JMenuItem edit_copy;
72 public JMenuItem edit_cut;
73 public JMenuItem edit_paste;
74 public JMenuItem edit_undo = null;
75 public JMenuItem edit_redo = null;
76 public JMenuItem edit_replace = null;
77 public JMenuItem edit_search = null;
78 public JMenuItem metadata_import = null;
79 public JMenuItem metadata_edit = null;
80 public JMenuItem metadata_export = 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 public MagicMenuItem metadata_view = null;
94
95 public MenuBar(MenuListener menu_listener)
96 {
97 file = new JMenu();
98 file.setMnemonic(KeyEvent.VK_F);
99 Dictionary.registerText(file, "Menu.File");
100
101 file_associations = new JMenuItem();
102 file_associations.addActionListener(Gatherer.g_man);
103 file_associations.setMnemonic(KeyEvent.VK_A);
104 Dictionary.registerText(file_associations, "Menu.File_Associations");
105
106 file_close = new JMenuItem();
107 file_close.addActionListener(Gatherer.g_man);
108 file_close.setEnabled(false);
109 file_close.setMnemonic(KeyEvent.VK_C);
110 Dictionary.registerText(file_close, "Menu.File_Close");
111
112 file_delete = new JMenuItem();
113 file_delete.addActionListener(Gatherer.g_man);
114 file_delete.setMnemonic(KeyEvent.VK_D);
115 Dictionary.registerText(file_delete, "Menu.File_Delete");
116
117 file_exit = new JMenuItem();
118 file_exit.addActionListener(Gatherer.g_man);
119 file_exit.setMnemonic(KeyEvent.VK_X);
120 Dictionary.registerText(file_exit, "Menu.File_Exit");
121
122 file_export = new JMenuItem();
123 file_export.addActionListener(Gatherer.g_man);
124 file_export.setMnemonic(KeyEvent.VK_E);
125 Dictionary.registerText(file_export, "Menu.File_Export");
126
127 file_new = new JMenuItem();
128 file_new.addActionListener(Gatherer.g_man);
129 file_new.setMnemonic(KeyEvent.VK_N);
130 Dictionary.registerText(file_new, "Menu.File_New");
131
132 file_open = new JMenuItem();
133 file_open.addActionListener(Gatherer.g_man);
134 file_open.setMnemonic(KeyEvent.VK_O);
135 Dictionary.registerText(file_open, "Menu.File_Open");
136
137 file_options = new JMenuItem();
138 file_options.addActionListener(Gatherer.g_man);
139 file_options.setMnemonic(KeyEvent.VK_P);
140 Dictionary.registerText(file_options, "Menu.File_Options");
141
142 file_save = new JMenuItem();
143 file_save.addActionListener(Gatherer.g_man);
144 file_save.setEnabled(false);
145 file_save.setMnemonic(KeyEvent.VK_S);
146 Dictionary.registerText(file_save, "Menu.File_Save");
147
148 // file_save_as = new JMenuItem();
149 // file_save_as.addActionListener(Gatherer.g_man);
150 // file_save_as.setEnabled(false);
151 // file_save_as.setMnemonic(KeyEvent.VK_A);
152 // Dictionary.registerText(file_save_as, "Menu.File_Save_As");
153
154 // Layout (file menu)
155 file.add(file_new);
156 file.add(file_open);
157 file.add(file_save);
158 // file.add(file_save_as);
159 file.add(file_close);
160 file.add(new JSeparator());
161 file.add(file_delete);
162 file.add(file_export);
163 file.add(new JSeparator());
164 file.add(file_associations);
165 file.add(file_options);
166 file.add(new JSeparator());
167 file.add(file_exit);
168
169 // Edit menu
170 edit = new JMenu();
171 edit.setMnemonic(KeyEvent.VK_E);
172 Dictionary.registerText(edit, "Menu.Edit");
173
174 edit_cut = new JMenuItem();
175 edit_cut.addActionListener(Gatherer.g_man);
176 edit_cut.setMnemonic(KeyEvent.VK_X);
177 Dictionary.registerText(edit_cut, "Menu.Edit_Cut");
178
179 edit_copy = new JMenuItem();
180 edit_copy.addActionListener(Gatherer.g_man);
181 edit_copy.setMnemonic(KeyEvent.VK_C);
182 Dictionary.registerText(edit_copy, "Menu.Edit_Copy");
183
184 edit_paste = new JMenuItem();
185 edit_paste.addActionListener(Gatherer.g_man);
186 edit_paste.setMnemonic(KeyEvent.VK_V);
187 Dictionary.registerText(edit_paste, "Menu.Edit_Paste");
188
189 // edit_undo = new JMenuItem();
190 // edit_undo.setEnabled(false);
191 // edit_undo.setMnemonic(KeyEvent.VK_U);
192 // Dictionary.registerText(edit_undo, "Menu.Edit_Undo");
193
194 // edit_redo = new JMenuItem();
195 // edit_redo.setEnabled(false);
196 // edit_redo.setMnemonic(KeyEvent.VK_D);
197 // Dictionary.registerText(edit_redo, "Menu.Edit_Redo");
198
199 // edit_search = new JMenuItem();
200 // edit_search.addActionListener(Gatherer.g_man);
201 // edit_search.setMnemonic(KeyEvent.VK_S);
202 // Dictionary.registerText(edit_search, "Menu.Edit_Search");
203
204 // edit_replace = new JMenuItem();
205 // edit_replace.addActionListener(Gatherer.g_man);
206 // edit_replace.setMnemonic(KeyEvent.VK_R);
207 // Dictionary.registerText(edit_replace, "Menu.Edit_Replace");
208
209 // Layout (edit menu)
210 edit.add(edit_cut);
211 edit.add(edit_copy);
212 edit.add(edit_paste);
213 // edit.add(new JSeparator());
214 // edit.add(edit_undo);
215 // edit.add(edit_redo);
216 // edit.add(new JSeparator());
217 // edit.add(edit_search);
218 // edit.add(edit_replace);
219
220 // Metadata menu
221 metadata = new JMenu();
222 metadata.setEnabled(false);
223 metadata.setMnemonic(KeyEvent.VK_M);
224 Dictionary.registerText(metadata, "Menu.Metadata");
225
226 metadata_import = new JMenuItem();
227 metadata_import.addActionListener(Gatherer.g_man);
228 metadata_import.setMnemonic(KeyEvent.VK_I);
229 Dictionary.registerText(metadata_import, "Menu.Metadata_Import");
230
231 metadata_edit = new JMenuItem();
232 metadata_edit.addActionListener(Gatherer.g_man);
233 metadata_edit.setMnemonic(KeyEvent.VK_E);
234 Dictionary.registerText(metadata_edit, "Menu.Metadata_Edit");
235
236 metadata_export = new JMenuItem();
237 metadata_export.addActionListener(Gatherer.g_man);
238 metadata_export.setMnemonic(KeyEvent.VK_X);
239 Dictionary.registerText(metadata_export, "Menu.Metadata_Export");
240
241 metadata_view = new MagicMenuItem(Dictionary.get("Menu.Metadata_View") + " " + Dictionary.get("FileActions.No_Selection"), KeyEvent.VK_A);
242 metadata_view.addActionListener(Gatherer.g_man);
243
244 // Layout (metadata sets menu)
245 metadata.add(metadata_import);
246 metadata.add(metadata_edit);
247 metadata.add(metadata_export);
248 metadata.add(metadata_view);
249
250 // Tools menu
251 // tools = new JMenu();
252 // tools.setEnabled(false);
253 // tools.setMnemonic(KeyEvent.VK_T);
254 // Dictionary.registerText(tools, "Menu.Tools");
255
256 // tools_log = new JMenuItem();
257 // tools_log.addActionListener(Gatherer.g_man);
258 // tools_log.setMnemonic(KeyEvent.VK_L);
259 // Dictionary.registerText(tools_log, "Menu.Tools_Log");
260
261 // tools_size = new JMenuItem();
262 // tools_size.addActionListener(Gatherer.g_man);
263 // tools_size.setMnemonic(KeyEvent.VK_C);
264 // Dictionary.registerText(tools_size, "Menu.Tools_Calculate_Record_Size");
265
266 // Layout (tools menu)
267 // tools.add(tools_log);
268 // tools.add(tools_size);
269
270 // Help menu
271 help = new JMenu();
272 help.setIcon(Utility.HELP_ICON);
273 Dictionary.setText(help, "Menu.Help");
274
275 help_about = new JMenuItem();
276 help_about.addActionListener(Gatherer.g_man);
277 Dictionary.registerText(help_about, "Menu.Help_About");
278
279 help_browse = new JMenuItem(Utility.BLANK_ICON);
280 help_browse.addActionListener(Gatherer.g_man);
281 Dictionary.registerText(help_browse, "GUI.Hunt");
282
283 help_build = new JMenuItem(Utility.BLANK_ICON);
284 help_build.addActionListener(Gatherer.g_man);
285 Dictionary.registerText(help_build, "GUI.Create");
286
287 help_collect = new JMenuItem(Utility.BLANK_ICON);
288 help_collect.addActionListener(Gatherer.g_man);
289 Dictionary.registerText(help_collect, "GUI.Gather");
290
291 help_design = new JMenuItem(Utility.BLANK_ICON);
292 help_design.addActionListener(Gatherer.g_man);
293 Dictionary.registerText(help_design, "GUI.Design");
294
295 help_export = new JMenuItem(Utility.BLANK_ICON);
296 help_export.addActionListener(Gatherer.g_man);
297 Dictionary.registerText(help_export, "GUI.Export");
298
299 help_general = new JMenuItem();
300 help_general.addActionListener(Gatherer.g_man);
301 Dictionary.registerText(help_general, "Source.General");
302
303 help_metaedit = new JMenuItem(Utility.BLANK_ICON);
304 help_metaedit.addActionListener(Gatherer.g_man);
305 Dictionary.registerText(help_metaedit, "GUI.Enrich");
306
307 help_mirror = new JMenuItem(Utility.BLANK_ICON);
308 help_mirror.addActionListener(Gatherer.g_man);
309 Dictionary.registerText(help_mirror, "GUI.Mirror");
310
311 help_preview = new JMenuItem(Utility.BLANK_ICON);
312 help_preview.addActionListener(Gatherer.g_man);
313 Dictionary.registerText(help_preview, "GUI.Preview");
314
315 // Layout (help menu)
316 help.add(help_general);
317 help.add(new JSeparator());
318 if (Gatherer.config.get("workflow.browse", true)) {
319 help.add(help_browse);
320 }
321 if (Gatherer.config.get("workflow.mirror", true)) {
322 help.add(help_mirror);
323 }
324 if (Gatherer.config.get("workflow.gather", true)) {
325 help.add(help_collect);
326 }
327 if (Gatherer.config.get("workflow.enrich", true)) {
328 help.add(help_metaedit);
329 }
330 if (Gatherer.config.get("workflow.design", true)) {
331 help.add(help_design);
332 }
333 if (Gatherer.config.get("workflow.export", true)) {
334 help.add(help_export);
335 }
336 if (Gatherer.config.get("workflow.create", true)) {
337 help.add(help_build);
338 }
339 if (Gatherer.config.get("workflow.preview", true)) {
340 help.add(help_preview);
341 }
342 help.add(new JSeparator());
343 help.add(help_about);
344
345 // Layout (menu bar)
346 this.add(file);
347 this.add(Box.createHorizontalStrut(15));
348 this.add(edit);
349 this.add(Box.createHorizontalStrut(15));
350 this.add(metadata);
351 // this.add(Box.createHorizontalStrut(15));
352 // this.add(tools);
353 this.add(Box.createHorizontalGlue());
354 this.add(help);
355 }
356
357 public void collectionChanged(boolean ready) {
358 file_close.setEnabled(ready);
359 file_save.setEnabled(ready);
360 // file_save_as.setEnabled(ready);
361 metadata.setEnabled(ready);
362 // tools.setEnabled(ready);
363 if (ready) {
364 // Gatherer.c_man.undo.registerRedoSource(edit_redo);
365 // Gatherer.c_man.undo.registerUndoSource(edit_undo);
366 }
367 }
368
369 /** Once a quit has been requested by the user, prevent any further menu selections. */
370 public void exit() {
371 file.setEnabled(false);
372 edit.setEnabled(false);
373 metadata.setEnabled(false);
374 // tools.setEnabled(false);
375 help.setEnabled(false);
376 }
377
378 public void setMetaAuditSuffix(String metaaudit_suffix) {
379 ///ystem.err.println("**** Set suffix: " + metaaudit_suffix);
380 if(metaaudit_suffix == null) {
381 metadata_view.setText(Dictionary.get("Menu.Metadata_View") + " " + Dictionary.get("FileActions.No_Selection"));
382 metadata_view.setEnabled(false);
383 }
384 else {
385 ///ystem.err.println("Set metadata view suffix: " + metaaudit_suffix);
386 metadata_view.setText(Dictionary.get("Menu.Metadata_View") + " " + metaaudit_suffix);
387 metadata_view.setEnabled(true);
388 }
389 }
390
391 /** 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. */
392 /* private void tabEnabled(int tab_index, boolean state) {
393 JMenuItem selected = help.getItem(tab_index + 2); // Remember general and separator items
394 selected.setEnabled(state);
395 } */
396
397 /** In order to provide context aware help advice we keep track of which
398 * tab the user has open, and then highlight that help menu item with
399 * separators.
400 * @param tab_index The index of the selected tab (0-7).
401 */
402 public void tabSelected(int tab_index) {
403 JMenuItem selected;
404 if(current_tab != -1) {
405 // Remove the image
406 selected = help.getItem(current_tab);
407 if(selected != null) {
408 selected.setIcon(Utility.BLANK_ICON);
409 }
410 }
411 current_tab = tab_index + 2;
412 selected = help.getItem(current_tab);
413 if(selected != null) {
414 selected.setIcon(Utility.HELP_ICON);
415 }
416 selected = null;
417 }
418
419
420 public class MagicMenuItem
421 extends JMenuItem {
422
423 private boolean can_enable;
424 private boolean should_enable;
425
426 public MagicMenuItem(String title, int key_event) {
427 super(title, key_event);
428 super.setEnabled(false);
429 can_enable = false;
430 should_enable = false;
431 }
432
433 public void setCanEnable(boolean can_enable) {
434 this.can_enable = can_enable;
435 if (can_enable) {
436 super.setEnabled(should_enable);
437 }
438 else {
439 super.setEnabled(false);
440 }
441 }
442
443 public void setEnabled(boolean should_enable) {
444 this.should_enable = should_enable;
445 if (can_enable) {
446 super.setEnabled(should_enable);
447 }
448 }
449 }
450}
Note: See TracBrowser for help on using the repository browser.