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