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

Last change on this file since 9888 was 9243, checked in by davidb, 19 years ago

Renaming of ExportPrompt class the WriteCDImagePrompt and introduction
of ExportAsPrompt.

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