1 | package 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 | */
|
---|
38 | import java.awt.*;
|
---|
39 | import java.awt.event.*;
|
---|
40 | import javax.swing.*;
|
---|
41 | import javax.swing.event.*;
|
---|
42 | import org.greenstone.gatherer.Gatherer;
|
---|
43 | import 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 | */
|
---|
48 | public 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 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(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(Box.createHorizontalStrut(15));
|
---|
148 | this.add(edit);
|
---|
149 |
|
---|
150 | edit_copy = new JMenuItem(get("Edit_Copy") + " (ctrl-c)", KeyEvent.VK_C);
|
---|
151 | edit_copy.addActionListener(Gatherer.g_man);
|
---|
152 |
|
---|
153 | edit_cut = new JMenuItem(get("Edit_Cut") + " (ctrl-x)", KeyEvent.VK_X);
|
---|
154 | edit_cut.addActionListener(Gatherer.g_man);
|
---|
155 |
|
---|
156 | edit_paste = new JMenuItem(get("Edit_Paste") + " (ctrl-v)", KeyEvent.VK_V);
|
---|
157 | edit_paste.addActionListener(Gatherer.g_man);
|
---|
158 |
|
---|
159 | edit_undo = new JMenuItem(get("Edit_Undo"), KeyEvent.VK_U);
|
---|
160 | edit_undo.setEnabled(false);
|
---|
161 |
|
---|
162 | edit_redo = new JMenuItem(get("Edit_Redo"), KeyEvent.VK_D);
|
---|
163 | edit_redo.setEnabled(false);
|
---|
164 |
|
---|
165 | edit_search = new JMenuItem(get("Edit_Search"), KeyEvent.VK_S);
|
---|
166 | edit_search.addActionListener(Gatherer.g_man);
|
---|
167 |
|
---|
168 | edit_replace = new JMenuItem(get("Edit_Replace"), KeyEvent.VK_R);
|
---|
169 | edit_replace.addActionListener(Gatherer.g_man);
|
---|
170 |
|
---|
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);
|
---|
177 | //edit.add(new JSeparator());
|
---|
178 | //edit.add(edit_search);
|
---|
179 | //edit.add(edit_replace);
|
---|
180 |
|
---|
181 | // Metadata menu
|
---|
182 | metadata = new JMenu(get("Metadata"));
|
---|
183 | metadata.setEnabled(false);
|
---|
184 | metadata.setMnemonic(KeyEvent.VK_M);
|
---|
185 |
|
---|
186 | metadata_add = new JMenuItem(get("Metadata_Add"), KeyEvent.VK_I);
|
---|
187 | metadata_add.addActionListener(Gatherer.g_man);
|
---|
188 |
|
---|
189 | metadata_edit = new JMenuItem(get("Metadata_Edit"), KeyEvent.VK_E);
|
---|
190 | metadata_edit.addActionListener(Gatherer.g_man);
|
---|
191 |
|
---|
192 | metadata_export = new JMenuItem(get("Metadata_Export"), KeyEvent.VK_X);
|
---|
193 | metadata_export.addActionListener(Gatherer.g_man);
|
---|
194 |
|
---|
195 | metadata_view = new MagicMenuItem(get("Metadata_View") + " " + get("FileActions.No_Selection"), KeyEvent.VK_A);
|
---|
196 | metadata_view.addActionListener(Gatherer.g_man);
|
---|
197 |
|
---|
198 | metadata.add(metadata_add);
|
---|
199 | metadata.add(metadata_edit);
|
---|
200 | metadata.add(metadata_export);
|
---|
201 | metadata.add(metadata_view);
|
---|
202 | this.add(Box.createHorizontalStrut(15));
|
---|
203 | this.add(metadata);
|
---|
204 |
|
---|
205 | // Tools menu
|
---|
206 | tools = new JMenu(get("Tools"));
|
---|
207 |
|
---|
208 | tools_log = new JMenuItem(get("Tools_Log"), KeyEvent.VK_L);
|
---|
209 | tools_log.addActionListener(Gatherer.g_man);
|
---|
210 |
|
---|
211 | tools_size = new JMenuItem("Calculate Record Size", KeyEvent.VK_S);
|
---|
212 | tools_size.addActionListener(Gatherer.g_man);
|
---|
213 |
|
---|
214 | tools.add(tools_log);
|
---|
215 | tools.add(tools_size);
|
---|
216 | //this.add(Box.createHorizontalStrut(15));
|
---|
217 | //this.add(tools);
|
---|
218 |
|
---|
219 | // Help menu
|
---|
220 | help = new JMenu(get("Help"));
|
---|
221 | //help.addMenuListener(menu_listener);
|
---|
222 | help.setIcon(Utility.HELP_ICON);
|
---|
223 |
|
---|
224 | help_about = new JMenuItem(get("Help_About"));
|
---|
225 | help_about.addActionListener(Gatherer.g_man);
|
---|
226 |
|
---|
227 | help_browse = new JMenuItem(get("GUI.Browser"), Utility.BLANK_ICON);
|
---|
228 | help_browse.addActionListener(Gatherer.g_man);
|
---|
229 |
|
---|
230 | help_build = new JMenuItem(get("GUI.Create"), Utility.BLANK_ICON);
|
---|
231 | help_build.addActionListener(Gatherer.g_man);
|
---|
232 |
|
---|
233 | help_collect = new JMenuItem(get("GUI.Collection"), Utility.BLANK_ICON);
|
---|
234 | help_collect.addActionListener(Gatherer.g_man);
|
---|
235 |
|
---|
236 | help_design = new JMenuItem(get("GUI.Build"), Utility.BLANK_ICON);
|
---|
237 | help_design.addActionListener(Gatherer.g_man);
|
---|
238 |
|
---|
239 | help_export = new JMenuItem(get("GUI.Export"), Utility.BLANK_ICON);
|
---|
240 | help_export.addActionListener(Gatherer.g_man);
|
---|
241 |
|
---|
242 | help_general = new JMenuItem(get("Source.General"));
|
---|
243 | help_general.addActionListener(Gatherer.g_man);
|
---|
244 |
|
---|
245 | help_metaedit = new JMenuItem(get("GUI.MetaEdit"), Utility.BLANK_ICON);
|
---|
246 | help_metaedit.addActionListener(Gatherer.g_man);
|
---|
247 |
|
---|
248 | help_mirror = new JMenuItem(get("GUI.Mirroring"), Utility.BLANK_ICON);
|
---|
249 | help_mirror.addActionListener(Gatherer.g_man);
|
---|
250 |
|
---|
251 | help_preview = new JMenuItem(get("GUI.Preview"), Utility.BLANK_ICON);
|
---|
252 | help_preview.addActionListener(Gatherer.g_man);
|
---|
253 |
|
---|
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 | }
|
---|
286 |
|
---|
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 | }
|
---|
298 |
|
---|
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 |
|
---|
307 | public void setMetaAuditSuffix(String metaaudit_suffix) {
|
---|
308 | System.err.println("**** Set suffix: " + metaaudit_suffix);
|
---|
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 | }
|
---|
318 | }
|
---|
319 |
|
---|
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 | }
|
---|
325 |
|
---|
326 | /** In order to provide context aware help advice we keep track of which
|
---|
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 | */
|
---|
331 | public void tabSelected(int tab_index) {
|
---|
332 | JMenuItem selected;
|
---|
333 | if(current_tab != -1) {
|
---|
334 | // Remove the image
|
---|
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 | }
|
---|
347 |
|
---|
348 | /** Retrieves a key from the Dictionary, using no extra arguments.
|
---|
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 | */
|
---|
353 | private String get(String key) {
|
---|
354 | return get(key, null);
|
---|
355 | }
|
---|
356 |
|
---|
357 | /** Retrieves a key from the Dictionary, providing extra arguments to
|
---|
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 | */
|
---|
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 | }
|
---|
372 |
|
---|
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 |
|
---|
405 | private class NonFocusMenu
|
---|
406 | extends JMenu {
|
---|
407 | public NonFocusMenu(String name) {
|
---|
408 | super(name);
|
---|
409 | setFocusPainted(false);
|
---|
410 | }
|
---|
411 |
|
---|
412 | public boolean isFocusable(){
|
---|
413 | return false;
|
---|
414 | }
|
---|
415 |
|
---|
416 | public void requestFocus(){
|
---|
417 | }
|
---|
418 |
|
---|
419 | public boolean requestFocus(boolean t){
|
---|
420 | return false;
|
---|
421 | }
|
---|
422 |
|
---|
423 | public void setFocusable(boolean f) {
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | private class NonFocusMenuItem
|
---|
428 | extends JMenuItem {
|
---|
429 | public NonFocusMenuItem(String name, int key) {
|
---|
430 | super(name, key);
|
---|
431 | setFocusPainted(false);
|
---|
432 | }
|
---|
433 |
|
---|
434 | public boolean isFocusable(){
|
---|
435 | return false;
|
---|
436 | }
|
---|
437 |
|
---|
438 | public void requestFocus(){
|
---|
439 | }
|
---|
440 |
|
---|
441 | public boolean requestFocus(boolean t){
|
---|
442 | return false;
|
---|
443 | }
|
---|
444 |
|
---|
445 | public void setFocusable(boolean f) {
|
---|
446 | }
|
---|
447 |
|
---|
448 | }
|
---|
449 | }
|
---|