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

Last change on this file since 10556 was 10345, checked in by mdewsnip, 19 years ago

Removed some more crap out of the Utility class.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.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.JarTools;
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{
55 static public ImageIcon BLANK_ICON = JarTools.getImage("blank.gif");
56 static public ImageIcon HELP_ICON = JarTools.getImage("help.gif");
57
58 /** The icon to be displayed alongside the context choosen help file. */
59 private int current_tab = -1;
60
61 private JMenu file = null;
62 private JMenu edit = null;
63 public JMenu help = null;
64 public JMenuItem file_associations;
65 public JMenuItem file_cdimage = null;
66 public JMenuItem file_close = null;
67 public JMenuItem file_delete = null;
68 public JMenuItem file_exit = null;
69 public JMenuItem file_exportas = null;
70 public JMenuItem file_new = null;
71 public JMenuItem file_open = null;
72 public JMenuItem file_options = null;
73 public JMenuItem file_save = null;
74 public JMenuItem edit_copy;
75 public JMenuItem edit_cut;
76 public JMenuItem edit_paste;
77 public JMenuItem help_general;
78 public JMenuItem help_download;
79 public JMenuItem help_gather;
80 public JMenuItem help_enrich;
81 public JMenuItem help_design;
82 public JMenuItem help_create;
83 public JMenuItem help_about;
84
85
86 public MenuBar(MenuListener menu_listener)
87 {
88 file = new JMenu();
89 file.setMnemonic(KeyEvent.VK_F);
90 Dictionary.registerText(file, "Menu.File");
91
92 file_associations = new JMenuItem();
93 file_associations.addActionListener(Gatherer.g_man);
94 file_associations.setMnemonic(KeyEvent.VK_A);
95 Dictionary.registerText(file_associations, "Menu.File_Associations");
96
97 file_cdimage = new JMenuItem();
98 file_cdimage.addActionListener(Gatherer.g_man);
99 file_cdimage.setMnemonic(KeyEvent.VK_I);
100 Dictionary.registerText(file_cdimage, "Menu.File_CDimage");
101
102 file_close = new JMenuItem();
103 file_close.addActionListener(Gatherer.g_man);
104 file_close.setEnabled(false);
105 file_close.setMnemonic(KeyEvent.VK_C);
106 Dictionary.registerText(file_close, "Menu.File_Close");
107
108 file_delete = new JMenuItem();
109 file_delete.addActionListener(Gatherer.g_man);
110 file_delete.setMnemonic(KeyEvent.VK_D);
111 Dictionary.registerText(file_delete, "Menu.File_Delete");
112
113 file_exit = new JMenuItem();
114 file_exit.addActionListener(Gatherer.g_man);
115 file_exit.setMnemonic(KeyEvent.VK_X);
116 Dictionary.registerText(file_exit, "Menu.File_Exit");
117
118 file_exportas = new JMenuItem();
119 file_exportas.addActionListener(Gatherer.g_man);
120 file_exportas.setMnemonic(KeyEvent.VK_E);
121 Dictionary.registerText(file_exportas, "Menu.File_ExportAs");
122
123 file_new = new JMenuItem();
124 file_new.addActionListener(Gatherer.g_man);
125 file_new.setMnemonic(KeyEvent.VK_N);
126 Dictionary.registerText(file_new, "Menu.File_New");
127
128 file_open = new JMenuItem();
129 file_open.addActionListener(Gatherer.g_man);
130 file_open.setMnemonic(KeyEvent.VK_O);
131 Dictionary.registerText(file_open, "Menu.File_Open");
132
133 file_options = new JMenuItem();
134 file_options.addActionListener(Gatherer.g_man);
135 file_options.setMnemonic(KeyEvent.VK_P);
136 Dictionary.registerText(file_options, "Menu.File_Options");
137
138 file_save = new JMenuItem();
139 file_save.addActionListener(Gatherer.g_man);
140 file_save.setEnabled(false);
141 file_save.setMnemonic(KeyEvent.VK_S);
142 Dictionary.registerText(file_save, "Menu.File_Save");
143
144 // Layout (file menu)
145 file.add(file_new);
146 file.add(file_open);
147 file.add(file_save);
148 file.add(file_close);
149 file.add(new JSeparator());
150 file.add(file_delete);
151 file.add(file_exportas);
152 file.add(file_cdimage);
153 file.add(new JSeparator());
154 file.add(file_associations);
155 file.add(file_options);
156 file.add(new JSeparator());
157 file.add(file_exit);
158
159 // Edit menu
160 edit = new JMenu();
161 edit.setMnemonic(KeyEvent.VK_E);
162 Dictionary.registerText(edit, "Menu.Edit");
163
164 edit_cut = new JMenuItem();
165 edit_cut.addActionListener(Gatherer.g_man);
166 edit_cut.setMnemonic(KeyEvent.VK_X);
167 Dictionary.registerText(edit_cut, "Menu.Edit_Cut");
168
169 edit_copy = new JMenuItem();
170 edit_copy.addActionListener(Gatherer.g_man);
171 edit_copy.setMnemonic(KeyEvent.VK_C);
172 Dictionary.registerText(edit_copy, "Menu.Edit_Copy");
173
174 edit_paste = new JMenuItem();
175 edit_paste.addActionListener(Gatherer.g_man);
176 edit_paste.setMnemonic(KeyEvent.VK_V);
177 Dictionary.registerText(edit_paste, "Menu.Edit_Paste");
178
179 // Layout (edit menu)
180 edit.add(edit_cut);
181 edit.add(edit_copy);
182 edit.add(edit_paste);
183
184 // Help menu
185 help = new JMenu();
186 help.setIcon(HELP_ICON);
187 Dictionary.setText(help, "Menu.Help");
188
189 help_general = new JMenuItem();
190 help_general.addActionListener(Gatherer.g_man);
191 Dictionary.registerText(help_general, "Source.General");
192
193 help_download = new JMenuItem(BLANK_ICON);
194 help_download.addActionListener(Gatherer.g_man);
195 Dictionary.registerText(help_download, "GUI.Download");
196
197 help_gather = new JMenuItem(BLANK_ICON);
198 help_gather.addActionListener(Gatherer.g_man);
199 Dictionary.registerText(help_gather, "GUI.Gather");
200
201 help_enrich = new JMenuItem(BLANK_ICON);
202 help_enrich.addActionListener(Gatherer.g_man);
203 Dictionary.registerText(help_enrich, "GUI.Enrich");
204
205 help_design = new JMenuItem(BLANK_ICON);
206 help_design.addActionListener(Gatherer.g_man);
207 Dictionary.registerText(help_design, "GUI.Design");
208
209 help_create = new JMenuItem(BLANK_ICON);
210 help_create.addActionListener(Gatherer.g_man);
211 Dictionary.registerText(help_create, "GUI.Create");
212
213 help_about = new JMenuItem();
214 help_about.addActionListener(Gatherer.g_man);
215 Dictionary.registerText(help_about, "Menu.Help_About");
216
217 // Layout (help menu)
218 help.add(help_general);
219 help.add(new JSeparator());
220 if (Configuration.get("workflow.download", true)) {
221 help.add(help_download);
222 }
223 if (Configuration.get("workflow.gather", true)) {
224 help.add(help_gather);
225 }
226 if (Configuration.get("workflow.enrich", true)) {
227 help.add(help_enrich);
228 }
229 if (Configuration.get("workflow.design", true)) {
230 help.add(help_design);
231 }
232 if (Configuration.get("workflow.create", true)) {
233 help.add(help_create);
234 }
235 help.add(new JSeparator());
236 help.add(help_about);
237
238 // Layout (menu bar)
239 this.add(file);
240 this.add(Box.createHorizontalStrut(15));
241 this.add(edit);
242 this.add(Box.createHorizontalGlue());
243 this.add(help);
244 }
245
246 /** Once a quit has been requested by the user, prevent any further menu selections. */
247 public void exit() {
248 file.setEnabled(false);
249 edit.setEnabled(false);
250 help.setEnabled(false);
251 }
252
253 public void refresh(int refresh_reason, boolean ready)
254 {
255 file_close.setEnabled(ready);
256 file_save.setEnabled(ready);
257 }
258
259
260 /** In order to provide context aware help advice we keep track of which
261 * tab the user has open, and then highlight that help menu item with
262 * separators.
263 * @param tab_index The index of the selected tab (0-7).
264 */
265 public void tabSelected(int tab_index) {
266 JMenuItem selected;
267 if(current_tab != -1) {
268 // Remove the image
269 selected = help.getItem(current_tab);
270 if(selected != null) {
271 selected.setIcon(BLANK_ICON);
272 }
273 }
274 current_tab = tab_index + 2;
275 selected = help.getItem(current_tab);
276 if(selected != null) {
277 selected.setIcon(HELP_ICON);
278 }
279 selected = null;
280 }
281}
Note: See TracBrowser for help on using the repository browser.