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

Last change on this file since 18376 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

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