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 | /** Constructor - original. Called when GEMS is launched as a standalone application.
|
---|
139 | * Sets up a very basic static-looking Configuration object, and Dictionary.
|
---|
140 | * Do not call if GEMS is launched through GLI, as this constructor will erase and replace
|
---|
141 | * GLI's carefully configured Configuration and Dictionary causing hard to track down errors.
|
---|
142 | * So don't call this constructor if standalone = false.
|
---|
143 | */
|
---|
144 | public GEMS(String gsdl_path, String gsdl3_path, String metadata_path, boolean standalone, boolean new_set)
|
---|
145 | {
|
---|
146 | self = this;
|
---|
147 | JarTools.initialise(this);
|
---|
148 | // Load GLI config file: set up the Configuration so we can set up the Dictionary language
|
---|
149 | // Determine the GLI user directory path
|
---|
150 | String gli_user_directory_path = System.getProperty("user.home") + File.separator;
|
---|
151 | if (Utility.isWindows()) {
|
---|
152 | gli_user_directory_path += "Application Data" + File.separator + "Greenstone" + File.separator + "GLI" + File.separator;
|
---|
153 | }
|
---|
154 | else {
|
---|
155 | gli_user_directory_path += ".gli" + File.separator;
|
---|
156 | }
|
---|
157 |
|
---|
158 | // Since GEMS launched standalone, need to set up Configuration and Dictionary
|
---|
159 | new Configuration(gli_user_directory_path, gsdl_path, gsdl3_path,
|
---|
160 | null /*gsdl3_src_path*/, null /*site_name*/, null /*fedora_info*/); // null for parameters unknown to GEMS
|
---|
161 |
|
---|
162 | // Read Dictionary in the locale specified in the config.xml
|
---|
163 | new Dictionary(Configuration.getLocale("general.locale", true), Configuration.getFont("general.font", true));
|
---|
164 | init(metadata_path, standalone, new_set);
|
---|
165 | }
|
---|
166 |
|
---|
167 | /** Constructor - overloaded to use existing Configuration and Dictionary
|
---|
168 | * This Constructor is used when GEMS is launched through GLI.
|
---|
169 | * It's crucial for GLI to launch GEMS with this constructor as the other one will erase and
|
---|
170 | * replace GLI's carefully set-up Configuration and Dictionary, resulting in subtle but major
|
---|
171 | * flow-on errors particularly because of the alternate's cutdown version of Configuration.
|
---|
172 | */
|
---|
173 | public GEMS(String metadata_path, boolean new_set)
|
---|
174 | {
|
---|
175 | self = this;
|
---|
176 | JarTools.initialise(this);
|
---|
177 |
|
---|
178 | // When GEMS is launched through GLI (so not standalone)
|
---|
179 | // a Configuration and Dictionary is already set up
|
---|
180 |
|
---|
181 | init(metadata_path, false /*standalone*/, new_set);
|
---|
182 | }
|
---|
183 |
|
---|
184 | private void init(String metadata_path, boolean standalone, boolean new_set) {
|
---|
185 | screen_size = Configuration.screen_size;
|
---|
186 |
|
---|
187 | //msm = new MetadataSetManager(Configuration.gsdl_path,Configuration.gsdl3_path);
|
---|
188 | // dangerously side-effecting version of MetadataSetManager constructor that
|
---|
189 | // erases Configuration all over again (as the original GEMS constructor also did)
|
---|
190 | // and is noticeable when remote GS3 server cryptically fails because
|
---|
191 | // Configuration.site_name is suddenly null due to these constructors.
|
---|
192 | // Creating/adding a new metadata set also prevents GLI > Preferences from opening
|
---|
193 | // because Configuration.site_name is nulled as a consequence of launching GEMS through GLI
|
---|
194 |
|
---|
195 | // Instead, call the MetadataSetManager() constructor as it reuses existing Configuration,
|
---|
196 | // whether this is a basic Configuration created by standalone GEMS
|
---|
197 | // or a carefully and highly configured Configuration object created by GLI launching GEMS.
|
---|
198 | msm = new MetadataSetManager();
|
---|
199 |
|
---|
200 | stand_alone = standalone;
|
---|
201 | listeners = new ArrayList();
|
---|
202 |
|
---|
203 | addWindowListener(new WindowAdapter(){
|
---|
204 | public void windowClosing(WindowEvent e){
|
---|
205 | metadata_set_model.save(true);
|
---|
206 | if (stand_alone){
|
---|
207 | System.exit(0);
|
---|
208 | }
|
---|
209 | else {
|
---|
210 | notifyListeners();
|
---|
211 | setVisible(false);
|
---|
212 | }
|
---|
213 | }
|
---|
214 | });
|
---|
215 |
|
---|
216 | setSize(SIZE);
|
---|
217 | setTitle(Dictionary.get("GEMS.Title"));
|
---|
218 | setJMenuBar(new GEMSMenuBar());
|
---|
219 |
|
---|
220 | addWindowFocusListener(this);
|
---|
221 |
|
---|
222 | card_layout = new CardLayout();
|
---|
223 | card_pane = new JPanel();
|
---|
224 |
|
---|
225 | metadata_set_model = new MetadataSetModel(msm);
|
---|
226 | msm.setMetadataSetModel(metadata_set_model);
|
---|
227 | meta_set_tree = new MetadataSetTree(self);
|
---|
228 | metadata_set_model.addObserver(meta_set_tree);
|
---|
229 |
|
---|
230 | attribute_table = new AttributeTable(false);
|
---|
231 | MetadataElementModel mem = new MetadataElementModel();
|
---|
232 | mem.addMetadataElementListener((MetadataElementListener)attribute_table);
|
---|
233 | attribute_table.addAttributeListener(metadata_set_model);
|
---|
234 |
|
---|
235 | language_dependent_attribute_table = new AttributeTable(true);
|
---|
236 | mem.addMetadataElementListener((MetadataElementListener)language_dependent_attribute_table);
|
---|
237 | language_dependent_attribute_table.addAttributeListener(metadata_set_model);
|
---|
238 |
|
---|
239 | MetadataSetInfo msti= new MetadataSetInfo();
|
---|
240 | msti.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
241 | msti.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
242 | msti.setMetadataSetModel(metadata_set_model);
|
---|
243 |
|
---|
244 | open_prompt = new OpenMetadataSetPrompt(self,msm);
|
---|
245 | open_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
246 | open_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
247 | open_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
248 |
|
---|
249 | delete_prompt = new DeleteMetadataSetPrompt(self,msm);
|
---|
250 | delete_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
251 | delete_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
252 | delete_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
253 |
|
---|
254 | new_prompt = new NewMetadataSetPrompt(self,msm);
|
---|
255 | new_prompt.addMetadataSetListener((MetadataSetListener)metadata_set_model);
|
---|
256 | new_prompt.addMetadataSetListener((MetadataSetListener)attribute_table);
|
---|
257 | new_prompt.addMetadataSetListener((MetadataSetListener)language_dependent_attribute_table);
|
---|
258 |
|
---|
259 |
|
---|
260 | // load the initial metadataset
|
---|
261 | if (metadata_path !=null && !metadata_path.equals("")){
|
---|
262 | open_prompt.openMetadataSet(metadata_path);
|
---|
263 | }
|
---|
264 | else{
|
---|
265 | if (new_set) new_prompt.display();
|
---|
266 | }
|
---|
267 |
|
---|
268 | // the set tree
|
---|
269 | JScrollPane treePane = new JScrollPane(meta_set_tree);
|
---|
270 | // the language independent attributes
|
---|
271 | JScrollPane tablePane = new JScrollPane(attribute_table);
|
---|
272 | // the language dependent attributes
|
---|
273 | JScrollPane langTablePane = new JScrollPane(language_dependent_attribute_table);
|
---|
274 |
|
---|
275 | // no set loaded pane
|
---|
276 | JPanel no_set_loaded_pane = new JPanel();
|
---|
277 | no_set_loaded_pane.setBackground(Color.lightGray);
|
---|
278 | JLabel no_set_loaded_label = new JLabel(Dictionary.get("GEMS.No_Set_Loaded"));
|
---|
279 | no_set_loaded_label.setHorizontalAlignment(JLabel.CENTER);
|
---|
280 | no_set_loaded_label.setVerticalAlignment(JLabel.CENTER);
|
---|
281 |
|
---|
282 | no_set_loaded_pane.setLayout(new BorderLayout());
|
---|
283 | no_set_loaded_pane.add(no_set_loaded_label, BorderLayout.CENTER);
|
---|
284 |
|
---|
285 | JPanel buttonPane = new JPanel(new GridLayout(1,2));
|
---|
286 |
|
---|
287 | JButton arrow_up_button = new GLIButton(Dictionary.get("GEMS.Move_Up"));
|
---|
288 | arrow_up_button.setIcon(JarTools.getImage("arrow-up.gif"));
|
---|
289 |
|
---|
290 | JButton arrow_down_button = new GLIButton(Dictionary.get("GEMS.Move_Down"));
|
---|
291 | arrow_down_button.setIcon(JarTools.getImage("arrow-down.gif"));
|
---|
292 |
|
---|
293 | arrow_up_button.setActionCommand(GEMSConstants.MOVE_UP);
|
---|
294 | arrow_up_button.addActionListener(meta_set_tree);
|
---|
295 | arrow_down_button.addActionListener(meta_set_tree);
|
---|
296 | arrow_down_button.setActionCommand(GEMSConstants.MOVE_DOWN);
|
---|
297 |
|
---|
298 | buttonPane.add(arrow_up_button);
|
---|
299 | buttonPane.add(arrow_down_button);
|
---|
300 |
|
---|
301 | JPanel leftPane = new JPanel(new BorderLayout());
|
---|
302 | leftPane.add(treePane,BorderLayout.CENTER);
|
---|
303 | leftPane.add(buttonPane,BorderLayout.SOUTH);
|
---|
304 |
|
---|
305 | JLabel selected_language_label = new JLabel(Dictionary.get("GEMS.SelectedLanguage"));
|
---|
306 | selected_language_label.setOpaque(true);
|
---|
307 |
|
---|
308 | Vector language_vector = new Vector(msm.getLanguageList());
|
---|
309 | language_vector.add(0, Dictionary.get("GEMS.Language"));
|
---|
310 | JComboBox language_combo = new JComboBox(language_vector);
|
---|
311 |
|
---|
312 | language_combo.addActionListener(new ActionListener(){
|
---|
313 | public void actionPerformed(ActionEvent e){
|
---|
314 | JComboBox language_combo = (JComboBox) e.getSource();
|
---|
315 | String langInfo = (String)language_combo.getSelectedItem();
|
---|
316 | if (!langInfo.equals(Dictionary.get("GEMS.Language"))) {
|
---|
317 | String lang = langInfo.split("\\s")[0];
|
---|
318 | language_dependent_attribute_table.addNewLanguage(lang);
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | });
|
---|
323 |
|
---|
324 | JLabel language_label = new JLabel(Dictionary.get("GEMS.LanguageDependent"));
|
---|
325 | language_label.setOpaque(true);
|
---|
326 |
|
---|
327 |
|
---|
328 | JPanel selectLangPane = new JPanel(new BorderLayout(5,5));
|
---|
329 | selectLangPane.add(selected_language_label,BorderLayout.WEST);
|
---|
330 | selectLangPane.add(language_combo, BorderLayout.CENTER);
|
---|
331 |
|
---|
332 |
|
---|
333 | JPanel languagePane = new JPanel(new BorderLayout(5,5));
|
---|
334 | languagePane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
335 | languagePane.add(language_label,BorderLayout.NORTH);
|
---|
336 | languagePane.add(selectLangPane,BorderLayout.CENTER);
|
---|
337 |
|
---|
338 |
|
---|
339 | JPanel languageAttributePane = new JPanel(new BorderLayout());
|
---|
340 | languageAttributePane.add(languagePane,BorderLayout.NORTH);
|
---|
341 | languageAttributePane.add(langTablePane,BorderLayout.CENTER);
|
---|
342 |
|
---|
343 | JLabel attribute_label = new JLabel(Dictionary.get("GEMS.Attribute_Table"));
|
---|
344 | attribute_label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
345 | JPanel mainAttributePane = new JPanel(new BorderLayout());
|
---|
346 | mainAttributePane.add(attribute_label, BorderLayout.NORTH);
|
---|
347 | mainAttributePane.add(tablePane, BorderLayout.CENTER);
|
---|
348 |
|
---|
349 | attribute_tables_split_pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,mainAttributePane,languageAttributePane);
|
---|
350 |
|
---|
351 | metadata_set_details_split_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPane,attribute_tables_split_pane);
|
---|
352 |
|
---|
353 | card_pane.setLayout(card_layout);
|
---|
354 | card_pane.add(no_set_loaded_pane, NO_SET_LOADED_CARD);
|
---|
355 | card_pane.add(metadata_set_details_split_pane, SET_LOADED_CARD);
|
---|
356 |
|
---|
357 | getContentPane().add(card_pane,BorderLayout.CENTER);
|
---|
358 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
359 |
|
---|
360 | if (stand_alone) {
|
---|
361 | setVisible(true);
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 | public void setVisible(boolean visible) {
|
---|
366 | super.setVisible(visible);
|
---|
367 | if (visible) {
|
---|
368 | attribute_tables_split_pane.setDividerLocation(0.3);
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | // called from GLI
|
---|
373 | public void displayMetadataSet(String metadata_path){
|
---|
374 | open_prompt.openMetadataSet(metadata_path);
|
---|
375 | updateCardLayout(true);
|
---|
376 | setVisible(true);
|
---|
377 | }
|
---|
378 |
|
---|
379 | // called from GLI
|
---|
380 | public void newMetadataSet(){
|
---|
381 | new_prompt.display();
|
---|
382 | if (!new_prompt.isCancelled()) {
|
---|
383 | updateCardLayout(true);
|
---|
384 | setVisible(true);
|
---|
385 | }
|
---|
386 |
|
---|
387 | }
|
---|
388 |
|
---|
389 | public void addGEMSListener(GEMSListener listener){
|
---|
390 | listeners.add(listener);
|
---|
391 | }
|
---|
392 |
|
---|
393 | public void removeGEMSListener(GEMSListener listener){
|
---|
394 | listeners.remove(listener);
|
---|
395 | }
|
---|
396 |
|
---|
397 | public void notifyListeners(){
|
---|
398 | for (int i=0;i<listeners.size();i++){
|
---|
399 | GEMSListener listener = (GEMSListener) listeners.get(i);
|
---|
400 | listener.gemsIsClosed();
|
---|
401 | }
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | public void exit(){
|
---|
406 | //clean up things
|
---|
407 | cleanUpListeners();
|
---|
408 | }
|
---|
409 |
|
---|
410 | protected void cleanUpListeners() {
|
---|
411 | MetadataSetInfo msti= new MetadataSetInfo();
|
---|
412 | msti.removeAllMetadataSetListeners();
|
---|
413 | MetadataElementModel mem= new MetadataElementModel();
|
---|
414 | mem.removeAllMetadataElementListeners();
|
---|
415 |
|
---|
416 | }
|
---|
417 |
|
---|
418 | public void windowGainedFocus(WindowEvent e) {
|
---|
419 | //System.out.println("windowGainedFocus.");
|
---|
420 | }
|
---|
421 |
|
---|
422 | public void windowLostFocus(WindowEvent e) {
|
---|
423 | //System.out.println("windowLostFocus.");
|
---|
424 |
|
---|
425 | //save stuff
|
---|
426 |
|
---|
427 | }
|
---|
428 |
|
---|
429 | protected void updateCardLayout(boolean set_loaded) {
|
---|
430 | if (set_loaded) {
|
---|
431 | card_layout.show(card_pane, SET_LOADED_CARD);
|
---|
432 | } else {
|
---|
433 | card_layout.show(card_pane, NO_SET_LOADED_CARD);
|
---|
434 | }
|
---|
435 | }
|
---|
436 |
|
---|
437 | private class GEMSMenuBar
|
---|
438 | extends JMenuBar
|
---|
439 | implements ActionListener
|
---|
440 | {
|
---|
441 | private JMenu file = null;
|
---|
442 | private JMenu edit = null;
|
---|
443 |
|
---|
444 | public JMenuItem file_exit = null;
|
---|
445 | public JMenuItem file_new = null;
|
---|
446 | public JMenuItem file_open = null;
|
---|
447 | public JMenuItem file_close = null;
|
---|
448 | public JMenuItem file_save = null;
|
---|
449 | public JMenuItem edit_copy = null;
|
---|
450 | public JMenuItem edit_cut = null;
|
---|
451 | public JMenuItem edit_paste = null;
|
---|
452 | public JMenuItem help_help = null;
|
---|
453 | public JMenuItem file_delete = null;
|
---|
454 | //public JMenuItem file_preferences = null;
|
---|
455 | public GEMSMenuBar()
|
---|
456 | {
|
---|
457 | file = new JMenu();
|
---|
458 | file.setText(Dictionary.get("Menu.File"));
|
---|
459 |
|
---|
460 | file_exit = new JMenuItem(Dictionary.get("Menu.File_Exit"));
|
---|
461 | file_exit.addActionListener(this);
|
---|
462 |
|
---|
463 | file_new = new JMenuItem(Dictionary.get("Menu.File_New"));
|
---|
464 | file_new.addActionListener(this);
|
---|
465 |
|
---|
466 | file_open = new JMenuItem(Dictionary.get("Menu.File_Open"));
|
---|
467 | file_open.addActionListener(this);
|
---|
468 |
|
---|
469 | file_close = new JMenuItem(Dictionary.get("Menu.File_Close"));
|
---|
470 | file_close.addActionListener(this);
|
---|
471 |
|
---|
472 | file_save = new JMenuItem(Dictionary.get("Menu.File_Save"));
|
---|
473 | file_save.addActionListener(this);
|
---|
474 |
|
---|
475 | file_delete = new JMenuItem(Dictionary.get("Menu.File_Delete"));
|
---|
476 | file_delete.addActionListener(this);
|
---|
477 |
|
---|
478 | //file_preferences = new JMenuItem(Dictionary.get("Menu.File_Options"));
|
---|
479 | //file_preferences.addActionListener(this);
|
---|
480 |
|
---|
481 | if (!stand_alone) {
|
---|
482 | // when running from GLI, we disable most of the menu so
|
---|
483 | // that we have control over what sets the user is editing
|
---|
484 | file_new.setEnabled(false);
|
---|
485 | file_open.setEnabled(false);
|
---|
486 | file_close.setEnabled(false);
|
---|
487 | file_delete.setEnabled(false);
|
---|
488 | }
|
---|
489 |
|
---|
490 | // Layout (file menu)
|
---|
491 | file.add(file_new);
|
---|
492 | file.add(file_open);
|
---|
493 | file.add(file_close);
|
---|
494 | file.add(file_save);
|
---|
495 | file.add(file_delete);
|
---|
496 | file.add(new JSeparator());
|
---|
497 | //file.add(file_preferences);
|
---|
498 | //file.add(new JSeparator());
|
---|
499 | file.add(file_exit);
|
---|
500 |
|
---|
501 | // Edit menu
|
---|
502 | edit = new JMenu();
|
---|
503 | edit.setText(Dictionary.get("Menu.Edit"));
|
---|
504 |
|
---|
505 | String modkey = "ctrl";
|
---|
506 | if(Utility.isMac()) { // on Mac, we now use the Apple key instead of Ctrl for GLI/GEMS edit shortcuts
|
---|
507 | // http://stackoverflow.com/questions/5585919/creating-unicode-character-from-its-number
|
---|
508 | char appleKeyCodepoint = 0x2318; // applekey symbol unicode codepoint: U+2318 (\u2318)
|
---|
509 | String appleKeySymbol = String.valueOf(appleKeyCodepoint);
|
---|
510 | modkey = appleKeySymbol;
|
---|
511 | }
|
---|
512 |
|
---|
513 | edit_cut = new JMenuItem(Dictionary.get("Menu.Edit_Cut", modkey));
|
---|
514 | edit_cut.addActionListener(this);
|
---|
515 |
|
---|
516 | edit_copy = new JMenuItem(Dictionary.get("Menu.Edit_Copy", modkey));
|
---|
517 | edit_copy.addActionListener(this);
|
---|
518 |
|
---|
519 | edit_paste = new JMenuItem(Dictionary.get("Menu.Edit_Paste", modkey));
|
---|
520 | edit_paste.addActionListener(this);
|
---|
521 |
|
---|
522 | // Layout (edit menu)
|
---|
523 | edit.add(edit_cut);
|
---|
524 | edit.add(edit_copy);
|
---|
525 | edit.add(edit_paste);
|
---|
526 |
|
---|
527 |
|
---|
528 | // Layout (menu bar)
|
---|
529 | this.add(file);
|
---|
530 | this.add(Box.createHorizontalStrut(15));
|
---|
531 | this.add(edit);
|
---|
532 | this.add(Box.createHorizontalGlue());
|
---|
533 | //this.add(help);
|
---|
534 | }
|
---|
535 |
|
---|
536 |
|
---|
537 | public void actionPerformed(ActionEvent event)
|
---|
538 | {
|
---|
539 | Object event_source = event.getSource();
|
---|
540 |
|
---|
541 | // File -> New
|
---|
542 | if (event_source == file_new) {
|
---|
543 | new_prompt.display();
|
---|
544 | if (!new_prompt.isCancelled()) {
|
---|
545 | updateCardLayout(true);
|
---|
546 | }
|
---|
547 | return;
|
---|
548 | }
|
---|
549 |
|
---|
550 | // File -> Open
|
---|
551 | if (event_source == file_open) {
|
---|
552 | open_prompt.display();
|
---|
553 | if (!open_prompt.isCancelled()) {
|
---|
554 | updateCardLayout(true);
|
---|
555 | }
|
---|
556 | return;
|
---|
557 | }
|
---|
558 |
|
---|
559 | // File -> Close
|
---|
560 | if (event_source == file_close) {
|
---|
561 | metadata_set_model.save(true);
|
---|
562 | updateCardLayout(false);
|
---|
563 | return;
|
---|
564 | }
|
---|
565 | // File -> Delete
|
---|
566 | if (event_source == file_delete) {
|
---|
567 | delete_prompt.display();
|
---|
568 | return;
|
---|
569 | }
|
---|
570 |
|
---|
571 |
|
---|
572 | // File -> Save
|
---|
573 | if (event_source == file_save) {
|
---|
574 | metadata_set_model.save(false);
|
---|
575 | return;
|
---|
576 | }
|
---|
577 |
|
---|
578 | // File -> Exit
|
---|
579 | if (event_source == file_exit) {
|
---|
580 | metadata_set_model.save(true);
|
---|
581 | if (stand_alone){
|
---|
582 | System.exit(0);
|
---|
583 | }
|
---|
584 | else {
|
---|
585 | self.notifyListeners();
|
---|
586 | self.setVisible(false);
|
---|
587 | return;
|
---|
588 | }
|
---|
589 | }
|
---|
590 |
|
---|
591 | /// File -> Preferences
|
---|
592 | // if(event_source == file_preferences){
|
---|
593 | // GEMSPreferences GemsPreferences = new GEMSPreferences();
|
---|
594 | //}
|
---|
595 |
|
---|
596 | // Edit -> Cut
|
---|
597 | if (event_source == edit_cut) {
|
---|
598 | try {
|
---|
599 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
600 | // Get the component with selected text as a JTextComponent
|
---|
601 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
|
---|
602 | // Cut the text to the clipboard
|
---|
603 | text.cut();
|
---|
604 | }
|
---|
605 | catch (ClassCastException cce) {
|
---|
606 | // If the component is not a text component ignore the cut command
|
---|
607 | DebugStream.println(cce.toString());
|
---|
608 | }
|
---|
609 | return;
|
---|
610 | }
|
---|
611 |
|
---|
612 | // Edit -> Copy
|
---|
613 | if (event_source == edit_copy) {
|
---|
614 | try {
|
---|
615 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
616 | // Get the component with selected text as a JTextComponent
|
---|
617 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
|
---|
618 | text.copy();
|
---|
619 | }
|
---|
620 | catch (Exception cce) {
|
---|
621 | // If the component is not a text component ignore the copy command
|
---|
622 | DebugStream.println(cce.toString());
|
---|
623 | }
|
---|
624 | return;
|
---|
625 | }
|
---|
626 |
|
---|
627 | // Edit -> Paste
|
---|
628 | if (event_source == edit_paste) {
|
---|
629 | try {
|
---|
630 | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
---|
631 | // Get the component with selected text as a JTextComponent
|
---|
632 | JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
|
---|
633 | // Cut the text to the clipboard
|
---|
634 | text.paste();
|
---|
635 | }
|
---|
636 | catch (ClassCastException cce) {
|
---|
637 | // If the component is not a text component ignore the paste command
|
---|
638 | DebugStream.println(cce.toString());
|
---|
639 | }
|
---|
640 | return;
|
---|
641 | }
|
---|
642 |
|
---|
643 | }
|
---|
644 | }
|
---|
645 |
|
---|
646 | }
|
---|