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

Last change on this file since 8238 was 8238, checked in by mdewsnip, 20 years ago

Converted to proper Unix files.

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