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

Last change on this file since 28628 was 28628, checked in by ak19, 10 years ago

Still related to the previous 2 commits (28626 and 28627). Adding a stackoverflow link on how to convert unicode codepoints into strings, which can come in handy for codepoints that are representing numbers larger than a char.

  • 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.JarTools;
47import org.greenstone.gatherer.util.Utility;
48
49/** The menu bar for the Gatherer main GUI.
50 * @author John Thompson, Greenstone Digital Library, University of Waikato
51 * @version 2.2
52 */
53public class MenuBar
54 extends JMenuBar
55{
56 static public ImageIcon BLANK_ICON = JarTools.getImage("blank.gif");
57 static public ImageIcon HELP_ICON = JarTools.getImage("help.png");
58
59 /** The icon to be displayed alongside the context choosen help file. */
60 private int current_tab = -1;
61
62 public JMenu file = null;
63 public JMenu edit = null;
64 public JMenu help = null;
65 public JMenuItem file_associations;
66 public JMenuItem file_cdimage = null;
67 public JMenuItem file_close = null;
68 public JMenuItem file_delete = null;
69 public JMenuItem file_exit = null;
70 public JMenuItem file_exportas = null;
71 public JMenuItem file_new = null;
72 public JMenuItem file_open = null;
73 public JMenuItem file_options = null;
74 public JMenuItem file_save = null;
75 public JMenuItem edit_copy;
76 public JMenuItem edit_cut;
77 public JMenuItem edit_paste;
78 public JMenuItem help_general;
79 public JMenuItem help_download;
80 public JMenuItem help_gather;
81 public JMenuItem help_enrich;
82 public JMenuItem help_design;
83 public JMenuItem help_create;
84 public JMenuItem help_format;
85 public JMenuItem help_about;
86
87
88 public MenuBar(MenuListener menu_listener)
89 {
90 this.setComponentOrientation(Dictionary.getOrientation());
91
92 file = new JMenu();
93 file.setEnabled(false);
94 file.setText(Dictionary.get("Menu.File"));
95 file.setComponentOrientation(Dictionary.getOrientation());
96
97 file_associations = new JMenuItem(Dictionary.get("Menu.File_Associations"));
98 file_associations.addActionListener(Gatherer.g_man);
99 file_associations.setComponentOrientation(Dictionary.getOrientation());
100
101 file_cdimage = new JMenuItem(Dictionary.get("Menu.File_CDimage"));
102 file_cdimage.addActionListener(Gatherer.g_man);
103 file_cdimage.setEnabled(!Gatherer.isGsdlRemote);
104 file_cdimage.setComponentOrientation(Dictionary.getOrientation());
105
106 file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
107 file_close.addActionListener(Gatherer.g_man);
108 file_close.setEnabled(false);
109 file_close.setComponentOrientation(Dictionary.getOrientation());
110
111 file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
112 file_delete.addActionListener(Gatherer.g_man);
113 file_delete.setComponentOrientation(Dictionary.getOrientation());
114
115 file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
116 file_exit.addActionListener(Gatherer.g_man);
117 file_exit.setComponentOrientation(Dictionary.getOrientation());
118
119 file_exportas = new JMenuItem(Dictionary.get("Menu.File_ExportAs"));
120 file_exportas.addActionListener(Gatherer.g_man);
121 file_exportas.setEnabled(!Gatherer.isGsdlRemote);
122 file_exportas.setComponentOrientation(Dictionary.getOrientation());
123
124 file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
125 file_new.addActionListener(Gatherer.g_man);
126 file_new.setComponentOrientation(Dictionary.getOrientation());
127
128 file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
129 file_open.addActionListener(Gatherer.g_man);
130 file_open.setComponentOrientation(Dictionary.getOrientation());
131
132 file_options = new JMenuItem(Dictionary.get("Menu.File_Options"));
133 file_options.addActionListener(Gatherer.g_man);
134 file_options.setComponentOrientation(Dictionary.getOrientation());
135
136 file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
137 file_save.addActionListener(Gatherer.g_man);
138 file_save.setEnabled(false);
139 file_save.setComponentOrientation(Dictionary.getOrientation());
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_exportas);
149 // these currently don't work. better to just disable them?
150 if (!Gatherer.GS3) {
151 file.add(file_cdimage);
152 }
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.setEnabled(false);
162 edit.setText(Dictionary.get("Menu.Edit"));
163 edit.setComponentOrientation(Dictionary.getOrientation());
164
165 String modkey = "ctrl";
166 if(Utility.isMac()) { // on Mac, we now use the Apple key instead of Ctrl for GLI/GEMS edit shortcuts
167 // http://stackoverflow.com/questions/5585919/creating-unicode-character-from-its-number
168 char appleKeyCodepoint = 0x2318; // applekey symbol unicode codepoint: U+2318 (\u2318)
169 String appleKeySymbol = String.valueOf(appleKeyCodepoint);
170 modkey = appleKeySymbol;
171 }
172
173 edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
174 edit_cut.addActionListener(Gatherer.g_man);
175 edit_cut.setComponentOrientation(Dictionary.getOrientation());
176
177 edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
178 edit_copy.addActionListener(Gatherer.g_man);
179 edit_copy.setComponentOrientation(Dictionary.getOrientation());
180
181 edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
182 edit_paste.addActionListener(Gatherer.g_man);
183 edit_paste.setComponentOrientation(Dictionary.getOrientation());
184 // Layout (edit menu)
185 edit.add(edit_cut);
186 edit.add(edit_copy);
187 edit.add(edit_paste);
188
189 // Help menu
190 help = new JMenu();
191 help.setIcon(HELP_ICON);
192 help.setText(Dictionary.get("Menu.Help"));
193 help.setComponentOrientation(Dictionary.getOrientation());
194
195 help_general = new JMenuItem(Dictionary.get("Source.General"));
196 help_general.addActionListener(Gatherer.g_man);
197 help_general.setComponentOrientation(Dictionary.getOrientation());
198
199 help_download = new JMenuItem(Dictionary.get("GUI.Download"), BLANK_ICON);
200 help_download.addActionListener(Gatherer.g_man);
201 help_download.setComponentOrientation(Dictionary.getOrientation());
202
203 help_gather = new JMenuItem(Dictionary.get("GUI.Gather"), BLANK_ICON);
204 help_gather.addActionListener(Gatherer.g_man);
205 help_gather.setComponentOrientation(Dictionary.getOrientation());
206
207 help_enrich = new JMenuItem(Dictionary.get("GUI.Enrich"), BLANK_ICON);
208 help_enrich.addActionListener(Gatherer.g_man);
209 help_enrich.setComponentOrientation(Dictionary.getOrientation());
210
211 help_design = new JMenuItem(Dictionary.get("GUI.Design"), BLANK_ICON);
212 help_design.addActionListener(Gatherer.g_man);
213 help_design.setComponentOrientation(Dictionary.getOrientation());
214
215 help_create = new JMenuItem(Dictionary.get("GUI.Create"), BLANK_ICON);
216 help_create.addActionListener(Gatherer.g_man);
217 help_create.setComponentOrientation(Dictionary.getOrientation());
218
219 help_format = new JMenuItem(Dictionary.get("GUI.Format"), BLANK_ICON);
220 help_format.addActionListener(Gatherer.g_man);
221 help_format.setComponentOrientation(Dictionary.getOrientation());
222
223 help_about = new JMenuItem(Dictionary.get("Menu.Help_About"));
224 help_about.addActionListener(Gatherer.g_man);
225 help_about.setComponentOrientation(Dictionary.getOrientation());
226
227 // Layout (help menu)
228 help.add(help_general);
229 help.add(new JSeparator());
230 if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
231 help.add(help_download);
232 }
233 if (Configuration.get("workflow.gather", true)) {
234 help.add(help_gather);
235 }
236 if (Configuration.get("workflow.enrich", true)) {
237 help.add(help_enrich);
238 }
239 if (Configuration.get("workflow.design", true)) {
240 help.add(help_design);
241 }
242 if (Configuration.get("workflow.create", true)) {
243 help.add(help_create);
244 }
245 if (Configuration.get("workflow.format", true)) {
246 help.add(help_format);
247 }
248 help.add(new JSeparator());
249 help.add(help_about);
250
251 // Layout (menu bar)
252 this.add(file);
253 this.add(Box.createHorizontalStrut(15));
254 this.add(edit);
255 this.add(Box.createHorizontalGlue());
256 this.add(help);
257 }
258
259 /** Once a quit has been requested by the user, prevent any further menu selections. */
260 public void exit() {
261 file.setEnabled(false);
262 edit.setEnabled(false);
263 help.setEnabled(false);
264 }
265
266 public void refresh(int refresh_reason, boolean ready)
267 {
268 file_close.setEnabled(ready);
269 file_save.setEnabled(ready);
270 }
271
272
273 /** In order to provide context aware help advice we keep track of which
274 * tab the user has open, and then highlight that help menu item with
275 * separators.
276 * @param tab_index The index of the selected tab (0-7).
277 */
278 public void tabSelected(int tab_index) {
279 JMenuItem selected;
280 if(current_tab != -1) {
281 // Remove the image
282 selected = help.getItem(current_tab);
283 if(selected != null) {
284 selected.setIcon(BLANK_ICON);
285 }
286 }
287 current_tab = tab_index + 2;
288 selected = help.getItem(current_tab);
289 if(selected != null) {
290 selected.setIcon(HELP_ICON);
291 }
292 selected = null;
293 }
294}
Note: See TracBrowser for help on using the repository browser.