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 |
|
---|
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 |
|
---|
88 | private GEMS self = null;
|
---|
89 |
|
---|
90 | private OpenMetadataSetPrompt open_prompt;
|
---|
91 | private DeleteMetadataSetPrompt delete_prompt;
|
---|
92 | private NewMetadataSetPrompt new_prompt;
|
---|
93 |
|
---|
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;
|
---|
98 |
|
---|
99 | /** Um, the size of the screen I'd guess. */
|
---|
100 | private Dimension screen_size = null;
|
---|
101 |
|
---|
102 | private MetadataSetManager msm;
|
---|
103 |
|
---|
104 | private AttributeTable attribute_table; // meta_element_table
|
---|
105 | private AttributeTable language_dependent_attribute_table; //lang_element_table;
|
---|
106 |
|
---|
107 | private MetadataSetTree meta_set_tree;
|
---|
108 |
|
---|
109 | private MetadataSetModel metadata_set_model;
|
---|
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 |
|
---|
134 | new GEMS(go.gsdl_path,go.gsdl3_path,go.metadata_path,true,go.new_set);
|
---|
135 |
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /** Constructor.
|
---|
140 | */
|
---|
141 | public GEMS(String gsdl_path, String gsdl3_path, String metadata_path, boolean standalone, boolean new_set)
|
---|
142 | {
|
---|
143 | self = this;
|
---|
144 | JarTools.initialise(this);
|
---|
145 | screen_size = Configuration.screen_size;
|
---|
146 | msm = new MetadataSetManager(gsdl_path,gsdl3_path);
|
---|
147 | stand_alone = standalone;
|
---|
148 | listeners = new ArrayList();
|
---|
149 |
|
---|
150 | addWindowListener(new WindowAdapter(){
|
---|
151 | public void windowClosing(WindowEvent e){
|
---|
152 | metadata_set_model.save(true);
|
---|
153 | if (stand_alone){
|
---|
154 | System.exit(0);
|
---|
155 | }
|
---|
156 | else {
|
---|
157 | notifyListeners();
|
---|
158 | setVisible(false);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | });
|
---|
162 |
|
---|
163 | setSize(SIZE);
|
---|
164 | setTitle(Dictionary.get("GEMS.Title"));
|
---|
165 | setJMenuBar(new GEMSMenuBar());
|
---|
166 |
|
---|
167 | addWindowFocusListener(this);
|
---|
168 |
|
---|
169 | card_layout = new CardLayout();
|
---|
170 | card_pane = new JPanel();
|
---|
171 |
|
---|
172 | metadata_set_model = new MetadataSetModel(msm);
|
---|
173 | msm.setMetadataSetModel(metadata_set_model);
|
---|
174 | meta_set_tree = new MetadataSetTree(self);
|
---|
175 | metadata_set_model.addObserver(meta_set_tree);
|
---|
176 |
|
---|
177 | attribute_table = new AttributeTable(false);
|
---|
178 | MetadataElementModel mem = new MetadataElementModel();
|
---|
179 | mem.addMetadataElementListener((MetadataElementListener)attribute_table);
|
---|
180 | attribute_table.addAttributeListener(metadata_set_model);
|
---|
181 |
|
---|
182 | language_dependent_attribute_table = new AttributeTable(true);
|
---|
183 | mem.addMetadataElementListener((MetadataElementListener)language_dependent_attribute_table);
|
---|
184 | language_dependent_attribute_table.addAttributeListener(metadata_set_model);
|
---|
185 |
|
---|
186 | MetadataSetInfo msti= new MetadataSetInfo();
|
---|
187 | msti.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
188 | msti.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
189 | msti.setMetadataSetModel(metadata_set_model);
|
---|
190 |
|
---|
191 | open_prompt = new OpenMetadataSetPrompt(self,msm);
|
---|
192 | open_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
193 | open_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
194 | open_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
195 |
|
---|
196 | delete_prompt = new DeleteMetadataSetPrompt(self,msm);
|
---|
197 | delete_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
198 | delete_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
199 | delete_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
200 |
|
---|
201 | new_prompt = new NewMetadataSetPrompt(self,msm);
|
---|
202 | new_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
203 | new_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
204 | new_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
205 |
|
---|
206 |
|
---|
207 | // load the initial metadataset
|
---|
208 | if (metadata_path !=null && !metadata_path.equals("")){
|
---|
209 | open_prompt.openMetadataSet(metadata_path);
|
---|
210 | }
|
---|
211 | else{
|
---|
212 | if (new_set) new_prompt.display();
|
---|
213 | }
|
---|
214 |
|
---|
215 | // the set tree
|
---|
216 | JScrollPane treePane = new JScrollPane(meta_set_tree);
|
---|
217 | // the language independent attributes
|
---|
218 | JScrollPane tablePane = new JScrollPane(attribute_table);
|
---|
219 | // the language dependent attributes
|
---|
220 | JScrollPane langTablePane = new JScrollPane(language_dependent_attribute_table);
|
---|
221 |
|
---|
222 | // no set loaded pane
|
---|
223 | JPanel no_set_loaded_pane = new JPanel();
|
---|
224 | no_set_loaded_pane.setBackground(Color.lightGray);
|
---|
225 | JLabel no_set_loaded_label = new JLabel(Dictionary.get("GEMS.No_Set_Loaded"));
|
---|
226 | no_set_loaded_label.setHorizontalAlignment(JLabel.CENTER);
|
---|
227 | no_set_loaded_label.setVerticalAlignment(JLabel.CENTER);
|
---|
228 |
|
---|
229 | no_set_loaded_pane.setLayout(new BorderLayout());
|
---|
230 | no_set_loaded_pane.add(no_set_loaded_label, BorderLayout.CENTER);
|
---|
231 |
|
---|
232 | JPanel buttonPane = new JPanel(new GridLayout(1,2));
|
---|
233 |
|
---|
234 | JButton arrow_up_button = new GLIButton(Dictionary.get("GEMS.Move_Up"));
|
---|
235 | arrow_up_button.setIcon(JarTools.getImage("arrow-up.gif"));
|
---|
236 |
|
---|
237 | JButton arrow_down_button = new GLIButton(Dictionary.get("GEMS.Move_Down"));
|
---|
238 | arrow_down_button.setIcon(JarTools.getImage("arrow-down.gif"));
|
---|
239 |
|
---|
240 | arrow_up_button.setActionCommand(GEMSConstants.MOVE_UP);
|
---|
241 | arrow_up_button.addActionListener(meta_set_tree);
|
---|
242 | arrow_down_button.addActionListener(meta_set_tree);
|
---|
243 | arrow_down_button.setActionCommand(GEMSConstants.MOVE_DOWN);
|
---|
244 |
|
---|
245 | buttonPane.add(arrow_up_button);
|
---|
246 | buttonPane.add(arrow_down_button);
|
---|
247 |
|
---|
248 | JPanel leftPane = new JPanel(new BorderLayout());
|
---|
249 | leftPane.add(treePane,BorderLayout.CENTER);
|
---|
250 | leftPane.add(buttonPane,BorderLayout.SOUTH);
|
---|
251 |
|
---|
252 | JLabel selected_language_label = new JLabel(Dictionary.get("GEMS.SelectedLanguage"));
|
---|
253 | selected_language_label.setOpaque(true);
|
---|
254 |
|
---|
255 | Vector language_vector = new Vector(msm.getLanguageList());
|
---|
256 | language_vector.add(0, Dictionary.get("GEMS.Language"));
|
---|
257 | JComboBox language_combo = new JComboBox(language_vector);
|
---|
258 |
|
---|
259 | language_combo.addActionListener(new ActionListener(){
|
---|
260 | public void actionPerformed(ActionEvent e){
|
---|
261 | JComboBox language_combo = (JComboBox) e.getSource();
|
---|
262 | String langInfo = (String)language_combo.getSelectedItem();
|
---|
263 | if (!langInfo.equals(Dictionary.get("GEMS.Language"))) {
|
---|
264 | String lang = langInfo.split("\\s")[0];
|
---|
265 | language_dependent_attribute_table.addNewLanguage(lang);
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | });
|
---|
270 |
|
---|
271 | JLabel language_label = new JLabel(Dictionary.get("GEMS.LanguageDependent"));
|
---|
272 | language_label.setOpaque(true);
|
---|
273 |
|
---|
274 |
|
---|
275 | JPanel selectLangPane = new JPanel(new BorderLayout(5,5));
|
---|
276 | selectLangPane.add(selected_language_label,BorderLayout.WEST);
|
---|
277 | selectLangPane.add(language_combo, BorderLayout.CENTER);
|
---|
278 |
|
---|
279 |
|
---|
280 | JPanel languagePane = new JPanel(new BorderLayout(5,5));
|
---|
281 | languagePane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
282 | languagePane.add(language_label,BorderLayout.NORTH);
|
---|
283 | languagePane.add(selectLangPane,BorderLayout.CENTER);
|
---|
284 |
|
---|
285 |
|
---|
286 | JPanel languageAttributePane = new JPanel(new BorderLayout());
|
---|
287 | languageAttributePane.add(languagePane,BorderLayout.NORTH);
|
---|
288 | languageAttributePane.add(langTablePane,BorderLayout.CENTER);
|
---|
289 |
|
---|
290 | JLabel attribute_label = new JLabel(Dictionary.get("GEMS.Attribute_Table"));
|
---|
291 | attribute_label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
292 | JPanel mainAttributePane = new JPanel(new BorderLayout());
|
---|
293 | mainAttributePane.add(attribute_label, BorderLayout.NORTH);
|
---|
294 | mainAttributePane.add(tablePane, BorderLayout.CENTER);
|
---|
295 |
|
---|
296 | attribute_tables_split_pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,mainAttributePane,languageAttributePane);
|
---|
297 |
|
---|
298 | metadata_set_details_split_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPane,attribute_tables_split_pane);
|
---|
299 |
|
---|
300 | card_pane.setLayout(card_layout);
|
---|
301 | card_pane.add(no_set_loaded_pane, NO_SET_LOADED_CARD);
|
---|
302 | card_pane.add(metadata_set_details_split_pane, SET_LOADED_CARD);
|
---|
303 |
|
---|
304 | getContentPane().add(card_pane,BorderLayout.CENTER);
|
---|
305 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
306 | if (stand_alone)
|
---|
307 | setVisible(true);
|
---|
308 | }
|
---|
309 |
|
---|
310 | public void setVisible(boolean visible) {
|
---|
311 | super.setVisible(visible);
|
---|
312 | if (visible) {
|
---|
313 | attribute_tables_split_pane.setDividerLocation(0.3);
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | // called from GLI
|
---|
318 | public void displayMetadataSet(String metadata_path){
|
---|
319 | open_prompt.openMetadataSet(metadata_path);
|
---|
320 | updateCardLayout(true);
|
---|
321 | setVisible(true);
|
---|
322 | }
|
---|
323 |
|
---|
324 | // called from GLI
|
---|
325 | public void newMetadataSet(){
|
---|
326 | new_prompt.display();
|
---|
327 | if (!new_prompt.isCancelled()) {
|
---|
328 | updateCardLayout(true);
|
---|
329 | setVisible(true);
|
---|
330 | }
|
---|
331 |
|
---|
332 | }
|
---|
333 |
|
---|
334 | public void addGEMSListener(GEMSListener listener){
|
---|
335 | listeners.add(listener);
|
---|
336 | }
|
---|
337 |
|
---|
338 | public void removeGEMSListener(GEMSListener listener){
|
---|
339 | listeners.remove(listener);
|
---|
340 | }
|
---|
341 |
|
---|
342 | public void notifyListeners(){
|
---|
343 | for (int i=0;i<listeners.size();i++){
|
---|
344 | GEMSListener listener = (GEMSListener) listeners.get(i);
|
---|
345 | listener.gemsIsClosed();
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | public void exit(){
|
---|
351 | //clean up things
|
---|
352 | cleanUpListeners();
|
---|
353 | }
|
---|
354 |
|
---|
355 | protected void cleanUpListeners() {
|
---|
356 | MetadataSetInfo msti= new MetadataSetInfo();
|
---|
357 | msti.removeAllMetadataSetListeners();
|
---|
358 | MetadataElementModel mem= new MetadataElementModel();
|
---|
359 | mem.removeAllMetadataElementListeners();
|
---|
360 |
|
---|
361 | }
|
---|
362 |
|
---|
363 | public void windowGainedFocus(WindowEvent e) {
|
---|
364 | //System.out.println("windowGainedFocus.");
|
---|
365 | }
|
---|
366 |
|
---|
367 | public void windowLostFocus(WindowEvent e) {
|
---|
368 | //System.out.println("windowLostFocus.");
|
---|
369 |
|
---|
370 | //save stuff
|
---|
371 |
|
---|
372 | }
|
---|
373 |
|
---|
374 | protected void updateCardLayout(boolean set_loaded) {
|
---|
375 | if (set_loaded) {
|
---|
376 | card_layout.show(card_pane, SET_LOADED_CARD);
|
---|
377 | } else {
|
---|
378 | card_layout.show(card_pane, NO_SET_LOADED_CARD);
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | private class GEMSMenuBar
|
---|
383 | extends JMenuBar
|
---|
384 | implements ActionListener
|
---|
385 | {
|
---|
386 | private JMenu file = null;
|
---|
387 | private JMenu edit = null;
|
---|
388 |
|
---|
389 | public JMenuItem file_exit = null;
|
---|
390 | public JMenuItem file_new = null;
|
---|
391 | public JMenuItem file_open = null;
|
---|
392 | public JMenuItem file_close = null;
|
---|
393 | public JMenuItem file_save = null;
|
---|
394 | public JMenuItem edit_copy = null;
|
---|
395 | public JMenuItem edit_cut = null;
|
---|
396 | public JMenuItem edit_paste = null;
|
---|
397 | public JMenuItem help_help = null;
|
---|
398 | public JMenuItem file_delete = null;
|
---|
399 | //public JMenuItem file_preferences = null;
|
---|
400 | public GEMSMenuBar()
|
---|
401 | {
|
---|
402 | file = new JMenu();
|
---|
403 | file.setText(Dictionary.get("Menu.File"));
|
---|
404 |
|
---|
405 | file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
|
---|
406 | file_exit.addActionListener(this);
|
---|
407 |
|
---|
408 | file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
|
---|
409 | file_new.addActionListener(this);
|
---|
410 |
|
---|
411 | file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
|
---|
412 | file_open.addActionListener(this);
|
---|
413 |
|
---|
414 | file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
|
---|
415 | file_close.addActionListener(this);
|
---|
416 |
|
---|
417 | file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
|
---|
418 | file_save.addActionListener(this);
|
---|
419 |
|
---|
420 | file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
|
---|
421 | file_delete.addActionListener(this);
|
---|
422 |
|
---|
423 | //file_preferences = new JMenuItem(Dictionary.get("Menu.File_Options"));
|
---|
424 | //file_preferences.addActionListener(this);
|
---|
425 |
|
---|
426 | if (!stand_alone) {
|
---|
427 | // when running from GLI, we disable most of the menu so
|
---|
428 | // that we have control over what sets the user is editing
|
---|
429 | file_new.setEnabled(false);
|
---|
430 | file_open.setEnabled(false);
|
---|
431 | file_close.setEnabled(false);
|
---|
432 | file_delete.setEnabled(false);
|
---|
433 | }
|
---|
434 |
|
---|
435 | // Layout (file menu)
|
---|
436 | file.add(file_new);
|
---|
437 | file.add(file_open);
|
---|
438 | file.add(file_close);
|
---|
439 | file.add(file_save);
|
---|
440 | file.add(file_delete);
|
---|
441 | file.add(new JSeparator());
|
---|
442 | //file.add(file_preferences);
|
---|
443 | //file.add(new JSeparator());
|
---|
444 | file.add(file_exit);
|
---|
445 |
|
---|
446 | // Edit menu
|
---|
447 | edit = new JMenu();
|
---|
448 | edit.setText(Dictionary.get("Menu.Edit"));
|
---|
449 |
|
---|
450 | edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut"));
|
---|
451 | edit_cut.addActionListener(this);
|
---|
452 |
|
---|
453 | edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy"));
|
---|
454 | edit_copy.addActionListener(this);
|
---|
455 |
|
---|
456 | edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste"));
|
---|
457 | edit_paste.addActionListener(this);
|
---|
458 |
|
---|
459 | // Layout (edit menu)
|
---|
460 | edit.add(edit_cut);
|
---|
461 | edit.add(edit_copy);
|
---|
462 | edit.add(edit_paste);
|
---|
463 |
|
---|
464 |
|
---|
465 | // Layout (menu bar)
|
---|
466 | this.add(file);
|
---|
467 | this.add(Box.createHorizontalStrut(15));
|
---|
468 | this.add(edit);
|
---|
469 | this.add(Box.createHorizontalGlue());
|
---|
470 | //this.add(help);
|
---|
471 | }
|
---|
472 |
|
---|
473 |
|
---|
474 | public void actionPerformed(ActionEvent event)
|
---|
475 | {
|
---|
476 | Object event_source = event.getSource();
|
---|
477 |
|
---|
478 | // File -> New
|
---|
479 | if (event_source == file_new) {
|
---|
480 | new_prompt.display();
|
---|
481 | if (!new_prompt.isCancelled()) {
|
---|
482 | updateCardLayout(true);
|
---|
483 | }
|
---|
484 | return;
|
---|
485 | }
|
---|
486 |
|
---|
487 | // File -> Open
|
---|
488 | if (event_source == file_open) {
|
---|
489 | open_prompt.display();
|
---|
490 | if (!open_prompt.isCancelled()) {
|
---|
491 | updateCardLayout(true);
|
---|
492 | }
|
---|
493 | return;
|
---|
494 | }
|
---|
495 |
|
---|
496 | // File -> Close
|
---|
497 | if (event_source == file_close) {
|
---|
498 | metadata_set_model.save(true);
|
---|
499 | updateCardLayout(false);
|
---|
500 | return;
|
---|
501 | }
|
---|
502 | // File -> Delete
|
---|
503 | if (event_source == file_delete) {
|
---|
504 | delete_prompt.display();
|
---|
505 | return;
|
---|
506 | }
|
---|
507 |
|
---|
508 |
|
---|
509 | // File -> Save
|
---|
510 | if (event_source == file_save) {
|
---|
511 | metadata_set_model.save(false);
|
---|
512 | return;
|
---|
513 | }
|
---|
514 |
|
---|
515 | // File -> Exit
|
---|
516 | if (event_source == file_exit) {
|
---|
517 | metadata_set_model.save(true);
|
---|
518 | if (stand_alone){
|
---|
519 | System.exit(0);
|
---|
520 | }
|
---|
521 | else {
|
---|
522 | self.notifyListeners();
|
---|
523 | self.setVisible(false);
|
---|
524 | return;
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | /// File -> Preferences
|
---|
529 | // if(event_source == file_preferences){
|
---|
530 | // GEMSPreferences GemsPreferences = new GEMSPreferences();
|
---|
531 | //}
|
---|
532 |
|
---|
533 | // Edit -> Cut
|
---|
534 | if (event_source == edit_cut) {
|
---|
535 | try {
|
---|
536 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
537 | // Get the component with selected text as a JTextComponent
|
---|
538 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
|
---|
539 | // Cut the text to the clipboard
|
---|
540 | text.cut();
|
---|
541 | }
|
---|
542 | catch (ClassCastException cce) {
|
---|
543 | // If the component is not a text component ignore the cut command
|
---|
544 | DebugStream.println(cce.toString());
|
---|
545 | }
|
---|
546 | return;
|
---|
547 | }
|
---|
548 |
|
---|
549 | // Edit -> Copy
|
---|
550 | if (event_source == edit_copy) {
|
---|
551 | try {
|
---|
552 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
553 | // Get the component with selected text as a JTextComponent
|
---|
554 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
|
---|
555 | text.copy();
|
---|
556 | }
|
---|
557 | catch (Exception cce) {
|
---|
558 | // If the component is not a text component ignore the copy command
|
---|
559 | DebugStream.println(cce.toString());
|
---|
560 | }
|
---|
561 | return;
|
---|
562 | }
|
---|
563 |
|
---|
564 | // Edit -> Paste
|
---|
565 | if (event_source == edit_paste) {
|
---|
566 | try {
|
---|
567 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
568 | // Get the component with selected text as a JTextComponent
|
---|
569 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
|
---|
570 | // Cut the text to the clipboard
|
---|
571 | text.paste();
|
---|
572 | }
|
---|
573 | catch (ClassCastException cce) {
|
---|
574 | // If the component is not a text component ignore the paste command
|
---|
575 | DebugStream.println(cce.toString());
|
---|
576 | }
|
---|
577 | return;
|
---|
578 | }
|
---|
579 |
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | }
|
---|