[8238] | 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 | */
|
---|
| 37 | package org.greenstone.gatherer.gui;
|
---|
| 38 |
|
---|
| 39 | import java.awt.*;
|
---|
| 40 | import java.awt.event.*;
|
---|
| 41 | import javax.swing.*;
|
---|
| 42 | import javax.swing.event.*;
|
---|
| 43 | import org.greenstone.gatherer.Configuration;
|
---|
| 44 | import org.greenstone.gatherer.Dictionary;
|
---|
| 45 | import org.greenstone.gatherer.Gatherer;
|
---|
[10012] | 46 | import org.greenstone.gatherer.util.JarTools;
|
---|
[28626] | 47 | import org.greenstone.gatherer.util.Utility;
|
---|
[8238] | 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 | */
|
---|
| 53 | public class MenuBar
|
---|
[10012] | 54 | extends JMenuBar
|
---|
| 55 | {
|
---|
| 56 | static public ImageIcon BLANK_ICON = JarTools.getImage("blank.gif");
|
---|
[14680] | 57 | static public ImageIcon HELP_ICON = JarTools.getImage("help.png");
|
---|
[10012] | 58 |
|
---|
[8238] | 59 | /** The icon to be displayed alongside the context choosen help file. */
|
---|
| 60 | private int current_tab = -1;
|
---|
| 61 |
|
---|
[14230] | 62 | public JMenu file = null;
|
---|
| 63 | public JMenu edit = null;
|
---|
[8238] | 64 | public JMenu help = null;
|
---|
| 65 | public JMenuItem file_associations;
|
---|
[9243] | 66 | public JMenuItem file_cdimage = null;
|
---|
[8238] | 67 | public JMenuItem file_close = null;
|
---|
| 68 | public JMenuItem file_delete = null;
|
---|
| 69 | public JMenuItem file_exit = null;
|
---|
[9243] | 70 | public JMenuItem file_exportas = null;
|
---|
[34263] | 71 | public JMenuItem file_exportmeta = null;
|
---|
[8238] | 72 | public JMenuItem file_new = null;
|
---|
| 73 | public JMenuItem file_open = null;
|
---|
| 74 | public JMenuItem file_options = null;
|
---|
| 75 | public JMenuItem file_save = null;
|
---|
| 76 | public JMenuItem edit_copy;
|
---|
| 77 | public JMenuItem edit_cut;
|
---|
| 78 | public JMenuItem edit_paste;
|
---|
[30701] | 79 | public JMenuItem edit_config;
|
---|
[8992] | 80 | public JMenuItem help_general;
|
---|
| 81 | public JMenuItem help_download;
|
---|
| 82 | public JMenuItem help_gather;
|
---|
| 83 | public JMenuItem help_enrich;
|
---|
| 84 | public JMenuItem help_design;
|
---|
| 85 | public JMenuItem help_create;
|
---|
[12101] | 86 | public JMenuItem help_format;
|
---|
[8238] | 87 | public JMenuItem help_about;
|
---|
| 88 |
|
---|
[8992] | 89 |
|
---|
[8238] | 90 | public MenuBar(MenuListener menu_listener)
|
---|
| 91 | {
|
---|
[18370] | 92 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 93 |
|
---|
[8238] | 94 | file = new JMenu();
|
---|
[14249] | 95 | file.setEnabled(false);
|
---|
[12119] | 96 | file.setText(Dictionary.get("Menu.File"));
|
---|
[18370] | 97 | file.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 98 |
|
---|
[12119] | 99 | file_associations = new JMenuItem(Dictionary.get("Menu.File_Associations"));
|
---|
[8238] | 100 | file_associations.addActionListener(Gatherer.g_man);
|
---|
[18370] | 101 | file_associations.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 102 |
|
---|
[12119] | 103 | file_cdimage = new JMenuItem(Dictionary.get("Menu.File_CDimage"));
|
---|
[9243] | 104 | file_cdimage.addActionListener(Gatherer.g_man);
|
---|
[10726] | 105 | file_cdimage.setEnabled(!Gatherer.isGsdlRemote);
|
---|
[18370] | 106 | file_cdimage.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 107 |
|
---|
[12119] | 108 | file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
|
---|
[8238] | 109 | file_close.addActionListener(Gatherer.g_man);
|
---|
| 110 | file_close.setEnabled(false);
|
---|
[18370] | 111 | file_close.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 112 |
|
---|
[12119] | 113 | file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
|
---|
[8238] | 114 | file_delete.addActionListener(Gatherer.g_man);
|
---|
[18370] | 115 | file_delete.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 116 |
|
---|
[12119] | 117 | file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
|
---|
[8238] | 118 | file_exit.addActionListener(Gatherer.g_man);
|
---|
[18370] | 119 | file_exit.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 120 |
|
---|
[12119] | 121 | file_exportas = new JMenuItem(Dictionary.get("Menu.File_ExportAs"));
|
---|
[9243] | 122 | file_exportas.addActionListener(Gatherer.g_man);
|
---|
[23860] | 123 | file_exportas.setEnabled(!Gatherer.isGsdlRemote);
|
---|
[20123] | 124 | file_exportas.setComponentOrientation(Dictionary.getOrientation());
|
---|
[34263] | 125 |
|
---|
| 126 | file_exportmeta = new JMenuItem(Dictionary.get("Menu.File_ExportMeta"));
|
---|
| 127 | file_exportmeta.addActionListener(Gatherer.g_man);
|
---|
| 128 | file_exportmeta.setEnabled(!Gatherer.isGsdlRemote);
|
---|
| 129 | file_exportmeta.setComponentOrientation(Dictionary.getOrientation());
|
---|
[13899] | 130 |
|
---|
[12119] | 131 | file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
|
---|
[8238] | 132 | file_new.addActionListener(Gatherer.g_man);
|
---|
[18370] | 133 | file_new.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 134 |
|
---|
[12119] | 135 | file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
|
---|
[8238] | 136 | file_open.addActionListener(Gatherer.g_man);
|
---|
[18370] | 137 | file_open.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 138 |
|
---|
[12119] | 139 | file_options = new JMenuItem(Dictionary.get("Menu.File_Options"));
|
---|
[8238] | 140 | file_options.addActionListener(Gatherer.g_man);
|
---|
[18370] | 141 | file_options.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 142 |
|
---|
| 143 | file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
|
---|
[8238] | 144 | file_save.addActionListener(Gatherer.g_man);
|
---|
| 145 | file_save.setEnabled(false);
|
---|
[18370] | 146 | file_save.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 147 |
|
---|
[8238] | 148 | // Layout (file menu)
|
---|
| 149 | file.add(file_new);
|
---|
| 150 | file.add(file_open);
|
---|
| 151 | file.add(file_save);
|
---|
| 152 | file.add(file_close);
|
---|
| 153 | file.add(new JSeparator());
|
---|
| 154 | file.add(file_delete);
|
---|
[23860] | 155 | file.add(file_exportas);
|
---|
[34263] | 156 | file.add(file_exportmeta);
|
---|
[23860] | 157 | // these currently don't work. better to just disable them?
|
---|
[20123] | 158 | if (!Gatherer.GS3) {
|
---|
[23860] | 159 | file.add(file_cdimage);
|
---|
[20123] | 160 | }
|
---|
[8238] | 161 | file.add(new JSeparator());
|
---|
| 162 | file.add(file_associations);
|
---|
| 163 | file.add(file_options);
|
---|
| 164 | file.add(new JSeparator());
|
---|
| 165 | file.add(file_exit);
|
---|
| 166 |
|
---|
| 167 | // Edit menu
|
---|
| 168 | edit = new JMenu();
|
---|
[14249] | 169 | edit.setEnabled(false);
|
---|
[12119] | 170 | edit.setText(Dictionary.get("Menu.Edit"));
|
---|
[18370] | 171 | edit.setComponentOrientation(Dictionary.getOrientation());
|
---|
[28627] | 172 | String modkey = "ctrl";
|
---|
| 173 | if(Utility.isMac()) { // on Mac, we now use the Apple key instead of Ctrl for GLI/GEMS edit shortcuts
|
---|
[28628] | 174 | // http://stackoverflow.com/questions/5585919/creating-unicode-character-from-its-number
|
---|
[28627] | 175 | char appleKeyCodepoint = 0x2318; // applekey symbol unicode codepoint: U+2318 (\u2318)
|
---|
| 176 | String appleKeySymbol = String.valueOf(appleKeyCodepoint);
|
---|
| 177 | modkey = appleKeySymbol;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[28626] | 180 | edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
|
---|
[8238] | 181 | edit_cut.addActionListener(Gatherer.g_man);
|
---|
[18370] | 182 | edit_cut.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 183 |
|
---|
[28626] | 184 | edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
|
---|
[8238] | 185 | edit_copy.addActionListener(Gatherer.g_man);
|
---|
[18370] | 186 | edit_copy.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 187 |
|
---|
[28626] | 188 | edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
|
---|
[8238] | 189 | edit_paste.addActionListener(Gatherer.g_man);
|
---|
[18370] | 190 | edit_paste.setComponentOrientation(Dictionary.getOrientation());
|
---|
[30701] | 191 |
|
---|
[8238] | 192 | // Layout (edit menu)
|
---|
| 193 | edit.add(edit_cut);
|
---|
| 194 | edit.add(edit_copy);
|
---|
| 195 | edit.add(edit_paste);
|
---|
| 196 |
|
---|
[30701] | 197 | // if GS3, then we have a menu item that allows editing of config files
|
---|
| 198 | if(Gatherer.GS3) {
|
---|
| 199 |
|
---|
| 200 | edit_config = new JMenuItem(Dictionary.get("Menu.Edit_Config"));
|
---|
| 201 | // handle the actual Edit > ColConfig.xml menu item
|
---|
| 202 | edit_config.addActionListener(Gatherer.g_man);
|
---|
| 203 | edit_config.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 204 | edit.add(edit_config);
|
---|
| 205 | // The Edit menu itself now listens, in order to gray out the
|
---|
| 206 | // Edit > collectionConfig.xml option when no collection is open
|
---|
| 207 | // (JMenu doesn't work with ActionListener only with MenuListener, see
|
---|
| 208 | // http://stackoverflow.com/questions/9862165/jmenu-actionlistener)
|
---|
| 209 | edit.addMenuListener(menu_listener);
|
---|
| 210 |
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[8238] | 213 | // Help menu
|
---|
| 214 | help = new JMenu();
|
---|
[10012] | 215 | help.setIcon(HELP_ICON);
|
---|
[12119] | 216 | help.setText(Dictionary.get("Menu.Help"));
|
---|
[18370] | 217 | help.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 218 |
|
---|
[12119] | 219 | help_general = new JMenuItem(Dictionary.get("Source.General"));
|
---|
[8992] | 220 | help_general.addActionListener(Gatherer.g_man);
|
---|
[18370] | 221 | help_general.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 222 |
|
---|
[12119] | 223 | help_download = new JMenuItem(Dictionary.get("GUI.Download"), BLANK_ICON);
|
---|
[8992] | 224 | help_download.addActionListener(Gatherer.g_man);
|
---|
[18370] | 225 | help_download.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 226 |
|
---|
[12119] | 227 | help_gather = new JMenuItem(Dictionary.get("GUI.Gather"), BLANK_ICON);
|
---|
[8992] | 228 | help_gather.addActionListener(Gatherer.g_man);
|
---|
[18370] | 229 | help_gather.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 230 |
|
---|
[12119] | 231 | help_enrich = new JMenuItem(Dictionary.get("GUI.Enrich"), BLANK_ICON);
|
---|
[8992] | 232 | help_enrich.addActionListener(Gatherer.g_man);
|
---|
[18370] | 233 | help_enrich.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 234 |
|
---|
[12119] | 235 | help_design = new JMenuItem(Dictionary.get("GUI.Design"), BLANK_ICON);
|
---|
[8238] | 236 | help_design.addActionListener(Gatherer.g_man);
|
---|
[18370] | 237 | help_design.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 238 |
|
---|
[12119] | 239 | help_create = new JMenuItem(Dictionary.get("GUI.Create"), BLANK_ICON);
|
---|
[8992] | 240 | help_create.addActionListener(Gatherer.g_man);
|
---|
[18370] | 241 | help_create.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 242 |
|
---|
[12119] | 243 | help_format = new JMenuItem(Dictionary.get("GUI.Format"), BLANK_ICON);
|
---|
[12101] | 244 | help_format.addActionListener(Gatherer.g_man);
|
---|
[18370] | 245 | help_format.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 246 |
|
---|
[12119] | 247 | help_about = new JMenuItem(Dictionary.get("Menu.Help_About"));
|
---|
[8992] | 248 | help_about.addActionListener(Gatherer.g_man);
|
---|
[18370] | 249 | help_about.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 250 |
|
---|
[8238] | 251 | // Layout (help menu)
|
---|
| 252 | help.add(help_general);
|
---|
| 253 | help.add(new JSeparator());
|
---|
[19306] | 254 | if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
|
---|
[8992] | 255 | help.add(help_download);
|
---|
[8238] | 256 | }
|
---|
| 257 | if (Configuration.get("workflow.gather", true)) {
|
---|
[8992] | 258 | help.add(help_gather);
|
---|
[8238] | 259 | }
|
---|
| 260 | if (Configuration.get("workflow.enrich", true)) {
|
---|
[8992] | 261 | help.add(help_enrich);
|
---|
[8238] | 262 | }
|
---|
| 263 | if (Configuration.get("workflow.design", true)) {
|
---|
| 264 | help.add(help_design);
|
---|
| 265 | }
|
---|
| 266 | if (Configuration.get("workflow.create", true)) {
|
---|
[8992] | 267 | help.add(help_create);
|
---|
[8238] | 268 | }
|
---|
[12101] | 269 | if (Configuration.get("workflow.format", true)) {
|
---|
| 270 | help.add(help_format);
|
---|
| 271 | }
|
---|
[8238] | 272 | help.add(new JSeparator());
|
---|
| 273 | help.add(help_about);
|
---|
| 274 |
|
---|
| 275 | // Layout (menu bar)
|
---|
| 276 | this.add(file);
|
---|
| 277 | this.add(Box.createHorizontalStrut(15));
|
---|
| 278 | this.add(edit);
|
---|
| 279 | this.add(Box.createHorizontalGlue());
|
---|
| 280 | this.add(help);
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | /** Once a quit has been requested by the user, prevent any further menu selections. */
|
---|
| 284 | public void exit() {
|
---|
| 285 | file.setEnabled(false);
|
---|
| 286 | edit.setEnabled(false);
|
---|
| 287 | help.setEnabled(false);
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[8353] | 290 | public void refresh(int refresh_reason, boolean ready)
|
---|
| 291 | {
|
---|
| 292 | file_close.setEnabled(ready);
|
---|
| 293 | file_save.setEnabled(ready);
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[8238] | 296 |
|
---|
| 297 | /** In order to provide context aware help advice we keep track of which
|
---|
| 298 | * tab the user has open, and then highlight that help menu item with
|
---|
| 299 | * separators.
|
---|
| 300 | * @param tab_index The index of the selected tab (0-7).
|
---|
| 301 | */
|
---|
| 302 | public void tabSelected(int tab_index) {
|
---|
| 303 | JMenuItem selected;
|
---|
| 304 | if(current_tab != -1) {
|
---|
| 305 | // Remove the image
|
---|
| 306 | selected = help.getItem(current_tab);
|
---|
| 307 | if(selected != null) {
|
---|
[10012] | 308 | selected.setIcon(BLANK_ICON);
|
---|
[8238] | 309 | }
|
---|
| 310 | }
|
---|
| 311 | current_tab = tab_index + 2;
|
---|
| 312 | selected = help.getItem(current_tab);
|
---|
| 313 | if(selected != null) {
|
---|
[10012] | 314 | selected.setIcon(HELP_ICON);
|
---|
[8238] | 315 | }
|
---|
| 316 | selected = null;
|
---|
| 317 | }
|
---|
| 318 | }
|
---|