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