package org.greenstone.gatherer.gui; /** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * *

* * Author: John Thompson, Greenstone Digital Library, University of Waikato * *

* * Copyright (C) 1999 New Zealand Digital Library Project * *

* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * *

* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * *

* * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; import java.io.*; import java.lang.*; import java.net.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.text.*; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.collection.Collection; import org.greenstone.gatherer.collection.DeleteCollectionPrompt; import org.greenstone.gatherer.collection.LoadCollectionBox; import org.greenstone.gatherer.collection.SaveCollectionBox; import org.greenstone.gatherer.file.FileNode; import org.greenstone.gatherer.file.FileOpenActionListener; import org.greenstone.gatherer.gui.AboutDialog; import org.greenstone.gatherer.gui.BrowsingPane; import org.greenstone.gatherer.gui.CollectionPane; import org.greenstone.gatherer.gui.CreatePane; import org.greenstone.gatherer.gui.Filter; import org.greenstone.gatherer.gui.GConfigPane; import org.greenstone.gatherer.gui.MenuBar; import org.greenstone.gatherer.gui.MetaEditPane; import org.greenstone.gatherer.gui.MirrorPane; import org.greenstone.gatherer.gui.OpenCollectionDialog; import org.greenstone.gatherer.gui.OptionsBox; import org.greenstone.gatherer.gui.Preferences; import org.greenstone.gatherer.gui.PreviewPane; import org.greenstone.gatherer.gui.messages.MessagePane; import org.greenstone.gatherer.gui.metaaudit.MetaAuditFrame; import org.greenstone.gatherer.gui.tree.DragTree; import org.greenstone.gatherer.help.HelpFrame; import org.greenstone.gatherer.msm.ElementWrapper; import org.greenstone.gatherer.msm.Metadata; import org.greenstone.gatherer.sarm.SearchAndReplace; import org.greenstone.gatherer.shell.GShell; import org.greenstone.gatherer.util.TreeSynchronizer; import org.greenstone.gatherer.util.Utility; import org.greenstone.gatherer.valuetree.GValueNode; /** 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. */ public class GUIManager extends JFrame implements ActionListener, ChangeListener { /** The browsing pane behaves much like an internet browser, or at least will some day. */ public BrowsingPane browser_pane = null; /** The collection pane is more like a file manager where you drag files from one tree to another. */ public CollectionPane collection_pane = null; /** The create pane contains scripting options for importing and building collections into libraries. */ public CreatePane create_pane = null; public FileOpenActionListener foa_listener = new FileOpenActionListener(); /** The configuration pane allows you to edit the design of the library in terms of the collection configuration file. */ public GConfigPane config_pane = null; /** A reference to the currently instantiated help window, if any. */ public HelpFrame help = null; /** The menu bar. */ public MenuBar menu_bar = null; /** The message pane is optional and contains the log of messages sent. */ public MessagePane message_pane = null; public MetaAuditFrame meta_audit; /** The metaedit pane is used to assign, edit and remove metadata from files within the collection. */ public MetaEditPane metaedit_pane = null; /** The mirror pane contains controls for mirroring interent sites. */ public MirrorPane mirror_pane = null; /** The preview pane contains a preview of your build collection. */ public PreviewPane preview_pane = null; /** Are certain panes currently locked? */ private boolean locked = false; /** The size of the Gatherer window. */ private Dimension size = null; /** The filters used to dynamically filter the trees at user request. */ private HashMap filters = new HashMap(); /** The panel within the window that other components are placed on. */ private JPanel content_pane = null; /** The dummy export pane. */ private JPanel export_pane = new JPanel(); /** The last view pane selected. */ private JPanel previous_pane; /** The main tab pane containing the different views, available here to trap view change events. */ private JTabbedPane tab_pane = null; /** A reference to any existing search and replace module/dialog. */ private SearchAndReplace sar = null; /** A threaded tab changer to try and avoid NPE on exit. */ private TabUpdater tab_updater = null; /** 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. * @see org.greenstone.gatherer.Dictionary */ private ThreadGroup thread_group = null; /** Ensures that expansion events between like collection trees are synchronized. */ private TreeSynchronizer collection_tree_sync = null; /** Ensures that expansion events between like workspace trees are synchronized. */ private TreeSynchronizer workspace_tree_sync = null; /**Constructor. Enable window events and arranges all other components. * @param size The intial Dimension of the screen. * @param graphic The default GraphicsConfiguration for this platform. */ public GUIManager(Dimension size) { super(); // Initialization this.help = new HelpFrame(); this.size = size; this.collection_tree_sync = new TreeSynchronizer(); this.meta_audit = new MetaAuditFrame(collection_tree_sync, null); this.workspace_tree_sync = new TreeSynchronizer(); // Make the Tool tip hang around for a rediculous amount of time. ToolTipManager.sharedInstance().setDismissDelay(10000); // 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. Thread bob = new Thread(); thread_group = bob.getThreadGroup(); // Set up some other UI stuff. (fonts handled in Gatherer.main()) UIManager.put("FileChooser.lookInLabelText", Gatherer.dictionary.get("SaveCollectionBox.Look_In")); UIManager.put("FileChooser.filesOfTypeLabelText", Gatherer.dictionary.get("SaveCollectionBox.Files_Of_Type")); UIManager.put("FileChooser.fileNameLabelText", Gatherer.dictionary.get("SaveCollectionBox.File_Name")); } /** Any implementation of ActionListener 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. * @param event An ActionEvent containing information about the action that has occured. */ public void actionPerformed(ActionEvent event) { boolean cont = true; Object esrc = event.getSource(); // ************* // File Options. // ************* if(esrc == menu_bar.file_associations) { Gatherer.assoc_man.edit(); } else if(esrc == menu_bar.file_close) { if(!Gatherer.c_man.saved()) { cont = showSaveCollectionBox(true, false); } if(cont) { tab_pane.setSelectedComponent(collection_pane); } } else if(esrc == menu_bar.file_delete) { DeleteCollectionPrompt dcp = new DeleteCollectionPrompt(); dcp.display(); dcp.destroy(); dcp = null; System.gc(); } else if(esrc == menu_bar.file_exit) { menu_bar.exit(); exit(); } else if(esrc == menu_bar.file_new) { showNewCollectionPrompt(); } else if(esrc == menu_bar.file_open) { // if(!Gatherer.c_man.saved()) { // cont = showSaveCollectionBox(false, false); // } // if(cont) { //if(! showLoadCollectionBox(); //) { //collectionChanged(false); //} // } } else if(esrc == menu_bar.file_options) { new Preferences(); } else if(esrc == menu_bar.file_save) { Gatherer.c_man.saveCollection(false, false); } else if(esrc == menu_bar.file_save_as) { String name = JOptionPane.showInputDialog(this, "Enter new collection filename."); if(name != null) { Gatherer.c_man.saveCollectionAs(name); } } // ************* // Edit Options. // ************* else if(esrc == menu_bar.edit_copy) { try { KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); // Get the component with selected text as a JTextComponent JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner(); text.copy(); } catch (Exception cce) { // If the component is not a text component ignore the copy command Gatherer.println(cce.toString()); } } else if(esrc == menu_bar.edit_cut) { try { KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); // Get the component with selected text as a JTextComponent JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner(); // Cut the text to the clipboard text.cut(); } catch (ClassCastException cce) { // If the component is not a text component ignore the cut command Gatherer.println(cce.toString()); } } else if(esrc == menu_bar.edit_paste) { try { KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); // Get the component with selected text as a JTextComponent JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner(); // Cut the text to the clipboard text.paste(); } catch (ClassCastException cce) { // If the component is not a text component ignore the paste command Gatherer.println(cce.toString()); } } else if(esrc == menu_bar.edit_search) { if(sar != null) { sar.dispose(); } sar = new SearchAndReplace(false); } else if(esrc == menu_bar.edit_replace) { if(sar != null) { sar.dispose(); } sar = new SearchAndReplace(true); } // ************* // Tools Options. // ************* else if(esrc == menu_bar.tools_size) { FileNode records[] = metaedit_pane.getSelectedNode(); if(records != null && records.length > 0) { ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getMetadata(records[0].getFile()); if(metadatum.size() >= 4) { Metadata metadata = (Metadata) metadatum.get(0); ElementWrapper ew = metadata.getElement(); int SIZE = 5000; Object[] array = new Object[SIZE]; Runtime.getRuntime().gc(); long start = Runtime.getRuntime().freeMemory(); for (int i = 0; i < SIZE; i++) { array[i] = ew.copy(); } Runtime.getRuntime().gc(); long end = Runtime.getRuntime().freeMemory(); long difference = (( start - end ) / SIZE); ///ystem.out.println(difference + " bytes used." ); } } } // ************* // Help Options. // ************* else if(esrc == menu_bar.help_about) { new AboutDialog(this); } else if(esrc == menu_bar.help_browse) { help.setView("3.0"); } else if(esrc == menu_bar.help_build) { help.setView("8.0"); } else if(esrc == menu_bar.help_collect) { help.setView("5.0"); } else if(esrc == menu_bar.help_design) { help.setView("7.0"); } else if(esrc == menu_bar.help_general) { help.setView(""); } else if(esrc == menu_bar.help_metaedit) { help.setView("6.0"); } else if(esrc == menu_bar.help_mirror) { help.setView("4.0"); } else if(esrc == menu_bar.help_preview) { help.setView("9.0"); } // ***************** // Metadata Options. // ***************** else if(esrc == menu_bar.metadata_add) { Gatherer.c_man.getCollection().msm.importMDS(); } else if(esrc == menu_bar.metadata_edit) { showEditMetadataBox(); } else if(esrc == menu_bar.metadata_export) { Gatherer.c_man.getCollection().msm.exportMDS(); } else if(esrc == menu_bar.metadata_view) { showMetaAuditBox(); } else if(esrc == menu_bar.tools_log) { showLogBox(); } } /** 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. */ public void afterDisplay() { if(Gatherer.config.get("workflow.mirror", true)) { browser_pane.afterDisplay(); } metaedit_pane.afterDisplay(); } /** 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. * @param ready true if the collection is ready for editing, false otherwise. */ public void collectionChanged(final boolean ready) { if(Gatherer.config.get("workflow.mirror", true)) { mirror_pane.collectionChanged(ready); } menu_bar.collectionChanged(ready); // Inform the menu bar that the collections changed. collection_pane.collectionChanged(ready); // Used to update the collection workspace. metaedit_pane.collectionChanged(ready); // Very important that metaedit pane shows current collection and is listening to latest msm. config_pane.collectionChanged(ready); // Also important config pane is listening to latest msm. create_pane.collectionChanged(ready); // Used to indicate a new BuildOptions model should be loaded. preview_pane.collectionChanged(ready); // preview should know when teh coll has changed so it can reload the home page // Force tree model updates. Gatherer.c_man.refreshTrees(); if(!locked) { // Now enable tabs as necessary. Do this on event queue to prevent crazy NPEs if(tab_updater == null) { tab_updater = new TabUpdater(tab_pane, ready); } else { tab_updater.setReady(ready); } SwingUtilities.invokeLater(tab_updater); } // Finally display the collection name in the title bar. if(ready) { this.setTitle(Utility.PROGRAM_NAME + ":\"" + Gatherer.c_man.getCollection().getTitle() + "\""); } else { this.setTitle(Utility.PROGRAM_NAME + ": " + get("Collection.No_Collection")); } // Now is a good time to force a garbage collect. ///ystem.err.println("Calling garbage collection."); System.gc(); } /** Enabled events on the window to be trapped, creates all the visual components, then builds the tab and other layouts. */ public void display() { content_pane = (JPanel) this.getContentPane(); // Enable window-type events to be fired. enableEvents(AWTEvent.WINDOW_EVENT_MASK); // Initialise and layout sub-components, plus other window dressing. try { this.setSize(size); if(Gatherer.c_man.ready()) { this.setTitle(Utility.PROGRAM_NAME + ":\"" + Gatherer.c_man.getCollection().getTitle() + "\""); } else { this.setTitle(Utility.PROGRAM_NAME + ": " + get("Collection.No_Collection")); } // Pretty corner icon this.setIconImage(Utility.getImage("gatherer_small.gif").getImage()); // BorderLayout for the main screen. I'll try my best to avoid t // hese in subcomponents as they're space greedy. content_pane.setLayout(new BorderLayout()); // Create the menu-bar and stick it up the top. menu_bar = new MenuBar(new MenuListenerImpl()); content_pane.add(menu_bar, BorderLayout.NORTH); // Create the tabbed pane and plop it in the center where it will // expand to consume all available space like any good gas would. tab_pane = new JTabbedPane(); tab_pane.addChangeListener(this); tab_pane.setFont(Gatherer.config.getFont("general.font", false)); // May have to play with the order in which tabs are added. if(Gatherer.config.get("workflow.browse", true)) { browser_pane = new BrowsingPane(); tab_pane.addTab(get("Browser"), Utility.getImage("browsing.gif"), browser_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(browser_pane), Gatherer.config.get("workflow.browse", false)); } if(Gatherer.config.get("workflow.mirror", true)) { mirror_pane = new MirrorPane(workspace_tree_sync); mirror_pane.display(); tab_pane.addTab(get("Mirroring"), Utility.getImage("mirroring.gif"), mirror_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(mirror_pane), Gatherer.config.get("workflow.mirror", false)); } if(Gatherer.config.get("workflow.gather", true)) { collection_pane = new CollectionPane(workspace_tree_sync, collection_tree_sync); collection_pane.display(); tab_pane.addTab(get("Collection"), Utility.getImage("collection.gif"), collection_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(collection_pane), Gatherer.config.get("workflow.gather", false)); } if(Gatherer.config.get("workflow.enrich", true)) { metaedit_pane = new MetaEditPane(collection_tree_sync); metaedit_pane.display(); tab_pane.addTab(get("MetaEdit"), Utility.getImage("metaedit.gif"), metaedit_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(metaedit_pane), false); } if(Gatherer.config.get("workflow.design", true)) { config_pane = new GConfigPane(); config_pane.display(); tab_pane.addTab(get("Build"), Utility.getImage("build.gif"), config_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(config_pane), false); } if(Gatherer.config.get("workflow.export", true)) { tab_pane.addTab(get("Export"), Utility.getImage("export.gif"), export_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(export_pane), false); } if(Gatherer.config.get("workflow.create", true)) { create_pane = new CreatePane(); create_pane.display(); tab_pane.addTab(get("Create"), Utility.getImage("build session.gif"), create_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(create_pane), false); } if(Gatherer.config.get("workflow.preview", true)) { preview_pane = new PreviewPane(); preview_pane.display(); tab_pane.addTab(get("Preview"), Utility.getImage("final.gif"), preview_pane); tab_pane.setEnabledAt(tab_pane.indexOfComponent(preview_pane), false); } // Find the first tab that is enabled and select that. boolean found = false; for(int i = 0; !found && i < tab_pane.getTabCount(); i++) { if(tab_pane.isEnabledAt(i)) { tab_pane.setSelectedIndex(i); found = true; } } content_pane.add(tab_pane, BorderLayout.CENTER); // Drive a sessionReady event to update all controls to reflect current collection status. collectionChanged(Gatherer.c_man.ready()); } catch (Exception e) { Gatherer.printStackTrace(e); // The GUI failing to build is a app killer e.printStackTrace(); System.exit(1); } } /** 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. */ public void exit() { boolean cont = true; if(Gatherer.c_man.ready() && !Gatherer.c_man.saved()) { cont = showSaveCollectionBox(false, true); } else { help.destroy(); help = null; Gatherer.self.exit(); } } /** Retrieve the filter, or if one already exists, spawn a linked copy. */ public Filter getFilter(DragTree tree) { Filter filter = (Filter) filters.get(tree.getModel()); if(filter == null) { filter = new Filter(tree, null); filters.put(tree.getModel(), filter); return filter; } return filter.spawn(tree); } public Component getSelectedView() { return tab_pane.getSelectedComponent(); } /** 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. */ public void lockCollection(boolean import_stage, boolean lock) { locked = lock; if(import_stage) { int collection_pos = tab_pane.indexOfComponent(collection_pane); int metaedit_pos = tab_pane.indexOfComponent(metaedit_pane); int config_pos = tab_pane.indexOfComponent(config_pane); tab_pane.setEnabledAt(collection_pos, !lock); tab_pane.setEnabledAt(metaedit_pos, !lock); tab_pane.setEnabledAt(config_pos, !lock); } else { int config_pos = tab_pane.indexOfComponent(config_pane); tab_pane.setEnabledAt(config_pos, !lock); } } public void refreshTrees() { collection_pane.refreshTrees(); //metaedit_pane.refreshTrees(); } /** Allows the system to programatically set the selected tab. * @param component The view you wish to make visable in the tab pane as a Component. */ public void setSelectedView(Component component) { tab_pane.setSelectedComponent(component); } /** Specifies whether a certain tab is enabled or not. */ public void setTabEnabled(String rawname, boolean state) { // Retrieve the dictionary based name. String name = get(rawname); int index = tab_pane.indexOfTab(name); // Of course we may not have this tab available. if(index != -1) { // Some tabs are also dependant on if a collection is ready Component component = tab_pane.getComponentAt(index); if(component == preview_pane) { tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready() && Gatherer.c_man.built()); } else if(component == metaedit_pane || component == config_pane || component == export_pane || component == create_pane) { tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready()); } else { tab_pane.setEnabledAt(index, state); } // If this was the currently selected tab and it is now disabled, change the view to the first enabled tab. if(tab_pane.getSelectedIndex() == index && !state) { boolean found = false; for(int i = 0; !found && i < tab_pane.getTabCount(); i++) { if(tab_pane.isEnabledAt(i)) { tab_pane.setSelectedIndex(i); found = true; } } // If there are no tabs enabled, which should be impossible, then select the first tab if(!found) { tab_pane.setSelectedIndex(0); } } } } /** 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. */ public void showEditMetadataBox() { if(Gatherer.c_man.getCollection() != null) { Gatherer.c_man.getCollection().msm.editMDS(); } } /** When the load collection option is choosen this method is called to produce the modal file load prompt. */ public boolean showLoadCollectionBox() { boolean result = false; //LoadCollectionBox load_collection_box = new LoadCollectionBox(); File file; if(Gatherer.config.gsdl_path != null) { file = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)); } else { file = new File(Utility.BASE_DIR); } OpenCollectionDialog chooser = new OpenCollectionDialog(file); String filename = chooser.getFileName(); // User can cancel action. if(filename != null) { // If there is already a collection open, save and close it. if(Gatherer.c_man.ready()) { showSaveCollectionBox(true, false); // Wait until it is closed. try { synchronized(this) { while(Gatherer.c_man.reallyReady()) { wait(10); } } } catch(Exception error) { Gatherer.println("Exception: " + error); Gatherer.printStackTrace(error); } } result = Gatherer.c_man.loadCollection(filename); } return result; } /** When called this method causes the Log class in Gatherer to display a nice dialog box which contains the log. */ public void showLogBox() { Gatherer.log.display(); } /** 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. */ public void showMetaAuditBox() { wait(true); meta_audit.display(); wait(false); } /** This method is used to open the new collection box on the screen. */ public void showNewCollectionPrompt() { NewCollectionMetadataPrompt ncm_prompt = null; // Create the collection details prompt from new collection prompt NewCollectionDetailsPrompt ncd_prompt = new NewCollectionDetailsPrompt(); // If no previous collection was indicated as a model design, then show the metadata selection prompt from new collection prompt if(!ncd_prompt.isCancelled() && (ncd_prompt.getBase() == null)) { ncm_prompt = new NewCollectionMetadataPrompt(); } // Create the new collection (if not cancelled) in a new thread. if(!ncd_prompt.isCancelled() && (ncm_prompt == null || !ncm_prompt.isCancelled())) { // If there is already a collection open, save and close it. if(Gatherer.c_man.ready()) { showSaveCollectionBox(true, false); // Wait until it is closed. try { synchronized(this) { while(Gatherer.c_man.reallyReady()) { wait(10); } } } catch(Exception error) { Gatherer.println("Exception: " + error); Gatherer.printStackTrace(error); } } // Create new collection. CreationTask task = new CreationTask(ncd_prompt, ncm_prompt); // SwingUtilities.invokeLater(task); task.start(); // Close prompt. } // Done ncd_prompt = null; ncm_prompt = null; } private class CreationTask extends Thread { private NewCollectionDetailsPrompt ncd_prompt = null; private NewCollectionMetadataPrompt ncm_prompt = null; public CreationTask(NewCollectionDetailsPrompt ncd_prompt, NewCollectionMetadataPrompt ncm_prompt) { this.ncd_prompt = ncd_prompt; this.ncm_prompt = ncm_prompt; } public void run() { // System.err.println("Running CreationTask..."); if(ncm_prompt == null) { Gatherer.c_man.createCollection(ncd_prompt.getDescription(), ncd_prompt.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), ncd_prompt.getBase(), null); } else { Gatherer.c_man.createCollection(ncd_prompt.getDescription(), ncd_prompt.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), null, ncm_prompt.getSets()); } ncd_prompt.dispose(); ncd_prompt = null; if(ncm_prompt != null) { ncm_prompt.dispose(); ncm_prompt = null; } } } /** This method is used to open the options box on the screen. */ public void showOptionsBox() { new OptionsBox(); } /** This method is used to open the save collection box/prompt on the screen. * @return A boolean which is true if the collection was saved successfully, false otherwise. */ public boolean showSaveCollectionBox(boolean close_after, boolean exit_after) { //SaveCollectionBox save_collection_box = new SaveCollectionBox(); //Rectangle bounds = save_collection_box.getBounds(); //int result = save_collection_box.getUserOption(Gatherer.c_man.getCollection().getName()); //switch(result) { //case SaveCollectionBox.SAVE_YES: Gatherer.c_man.saveCollection(close_after, exit_after); // Wait until it is closed. try { synchronized(this) { while(Gatherer.c_man.reallyReady()) { wait(10); } } } catch(Exception error) { Gatherer.println("Exception: " + error); Gatherer.printStackTrace(error); } //content_pane.paintImmediately(bounds); return true; //case SaveCollectionBox.SAVE_NO: // Close collection. // if(close_after) { // tab_pane.setSelectedComponent(collection_pane); // Gatherer.c_man.closeCollection(); // } // if(exit_after) { // Gatherer.self.exit(); // } // return true; //default: // return false; //} } /** 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. * @param event A ChangeEvent containing information about the event that fired this call. */ public void stateChanged(ChangeEvent event) { if(previous_pane != null) { if(previous_pane == create_pane) { create_pane.loseFocus(); } } // "View assigned metadata" menu item is disabled by default menu_bar.metadata_view.setCanEnable(false); menu_bar.setMetaAuditSuffix(null); menu_bar.tabSelected(tab_pane.getSelectedIndex()); if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(collection_pane)) { collection_pane.gainFocus(); // "View assigned metadata" menu item is enabled for the "Gather" pane menu_bar.metadata_view.setCanEnable(true); } else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(metaedit_pane)) { metaedit_pane.gainFocus(); // "View assigned metadata" menu item is enabled for the "Enrich" pane menu_bar.metadata_view.setCanEnable(true); } else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(config_pane)) { config_pane.gainFocus(); } else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(create_pane)) { create_pane.gainFocus(); } else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(preview_pane)) { config_pane.saveConfiguration(); preview_pane.gainFocus(); } previous_pane = (JPanel) tab_pane.getSelectedComponent(); } public void wait(boolean waiting) { Component glass_pane = getGlassPane(); if(waiting) { // Show wait cursor. glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); glass_pane.setVisible(true); } else { // Hide wait cursor. glass_pane.setVisible(false); glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } glass_pane = null; } public void workflowUpdate(String raw, boolean state) { WorkflowUpdater task = new WorkflowUpdater(raw, state); SwingUtilities.invokeLater(task); task = null; } /** Retrieves a phrase from the Dictionary based on the key. * @param key A String uniquely identifying a phrase from the Dictionary. * @return The desired phrase as a String. * @see org.greenstone.gatherer.Dictionary */ private String get(String key) { return get(key, null); } /** Retrieves a phrase from the Dictionary based on the key and including the arguments. * @param key A String uniquely identifying a phrase from the Dictionary. * @param args A String[] of arguments available to be inserted into the phrase. * @return The desired phrase as a String. * @see org.greenstone.gatherer.Dictionary */ private String get(String key, String args[]) { if(key.indexOf('.') == -1) { key = "GUI." + key; } return Gatherer.dictionary.get(key, args); } /** 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. * @return true if we should wait for a thread, false if it is safe to continue. */ private boolean waitForThread() { Thread active[] = new Thread[thread_group.activeCount()]; int size = thread_group.enumerate(active); for(int i = 0; i < size; i++) { if(active[i].getName().equals(GShell.GSHELL_BUILD) || active[i].getName().equals(GShell.GSHELL_IMPORT) || active[i].getName().equals(GShell.GSHELL_NEW)) { return true; } } return false; } /**Overridden from JFrame so we can exit safely when window is closed (or destroyed). * @param event A WindowEvent containing information about the event that fred this call. */ protected void processWindowEvent(WindowEvent event) { if(event.getID() == WindowEvent.WINDOW_CLOSING) { exit(); } } /** 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. */ private class MenuListenerImpl implements MenuListener { /** Called whenever a popup menu is hidden, but we don't care. * @param e Some MenuEvent that we could care less about. */ public void menuCanceled(MenuEvent e) { } /** Called whenever a menu header (ie button) becomes unselected, but we don't care. * @param e Some MenuEvent that we could care less about. */ public void menuDeselected(MenuEvent e) { } /** 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. * @param e The MenuEvent whose source is checked. */ public void menuSelected(MenuEvent e) { if(e.getSource() == menu_bar.help) { if(menu_bar.help.isSelected()) { menu_bar.help.doClick(10); } } } } private class TabUpdater implements Runnable { private boolean ready = false; private int browse_pos = -1; private int mirror_pos = -1; private int config_pos = -1; private int create_pos = -1; private int export_pos = -1; private int metaedit_pos = -1; private int preview_pos = -1; private JTabbedPane tab_pane = null; public TabUpdater(JTabbedPane tab_pane, boolean ready) { this.ready = ready; this.tab_pane = tab_pane; browse_pos = tab_pane.indexOfComponent(browser_pane); mirror_pos = tab_pane.indexOfComponent(mirror_pane); metaedit_pos = tab_pane.indexOfComponent(metaedit_pane); config_pos = tab_pane.indexOfComponent(config_pane); export_pos = tab_pane.indexOfComponent(export_pane); create_pos = tab_pane.indexOfComponent(create_pane); preview_pos = tab_pane.indexOfComponent(preview_pane); } public void run() { if(browse_pos != -1) { if(ready) { tab_pane.setEnabledAt(browse_pos, Gatherer.config.get("workflow.browse", false)); } else { tab_pane.setEnabledAt(browse_pos, Gatherer.config.get("workflow.browse", true)); } } if(mirror_pos != -1) { if(ready) { tab_pane.setEnabledAt(mirror_pos, Gatherer.config.get("workflow.mirror", false)); } else { tab_pane.setEnabledAt(mirror_pos, Gatherer.config.get("workflow.mirror", true)); } } if(metaedit_pos != -1) { tab_pane.setEnabledAt(metaedit_pos, ready && Gatherer.config.get("workflow.enrich", false)); } if(config_pos != -1) { tab_pane.setEnabledAt(config_pos, ready && Gatherer.config.get("workflow.design", false)); } if(export_pos != -1) { tab_pane.setEnabledAt(export_pos, ready && Gatherer.config.get("workflow.export", false)); } if(create_pos != -1) { tab_pane.setEnabledAt(create_pos, ready && Gatherer.config.get("workflow.create", false)); } if(preview_pos != -1) { tab_pane.setEnabledAt(preview_pos, Gatherer.c_man != null && Gatherer.c_man.built() && Gatherer.config.get("workflow.preview", false)); } } public void setReady(boolean ready) { this.ready = ready; } } private class WorkflowUpdater implements Runnable { private boolean state; private String raw; public WorkflowUpdater(String raw, boolean state) { this.raw = raw; this.state = state; } public void run() { setTabEnabled(raw, state); } } }