[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;
|
---|
[8238] | 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;
|
---|
[8992] | 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;
|
---|
[12101] | 84 | public JMenuItem help_format;
|
---|
[8238] | 85 | public JMenuItem help_about;
|
---|
| 86 |
|
---|
[8992] | 87 |
|
---|
[8238] | 88 | public MenuBar(MenuListener menu_listener)
|
---|
| 89 | {
|
---|
[18370] | 90 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 91 |
|
---|
[8238] | 92 | file = new JMenu();
|
---|
[14249] | 93 | file.setEnabled(false);
|
---|
[12119] | 94 | file.setText(Dictionary.get("Menu.File"));
|
---|
[18370] | 95 | file.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 96 |
|
---|
[12119] | 97 | file_associations = new JMenuItem(Dictionary.get("Menu.File_Associations"));
|
---|
[8238] | 98 | file_associations.addActionListener(Gatherer.g_man);
|
---|
[18370] | 99 | file_associations.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 100 |
|
---|
[12119] | 101 | file_cdimage = new JMenuItem(Dictionary.get("Menu.File_CDimage"));
|
---|
[9243] | 102 | file_cdimage.addActionListener(Gatherer.g_man);
|
---|
[10726] | 103 | file_cdimage.setEnabled(!Gatherer.isGsdlRemote);
|
---|
[18370] | 104 | file_cdimage.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 105 |
|
---|
[12119] | 106 | file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
|
---|
[8238] | 107 | file_close.addActionListener(Gatherer.g_man);
|
---|
| 108 | file_close.setEnabled(false);
|
---|
[18370] | 109 | file_close.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 110 |
|
---|
[12119] | 111 | file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
|
---|
[8238] | 112 | file_delete.addActionListener(Gatherer.g_man);
|
---|
[18370] | 113 | file_delete.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 114 |
|
---|
[12119] | 115 | file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
|
---|
[8238] | 116 | file_exit.addActionListener(Gatherer.g_man);
|
---|
[18370] | 117 | file_exit.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 118 |
|
---|
[12119] | 119 | file_exportas = new JMenuItem(Dictionary.get("Menu.File_ExportAs"));
|
---|
[9243] | 120 | file_exportas.addActionListener(Gatherer.g_man);
|
---|
[23860] | 121 | file_exportas.setEnabled(!Gatherer.isGsdlRemote);
|
---|
[20123] | 122 | file_exportas.setComponentOrientation(Dictionary.getOrientation());
|
---|
[13899] | 123 |
|
---|
[12119] | 124 | file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
|
---|
[8238] | 125 | file_new.addActionListener(Gatherer.g_man);
|
---|
[18370] | 126 | file_new.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 127 |
|
---|
[12119] | 128 | file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
|
---|
[8238] | 129 | file_open.addActionListener(Gatherer.g_man);
|
---|
[18370] | 130 | file_open.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 131 |
|
---|
[12119] | 132 | file_options = new JMenuItem(Dictionary.get("Menu.File_Options"));
|
---|
[8238] | 133 | file_options.addActionListener(Gatherer.g_man);
|
---|
[18370] | 134 | file_options.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 135 |
|
---|
| 136 | file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
|
---|
[8238] | 137 | file_save.addActionListener(Gatherer.g_man);
|
---|
| 138 | file_save.setEnabled(false);
|
---|
[18370] | 139 | file_save.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 140 |
|
---|
[8238] | 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);
|
---|
[23860] | 148 | file.add(file_exportas);
|
---|
| 149 | // these currently don't work. better to just disable them?
|
---|
[20123] | 150 | if (!Gatherer.GS3) {
|
---|
[23860] | 151 | file.add(file_cdimage);
|
---|
[20123] | 152 | }
|
---|
[8238] | 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();
|
---|
[14249] | 161 | edit.setEnabled(false);
|
---|
[12119] | 162 | edit.setText(Dictionary.get("Menu.Edit"));
|
---|
[18370] | 163 | edit.setComponentOrientation(Dictionary.getOrientation());
|
---|
[28627] | 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
|
---|
[28628] | 167 | // http://stackoverflow.com/questions/5585919/creating-unicode-character-from-its-number
|
---|
[28627] | 168 | char appleKeyCodepoint = 0x2318; // applekey symbol unicode codepoint: U+2318 (\u2318)
|
---|
| 169 | String appleKeySymbol = String.valueOf(appleKeyCodepoint);
|
---|
| 170 | modkey = appleKeySymbol;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[28626] | 173 | edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
|
---|
[8238] | 174 | edit_cut.addActionListener(Gatherer.g_man);
|
---|
[18370] | 175 | edit_cut.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 176 |
|
---|
[28626] | 177 | edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
|
---|
[8238] | 178 | edit_copy.addActionListener(Gatherer.g_man);
|
---|
[18370] | 179 | edit_copy.setComponentOrientation(Dictionary.getOrientation());
|
---|
[12119] | 180 |
|
---|
[28626] | 181 | edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
|
---|
[8238] | 182 | edit_paste.addActionListener(Gatherer.g_man);
|
---|
[18370] | 183 | edit_paste.setComponentOrientation(Dictionary.getOrientation());
|
---|
[8238] | 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();
|
---|
[10012] | 191 | help.setIcon(HELP_ICON);
|
---|
[12119] | 192 | help.setText(Dictionary.get("Menu.Help"));
|
---|
[18370] | 193 | help.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 194 |
|
---|
[12119] | 195 | help_general = new JMenuItem(Dictionary.get("Source.General"));
|
---|
[8992] | 196 | help_general.addActionListener(Gatherer.g_man);
|
---|
[18370] | 197 | help_general.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 198 |
|
---|
[12119] | 199 | help_download = new JMenuItem(Dictionary.get("GUI.Download"), BLANK_ICON);
|
---|
[8992] | 200 | help_download.addActionListener(Gatherer.g_man);
|
---|
[18370] | 201 | help_download.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 202 |
|
---|
[12119] | 203 | help_gather = new JMenuItem(Dictionary.get("GUI.Gather"), BLANK_ICON);
|
---|
[8992] | 204 | help_gather.addActionListener(Gatherer.g_man);
|
---|
[18370] | 205 | help_gather.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 206 |
|
---|
[12119] | 207 | help_enrich = new JMenuItem(Dictionary.get("GUI.Enrich"), BLANK_ICON);
|
---|
[8992] | 208 | help_enrich.addActionListener(Gatherer.g_man);
|
---|
[18370] | 209 | help_enrich.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 210 |
|
---|
[12119] | 211 | help_design = new JMenuItem(Dictionary.get("GUI.Design"), BLANK_ICON);
|
---|
[8238] | 212 | help_design.addActionListener(Gatherer.g_man);
|
---|
[18370] | 213 | help_design.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 214 |
|
---|
[12119] | 215 | help_create = new JMenuItem(Dictionary.get("GUI.Create"), BLANK_ICON);
|
---|
[8992] | 216 | help_create.addActionListener(Gatherer.g_man);
|
---|
[18370] | 217 | help_create.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 218 |
|
---|
[12119] | 219 | help_format = new JMenuItem(Dictionary.get("GUI.Format"), BLANK_ICON);
|
---|
[12101] | 220 | help_format.addActionListener(Gatherer.g_man);
|
---|
[18370] | 221 | help_format.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 222 |
|
---|
[12119] | 223 | help_about = new JMenuItem(Dictionary.get("Menu.Help_About"));
|
---|
[8992] | 224 | help_about.addActionListener(Gatherer.g_man);
|
---|
[18370] | 225 | help_about.setComponentOrientation(Dictionary.getOrientation());
|
---|
| 226 |
|
---|
[8238] | 227 | // Layout (help menu)
|
---|
| 228 | help.add(help_general);
|
---|
| 229 | help.add(new JSeparator());
|
---|
[19306] | 230 | if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
|
---|
[8992] | 231 | help.add(help_download);
|
---|
[8238] | 232 | }
|
---|
| 233 | if (Configuration.get("workflow.gather", true)) {
|
---|
[8992] | 234 | help.add(help_gather);
|
---|
[8238] | 235 | }
|
---|
| 236 | if (Configuration.get("workflow.enrich", true)) {
|
---|
[8992] | 237 | help.add(help_enrich);
|
---|
[8238] | 238 | }
|
---|
| 239 | if (Configuration.get("workflow.design", true)) {
|
---|
| 240 | help.add(help_design);
|
---|
| 241 | }
|
---|
| 242 | if (Configuration.get("workflow.create", true)) {
|
---|
[8992] | 243 | help.add(help_create);
|
---|
[8238] | 244 | }
|
---|
[12101] | 245 | if (Configuration.get("workflow.format", true)) {
|
---|
| 246 | help.add(help_format);
|
---|
| 247 | }
|
---|
[8238] | 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 |
|
---|
[8353] | 266 | public void refresh(int refresh_reason, boolean ready)
|
---|
| 267 | {
|
---|
| 268 | file_close.setEnabled(ready);
|
---|
| 269 | file_save.setEnabled(ready);
|
---|
| 270 | }
|
---|
| 271 |
|
---|
[8238] | 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) {
|
---|
[10012] | 284 | selected.setIcon(BLANK_ICON);
|
---|
[8238] | 285 | }
|
---|
| 286 | }
|
---|
| 287 | current_tab = tab_index + 2;
|
---|
| 288 | selected = help.getItem(current_tab);
|
---|
| 289 | if(selected != null) {
|
---|
[10012] | 290 | selected.setIcon(HELP_ICON);
|
---|
[8238] | 291 | }
|
---|
| 292 | selected = null;
|
---|
| 293 | }
|
---|
| 294 | }
|
---|