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

Last change on this file since 8351 was 8351, checked in by kjdon, 20 years ago

removed some print statements

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