source: gli/trunk/src/org/greenstone/gatherer/gui/GUIManager.java@ 19438

Last change on this file since 19438 was 19438, checked in by kjdon, 15 years ago

If you change the language then the locale is set in the configuration, then when you come to save the collection config file, the worng locale is used, and you get the wrong language in the file for metadata anmes. So now we save the collection before setting the locale, but also need to call a new exit method in GUIManager so it doesn't overwrite our general.open_collection setting

  • Property svn:keywords set to Author Date Id Revision
File size: 33.6 KB
Line 
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 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.datatransfer.*;
41import java.awt.event.*;
42import java.io.File;
43import java.lang.*;
44import java.net.*;
45import java.util.*;
46import javax.swing.*;
47import javax.swing.event.*;
48import javax.swing.filechooser.*;
49import javax.swing.plaf.*;
50import javax.swing.text.*;
51import org.greenstone.gatherer.Configuration;
52import org.greenstone.gatherer.DebugStream;
53import org.greenstone.gatherer.Dictionary;
54import org.greenstone.gatherer.Gatherer;
55import org.greenstone.gatherer.collection.Collection;
56import org.greenstone.gatherer.collection.CollectionManager;
57import org.greenstone.gatherer.file.FileOpenActionListener;
58import org.greenstone.gatherer.file.WorkspaceTree;
59import org.greenstone.gatherer.gui.metaaudit.MetaAuditFrame;
60import org.greenstone.gatherer.gui.tree.DragTree;
61import org.greenstone.gatherer.metadata.MetadataSet;
62import org.greenstone.gatherer.metadata.MetadataXMLFileManager;
63import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
64import org.greenstone.gatherer.util.JarTools;
65import org.greenstone.gatherer.util.StaticStrings;
66import org.greenstone.gatherer.util.Utility;
67
68/** The GUIManager is in charge of creating the Gatherer window frame then filling it with the goodness of the view panes. GUIManager not only creates these panes, but allows some messaging between them. Furthermore GUIManager includes functionality from menu driven choices, simply as it was easier to put it here once and have it accessible from all pane children. */
69public class GUIManager
70 extends JFrame
71 implements ActionListener, ChangeListener, WindowFocusListener{
72 /** The download pane contains controls for downloading internet sites. */
73 public DownloadPane download_pane = null;
74 /** The gather pane is more like a file manager where you drag files from one tree to another. */
75 public GatherPane gather_pane = null;
76 /** The enrich pane is used to assign, edit and remove metadata from files within the collection. */
77 public EnrichPane enrich_pane = null;
78 /** The design pane allows you to edit the design of the library in terms of the collection configuration file. - the stuff that requires rebuilding */
79 public DesignPane design_pane = null;
80 /** The create pane contains scripting options for importing and building collections into libraries. */
81 public CreatePane create_pane = null;
82 /** The format pane allows you to edit the design of the library in terms of the collection configuration file. - the stuff that doesn't require rebuilding */
83 public FormatPane format_pane = null;
84
85 public FileOpenActionListener foa_listener = new FileOpenActionListener();
86
87
88 /** A reference to the currently instantiated help window, if any. */
89 private HelpFrame help = null;
90 /** The menu bar. */
91 public MenuBar menu_bar = null;
92 public MetaAuditFrame meta_audit;
93 /** Are certain panes currently locked? */
94 private boolean locked = false;
95 /** The size of the Gatherer window. */
96 private Dimension size = null;
97 /** The panel within the window that other components are placed on. */
98 private JPanel content_pane = null;
99 /** The last view pane selected. */
100 private JPanel previous_pane;
101 /** The main tab pane containing the different views, available here to trap view change events. */
102 private JTabbedPane tab_pane = null;
103 /** A threaded tab changer to try and avoid NPE on exit. */
104 private TabUpdater tab_updater = null;
105
106
107
108
109
110 final static String newline = "\n";
111 final static String space = " ";
112
113
114 /**Constructor. Enable window events and arranges all other components.
115 * @param size The intial <strong>Dimension</strong> of the screen.
116 */
117 public GUIManager(Dimension size) {
118 super();
119 this.setComponentOrientation(Dictionary.getOrientation());
120 // Initialization
121 this.help = new HelpFrame();
122 this.size = size;
123
124 this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
125
126 // Add a focus listener to ourselves. Thus if we gain focus when a Modal Dialog should instead have it, we can try to bring the modal dialog to the fore.
127 this.addFocusListener(new GLIGUIFocusListener());
128
129 this.addWindowFocusListener(this);
130
131 // Make the Tool tip hang around for a rediculous amount of time.
132 ToolTipManager.sharedInstance().setDismissDelay(10000);
133
134 // Set up some other UI stuff. (fonts handled in Gatherer.main())
135 UIManager.put("FileChooser.lookInLabelText", Dictionary.get("SaveCollectionBox.Look_In"));
136 UIManager.put("FileChooser.filesOfTypeLabelText", Dictionary.get("SaveCollectionBox.Files_Of_Type"));
137 UIManager.put("FileChooser.fileNameLabelText", Dictionary.get("SaveCollectionBox.File_Name"));
138 }
139
140
141 public void windowGainedFocus(WindowEvent e)
142 {
143 }
144
145
146 public void windowLostFocus(WindowEvent e)
147 {
148 // Save the loaded collection
149 if (Gatherer.c_man != null && Gatherer.c_man.ready() && Gatherer.c_man.getCollection().cdm != null) {
150 Gatherer.c_man.saveCollection();
151 }
152 }
153
154
155 private class GLIGUIFocusListener
156 extends FocusAdapter {
157 public void focusGained(FocusEvent e) {
158 if (ModalDialog.current_modal != null) {
159 ModalDialog.current_modal.makeVisible();
160 ModalDialog.current_modal.toFront();
161 }
162 }
163 }
164
165 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured. In this case we are listening to actions from the menu-bar, and should react appropriately.
166 * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
167 */
168 public void actionPerformed(ActionEvent event) {
169 Object esrc = event.getSource();
170 // *************
171 // File Options.
172 // *************
173 if (esrc == menu_bar.file_associations) {
174 Gatherer.assoc_man.edit();
175 }
176 else if (esrc == menu_bar.file_close) {
177 saveThenCloseCurrentCollection();
178 }
179 else if (esrc == menu_bar.file_delete) {
180 new DeleteCollectionTask().start();
181 }
182 else if (esrc == menu_bar.file_cdimage) {
183 WriteCDImagePrompt wcdip = new WriteCDImagePrompt();
184 wcdip.display();
185 wcdip.destroy();
186 wcdip = null;
187 }
188 else if (esrc == menu_bar.file_exportas) {
189 ExportAsPrompt eap = new ExportAsPrompt();
190 eap.display();
191 eap.destroy();
192 eap = null;
193 }
194 else if (esrc == menu_bar.file_exit) {
195 exit();
196 }
197 else if (esrc == menu_bar.file_new) {
198 new NewCollectionTask().start();
199 }
200 else if (esrc == menu_bar.file_open) {
201 new OpenCollectionTask().start();
202 }
203 else if (esrc == menu_bar.file_options) {
204 new Preferences();
205 }
206 else if (esrc == menu_bar.file_save) {
207 // Very important: make sure metadata values are saved too
208 enrich_pane.stopEditingAndRebuild();
209 // Make sure all the metadata has been saved to file
210 MetadataXMLFileManager.saveMetadataXMLFiles();
211
212 Gatherer.c_man.saveCollection();
213 }
214
215 // *************
216 // Edit Options.
217 // *************
218 else if(esrc == menu_bar.edit_copy) {
219 try {
220 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
221 // Get the component with selected text as a JTextComponent
222 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
223 text.copy();
224 }
225 catch (Exception cce) {
226 // If the component is not a text component ignore the copy command
227 DebugStream.println(cce.toString());
228 }
229 }
230 else if(esrc == menu_bar.edit_cut) {
231 try {
232 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
233 // Get the component with selected text as a JTextComponent
234 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
235 // Cut the text to the clipboard
236 text.cut();
237 }
238 catch (ClassCastException cce) {
239 // If the component is not a text component ignore the cut command
240 DebugStream.println(cce.toString());
241 }
242 }
243 else if(esrc == menu_bar.edit_paste) {
244 try {
245 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
246 // Get the component with selected text as a JTextComponent
247 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
248 // Cut the text to the clipboard
249 text.paste();
250 }
251 catch (ClassCastException cce) {
252 // If the component is not a text component ignore the paste command
253 DebugStream.println(cce.toString());
254 }
255 }
256
257 // *************
258 // Help Options.
259 // *************
260 else if (esrc == menu_bar.help_general) {
261 HelpFrame.setView("introduction");
262 }
263 else if (esrc == menu_bar.help_download) {
264 HelpFrame.setView("themirrorview");
265 }
266 else if (esrc == menu_bar.help_gather) {
267 HelpFrame.setView("collectingfiles");
268 }
269 else if (esrc == menu_bar.help_enrich) {
270 HelpFrame.setView("enrichingacollection");
271 }
272 else if (esrc == menu_bar.help_design) {
273 HelpFrame.setView("designingacollection");
274 }
275 else if (esrc == menu_bar.help_create) {
276 HelpFrame.setView("producingthecollection");
277 }
278 else if (esrc == menu_bar.help_format) {
279 HelpFrame.setView("formattingacollection");
280 }
281 else if (esrc == menu_bar.help_about) {
282 new AboutDialog(this);
283 }
284 }
285
286
287 /** Any actions that should happen after the display of the Gatherer window can be called here. Currently only updates the browser pane if it is active to work around bug in Mozilla renderer implementation.
288 */
289 public void afterDisplay() {
290 if (download_pane != null) {
291 download_pane.afterDisplay();
292 }
293 enrich_pane.afterDisplay();
294 }
295
296
297 public void closeCurrentCollection()
298 {
299 tab_pane.setSelectedComponent(gather_pane);
300 Gatherer.c_man.closeCollection();
301 }
302
303
304 public void saveThenCloseCurrentCollection()
305 {
306 Gatherer.c_man.saveCollection();
307 closeCurrentCollection();
308 }
309
310
311 /** This is called when we're absolutely finished with the GLI. It is *not* called when the applet is suspended.
312 */
313 public void destroy()
314 {
315 // Destroying create pane ensures the latest log has been closed
316 if (create_pane != null) {
317 create_pane.destroy();
318 }
319
320 // Deal to help
321 if (help != null) {
322 help.destroy();
323 help = null;
324 }
325 }
326
327
328 /** Enabled events on the window to be trapped, creates all the visual components, then builds the tab and other layouts.
329 */
330 public void display() {
331 content_pane = (JPanel) this.getContentPane();
332 content_pane.setComponentOrientation(Dictionary.getOrientation());
333
334 // Enable window-type events to be fired.
335 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
336 // Initialise and layout sub-components, plus other window dressing.
337 try {
338 this.setSize(size);
339
340 // Set the title
341 String collection_title = null;
342 String collection_name = null;
343 if (Gatherer.c_man.ready()) {
344 Collection collection = Gatherer.c_man.getCollection();
345 collection_title = collection.getTitle();
346 collection_name = collection.getGroupQualifiedName(true);
347 collection = null;
348 }
349 setTitle(collection_title, collection_name);
350 collection_title = null;
351 collection_name = null;
352
353 // Pretty corner icon
354 String gsmall_image = "gatherer_small.gif";
355 if (Configuration.fedora_info.isActive()) {
356 gsmall_image = "fli-" + gsmall_image;
357 }
358 this.setIconImage(JarTools.getImage(gsmall_image).getImage());
359 // BorderLayout for the main screen. I'll try my best to avoid these in subcomponents as they're space greedy.
360 content_pane.setLayout(new BorderLayout());
361 // Create the menu-bar and stick it up the top.
362 menu_bar = new MenuBar(new MenuListenerImpl());
363 menu_bar.setComponentOrientation(Dictionary.getOrientation());
364
365 //feedback changes
366 //content_pane.add(menu_bar, BorderLayout.NORTH);
367 this.setJMenuBar(menu_bar);
368 // end feedback changes
369
370 // Create the tabbed pane and plop it in the center where it will
371 // expand to consume all available space like any good gas would.
372 tab_pane = new JTabbedPane();
373 tab_pane.setComponentOrientation(Dictionary.getOrientation());
374 tab_pane.addChangeListener(this);
375 tab_pane.setFont(Configuration.getFont("general.font", false));
376
377 if (Configuration.get("workflow.download", true) && Gatherer.isDownloadEnabled) {
378 download_pane = new DownloadPane();
379 // "GUI.Download_Tooltip" is used automatically
380 tab_pane.addTab(Dictionary.get("GUI.Download"), JarTools.getImage("download.gif"), download_pane, Dictionary.get("GUI.Download_Tooltip"));
381 tab_pane.setEnabledAt(tab_pane.indexOfComponent(download_pane), Configuration.get("workflow.download", false));
382 }
383
384 gather_pane = new GatherPane();
385 gather_pane.display();
386 if (Configuration.get("workflow.gather", true)) {
387 // "GUI.Gather_Tooltip" is used automatically
388 tab_pane.addTab(Dictionary.get("GUI.Gather"), JarTools.getImage("gather.gif"), gather_pane, Dictionary.get("GUI.Gather_Tooltip"));
389 tab_pane.setEnabledAt(tab_pane.indexOfComponent(gather_pane), Configuration.get("workflow.gather", false));
390 }
391
392 enrich_pane = new EnrichPane();
393 enrich_pane.display();
394 if (Configuration.get("workflow.enrich", true)) {
395 // "GUI.Enrich_Tooltip" is used automatically
396 tab_pane.addTab(Dictionary.get("GUI.Enrich"), JarTools.getImage("enrich.gif"), enrich_pane, Dictionary.get("GUI.Enrich_Tooltip"));
397 tab_pane.setEnabledAt(tab_pane.indexOfComponent(enrich_pane), false);
398 }
399
400 design_pane = new DesignPane();
401 design_pane.display();
402 if (Configuration.get("workflow.design", true)) {
403 // "GUI.Design_Tooltip" is used automatically
404 if (Configuration.fedora_info.isActive()) {
405 tab_pane.addTab("Plugins", JarTools.getImage("design.gif"), design_pane, Dictionary.get("GUI.Design_Tooltip"));
406 }
407 else {
408 tab_pane.addTab(Dictionary.get("GUI.Design"), JarTools.getImage("design.gif"), design_pane, Dictionary.get("GUI.Design_Tooltip"));
409 }
410
411 tab_pane.setEnabledAt(tab_pane.indexOfComponent(design_pane), false);
412 }
413
414 create_pane = new CreatePane();
415 create_pane.setComponentOrientation(Dictionary.getOrientation());
416 create_pane.display();
417 if (Configuration.get("workflow.create", true)) {
418 // "GUI.Create_Tooltip" is used automatically
419 tab_pane.addTab(Dictionary.get("GUI.Create"), JarTools.getImage("create.gif"), create_pane, Dictionary.get("GUI.Create_Tooltip"));
420 tab_pane.setEnabledAt(tab_pane.indexOfComponent(create_pane), false);
421 }
422
423 format_pane = new FormatPane();
424 format_pane.setComponentOrientation(Dictionary.getOrientation());
425 format_pane.display();
426 if (Configuration.get("workflow.format", true)) {
427 tab_pane.addTab(Dictionary.get("GUI.Format"), JarTools.getImage("format.gif"), format_pane, Dictionary.get("GUI.Format_Tooltip"));
428 tab_pane.setEnabledAt(tab_pane.indexOfComponent(format_pane), false);
429 }
430
431 // The MetaAuditFrame must be created after the gather/enrich panes but before they get focus
432 meta_audit = new MetaAuditFrame();
433 meta_audit.setComponentOrientation(Dictionary.getOrientation());
434 // Select the collect pane if it is available
435 if (tab_pane.indexOfComponent(gather_pane) != -1) {
436 tab_pane.setSelectedComponent(gather_pane);
437 }
438 // Otherwise find the first tab that is enabled and select that.
439 else {
440 for (int i = 0; i < tab_pane.getTabCount(); i++) {
441 if (tab_pane.isEnabledAt(i)) {
442 tab_pane.setSelectedIndex(i);
443 break;
444 }
445 }
446 }
447
448 content_pane.add(tab_pane, BorderLayout.CENTER);
449
450 // Add an extra progress bar at the bottom of every screen when using a remote Greenstone server
451 if (Gatherer.isGsdlRemote) {
452 JPanel remote_greenstone_server_progress_panel = new JPanel();
453 //remote_greenstone_server_progress_panel.setComponentOrientation(Dictionary.getOrientation());
454 JLabel remote_greenstone_server_progress_label = new JLabel(Dictionary.get("RemoteGreenstoneServer.Progress"));
455 //remote_greenstone_server_progress_label.setComponentOrientation(Dictionary.getOrientation());
456 remote_greenstone_server_progress_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
457 remote_greenstone_server_progress_panel.setLayout(new BorderLayout());
458 remote_greenstone_server_progress_panel.add(remote_greenstone_server_progress_label, BorderLayout.LINE_START);
459 remote_greenstone_server_progress_panel.add(Gatherer.remoteGreenstoneServer.getProgressBar(), BorderLayout.CENTER);
460 content_pane.add(remote_greenstone_server_progress_panel, BorderLayout.SOUTH);
461 }
462
463 // Call refresh to update all controls to reflect current collection status.
464 refresh(-1, Gatherer.c_man.ready());
465 }
466 catch (Exception e) {
467 DebugStream.printStackTrace(e);
468 // The GUI failing to build is an app killer
469 e.printStackTrace();
470 System.exit(1);
471 }
472 }
473
474 public void exit()
475 {
476 exit(0);
477 }
478
479 // some cases we have already saved the collection, but don't want to
480 // override the general.open_collection value here
481 public void exitNoCollectionSave(int exit_status) {
482 // Store the current position and size of the GLI for next time
483 Configuration.setBounds("general.bounds", true, getBounds());
484
485 // Save configuration
486 Configuration.save();
487
488 // Hide the main window
489 setVisible(false);
490
491 // If we're running as an applet we don't quit here (we quit when the browser calls GathererApplet.destroy())
492 if (!Gatherer.isApplet) {
493 Gatherer.exit(exit_status);
494 }
495
496 }
497 /** This method ensures that all the things needing saving are saved before Gatherer.exit() is called.
498 */
499 public void exit(int exit_status)
500 {
501 // If we have a collection open remember it for next time, then save it and close it
502 if (Gatherer.c_man.ready()) {
503 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
504 true, CollectionManager.getLoadedCollectionColFilePath());
505 saveThenCloseCurrentCollection();
506 }
507 else {
508 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, null);
509 }
510
511 // Store the current position and size of the GLI for next time
512 Configuration.setBounds("general.bounds", true, getBounds());
513
514 // Save configuration
515 Configuration.save();
516
517 // Hide the main window
518 setVisible(false);
519
520 // If we're running as an applet we don't quit here (we quit when the browser calls GathererApplet.destroy())
521 if (!Gatherer.isApplet) {
522 Gatherer.exit(exit_status);
523 }
524 }
525
526
527 /** This method is called when the collection is being built, and is used to disable all controls in all pane which could change the state of the collection.
528 */
529 public void lockCollection(boolean import_stage, boolean lock)
530 {
531 locked = lock;
532
533 if (import_stage) {
534 int gather_pos = tab_pane.indexOfComponent(gather_pane);
535 if (gather_pos != -1) {
536 tab_pane.setEnabledAt(gather_pos, !lock);
537 }
538 int enrich_pos = tab_pane.indexOfComponent(enrich_pane);
539 if (enrich_pos != -1) {
540 tab_pane.setEnabledAt(enrich_pos, !lock);
541 }
542 }
543
544 int design_pos = tab_pane.indexOfComponent(design_pane);
545 if (design_pos != -1) {
546 tab_pane.setEnabledAt(design_pos, !lock);
547 }
548 }
549
550
551 public void modeChanged(int mode) {
552 // Set the title
553 String collection_title = null;
554 String collection_name = null;
555 if (Gatherer.c_man.ready()) {
556 Collection collection = Gatherer.c_man.getCollection();
557 collection_title = collection.getTitle();
558 collection_name = collection.getGroupQualifiedName(true);
559 collection = null;
560 }
561 setTitle(collection_title, collection_name);
562 collection_title = null;
563 collection_name = null;
564 // Now pass on the message to anyone who cares
565 if (download_pane != null) {
566 download_pane.modeChanged(mode);
567 }
568 if (gather_pane != null) {
569 gather_pane.modeChanged(mode);
570 }
571 if (enrich_pane != null) {
572 enrich_pane.modeChanged(mode);
573 }
574 if (design_pane != null) {
575 design_pane.modeChanged(mode);
576 }
577 if (create_pane != null) {
578 create_pane.modeChanged(mode);
579 }
580 if (format_pane != null) {
581 format_pane.modeChanged(mode);
582 }
583 }
584
585
586 public void refresh(int refresh_reason, boolean collection_loaded)
587 {
588 // Set the collection information in the title bar
589 if (collection_loaded) {
590 Collection collection = Gatherer.c_man.getCollection();
591 setTitle(collection.getTitle(), collection.getGroupQualifiedName(true));
592 }
593 else {
594 setTitle(null, null);
595 }
596
597 // Update the menu bar
598 menu_bar.refresh(refresh_reason, collection_loaded);
599
600 // Update the loaded panes
601 if (download_pane != null) {
602 download_pane.refresh(refresh_reason, collection_loaded);
603 }
604 if (gather_pane != null) {
605 gather_pane.refresh(refresh_reason, collection_loaded);
606 }
607 if (enrich_pane != null) {
608 enrich_pane.refresh(refresh_reason, collection_loaded);
609 }
610 if (design_pane != null) {
611 design_pane.refresh(refresh_reason, collection_loaded);
612 }
613 if (create_pane != null) {
614 create_pane.refresh(refresh_reason, collection_loaded);
615 }
616 if (format_pane != null) {
617 format_pane.refresh(refresh_reason, collection_loaded);
618 }
619
620 // Now enable tabs as necessary. Do this on event queue to prevent crazy NPEs
621 if (!locked) {
622 if (tab_updater == null) {
623 tab_updater = new TabUpdater(tab_pane, collection_loaded);
624 }
625 else {
626 tab_updater.setReady(collection_loaded);
627 }
628 SwingUtilities.invokeLater(tab_updater);
629 }
630 }
631
632
633 public void refreshCollectionTree(int refresh_reason)
634 {
635 if (gather_pane != null) {
636 gather_pane.refreshCollectionTree(refresh_reason);
637 }
638 }
639
640
641 public void refreshWorkspaceTree(int refresh_reason)
642 {
643 if (gather_pane != null) {
644 gather_pane.refreshWorkspaceTree(refresh_reason);
645 }
646 }
647
648
649 /** Specifies whether a certain tab is enabled or not. */
650 private void setTabEnabled(String rawname, boolean state) {
651 // Retrieve the dictionary based name.
652 String name = Dictionary.get("GUI." + rawname);
653 int index = tab_pane.indexOfTab(name);
654 // Of course we may not have this tab available.
655 if(index != -1) {
656 // Some tabs are also dependant on if a collection is ready
657 Component component = tab_pane.getComponentAt(index);
658 if(component == enrich_pane || component == design_pane || component == create_pane || component == format_pane) {
659 tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready());
660 }
661 else {
662 tab_pane.setEnabledAt(index, state);
663 }
664 // If this was the currently selected tab and it is now disabled, change the view to the first enabled tab.
665 if(tab_pane.getSelectedIndex() == index && !state) {
666 boolean found = false;
667 for(int i = 0; !found && i < tab_pane.getTabCount(); i++) {
668 if(tab_pane.isEnabledAt(i)) {
669 tab_pane.setSelectedIndex(i);
670 found = true;
671 }
672 }
673 // If there are no tabs enabled, which should be impossible, then select the first tab
674 if(!found) {
675 tab_pane.setSelectedIndex(0);
676 }
677 }
678 }
679 }
680
681 /** Change the string shown in the title bar of the main gui frame. If either value is null, the 'No Collection' string is shown instead.
682 * @param title
683 * @param name
684 */
685 public void setTitle(String title, String name) {
686
687 // Finally display the collection name in the title bar.
688 StringBuffer title_buffer = new StringBuffer(Configuration.getApplicationTitle());
689 title_buffer.append(StaticStrings.SPACE_CHARACTER);
690 title_buffer.append(Gatherer.PROGRAM_VERSION);
691 title_buffer.append(StaticStrings.SPACE_CHARACTER);
692 title_buffer.append(StaticStrings.SPACE_CHARACTER);
693 // Server version information
694 title_buffer.append(Gatherer.getServerVersionAsString());
695 title_buffer.append(StaticStrings.SPACE_CHARACTER);
696 title_buffer.append(StaticStrings.SPACE_CHARACTER);
697 // Describe the current user mode
698 title_buffer.append(StaticStrings.MODE_STR);
699 title_buffer.append(Configuration.getModeAsString());
700 title_buffer.append(StaticStrings.SPACE_CHARACTER);
701 title_buffer.append(StaticStrings.SPACE_CHARACTER);
702 // Now for the current collection
703 title_buffer.append(StaticStrings.COLLECTION_STR);
704 if (title != null && name != null) {
705 title_buffer.append(title);
706 title_buffer.append(StaticStrings.SPACE_CHARACTER);
707 title_buffer.append(StaticStrings.OPEN_PARENTHESIS_CHARACTER);
708 title_buffer.append(name);
709 title_buffer.append(StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
710 }
711 else {
712 title_buffer.append(Dictionary.get("Collection.No_Collection"));
713 }
714 this.setTitle(title_buffer.toString());
715 title_buffer = null;
716 }
717
718
719 private class OpenCollectionTask
720 extends Thread
721 {
722 public void run()
723 {
724 String collection_file_path = showOpenCollectionDialog();
725
726 // User has selected a collection to open
727 if (collection_file_path != null) {
728 // If there is already a collection open, save and close it
729 if (Gatherer.c_man.ready()) {
730 saveThenCloseCurrentCollection();
731 }
732
733 // Open the selected collection
734 Gatherer.c_man.loadCollection(collection_file_path);
735 }
736 }
737 }
738
739
740 /** When the load collection option is chosen this method is called to produce the modal file load prompt.
741 */
742 private String showOpenCollectionDialog()
743 {
744 OpenCollectionDialog dialog = new OpenCollectionDialog();
745 dialog.setComponentOrientation(Dictionary.getOrientation());
746 if (dialog.display() == OpenCollectionDialog.OK_OPTION) {
747 return dialog.getFileName();
748 }
749
750 // User must have cancelled the action
751 return null;
752 }
753
754
755 /** When called this method causes the MetadataAuditTable to display a nice dialog box which contains all the metadata assigned in the collection.
756 */
757 public void showMetaAuditBox() {
758 wait(true);
759 meta_audit.display();
760 wait(false);
761 }
762
763
764 private class NewCollectionTask
765 extends Thread
766 {
767 public void run()
768 {
769 // Create the collection details prompt from new collection prompt
770 NewCollectionDetailsPrompt ncd_prompt = new NewCollectionDetailsPrompt();
771
772 // Create the new collection (if not cancelled) in a new thread.
773 if (!ncd_prompt.isCancelled()) {
774 // If there is already a collection open, save and close it.
775 if (Gatherer.c_man.ready()) {
776 saveThenCloseCurrentCollection();
777 }
778
779 // Create new collection.
780 Gatherer.c_man.createCollection(ncd_prompt.getDescription(), Configuration.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), ncd_prompt.getBase(), new ArrayList());
781 ncd_prompt.dispose();
782 }
783
784 // Done
785 ncd_prompt = null;
786 }
787 }
788
789
790 private class DeleteCollectionTask
791 extends Thread
792 {
793 public void run()
794 {
795 // The rest is handled by the DeleteCollectionPrompt
796 DeleteCollectionPrompt dc_prompt = new DeleteCollectionPrompt();
797 if (dc_prompt.display()) {
798 //closeCurrentCollection();
799 }
800 dc_prompt.destroy();
801 dc_prompt = null;
802 }
803 }
804
805
806 /** Any implementation of ChangeListener must include this method so we can be informed when the state of one of the registered objects changes. In this case we are listening to view changes within the tabbed pane.
807 * @param event A ChangeEvent containing information about the event that fired this call.
808 */
809 public void stateChanged(ChangeEvent event)
810 {
811 if (previous_pane != null) {
812 if (previous_pane == gather_pane) {
813 gather_pane.loseFocus();
814 }
815 else if (previous_pane == enrich_pane) {
816 enrich_pane.loseFocus();
817 }
818 else if (previous_pane == design_pane) {
819 design_pane.loseFocus();
820 }
821 else if (previous_pane == create_pane) {
822 create_pane.loseFocus();
823 }
824 else if (previous_pane == format_pane) {
825 format_pane.loseFocus();
826 }
827 }
828
829 menu_bar.tabSelected(tab_pane.getSelectedIndex());
830 int selected_index = tab_pane.getSelectedIndex();
831 if (selected_index == tab_pane.indexOfComponent(download_pane)) {
832 download_pane.gainFocus();
833 }
834 else if (selected_index == tab_pane.indexOfComponent(gather_pane)) {
835 gather_pane.gainFocus();
836 }
837 else if (selected_index == tab_pane.indexOfComponent(enrich_pane)) {
838 enrich_pane.gainFocus();
839 }
840 else if (selected_index == tab_pane.indexOfComponent(design_pane)) {
841 design_pane.gainFocus();
842 }
843 else if (selected_index == tab_pane.indexOfComponent(create_pane)) {
844 create_pane.gainFocus();
845 }
846 else if (selected_index == tab_pane.indexOfComponent(format_pane)) {
847 format_pane.gainFocus();
848 }
849
850 previous_pane = (JPanel) tab_pane.getSelectedComponent();
851
852 }
853
854
855 private MouseListener mouse_blocker_listener = new MouseAdapter() {};
856
857 public void updateUI()
858 {
859 JPanel pane = (JPanel) getContentPane();
860 pane.updateUI();
861 // Also update all of the tabs according to workflow.
862 workflowUpdate("Download", Configuration.get("workflow.download", false));
863 workflowUpdate("Gather", Configuration.get("workflow.gather", false));
864 workflowUpdate("Enrich", Configuration.get("workflow.enrich", false));
865 workflowUpdate("Design", Configuration.get("workflow.design", false));
866 workflowUpdate("Create", Configuration.get("workflow.create", false));
867 workflowUpdate("Format", Configuration.get("workflow.format", false));
868 }
869
870 public void wait(boolean waiting) {
871 Component glass_pane = getGlassPane();
872 if(waiting) {
873 // Show wait cursor.
874 glass_pane.addMouseListener(mouse_blocker_listener);
875 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876 glass_pane.setVisible(true);
877 }
878 else {
879 // Hide wait cursor.
880 glass_pane.setVisible(false);
881 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
882 glass_pane.removeMouseListener(mouse_blocker_listener);
883 }
884 glass_pane = null;
885 }
886
887 public void workflowUpdate(String raw, boolean state) {
888 WorkflowUpdater task = new WorkflowUpdater(raw, state);
889 SwingUtilities.invokeLater(task);
890 task = null;
891 }
892
893
894 /**Overridden from JFrame so we can exit safely when window is closed (or destroyed).
895 * @param event A <strong>WindowEvent</strong> containing information about the event that fired this call.
896 */
897 protected void processWindowEvent(WindowEvent event) {
898 if(event.getID() == WindowEvent.WINDOW_CLOSING) {
899 exit();
900 }
901 }
902
903
904 /** Listens to actions upon the menu bar, and if it detects a click over the help menu brings the help window to the front if it has become hidden.
905 */
906 private class MenuListenerImpl
907 implements MenuListener {
908 /** Called whenever a popup menu is hidden, but we don't care.
909 * @param e Some <strong>MenuEvent</strong> that we could care less about.
910 */
911 public void menuCanceled(MenuEvent e) {
912 }
913 /** Called whenever a menu header (ie button) becomes unselected, but we don't care.
914 * @param e Some <strong>MenuEvent</strong> that we could care less about.
915 */
916 public void menuDeselected(MenuEvent e) {
917 }
918 /** This method, when a menu is first opened, is the only one we respond to by bringing the help window to the front if possible, but only if there is a help window and the help menu is the one opening.
919 * @param e The <strong>MenuEvent</strong> whose source is checked.
920 */
921 public void menuSelected(MenuEvent e) {
922 if(e.getSource() == menu_bar.help) {
923 if(menu_bar.help.isSelected()) {
924 menu_bar.help.doClick(10);
925 }
926 }
927 }
928 }
929
930 private class TabUpdater
931 implements Runnable {
932 private boolean ready = false;
933 private int download_pos = -1;
934 private int enrich_pos = -1;
935 private int design_pos = -1;
936 private int create_pos = -1;
937 private int format_pos = -1;
938 private int export_pos = -1;
939 private JTabbedPane tab_pane = null;
940
941 public TabUpdater(JTabbedPane tab_pane, boolean ready) {
942 this.ready = ready;
943 this.tab_pane = tab_pane;
944 download_pos = tab_pane.indexOfComponent(download_pane);
945 enrich_pos = tab_pane.indexOfComponent(enrich_pane);
946 design_pos = tab_pane.indexOfComponent(design_pane);
947 create_pos = tab_pane.indexOfComponent(create_pane);
948 format_pos = tab_pane.indexOfComponent(format_pane);
949 }
950
951 public void run()
952 {
953 if (download_pos != -1) {
954 if (ready) {
955 tab_pane.setEnabledAt(download_pos, Configuration.get("workflow.download", false));
956 }
957 else {
958 tab_pane.setEnabledAt(download_pos, Configuration.get("workflow.download", true));
959 }
960 }
961 if (enrich_pos != -1) {
962 tab_pane.setEnabledAt(enrich_pos, ready && Configuration.get("workflow.enrich", false));
963 }
964 if (design_pos != -1) {
965 tab_pane.setEnabledAt(design_pos, ready && Configuration.get("workflow.design", false) && Configuration.getMode() > Configuration.ASSISTANT_MODE);
966 }
967 if (create_pos != -1) {
968 tab_pane.setEnabledAt(create_pos, ready && Configuration.get("workflow.create", false));
969 }
970 if (format_pos != -1) {
971 tab_pane.setEnabledAt(format_pos, ready && Configuration.get("workflow.format", false) && Configuration.getMode() > Configuration.ASSISTANT_MODE);
972 }
973 }
974
975 public void setReady(boolean ready) {
976 this.ready = ready;
977 }
978 }
979
980 private class WorkflowUpdater
981 implements Runnable {
982 private boolean state;
983 private String raw;
984 public WorkflowUpdater(String raw, boolean state) {
985 this.raw = raw;
986 this.state = state;
987 }
988 public void run() {
989 setTabEnabled(raw, state);
990 }
991 }
992}
Note: See TracBrowser for help on using the repository browser.