[12564] | 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 th * University of Waikato, New Zealand.
|
---|
| 6 | *
|
---|
| 7 | * <BR><BR>
|
---|
| 8 | *
|
---|
| 9 | * Author: Shaoqun Wu, Greenstone Digital Library, University of Waikato
|
---|
| 10 | *
|
---|
| 11 | * <BR><BR>
|
---|
| 12 | *
|
---|
| 13 | * Copyright (C) 2006 New Zealand Digital Library Project
|
---|
| 14 | *
|
---|
| 15 | * <BR><BR>
|
---|
| 16 | *
|
---|
| 17 | * This program is free software; you can redistribute it and/or modify
|
---|
| 18 | * it under the terms of the GNU General Public License as published by
|
---|
| 19 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 20 | * (at your option) any later version.
|
---|
| 21 | *
|
---|
| 22 | * <BR><BR>
|
---|
| 23 | *
|
---|
| 24 | * This program is distributed in the hope that it will be useful,
|
---|
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 27 | * GNU General Public License for more details.
|
---|
| 28 | *
|
---|
| 29 | * <BR><BR>
|
---|
| 30 | *
|
---|
| 31 | * You should have received a copy of the GNU General Public License
|
---|
| 32 | * along with this program; if not, write to the Free Software
|
---|
| 33 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 34 | *############################################## ##########################
|
---|
| 35 | */
|
---|
| 36 | package org.greenstone.gatherer.gems;
|
---|
| 37 |
|
---|
| 38 | import java.awt.*;
|
---|
| 39 | import java.awt.event.*;
|
---|
| 40 | import java.util.*;
|
---|
| 41 | import javax.swing.*;
|
---|
| 42 | import java.lang.String;
|
---|
| 43 | import javax.swing.event.*;
|
---|
| 44 | import javax.swing.filechooser.*;
|
---|
| 45 | import javax.swing.text.*;
|
---|
| 46 | import javax.swing.tree.*;
|
---|
| 47 | import java.awt.*;
|
---|
| 48 | import java.awt.event.*;
|
---|
| 49 |
|
---|
| 50 | import java.io.File;
|
---|
| 51 |
|
---|
| 52 | import org.greenstone.gatherer.Configuration;
|
---|
| 53 | import org.greenstone.gatherer.DebugStream;
|
---|
| 54 | import org.greenstone.gatherer.Dictionary;
|
---|
| 55 | import org.greenstone.gatherer.GetOpt;
|
---|
| 56 | import org.greenstone.gatherer.gui.GComboBox;
|
---|
| 57 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
| 58 | import org.greenstone.gatherer.gui.HelpFrame;
|
---|
| 59 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
| 60 | import org.greenstone.gatherer.gui.NonWhitespaceField;
|
---|
| 61 | import org.greenstone.gatherer.util.Codec;
|
---|
| 62 | import org.greenstone.gatherer.util.JarTools;
|
---|
| 63 | import org.greenstone.gatherer.util.Utility;
|
---|
| 64 | import org.greenstone.gatherer.util.XMLTools;
|
---|
| 65 | import org.greenstone.gatherer.Dictionary;
|
---|
| 66 | import org.w3c.dom.*;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | /*
|
---|
| 70 | * @author Shaoqun Wu, Greenstone Digital Library, University of Waikato
|
---|
| 71 | * @version 2.4
|
---|
| 72 | */
|
---|
| 73 | public class GEMS
|
---|
| 74 | extends JFrame implements WindowFocusListener
|
---|
| 75 | {
|
---|
| 76 |
|
---|
| 77 | static final private Dimension SIZE = new Dimension(800,550);
|
---|
| 78 |
|
---|
[12681] | 79 | // we have a card pane to switch between the no set loaded view, and the
|
---|
| 80 | // set loaded view
|
---|
| 81 | private CardLayout card_layout = null;
|
---|
| 82 | private JPanel card_pane = null;
|
---|
| 83 | /** The name of the panel containing the "set loaded" card. */
|
---|
| 84 | private String SET_LOADED_CARD = "";
|
---|
| 85 | /** The name of the panel containing the "no set loaded" placeholder */
|
---|
| 86 | private String NO_SET_LOADED_CARD = "No set loaded";
|
---|
| 87 |
|
---|
[12564] | 88 | private GEMS self = null;
|
---|
| 89 |
|
---|
| 90 | private OpenMetadataSetPrompt open_prompt;
|
---|
| 91 | private DeleteMetadataSetPrompt delete_prompt;
|
---|
| 92 | private NewMetadataSetPrompt new_prompt;
|
---|
[12665] | 93 |
|
---|
[12681] | 94 | // this is the main panel that gets switched in once a set is loaded
|
---|
| 95 | private JSplitPane metadata_set_details_split_pane = null;
|
---|
| 96 | // this is the split with the attribute tables in it
|
---|
| 97 | private JSplitPane attribute_tables_split_pane = null;
|
---|
[12564] | 98 |
|
---|
| 99 | /** Um, the size of the screen I'd guess. */
|
---|
| 100 | private Dimension screen_size = null;
|
---|
| 101 |
|
---|
| 102 | private MetadataSetManager msm;
|
---|
| 103 |
|
---|
[12665] | 104 | private AttributeTable attribute_table; // meta_element_table
|
---|
| 105 | private AttributeTable language_dependent_attribute_table; //lang_element_table;
|
---|
[12564] | 106 |
|
---|
[12665] | 107 | private MetadataSetTree meta_set_tree;
|
---|
[12564] | 108 |
|
---|
[12665] | 109 | private MetadataSetModel metadata_set_model;
|
---|
[12564] | 110 |
|
---|
| 111 | private boolean stand_alone = true;
|
---|
| 112 |
|
---|
| 113 | private ArrayList listeners;
|
---|
| 114 |
|
---|
| 115 | static public void main(String[] args)
|
---|
| 116 | {
|
---|
| 117 | //TODO: add an option to open a paticular metadata set
|
---|
| 118 |
|
---|
| 119 | // Parse arguments
|
---|
| 120 | GetOpt go = new GetOpt(args);
|
---|
| 121 |
|
---|
| 122 | if (go.debug) {
|
---|
| 123 | DebugStream.enableDebugging();
|
---|
| 124 |
|
---|
| 125 | Calendar now = Calendar.getInstance();
|
---|
| 126 | String debug_file_path = "debug" + now.get(Calendar.DATE) + "-" + now.get(Calendar.MONTH) + "-" + now.get(Calendar.YEAR) + ".txt";
|
---|
| 127 |
|
---|
| 128 | // Debug file is created in the GLI directory
|
---|
| 129 | DebugStream.println("Debug file path: " + debug_file_path);
|
---|
| 130 | DebugStream.setDebugFile(debug_file_path);
|
---|
| 131 |
|
---|
| 132 | }
|
---|
| 133 | new GEMS(go.gsdl_path,go.metadata_path,true,go.new_set);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | /** Constructor.
|
---|
| 138 | */
|
---|
| 139 | public GEMS(String gsdl_path, String metadata_path, boolean standalone, boolean new_set)
|
---|
| 140 | {
|
---|
| 141 | self = this;
|
---|
| 142 | JarTools.initialise(this);
|
---|
| 143 | screen_size = Configuration.screen_size;
|
---|
| 144 | msm = new MetadataSetManager(gsdl_path);
|
---|
| 145 | stand_alone = standalone;
|
---|
| 146 | listeners = new ArrayList();
|
---|
| 147 |
|
---|
| 148 | addWindowListener(new WindowAdapter(){
|
---|
| 149 | public void windowClosing(WindowEvent e){
|
---|
| 150 | metadata_set_model.save(true);
|
---|
| 151 | if (stand_alone){
|
---|
| 152 | System.exit(0);
|
---|
| 153 | }
|
---|
[12665] | 154 | else {
|
---|
[12564] | 155 | notifyListeners();
|
---|
| 156 | setVisible(false);
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | });
|
---|
| 160 |
|
---|
| 161 | setSize(SIZE);
|
---|
| 162 | setTitle(Dictionary.get("GEMS.Title"));
|
---|
| 163 | setJMenuBar(new GEMSMenuBar());
|
---|
| 164 |
|
---|
| 165 | addWindowFocusListener(this);
|
---|
| 166 |
|
---|
[12681] | 167 | card_layout = new CardLayout();
|
---|
| 168 | card_pane = new JPanel();
|
---|
| 169 |
|
---|
[12564] | 170 | metadata_set_model = new MetadataSetModel(msm);
|
---|
| 171 | msm.setMetadataSetModel(metadata_set_model);
|
---|
[12572] | 172 | meta_set_tree = new MetadataSetTree();
|
---|
[12564] | 173 | metadata_set_model.addObserver(meta_set_tree);
|
---|
| 174 |
|
---|
[12665] | 175 | attribute_table = new AttributeTable(false);
|
---|
| 176 | MetadataElementModel mem = new MetadataElementModel();
|
---|
| 177 | mem.addMetadataElementListener((MetadataElementListener)attribute_table);
|
---|
| 178 | attribute_table.addAttributeListener(metadata_set_model);
|
---|
[12564] | 179 |
|
---|
[12665] | 180 | language_dependent_attribute_table = new AttributeTable(true);
|
---|
| 181 | mem.addMetadataElementListener((MetadataElementListener)language_dependent_attribute_table);
|
---|
| 182 | language_dependent_attribute_table.addAttributeListener(metadata_set_model);
|
---|
[12564] | 183 |
|
---|
| 184 | MetadataSetInfo msti= new MetadataSetInfo();
|
---|
[12665] | 185 | msti.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
| 186 | msti.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
[12572] | 187 | msti.setMetadataSetModel(metadata_set_model);
|
---|
[12564] | 188 |
|
---|
| 189 | open_prompt = new OpenMetadataSetPrompt(self,msm);
|
---|
| 190 | open_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
[12665] | 191 | open_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
| 192 | open_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
[12564] | 193 |
|
---|
| 194 | delete_prompt = new DeleteMetadataSetPrompt(self,msm);
|
---|
| 195 | delete_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
[12665] | 196 | delete_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
| 197 | delete_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
[12564] | 198 |
|
---|
| 199 | new_prompt = new NewMetadataSetPrompt(self,msm);
|
---|
| 200 | new_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
[12665] | 201 | new_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
| 202 | new_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
[12564] | 203 |
|
---|
| 204 |
|
---|
| 205 | // load the initial metadataset
|
---|
| 206 | if (metadata_path !=null && !metadata_path.equals("")){
|
---|
| 207 | open_prompt.openMetadataSet(metadata_path);
|
---|
| 208 | }
|
---|
| 209 | else{
|
---|
| 210 | if (new_set) new_prompt.display();
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[12665] | 213 | // the set tree
|
---|
[12564] | 214 | JScrollPane treePane = new JScrollPane(meta_set_tree);
|
---|
[12665] | 215 | // the language independent attributes
|
---|
| 216 | JScrollPane tablePane = new JScrollPane(attribute_table);
|
---|
| 217 | // the language dependent attributes
|
---|
| 218 | JScrollPane langTablePane = new JScrollPane(language_dependent_attribute_table);
|
---|
[12564] | 219 |
|
---|
[12681] | 220 | // no set loaded pane
|
---|
| 221 | JPanel no_set_loaded_pane = new JPanel();
|
---|
| 222 | no_set_loaded_pane.setBackground(Color.lightGray);
|
---|
| 223 | JLabel no_set_loaded_label = new JLabel(Dictionary.get("GEMS.No_Set_Loaded"));
|
---|
| 224 | no_set_loaded_label.setHorizontalAlignment(JLabel.CENTER);
|
---|
| 225 | no_set_loaded_label.setVerticalAlignment(JLabel.CENTER);
|
---|
[12564] | 226 |
|
---|
[12681] | 227 | no_set_loaded_pane.setLayout(new BorderLayout());
|
---|
| 228 | no_set_loaded_pane.add(no_set_loaded_label, BorderLayout.CENTER);
|
---|
| 229 |
|
---|
[12564] | 230 | JPanel buttonPane = new JPanel(new GridLayout(1,2));
|
---|
| 231 |
|
---|
[12572] | 232 | JButton arrow_up_button = new GLIButton(Dictionary.get("GEMS.Move_Up"));
|
---|
[12564] | 233 | arrow_up_button.setIcon(JarTools.getImage("arrow-up.gif"));
|
---|
| 234 |
|
---|
[12572] | 235 | JButton arrow_down_button = new GLIButton(Dictionary.get("GEMS.Move_Down"));
|
---|
[12564] | 236 | arrow_down_button.setIcon(JarTools.getImage("arrow-down.gif"));
|
---|
| 237 |
|
---|
| 238 | arrow_up_button.setActionCommand(GEMSConstants.MOVE_UP);
|
---|
| 239 | arrow_up_button.addActionListener(meta_set_tree);
|
---|
| 240 | arrow_down_button.addActionListener(meta_set_tree);
|
---|
| 241 | arrow_down_button.setActionCommand(GEMSConstants.MOVE_DOWN);
|
---|
| 242 |
|
---|
| 243 | buttonPane.add(arrow_up_button);
|
---|
| 244 | buttonPane.add(arrow_down_button);
|
---|
| 245 |
|
---|
| 246 | JPanel leftPane = new JPanel(new BorderLayout());
|
---|
| 247 | leftPane.add(treePane,BorderLayout.CENTER);
|
---|
| 248 | leftPane.add(buttonPane,BorderLayout.SOUTH);
|
---|
| 249 |
|
---|
[12665] | 250 | JLabel selected_language_label = new JLabel(Dictionary.get("GEMS.SelectedLanguage"));
|
---|
[12564] | 251 | selected_language_label.setOpaque(true);
|
---|
| 252 |
|
---|
[12665] | 253 | Vector language_vector = new Vector(msm.getLanguageList());
|
---|
| 254 | language_vector.add(0, Dictionary.get("GEMS.Language"));
|
---|
| 255 | JComboBox language_combo = new JComboBox(language_vector);
|
---|
| 256 |
|
---|
[12564] | 257 | language_combo.addActionListener(new ActionListener(){
|
---|
| 258 | public void actionPerformed(ActionEvent e){
|
---|
| 259 | JComboBox language_combo = (JComboBox) e.getSource();
|
---|
| 260 | String langInfo = (String)language_combo.getSelectedItem();
|
---|
[12665] | 261 | if (!langInfo.equals(Dictionary.get("GEMS.Language"))) {
|
---|
| 262 | String lang = langInfo.split("\\s")[0];
|
---|
| 263 | language_dependent_attribute_table.addNewLanguage(lang);
|
---|
| 264 | }
|
---|
[12564] | 265 | }
|
---|
| 266 |
|
---|
| 267 | });
|
---|
| 268 |
|
---|
[12665] | 269 | JLabel language_label = new JLabel(Dictionary.get("GEMS.LanguageDependent"));
|
---|
[12564] | 270 | language_label.setOpaque(true);
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 | JPanel selectLangPane = new JPanel(new BorderLayout(5,5));
|
---|
| 274 | selectLangPane.add(selected_language_label,BorderLayout.WEST);
|
---|
| 275 | selectLangPane.add(language_combo, BorderLayout.CENTER);
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 | JPanel languagePane = new JPanel(new BorderLayout(5,5));
|
---|
[12665] | 279 | languagePane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
[12564] | 280 | languagePane.add(language_label,BorderLayout.NORTH);
|
---|
| 281 | languagePane.add(selectLangPane,BorderLayout.CENTER);
|
---|
| 282 |
|
---|
| 283 |
|
---|
[12665] | 284 | JPanel languageAttributePane = new JPanel(new BorderLayout());
|
---|
[12564] | 285 | languageAttributePane.add(languagePane,BorderLayout.NORTH);
|
---|
| 286 | languageAttributePane.add(langTablePane,BorderLayout.CENTER);
|
---|
| 287 |
|
---|
[12665] | 288 | JLabel attribute_label = new JLabel(Dictionary.get("GEMS.Attribute_Table"));
|
---|
| 289 | attribute_label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 290 | JPanel mainAttributePane = new JPanel(new BorderLayout());
|
---|
| 291 | mainAttributePane.add(attribute_label, BorderLayout.NORTH);
|
---|
| 292 | mainAttributePane.add(tablePane, BorderLayout.CENTER);
|
---|
| 293 |
|
---|
[12681] | 294 | attribute_tables_split_pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,mainAttributePane,languageAttributePane);
|
---|
[12665] | 295 |
|
---|
[12681] | 296 | metadata_set_details_split_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPane,attribute_tables_split_pane);
|
---|
[12572] | 297 |
|
---|
[12681] | 298 | card_pane.setLayout(card_layout);
|
---|
| 299 | card_pane.add(no_set_loaded_pane, NO_SET_LOADED_CARD);
|
---|
| 300 | card_pane.add(metadata_set_details_split_pane, SET_LOADED_CARD);
|
---|
| 301 |
|
---|
| 302 | getContentPane().add(card_pane,BorderLayout.CENTER);
|
---|
[12564] | 303 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
| 304 | if (stand_alone)
|
---|
| 305 | setVisible(true);
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[12665] | 308 | public void setVisible(boolean visible) {
|
---|
| 309 | super.setVisible(visible);
|
---|
[12681] | 310 | attribute_tables_split_pane.setDividerLocation(0.3);
|
---|
[12665] | 311 | }
|
---|
| 312 |
|
---|
[12681] | 313 | // called from GLI
|
---|
[12564] | 314 | public void displayMetadataSet(String metadata_path){
|
---|
| 315 | open_prompt.openMetadataSet(metadata_path);
|
---|
[12727] | 316 | updateCardLayout(true);
|
---|
[12564] | 317 | setVisible(true);
|
---|
| 318 | }
|
---|
| 319 |
|
---|
[12681] | 320 | // called from GLI
|
---|
[12564] | 321 | public void newMetadataSet(){
|
---|
| 322 | new_prompt.display();
|
---|
[12727] | 323 | if (!new_prompt.isCancelled()) {
|
---|
| 324 | updateCardLayout(true);
|
---|
| 325 | setVisible(true);
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[12564] | 328 | }
|
---|
| 329 |
|
---|
| 330 | public void addGEMSListener(GEMSListener listener){
|
---|
| 331 | listeners.add(listener);
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | public void removeGEMSListener(GEMSListener listener){
|
---|
| 335 | listeners.remove(listener);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | public void notifyListeners(){
|
---|
| 339 | for (int i=0;i<listeners.size();i++){
|
---|
| 340 | GEMSListener listener = (GEMSListener) listeners.get(i);
|
---|
| 341 | listener.gemsIsClosed();
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 |
|
---|
| 346 | public void exit(){
|
---|
| 347 | //clean up things
|
---|
[12681] | 348 | cleanUpListeners();
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | protected void cleanUpListeners() {
|
---|
[12564] | 352 | MetadataSetInfo msti= new MetadataSetInfo();
|
---|
| 353 | msti.removeAllMetadataSetListeners();
|
---|
| 354 | MetadataElementModel mem= new MetadataElementModel();
|
---|
| 355 | mem.removeAllMetadataElementListeners();
|
---|
[12681] | 356 |
|
---|
[12564] | 357 | }
|
---|
[12665] | 358 |
|
---|
[12564] | 359 | public void windowGainedFocus(WindowEvent e) {
|
---|
| 360 | //System.out.println("windowGainedFocus.");
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | public void windowLostFocus(WindowEvent e) {
|
---|
| 364 | //System.out.println("windowLostFocus.");
|
---|
| 365 |
|
---|
| 366 | //save stuff
|
---|
| 367 |
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[12681] | 370 | protected void updateCardLayout(boolean set_loaded) {
|
---|
| 371 | if (set_loaded) {
|
---|
| 372 | card_layout.show(card_pane, SET_LOADED_CARD);
|
---|
| 373 | } else {
|
---|
| 374 | card_layout.show(card_pane, NO_SET_LOADED_CARD);
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
[12564] | 377 |
|
---|
| 378 | private class GEMSMenuBar
|
---|
| 379 | extends JMenuBar
|
---|
| 380 | implements ActionListener
|
---|
| 381 | {
|
---|
| 382 | private JMenu file = null;
|
---|
| 383 | private JMenu edit = null;
|
---|
| 384 |
|
---|
| 385 | public JMenuItem file_exit = null;
|
---|
| 386 | public JMenuItem file_new = null;
|
---|
| 387 | public JMenuItem file_open = null;
|
---|
[12665] | 388 | public JMenuItem file_close = null;
|
---|
[12564] | 389 | public JMenuItem file_save = null;
|
---|
| 390 | public JMenuItem edit_copy = null;
|
---|
| 391 | public JMenuItem edit_cut = null;
|
---|
| 392 | public JMenuItem edit_paste = null;
|
---|
| 393 | public JMenuItem help_help = null;
|
---|
| 394 | public JMenuItem file_delete = null;
|
---|
| 395 | //public JMenuItem file_preferences = null;
|
---|
| 396 | public GEMSMenuBar()
|
---|
| 397 | {
|
---|
| 398 | file = new JMenu();
|
---|
| 399 | file.setText(Dictionary.get("Menu.File"));
|
---|
| 400 |
|
---|
[12665] | 401 | file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
|
---|
[12564] | 402 | file_exit.addActionListener(this);
|
---|
| 403 |
|
---|
| 404 | file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
|
---|
| 405 | file_new.addActionListener(this);
|
---|
| 406 |
|
---|
| 407 | file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
|
---|
| 408 | file_open.addActionListener(this);
|
---|
| 409 |
|
---|
[12665] | 410 | file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
|
---|
| 411 | file_close.addActionListener(this);
|
---|
| 412 |
|
---|
[12564] | 413 | file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
|
---|
| 414 | file_save.addActionListener(this);
|
---|
| 415 |
|
---|
| 416 | file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
|
---|
| 417 | file_delete.addActionListener(this);
|
---|
| 418 |
|
---|
| 419 | //file_preferences = new JMenuItem(Dictionary.get("Menu.File_Options"));
|
---|
| 420 | //file_preferences.addActionListener(this);
|
---|
| 421 |
|
---|
| 422 | // Layout (file menu)
|
---|
| 423 | file.add(file_new);
|
---|
| 424 | file.add(file_open);
|
---|
[12665] | 425 | file.add(file_close);
|
---|
[12564] | 426 | file.add(file_save);
|
---|
| 427 | file.add(file_delete);
|
---|
| 428 | file.add(new JSeparator());
|
---|
| 429 | //file.add(file_preferences);
|
---|
[12665] | 430 | //file.add(new JSeparator());
|
---|
[12564] | 431 | file.add(file_exit);
|
---|
| 432 |
|
---|
| 433 | // Edit menu
|
---|
| 434 | edit = new JMenu();
|
---|
| 435 | edit.setText(Dictionary.get("Menu.Edit"));
|
---|
| 436 |
|
---|
| 437 | edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut"));
|
---|
| 438 | edit_cut.addActionListener(this);
|
---|
| 439 |
|
---|
| 440 | edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy"));
|
---|
| 441 | edit_copy.addActionListener(this);
|
---|
| 442 |
|
---|
| 443 | edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste"));
|
---|
| 444 | edit_paste.addActionListener(this);
|
---|
| 445 |
|
---|
| 446 | // Layout (edit menu)
|
---|
| 447 | edit.add(edit_cut);
|
---|
| 448 | edit.add(edit_copy);
|
---|
| 449 | edit.add(edit_paste);
|
---|
| 450 |
|
---|
| 451 |
|
---|
| 452 | // Layout (menu bar)
|
---|
| 453 | this.add(file);
|
---|
| 454 | this.add(Box.createHorizontalStrut(15));
|
---|
| 455 | this.add(edit);
|
---|
| 456 | this.add(Box.createHorizontalGlue());
|
---|
| 457 | //this.add(help);
|
---|
| 458 | }
|
---|
| 459 |
|
---|
| 460 |
|
---|
| 461 | public void actionPerformed(ActionEvent event)
|
---|
| 462 | {
|
---|
| 463 | Object event_source = event.getSource();
|
---|
| 464 |
|
---|
| 465 | // File -> New
|
---|
| 466 | if (event_source == file_new) {
|
---|
[12681] | 467 | new_prompt.display();
|
---|
| 468 | if (!new_prompt.isCancelled()) {
|
---|
| 469 | updateCardLayout(true);
|
---|
| 470 | }
|
---|
[12564] | 471 | return;
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | // File -> Open
|
---|
| 475 | if (event_source == file_open) {
|
---|
| 476 | open_prompt.display();
|
---|
[12681] | 477 | if (!open_prompt.isCancelled()) {
|
---|
| 478 | updateCardLayout(true);
|
---|
| 479 | }
|
---|
[12564] | 480 | return;
|
---|
| 481 | }
|
---|
| 482 |
|
---|
[12665] | 483 | // File -> Close
|
---|
| 484 | if (event_source == file_close) {
|
---|
[12681] | 485 | metadata_set_model.save(true);
|
---|
| 486 | updateCardLayout(false);
|
---|
| 487 | return;
|
---|
[12665] | 488 | }
|
---|
[12564] | 489 | // File -> Delete
|
---|
| 490 | if (event_source == file_delete) {
|
---|
| 491 | delete_prompt.display();
|
---|
| 492 | return;
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 |
|
---|
| 496 | // File -> Save
|
---|
| 497 | if (event_source == file_save) {
|
---|
| 498 | metadata_set_model.save(false);
|
---|
| 499 | return;
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | // File -> Exit
|
---|
| 503 | if (event_source == file_exit) {
|
---|
| 504 | metadata_set_model.save(true);
|
---|
| 505 | if (stand_alone){
|
---|
| 506 | System.exit(0);
|
---|
| 507 | }
|
---|
| 508 | else{
|
---|
| 509 | notifyListeners();
|
---|
| 510 | setVisible(false);
|
---|
| 511 | }
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | /// File -> Preferences
|
---|
| 515 | // if(event_source == file_preferences){
|
---|
| 516 | // GEMSPreferences GemsPreferences = new GEMSPreferences();
|
---|
| 517 | //}
|
---|
| 518 |
|
---|
| 519 | // Edit -> Cut
|
---|
| 520 | if (event_source == edit_cut) {
|
---|
| 521 | try {
|
---|
| 522 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
| 523 | // Get the component with selected text as a JTextComponent
|
---|
| 524 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
|
---|
| 525 | // Cut the text to the clipboard
|
---|
| 526 | text.cut();
|
---|
| 527 | }
|
---|
| 528 | catch (ClassCastException cce) {
|
---|
| 529 | // If the component is not a text component ignore the cut command
|
---|
| 530 | DebugStream.println(cce.toString());
|
---|
| 531 | }
|
---|
| 532 | return;
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | // Edit -> Copy
|
---|
| 536 | if (event_source == edit_copy) {
|
---|
| 537 | try {
|
---|
| 538 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
| 539 | // Get the component with selected text as a JTextComponent
|
---|
| 540 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
|
---|
| 541 | text.copy();
|
---|
| 542 | }
|
---|
| 543 | catch (Exception cce) {
|
---|
| 544 | // If the component is not a text component ignore the copy command
|
---|
| 545 | DebugStream.println(cce.toString());
|
---|
| 546 | }
|
---|
| 547 | return;
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | // Edit -> Paste
|
---|
| 551 | if (event_source == edit_paste) {
|
---|
| 552 | try {
|
---|
| 553 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
| 554 | // Get the component with selected text as a JTextComponent
|
---|
| 555 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
|
---|
| 556 | // Cut the text to the clipboard
|
---|
| 557 | text.paste();
|
---|
| 558 | }
|
---|
| 559 | catch (ClassCastException cce) {
|
---|
| 560 | // If the component is not a text component ignore the paste command
|
---|
| 561 | DebugStream.println(cce.toString());
|
---|
| 562 | }
|
---|
| 563 | return;
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | }
|
---|