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