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

Last change on this file since 9101 was 8992, checked in by mdewsnip, 19 years ago

Changed "Mirror" pane to "Download".

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