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

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

Finally committing the (many) changes to the GLI to use the new metadata code... I hope this doesn't have too many bugs in it and committing it now doesn't stuff anyone up! (Katherine said I could commit it, so blame her if anything goes wrong).

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