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

Last change on this file since 6394 was 6389, checked in by jmt12, 20 years ago

Introduced the idea of detail modes - these have an effect on several parts of the gui, such as disabling or hiding all regular expression based controls, simplifying the output from perl scripts and (having been given yet another new last minute feature to implement) displays a completely different create pane. Mode is stored in the config.xml and is changable via the Preferences controls

  • Property svn:keywords set to Author Date Id Revision
File size: 38.9 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.*;
43import java.lang.*;
44import java.net.*;
45import java.util.*;
46import javax.swing.*;
47import javax.swing.event.*;
48import javax.swing.plaf.*;
49import javax.swing.text.*;
50import org.greenstone.gatherer.Configuration;
51import org.greenstone.gatherer.Dictionary;
52import org.greenstone.gatherer.Gatherer;
53import org.greenstone.gatherer.collection.Collection;
54import org.greenstone.gatherer.collection.DeleteCollectionPrompt;
55import org.greenstone.gatherer.collection.ExportCollectionPrompt;
56import org.greenstone.gatherer.collection.SaveCollectionBox;
57import org.greenstone.gatherer.file.FileNode;
58import org.greenstone.gatherer.file.FileOpenActionListener;
59import org.greenstone.gatherer.gui.AboutDialog;
60import org.greenstone.gatherer.gui.BrowsingPane;
61import org.greenstone.gatherer.gui.CollectionPane;
62import org.greenstone.gatherer.gui.CreatePane;
63import org.greenstone.gatherer.gui.Filter;
64import org.greenstone.gatherer.gui.GConfigPane;
65import org.greenstone.gatherer.gui.MenuBar;
66import org.greenstone.gatherer.gui.MetaEditPane;
67import org.greenstone.gatherer.gui.MirrorPane;
68import org.greenstone.gatherer.gui.OpenCollectionDialog;
69import org.greenstone.gatherer.gui.Preferences;
70//import org.greenstone.gatherer.gui.PreviewPane;
71import org.greenstone.gatherer.gui.SimpleOpenCollectionDialog;
72import org.greenstone.gatherer.gui.metaaudit.MetaAuditFrame;
73import org.greenstone.gatherer.gui.tree.DragTree;
74import org.greenstone.gatherer.gui.tree.WorkspaceTree;
75import org.greenstone.gatherer.help.HelpFrame;
76import org.greenstone.gatherer.mem.MetadataEditorManager;
77import org.greenstone.gatherer.msm.ElementWrapper;
78import org.greenstone.gatherer.msm.Metadata;
79import org.greenstone.gatherer.shell.GShell;
80import org.greenstone.gatherer.util.StaticStrings;
81import org.greenstone.gatherer.util.TreeSynchronizer;
82import org.greenstone.gatherer.util.Utility;
83
84/** 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. */
85public class GUIManager
86 extends JFrame
87 implements ActionListener, ChangeListener {
88 /** The browsing pane behaves much like an internet browser, or at least will some day. */
89 public BrowsingPane browser_pane = null;
90 /** The collection pane is more like a file manager where you drag files from one tree to another. */
91 public CollectionPane collection_pane = null;
92 /** The create pane contains scripting options for importing and building collections into libraries. */
93 public CreatePane create_pane = null;
94
95 public FileOpenActionListener foa_listener = new FileOpenActionListener();
96
97 /** The configuration pane allows you to edit the design of the library in terms of the collection configuration file. */
98 public GConfigPane config_pane = null;
99 /** A reference to the currently instantiated help window, if any. */
100 public HelpFrame help = null;
101 /** The menu bar. */
102 public MenuBar menu_bar = null;
103 public MetaAuditFrame meta_audit;
104 /** The metaedit pane is used to assign, edit and remove metadata from files within the collection. */
105 public MetaEditPane metaedit_pane = null;
106 /** The mirror pane contains controls for mirroring internet sites. */
107 public MirrorPane mirror_pane = null;
108 /** The preview pane contains a preview of your build collection. */
109 //public PreviewPane preview_pane = null;
110 /** Are certain panes currently locked? */
111 private boolean locked = false;
112 /** The size of the Gatherer window. */
113 private Dimension size = null;
114 /** The filters used to dynamically filter the trees at user request. */
115 private HashMap filters = new HashMap();
116 /** The panel within the window that other components are placed on. */
117 private JPanel content_pane = null;
118 /** The dummy export pane. */
119 private JPanel export_pane = new JPanel();
120 /** The last view pane selected. */
121 private JPanel previous_pane;
122 /** The main tab pane containing the different views, available here to trap view change events. */
123 private JTabbedPane tab_pane = null;
124 /** A reference to any existing search and replace module/dialog. */
125 // private SearchAndReplace sar = null;
126 /** A threaded tab changer to try and avoid NPE on exit. */
127 private TabUpdater tab_updater = null;
128 /** The thread group this manager, and hence its child graphical rendering threads, belong to. In a vain attempts to make the Dictionary work across threads.
129 * @see org.greenstone.gatherer.Dictionary
130 */
131 private ThreadGroup thread_group = null;
132 /** Ensures that expansion events between like collection trees are synchronized. */
133 private TreeSynchronizer collection_tree_sync = null;
134 /** Ensures that expansion events between like workspace trees are synchronized. */
135 private TreeSynchronizer workspace_tree_sync = null;
136 /**Constructor. Enable window events and arranges all other components.
137 * @param size The intial <strong>Dimension</strong> of the screen.
138 * @param graphic The default <strong>GraphicsConfiguration</strong> for this platform.
139 */
140 public GUIManager(Dimension size) {
141 super();
142 // Initialization
143 this.help = new HelpFrame();
144 this.size = size;
145 this.collection_tree_sync = new TreeSynchronizer();
146 this.meta_audit = new MetaAuditFrame(collection_tree_sync, null);
147 this.workspace_tree_sync = new TreeSynchronizer();
148 // Make the Tool tip hang around for a rediculous amount of time.
149 ToolTipManager.sharedInstance().setDismissDelay(10000);
150 // Get a reference to the main thread group. Create a new thread, which defaults into the same thread group, then get its thread group. Easy.
151 Thread bob = new Thread();
152 thread_group = bob.getThreadGroup();
153 // Set up some other UI stuff. (fonts handled in Gatherer.main())
154 UIManager.put("FileChooser.lookInLabelText", Dictionary.get("SaveCollectionBox.Look_In"));
155 UIManager.put("FileChooser.filesOfTypeLabelText", Dictionary.get("SaveCollectionBox.Files_Of_Type"));
156 UIManager.put("FileChooser.fileNameLabelText", Dictionary.get("SaveCollectionBox.File_Name"));
157 }
158 /** 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.
159 * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
160 */
161 public void actionPerformed(ActionEvent event) {
162 boolean cont = true;
163 Object esrc = event.getSource();
164 // *************
165 // File Options.
166 // *************
167 if(esrc == menu_bar.file_associations) {
168 Gatherer.assoc_man.edit();
169 }
170 else if(esrc == menu_bar.file_close) {
171 // if(!Gatherer.c_man.saved()) {
172 cont = showSaveCollectionBox(true, false);
173 // }
174 if(cont) {
175 tab_pane.setSelectedComponent(collection_pane);
176 }
177 }
178 else if(esrc == menu_bar.file_delete) {
179 DeleteCollectionPrompt dcp = new DeleteCollectionPrompt();
180 if(dcp.display()) {
181 Gatherer.c_man.closeCollection();
182 }
183 dcp.destroy();
184 dcp = null;
185 System.gc();
186 }
187 else if(esrc == menu_bar.file_export) {
188 ExportCollectionPrompt ecp = new ExportCollectionPrompt();
189 ecp.display();
190 ecp.destroy();
191 ecp = null;
192 }
193 else if(esrc == menu_bar.file_exit) {
194 menu_bar.exit();
195 exit();
196 }
197 else if(esrc == menu_bar.file_new) {
198 showNewCollectionPrompt();
199 }
200 else if(esrc == menu_bar.file_open) {
201 if (showLoadCollectionBox()) {
202 tab_pane.setSelectedComponent(collection_pane);
203 }
204 }
205 else if(esrc == menu_bar.file_options) {
206 // Just incase the user has edited the GeneralSettings of a collection without losing focus afterwards. Well I'm forever losing foc... ooh shiney.
207 config_pane.loseFocus();
208 // And spawn a new preferences.
209 new Preferences();
210 }
211 else if(esrc == menu_bar.file_save) {
212 Gatherer.c_man.saveCollection(false, false);
213 }
214// else if(esrc == menu_bar.file_save_as) {
215// String name = JOptionPane.showInputDialog(this, "Enter new collection filename.");
216// if(name != null) {
217// Gatherer.c_man.saveCollectionAs(name);
218// }
219// }
220 // *************
221 // Edit Options.
222 // *************
223 else if(esrc == menu_bar.edit_copy) {
224 try {
225 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
226 // Get the component with selected text as a JTextComponent
227 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
228 text.copy();
229 }
230 catch (Exception cce) {
231 // If the component is not a text component ignore the copy command
232 Gatherer.println(cce.toString());
233 }
234 }
235 else if(esrc == menu_bar.edit_cut) {
236 try {
237 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
238 // Get the component with selected text as a JTextComponent
239 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
240 // Cut the text to the clipboard
241 text.cut();
242 }
243 catch (ClassCastException cce) {
244 // If the component is not a text component ignore the cut command
245 Gatherer.println(cce.toString());
246 }
247 }
248 else if(esrc == menu_bar.edit_paste) {
249 try {
250 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
251 // Get the component with selected text as a JTextComponent
252 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
253 // Cut the text to the clipboard
254 text.paste();
255 }
256 catch (ClassCastException cce) {
257 // If the component is not a text component ignore the paste command
258 Gatherer.println(cce.toString());
259 }
260 }
261// else if(esrc == menu_bar.edit_search) {
262// if(sar != null) {
263// sar.dispose();
264// }
265// sar = new SearchAndReplace(false);
266// }
267// else if(esrc == menu_bar.edit_replace) {
268// if(sar != null) {
269// sar.dispose();
270// }
271// sar = new SearchAndReplace(true);
272// }
273
274 // *************
275 // Tools Options.
276 // *************
277// else if(esrc == menu_bar.tools_size) {
278// FileNode records[] = metaedit_pane.getSelectedNode();
279// if(records != null && records.length > 0) {
280// ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getMetadata(records[0].getFile());
281// if(metadatum.size() >= 4) {
282// Metadata metadata = (Metadata) metadatum.get(0);
283// ElementWrapper ew = metadata.getElement();
284
285// int SIZE = 5000;
286// Object[] array = new Object[SIZE];
287// Runtime.getRuntime().gc();
288// long start = Runtime.getRuntime().freeMemory();
289// for (int i = 0; i < SIZE; i++) {
290// array[i] = ew.copy();
291// }
292// Runtime.getRuntime().gc();
293// long end = Runtime.getRuntime().freeMemory();
294// long difference = (( start - end ) / SIZE);
295// ///ystem.out.println(difference + " bytes used." );
296// }
297// }
298// }
299
300 // *************
301 // Help Options.
302 // *************
303 else if(esrc == menu_bar.help_about) {
304 new AboutDialog(this);
305 }
306 else if(esrc == menu_bar.help_browse) {
307 help.setView("huntingforfiles");
308 }
309 else if(esrc == menu_bar.help_build) {
310 help.setView("producingthecollection");
311 }
312 else if(esrc == menu_bar.help_collect) {
313 help.setView("collectingfiles");
314 }
315 else if(esrc == menu_bar.help_design) {
316 help.setView("designingacollection");
317 }
318 else if(esrc == menu_bar.help_general) {
319 help.setView("introduction");
320 }
321 else if(esrc == menu_bar.help_metaedit) {
322 help.setView("enrichingacollection");
323 }
324 else if(esrc == menu_bar.help_mirror) {
325 help.setView("downloadingfiles");
326 }
327 else if(esrc == menu_bar.help_preview) {
328 help.setView("previewingthecollection");
329 }
330 // *****************
331 // Metadata Options.
332 // *****************
333 else if(esrc == menu_bar.metadata_import) {
334 Gatherer.c_man.getCollection().msm.importMDS();
335 }
336 else if(esrc == menu_bar.metadata_edit) {
337 showEditMetadataBox();
338 }
339 else if(esrc == menu_bar.metadata_export) {
340 Gatherer.c_man.getCollection().msm.exportMDS();
341 }
342 else if(esrc == menu_bar.metadata_view) {
343 showMetaAuditBox();
344 }
345 }
346 /** 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.
347 */
348 public void afterDisplay() {
349 if(Gatherer.config.get("workflow.mirror", true)) {
350 browser_pane.afterDisplay();
351 }
352 metaedit_pane.afterDisplay();
353 }
354 /** Once a collection has been made available to Gatherer, either by its creation or by it being reloaded, we need to inform all the visual components to update necessary data components (such as tree models), enable certain controls that depend on a collection being accessible, and refresh themselves.
355 * @param ready <i>true</i> if the collection is ready for editing, <i>false</i> otherwise.
356 */
357 public void collectionChanged(final boolean ready) {
358 if(Gatherer.config.get("workflow.mirror", true)) {
359 mirror_pane.collectionChanged(ready);
360 }
361 menu_bar.collectionChanged(ready); // Inform the menu bar that the collections changed.
362 collection_pane.collectionChanged(ready); // Used to update the collection workspace.
363 metaedit_pane.collectionChanged(ready); // Very important that metaedit pane shows current collection and is listening to latest msm.
364 config_pane.collectionChanged(ready); // Also important config pane is listening to latest msm.
365 create_pane.collectionChanged(ready); // Used to indicate a new BuildOptions model should be loaded.
366 //preview_pane.collectionChanged(ready); // preview should know when teh coll has changed so it can reload the home page
367
368 if(!locked) {
369 // Now enable tabs as necessary. Do this on event queue to prevent crazy NPEs
370 if(tab_updater == null) {
371 tab_updater = new TabUpdater(tab_pane, ready);
372 }
373 else {
374 tab_updater.setReady(ready);
375 }
376 SwingUtilities.invokeLater(tab_updater);
377 }
378 // Set the title
379 String collection_title = null;
380 String collection_name = null;
381 if (ready) {
382 Collection collection = Gatherer.c_man.getCollection();
383 collection_title = collection.getTitle();
384 collection_name = collection.getName();
385 collection = null;
386 }
387 setTitle(collection_title, collection_name);
388 collection_title = null;
389 collection_name = null;
390 // Now is a good time to force a garbage collect.
391 ///ystem.err.println("Calling garbage collection.");
392 System.gc();
393 }
394
395 public void destroy() {
396 // Destroying create pane ensures the latest log has been closed
397 if(create_pane != null) {
398 create_pane.destroy();
399 }
400 }
401
402 /** Enabled events on the window to be trapped, creates all the visual components, then builds the tab and other layouts.
403 */
404 public void display() {
405 content_pane = (JPanel) this.getContentPane();
406 // Enable window-type events to be fired.
407 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
408 // Initialise and layout sub-components, plus other window dressing.
409 try {
410 this.setSize(size);
411
412 // Set the title
413 String collection_title = null;
414 String collection_name = null;
415 if (Gatherer.c_man.ready()) {
416 Collection collection = Gatherer.c_man.getCollection();
417 collection_title = collection.getTitle();
418 collection_name = collection.getName();
419 collection = null;
420 }
421 setTitle(collection_title, collection_name);
422 collection_title = null;
423 collection_name = null;
424
425 // Pretty corner icon
426 this.setIconImage(Utility.getImage("gatherer_small.gif").getImage());
427 // BorderLayout for the main screen. I'll try my best to avoid t
428 // hese in subcomponents as they're space greedy.
429 content_pane.setLayout(new BorderLayout());
430 // Create the menu-bar and stick it up the top.
431 menu_bar = new MenuBar(new MenuListenerImpl());
432 content_pane.add(menu_bar, BorderLayout.NORTH);
433 // Create the tabbed pane and plop it in the center where it will
434 // expand to consume all available space like any good gas would.
435 tab_pane = new JTabbedPane();
436 tab_pane.addChangeListener(this);
437 tab_pane.setFont(Gatherer.config.getFont("general.font", false));
438
439 // May have to play with the order in which tabs are added.
440 if(Gatherer.config.get("workflow.browse", true)) {
441 browser_pane = new BrowsingPane();
442 tab_pane.addTab("GUI.Hunt", Utility.getImage("browsing.gif"), browser_pane);
443 tab_pane.setEnabledAt(tab_pane.indexOfComponent(browser_pane), Gatherer.config.get("workflow.browse", false));
444 }
445
446 if(Gatherer.config.get("workflow.mirror", true)) {
447 mirror_pane = new MirrorPane();
448 tab_pane.addTab("GUI.Mirror", Utility.getImage("mirroring.gif"), mirror_pane);
449 tab_pane.setEnabledAt(tab_pane.indexOfComponent(mirror_pane), Gatherer.config.get("workflow.mirror", false));
450 }
451
452 collection_pane = new CollectionPane(workspace_tree_sync, collection_tree_sync);
453 collection_pane.display();
454 if(Gatherer.config.get("workflow.gather", true)) {
455 tab_pane.addTab("GUI.Gather", Utility.getImage("collection.gif"), collection_pane);
456 tab_pane.setEnabledAt(tab_pane.indexOfComponent(collection_pane), Gatherer.config.get("workflow.gather", false));
457 }
458
459 metaedit_pane = new MetaEditPane(collection_tree_sync);
460 metaedit_pane.display();
461 if(Gatherer.config.get("workflow.enrich", true)) {
462 tab_pane.addTab("GUI.Enrich", Utility.getImage("metaedit.gif"), metaedit_pane);
463 tab_pane.setEnabledAt(tab_pane.indexOfComponent(metaedit_pane), false);
464 }
465
466 config_pane = new GConfigPane();
467 config_pane.display();
468 if(Gatherer.config.get("workflow.design", true)) {
469 tab_pane.addTab("GUI.Design", Utility.getImage("build.gif"), config_pane);
470 tab_pane.setEnabledAt(tab_pane.indexOfComponent(config_pane), false);
471 }
472
473 if(Gatherer.config.get("workflow.export", true)) {
474 tab_pane.addTab("GUI.Export", Utility.getImage("export.gif"), export_pane);
475 tab_pane.setEnabledAt(tab_pane.indexOfComponent(export_pane), false);
476 }
477
478 create_pane = new CreatePane();
479 create_pane.display();
480 if(Gatherer.config.get("workflow.create", true)) {
481 tab_pane.addTab("GUI.Create", Utility.getImage("build session.gif"), create_pane);
482 tab_pane.setEnabledAt(tab_pane.indexOfComponent(create_pane), false);
483 }
484
485 //preview_pane = new PreviewPane();
486 //preview_pane.display();
487 //if(Gatherer.config.get("workflow.preview", true)) {
488 //tab_pane.addTab("GUI.Preview", Utility.getImage("final.gif"), preview_pane);
489 //tab_pane.setEnabledAt(tab_pane.indexOfComponent(preview_pane), false);
490 //}
491
492 // Find the first tab that is enabled and select that.
493 boolean found = false;
494 for(int i = 0; !found && i < tab_pane.getTabCount(); i++) {
495 if(tab_pane.isEnabledAt(i)) {
496 tab_pane.setSelectedIndex(i);
497 found = true;
498 }
499 }
500
501 Dictionary.register(tab_pane);
502 content_pane.add(tab_pane, BorderLayout.CENTER);
503 // Drive a sessionReady event to update all controls to reflect current collection status.
504 collectionChanged(Gatherer.c_man.ready());
505 }
506 catch (Exception e) {
507 Gatherer.printStackTrace(e);
508 // The GUI failing to build is a app killer
509 e.printStackTrace();
510 System.exit(1);
511 }
512 }
513 /** When called this method ensures that all the things needing saving are saved before Gatherer.exit() is called. This includes a save collection prompt if necessary.
514 */
515 public void exit() {
516 boolean cont = true;
517 if(Gatherer.c_man.ready() && !Gatherer.c_man.saved()) {
518 cont = showSaveCollectionBox(false, true);
519 }
520 else {
521 // Deal to help
522 if(help != null) {
523 help.destroy();
524 help = null;
525 }
526 Gatherer.self.exit();
527 }
528 }
529 /** Retrieve the filter, or if one already exists, spawn a linked copy. */
530 public Filter getFilter(DragTree tree) {
531 Filter filter = (Filter) filters.get(tree.getModel());
532 if (filter == null) {
533 filter = new Filter(tree, null);
534 filters.put(tree.getModel(), filter);
535 return filter;
536 }
537 return filter.spawn(tree);
538 }
539
540 public Component getSelectedView() {
541 return tab_pane.getSelectedComponent();
542 }
543 /** 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.
544 */
545 public void lockCollection(boolean import_stage, boolean lock) {
546 locked = lock;
547 if(import_stage) {
548 int collection_pos = tab_pane.indexOfComponent(collection_pane);
549 int metaedit_pos = tab_pane.indexOfComponent(metaedit_pane);
550 int config_pos = tab_pane.indexOfComponent(config_pane);
551 tab_pane.setEnabledAt(collection_pos, !lock);
552 tab_pane.setEnabledAt(metaedit_pos, !lock);
553 tab_pane.setEnabledAt(config_pos, !lock);
554 }
555 else {
556 int config_pos = tab_pane.indexOfComponent(config_pane);
557 tab_pane.setEnabledAt(config_pos, !lock);
558 }
559 }
560
561 public void modeChanged(int mode) {
562 // Set the title
563 String collection_title = null;
564 String collection_name = null;
565 if (Gatherer.c_man.ready()) {
566 Collection collection = Gatherer.c_man.getCollection();
567 collection_title = collection.getTitle();
568 collection_name = collection.getName();
569 collection = null;
570 }
571 setTitle(collection_title, collection_name);
572 collection_title = null;
573 collection_name = null;
574 // Now pass on the message to anyone who cares
575 if(collection_pane != null) {
576 collection_pane.modeChanged(mode);
577 }
578 if(config_pane != null) {
579 config_pane.modeChanged(mode);
580 }
581 if(create_pane != null) {
582 create_pane.modeChanged(mode);
583 }
584 if(metaedit_pane != null) {
585 metaedit_pane.modeChanged(mode);
586 }
587 }
588
589 public void refreshTrees(int refresh_reason)
590 {
591 if(collection_pane != null) {
592 collection_pane.refreshWorkspaceTree(refresh_reason);
593 collection_pane.refreshCollectionTree(refresh_reason);
594 }
595 if(metaedit_pane != null) {
596 metaedit_pane.refreshTrees();
597 }
598 }
599
600 /** Allows the system to programatically set the selected tab.
601 * @param component The view you wish to make visable in the tab pane as a <strong>Component</strong>.
602 */
603 public void setSelectedView(Component component) {
604 tab_pane.setSelectedComponent(component);
605 }
606
607 /** Specifies whether a certain tab is enabled or not. */
608 public void setTabEnabled(String rawname, boolean state) {
609 // Retrieve the dictionary based name.
610 String name = Dictionary.get("GUI." + rawname);
611 int index = tab_pane.indexOfTab(name);
612 // Of course we may not have this tab available.
613 if(index != -1) {
614 // Some tabs are also dependant on if a collection is ready
615 Component component = tab_pane.getComponentAt(index);
616 //if(component == preview_pane) {
617 //tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready() && Gatherer.c_man.built());
618 //}
619 //else
620 if(component == metaedit_pane || component == config_pane || component == export_pane || component == create_pane) {
621 tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready());
622 }
623 else {
624 tab_pane.setEnabledAt(index, state);
625 }
626 // If this was the currently selected tab and it is now disabled, change the view to the first enabled tab.
627 if(tab_pane.getSelectedIndex() == index && !state) {
628 boolean found = false;
629 for(int i = 0; !found && i < tab_pane.getTabCount(); i++) {
630 if(tab_pane.isEnabledAt(i)) {
631 tab_pane.setSelectedIndex(i);
632 found = true;
633 }
634 }
635 // If there are no tabs enabled, which should be impossible, then select the first tab
636 if(!found) {
637 tab_pane.setSelectedIndex(0);
638 }
639 }
640 }
641 // If the rawname was mirror then rebuild workspace tree to remove caches.
642 if (rawname.equals("Mirror")) {
643 collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
644 }
645 }
646
647 /** 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.
648 * @param title
649 * @param name
650 */
651 public void setTitle(String title, String name) {
652 // Finally display the collection name in the title bar.
653 StringBuffer title_buffer = new StringBuffer(Utility.PROGRAM_NAME);
654 title_buffer.append(StaticStrings.SPACE_CHARACTER);
655 title_buffer.append(StaticStrings.SPACE_CHARACTER);
656 // Describe the current user mode
657 title_buffer.append(StaticStrings.MODE_STR);
658 title_buffer.append(Gatherer.config.getModeAsString());
659 title_buffer.append(StaticStrings.SPACE_CHARACTER);
660 title_buffer.append(StaticStrings.SPACE_CHARACTER);
661 // Now for the current collection
662 title_buffer.append(StaticStrings.COLLECTION_STR);
663 if (title != null && name != null) {
664 title_buffer.append(title);
665 title_buffer.append(StaticStrings.SPACE_CHARACTER);
666 title_buffer.append(StaticStrings.OPEN_PARENTHESIS_CHARACTER);
667 title_buffer.append(name);
668 title_buffer.append(StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
669 }
670 else {
671 title_buffer.append(Dictionary.get("Collection.No_Collection"));
672 }
673 this.setTitle(title_buffer.toString());
674 title_buffer = null;
675 }
676
677 /** When the edit metadata option is choosen from the menu, this method is called to ensure we only edit the metadata if there is metadata loaded.
678 */
679 public void showEditMetadataBox() {
680 if(Gatherer.c_man.getCollection() != null) {
681 Gatherer.c_man.getCollection().msm.editMDS(null, MetadataEditorManager.NORMAL);
682 }
683 }
684 /** When the load collection option is choosen this method is called to produce the modal file load prompt.
685 */
686 public boolean showLoadCollectionBox() {
687 boolean result = false;
688 // We first try the simple open collection dialog
689 SimpleOpenCollectionDialog dialog = new SimpleOpenCollectionDialog();
690 int user_choice = dialog.display();
691 String filename = null;
692 // The user may choose to go to the advanced 'browse' dialog
693 if(user_choice == SimpleOpenCollectionDialog.OK_OPTION) {
694 filename = dialog.getFileName();
695 }
696 else if(user_choice == SimpleOpenCollectionDialog.BROWSE_OPTION) {
697 File file;
698 if(Gatherer.config.gsdl_path != null) {
699 file = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
700 }
701 else {
702 file = new File(Utility.BASE_DIR);
703 }
704 OpenCollectionDialog chooser = new OpenCollectionDialog(file);
705 file = null;
706 filename = chooser.getFileName();
707 chooser.destroy();
708 chooser = null;
709 }
710 dialog.destroy();
711 dialog = null;
712 // User can cancel action.
713 if(filename != null) {
714 // If there is already a collection open, save and close it.
715 if(Gatherer.c_man.ready()) {
716 showSaveCollectionBox(true, false);
717 // Wait until it is closed.
718 try {
719 synchronized(this) {
720 while(Gatherer.c_man.reallyReady()) {
721 wait(10);
722 }
723 }
724 }
725 catch(Exception error) {
726 Gatherer.println("Exception: " + error);
727 Gatherer.printStackTrace(error);
728 }
729 }
730 result = Gatherer.c_man.loadCollection(filename);
731 filename = null;
732 }
733 return result;
734 }
735
736 /** When called this method causes the MetaAuditBox class in CollectionManager to display a nice dialog box which contains all the metadata assigned in the collection.
737 */
738 public void showMetaAuditBox() {
739 wait(true);
740 meta_audit.display();
741 wait(false);
742 }
743 /** This method is used to open the new collection box on the screen.
744 */
745 public void showNewCollectionPrompt() {
746 NewCollectionMetadataPrompt ncm_prompt = null;
747 // Create the collection details prompt from new collection prompt
748 NewCollectionDetailsPrompt ncd_prompt = new NewCollectionDetailsPrompt();
749 // If no previous collection was indicated as a model design, then show the metadata selection prompt from new collection prompt
750 if(!ncd_prompt.isCancelled() && (ncd_prompt.getBase() == null)) {
751 ncm_prompt = new NewCollectionMetadataPrompt();
752 }
753 // Create the new collection (if not cancelled) in a new thread.
754 if(!ncd_prompt.isCancelled() && (ncm_prompt == null || !ncm_prompt.isCancelled())) {
755 // If there is already a collection open, save and close it.
756 if(Gatherer.c_man.ready()) {
757 showSaveCollectionBox(true, false);
758 // Wait until it is closed.
759 try {
760 synchronized(this) {
761 while(Gatherer.c_man.reallyReady()) {
762 wait(10);
763 }
764 }
765 }
766 catch(Exception error) {
767 Gatherer.println("Exception: " + error);
768 Gatherer.printStackTrace(error);
769 }
770 }
771
772 // Create new collection.
773 CreationTask task = new CreationTask(ncd_prompt, ncm_prompt);
774 // SwingUtilities.invokeLater(task);
775 task.start();
776 // Close prompt.
777 }
778 // Done
779 ncd_prompt = null;
780 ncm_prompt = null;
781 }
782 private class CreationTask
783 extends Thread {
784 private NewCollectionDetailsPrompt ncd_prompt = null;
785 private NewCollectionMetadataPrompt ncm_prompt = null;
786 public CreationTask(NewCollectionDetailsPrompt ncd_prompt, NewCollectionMetadataPrompt ncm_prompt) {
787 this.ncd_prompt = ncd_prompt;
788 this.ncm_prompt = ncm_prompt;
789 }
790
791 public void run() {
792 ///ystem.err.println("Running CreationTask...");
793 if(ncm_prompt == null) {
794 Gatherer.c_man.createCollection(ncd_prompt.getDescription(), Gatherer.config.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), ncd_prompt.getBase(), null);
795 }
796 else {
797 Gatherer.c_man.createCollection(ncd_prompt.getDescription(), Gatherer.config.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), null, ncm_prompt.getSets());
798 }
799 // Now that the collection specific settings are loaded we can set the 'view extracted metadata' property
800 // do we want to have this in here???
801 //Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, true);
802 ncd_prompt.dispose();
803 ncd_prompt = null;
804 if(ncm_prompt != null) {
805 ncm_prompt.dispose();
806 ncm_prompt = null;
807 }
808 }
809 }
810
811
812 /** This method is used to open the save collection box/prompt on the screen.
813 * @return A <i>boolean</i> which is <i>true</i> if the collection was saved successfully, <i>false</i> otherwise.
814 */
815 public boolean showSaveCollectionBox(boolean close_after, boolean exit_after) {
816 //SaveCollectionBox save_collection_box = new SaveCollectionBox();
817 //Rectangle bounds = save_collection_box.getBounds();
818 //int result = save_collection_box.getUserOption(Gatherer.c_man.getCollection().getName());
819 //switch(result) {
820 //case SaveCollectionBox.SAVE_YES:
821 Gatherer.c_man.saveCollection(close_after, exit_after);
822 // Wait until it is closed.
823 try {
824 synchronized(this) {
825 while(Gatherer.c_man.reallyReady()) {
826 wait(10);
827 }
828 }
829 }
830 catch(Exception error) {
831 Gatherer.println("Exception: " + error);
832 Gatherer.printStackTrace(error);
833 }
834
835 //content_pane.paintImmediately(bounds);
836 return true;
837 //case SaveCollectionBox.SAVE_NO:
838 // Close collection.
839 // if(close_after) {
840 // tab_pane.setSelectedComponent(collection_pane);
841 // Gatherer.c_man.closeCollection();
842 // }
843 // if(exit_after) {
844 // Gatherer.self.exit();
845 // }
846 // return true;
847 //default:
848 // return false;
849 //}
850 }
851 /** 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.
852 * @param event A ChangeEvent containing information about the event that fired this call.
853 */
854 public void stateChanged(ChangeEvent event) {
855 if(previous_pane != null) {
856 if(previous_pane == create_pane) {
857 create_pane.loseFocus();
858 }
859 else if(previous_pane == config_pane) {
860 config_pane.loseFocus();
861 }
862 }
863 // "View assigned metadata" menu item is disabled by default
864 menu_bar.metadata_view.setCanEnable(false);
865 menu_bar.setMetaAuditSuffix(null);
866
867 menu_bar.tabSelected(tab_pane.getSelectedIndex());
868 if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(collection_pane)) {
869 collection_pane.gainFocus();
870 // "View assigned metadata" menu item is enabled for the "Gather" pane
871 menu_bar.metadata_view.setCanEnable(true);
872 }
873 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(metaedit_pane)) {
874 metaedit_pane.gainFocus();
875 // "View assigned metadata" menu item is enabled for the "Enrich" pane
876 menu_bar.metadata_view.setCanEnable(true);
877 }
878 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(config_pane)) {
879 config_pane.gainFocus();
880 }
881 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(create_pane)) {
882 create_pane.gainFocus();
883 }
884 //else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(preview_pane)) {
885 //config_pane.saveConfiguration();
886 //preview_pane.gainFocus();
887 //}
888
889 previous_pane = (JPanel) tab_pane.getSelectedComponent();
890 }
891
892 private MouseListener mouse_blocker_listener = new MouseAdapter() {};
893
894 public void wait(boolean waiting) {
895 Component glass_pane = getGlassPane();
896 if(waiting) {
897 // Show wait cursor.
898 glass_pane.addMouseListener(mouse_blocker_listener);
899 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
900 glass_pane.setVisible(true);
901 }
902 else {
903 // Hide wait cursor.
904 glass_pane.setVisible(false);
905 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
906 glass_pane.removeMouseListener(mouse_blocker_listener);
907 }
908 glass_pane = null;
909 }
910
911 public void workflowUpdate(String raw, boolean state) {
912 WorkflowUpdater task = new WorkflowUpdater(raw, state);
913 SwingUtilities.invokeLater(task);
914 task = null;
915 }
916
917 /** Called to determine if we should wait for a thread to finish before continuing. We wait for threads if they are named: GSHELL_BUILD, GSHELL_IMPORT, or GSHELL_NEW.
918 * @return <i>true</i> if we should wait for a thread, <i>false</i> if it is safe to continue.
919 */
920 private boolean waitForThread() {
921 Thread active[] = new Thread[thread_group.activeCount()];
922 int size = thread_group.enumerate(active);
923 for(int i = 0; i < size; i++) {
924 if(active[i].getName().equals(GShell.GSHELL_BUILD) ||
925 active[i].getName().equals(GShell.GSHELL_IMPORT) ||
926 active[i].getName().equals(GShell.GSHELL_NEW)) {
927 return true;
928 }
929 }
930 return false;
931 }
932
933
934 /**Overridden from JFrame so we can exit safely when window is closed (or destroyed).
935 * @param event A <strong>WindowEvent</strong> containing information about the event that fired this call.
936 */
937 protected void processWindowEvent(WindowEvent event) {
938 if(event.getID() == WindowEvent.WINDOW_CLOSING) {
939 exit();
940 }
941 }
942 /** 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.
943 */
944 private class MenuListenerImpl
945 implements MenuListener {
946 /** Called whenever a popup menu is hidden, but we don't care.
947 * @param e Some <strong>MenuEvent</strong> that we could care less about.
948 */
949 public void menuCanceled(MenuEvent e) {
950 }
951 /** Called whenever a menu header (ie button) becomes unselected, but we don't care.
952 * @param e Some <strong>MenuEvent</strong> that we could care less about.
953 */
954 public void menuDeselected(MenuEvent e) {
955 }
956 /** 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.
957 * @param e The <strong>MenuEvent</strong> whose source is checked.
958 */
959 public void menuSelected(MenuEvent e) {
960 if(e.getSource() == menu_bar.help) {
961 if(menu_bar.help.isSelected()) {
962 menu_bar.help.doClick(10);
963 }
964 }
965 }
966 }
967 private class TabUpdater
968 implements Runnable {
969 private boolean ready = false;
970 private int browse_pos = -1;
971 private int mirror_pos = -1;
972 private int config_pos = -1;
973 private int create_pos = -1;
974 private int export_pos = -1;
975 private int metaedit_pos = -1;
976 //private int preview_pos = -1;
977 private JTabbedPane tab_pane = null;
978 public TabUpdater(JTabbedPane tab_pane, boolean ready) {
979 this.ready = ready;
980 this.tab_pane = tab_pane;
981 browse_pos = tab_pane.indexOfComponent(browser_pane);
982 mirror_pos = tab_pane.indexOfComponent(mirror_pane);
983 metaedit_pos = tab_pane.indexOfComponent(metaedit_pane);
984 config_pos = tab_pane.indexOfComponent(config_pane);
985 export_pos = tab_pane.indexOfComponent(export_pane);
986 create_pos = tab_pane.indexOfComponent(create_pane);
987 //preview_pos = tab_pane.indexOfComponent(preview_pane);
988 }
989 public void run() {
990 if(browse_pos != -1) {
991 if(ready) {
992 tab_pane.setEnabledAt(browse_pos, Gatherer.config.get("workflow.browse", false));
993 }
994 else {
995 tab_pane.setEnabledAt(browse_pos, Gatherer.config.get("workflow.browse", true));
996 }
997 }
998 if(mirror_pos != -1) {
999 if(ready) {
1000 tab_pane.setEnabledAt(mirror_pos, Gatherer.config.get("workflow.mirror", false));
1001 }
1002 else {
1003 tab_pane.setEnabledAt(mirror_pos, Gatherer.config.get("workflow.mirror", true));
1004 }
1005 }
1006 if(metaedit_pos != -1) {
1007 tab_pane.setEnabledAt(metaedit_pos, ready && Gatherer.config.get("workflow.enrich", false));
1008 }
1009 if(config_pos != -1) {
1010 tab_pane.setEnabledAt(config_pos, ready && Gatherer.config.get("workflow.design", false) && Gatherer.config.getMode() > Configuration.ASSISTANT_MODE);
1011 }
1012 if(export_pos != -1) {
1013 tab_pane.setEnabledAt(export_pos, ready && Gatherer.config.get("workflow.export", false));
1014 }
1015 if(create_pos != -1) {
1016 tab_pane.setEnabledAt(create_pos, ready && Gatherer.config.get("workflow.create", false));
1017 }
1018// if(preview_pos != -1) {
1019// tab_pane.setEnabledAt(preview_pos, Gatherer.c_man != null && Gatherer.c_man.built() && Gatherer.config.get("workflow.preview", false));
1020// }
1021 }
1022 public void setReady(boolean ready) {
1023 this.ready = ready;
1024 }
1025 }
1026
1027 private class WorkflowUpdater
1028 implements Runnable {
1029 private boolean state;
1030 private String raw;
1031 public WorkflowUpdater(String raw, boolean state) {
1032 this.raw = raw;
1033 this.state = state;
1034 }
1035 public void run() {
1036 setTabEnabled(raw, state);
1037 }
1038 }
1039}
1040
1041
Note: See TracBrowser for help on using the repository browser.