/** *######################################################################### * * 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. *######################################################################## */ package org.greenstone.gatherer.gui; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.DebugStream; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.collection.CollectionTree; import org.greenstone.gatherer.collection.CollectionTreeNode; import org.greenstone.gatherer.file.FileNode; import org.greenstone.gatherer.file.FileOpenActionListener; import org.greenstone.gatherer.file.FileQueue; import org.greenstone.gatherer.file.FileSystemModel; import org.greenstone.gatherer.file.RecycleBin; import org.greenstone.gatherer.file.WorkspaceTree; import org.greenstone.gatherer.file.WorkspaceTreeNode; import org.greenstone.gatherer.gui.tree.DragTree; import org.greenstone.gatherer.gui.ExplodeMetadataPrompt; import org.greenstone.gatherer.util.DragComponent; import org.greenstone.gatherer.util.DragGroup; import org.greenstone.gatherer.util.JarTools; import org.greenstone.gatherer.util.TreeSynchronizer; import org.greenstone.gatherer.util.Utility; /** The collection pane is analogous with a file manager. It is there that the user chooses which files to include in their collection and what structure the file hierarchy should take. The later aspect is not important for the Greenstone Suite, but is usefull for grouping files for ease of metadata markup. The view essentially consists of two file trees, one denoting the entire source workspace and the other the files within your collection. The trees themselves have a title bar at the top, a filter control at the bottom, and are coloured to indicate activity (grey for disabled). The remainder of the screen is taken by a status area, to indicate current file job progress during copying etc, and three buttons for controlling features of the view. * @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.3 */ public class GatherPane extends JPanel implements ActionListener { /** The group encompassing all of the components available as drop targets for drag and drop actions. Required so that only one component renders the ghost and higlights itself as a target, which the other members are restored to their original, pristine, condition. */ private DragGroup group = null; /** The tree showing the files within the collection. */ private CollectionTree collection_tree = null; /** The threaded queue that handles the actually movement of files, so that the gui remains responsive. */ private FileQueue file_queue = null; /** The filter currently applied to the collection tree. */ private Filter collection_filter = null; /** The filter currently applied to the workspace tree. */ private Filter workspace_filter = null; /** The button used to cancel all pending file queue jobs. */ private JButton stop_action = null; /** The button used to create a new folder in the collection tree. */ private JButton new_folder = null; /** The label shown at the top of the collection tree. */ private JLabel collection_label = null; /** The label shown in the status area explaining the file apon which action is taking place. */ private JLabel filename_label = null; /** The label shown explaining the current state of the file queue thread. */ private JLabel status_label = null; /** The label at the top of the workspace tree. */ private JLabel workspace_label = null; /** The panel that contains the collection tree. */ private JPanel collection_pane = null; /** The panel that contains the various controls including the status area. */ private JPanel control_pane = null; /** The panel that contains the workspace tree. */ private JPanel workspace_pane = null; /** The scrollable area into which the collection tree is placed. */ private JScrollPane collection_scroll = null; /** The scrollable area into which the workspace tree is placed. */ private JScrollPane workspace_scroll = null; /** A split pane seperating the two trees, allowing for the screen real-estate for each to be changed. */ private JSplitPane tree_pane = null; /** Ensures that expansion and selection events between collection trees based on the same model are synchronized. */ private TreeSynchronizer collection_tree_sync = null; /** The minimum size a gui component can become. */ static private Dimension MIN_SIZE = new Dimension( 90, 90); /** The default size of the status area. */ static private Dimension STATUS_SIZE = new Dimension(450, 120); /** The initial size of the trees. */ static private Dimension TREE_SIZE = new Dimension(400, 430); /** The tree showing the available source workspace. */ public WorkspaceTree workspace_tree = null; /* Constructor. * @param tree_sync Ensures that expansion events between like trees are synchronized. * @see org.greenstone.gatherer.file.FileManager * @see org.greenstone.gatherer.file.FileQueue */ public GatherPane(TreeSynchronizer collection_tree_sync) { this.group = new DragGroup(); this.file_queue = Gatherer.f_man.getQueue(); this.collection_tree_sync = collection_tree_sync; // Create components. stop_action = new GLIButton(); stop_action.addActionListener(this); stop_action.setEnabled(false); stop_action.setMnemonic(KeyEvent.VK_S); file_queue.registerStopButton(stop_action); Dictionary.registerBoth(stop_action, "Collection.Stop", "Collection.Stop_Tooltip"); new_folder = new GLIButton(JarTools.getImage("folder.gif")); new_folder.addActionListener(this); new_folder.setEnabled(false); new_folder.setMinimumSize(MIN_SIZE); new_folder.setMnemonic(KeyEvent.VK_N); new_folder.setPreferredSize(MIN_SIZE); Dictionary.registerTooltip(new_folder, "Collection.New_Folder_Tooltip"); } /** Any implementation of ActionListener requires this method so that when an action is performed the appropriate effect can occur. In this case there are three valid possibilities. If the action occured on the recycle bin, then delete the current selection from the collection tree. If the action instead occured on the new folder button, then create a new folder under the current (single) selection in the collection tree. And finally if the cancel button was pressed, cancel the current, and remaining, jobs on the file queue. */ public void actionPerformed(ActionEvent event) { // If a user has clicked on the bin button directly remove whatever // files are selected in the active tree. if (event.getSource() == Gatherer.recycle_bin) { if (!Gatherer.recycle_bin.ignore()) { // Find the active tree (you've made selections in). DragTree tree = (DragTree) group.getActive(); // Fudge things a bit group.setSource(tree); // Determine the selection. TreePath paths[] = tree.getSelectionPaths(); if(paths != null) { FileNode[] source_nodes = new FileNode[paths.length]; for(int i = 0; i < paths.length; i++) { source_nodes[i] = (FileNode)(paths[i].getLastPathComponent()); } Gatherer.f_man.action(tree, source_nodes, Gatherer.recycle_bin, null); } } } // If a user has clicked on new_folder create a new folder under // whatever node is selected. else if(event.getSource() == new_folder && collection_tree != null) { int count = collection_tree.getSelectionCount(); boolean error = false; if(count == 1) { TreePath path = collection_tree.getSelectionPath(); CollectionTreeNode node = (CollectionTreeNode) path.getLastPathComponent(); if (node.getAllowsChildren()) { Gatherer.f_man.newFolder(collection_tree, node); } else { // try the parent CollectionTreeNode parent = (CollectionTreeNode) node.getParent(); if (parent!=null && parent.getAllowsChildren()) { Gatherer.f_man.newFolder(collection_tree, parent); } else { error = true; } } } else { error = true; } if(error) { // instead of an error, we now create a new folder at the root CollectionTreeNode node = (CollectionTreeNode) collection_tree.getModel().getRoot(); Gatherer.f_man.newFolder(collection_tree, node); } } else if(event.getSource() == stop_action) { file_queue.cancelAction(); } } /** Generates the pane on controls used to 'collect' files into the collection. Resposible for creating, connecting and laying out these controls. */ public void display() { // Workspace Tree workspace_pane = new JPanel(); workspace_pane.setMinimumSize(MIN_SIZE); workspace_pane.setPreferredSize(TREE_SIZE); workspace_pane.setSize(TREE_SIZE); workspace_label = new JLabel(); workspace_label.setOpaque(true); workspace_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false)); workspace_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false)); Dictionary.registerText(workspace_label, "Collection.Workspace"); workspace_tree = new WorkspaceTree(Utility.WORKSPACE_TREE); group.add(workspace_tree); workspace_scroll = new JScrollPane(workspace_tree); workspace_filter = Gatherer.g_man.getFilter(workspace_tree); workspace_filter.setBackground(Configuration.getColor("coloring.workspace_heading_background", false)); workspace_filter.setEditable(Configuration.getMode() > Configuration.LIBRARIAN_MODE); Dictionary.registerTooltip(workspace_filter.getComboBox(), "Collection.Filter_Tooltip"); // Collection Tree collection_pane = new JPanel(); collection_pane.setMinimumSize(MIN_SIZE); collection_pane.setPreferredSize(TREE_SIZE); collection_pane.setSize(TREE_SIZE); collection_label = new JLabel(); collection_label.setOpaque(true); Dictionary.registerText(collection_label, "Collection.No_Collection"); collection_tree = new CollectionTree(Utility.COLLECTION_TREE, Gatherer.c_man.getCollectionTreeModel(), true); collection_tree.setEnabled(Gatherer.c_man.getCollectionTreeModel() != null); group.add(collection_tree); collection_scroll = new JScrollPane(collection_tree); collection_filter = Gatherer.g_man.getFilter(collection_tree); collection_filter.setBackground(Configuration.getColor("coloring.collection_heading_background", false)); collection_filter.setEditable(Configuration.getMode() > Configuration.LIBRARIAN_MODE); Dictionary.registerTooltip(collection_filter.getComboBox(), "Collection.Filter_Tooltip"); tree_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); // Status pane control_pane = new JPanel(); JPanel inner_pane = new JPanel(); inner_pane.setSize(STATUS_SIZE); JPanel file_pane = new JPanel(); JPanel progress_pane = new JPanel(); JLabel file_status = file_queue.getFileStatus(); JProgressBar progress_bar = file_queue.getProgressBar(); JPanel button_pane = new JPanel(); RecycleBin recycle_bin = Gatherer.recycle_bin; recycle_bin.addActionListener(this); recycle_bin.setMinimumSize(MIN_SIZE); recycle_bin.setPreferredSize(MIN_SIZE); Dictionary.registerTooltip(recycle_bin, "Collection.Delete_Tooltip"); group.add(recycle_bin); // Layout Components. workspace_pane.setLayout(new BorderLayout()); workspace_pane.add(workspace_label, BorderLayout.NORTH); workspace_pane.add(workspace_scroll, BorderLayout.CENTER); workspace_pane.add(workspace_filter, BorderLayout.SOUTH); collection_pane.setLayout(new BorderLayout()); collection_pane.add(collection_label, BorderLayout.NORTH); collection_pane.add(collection_scroll, BorderLayout.CENTER); collection_pane.add(collection_filter, BorderLayout.SOUTH); tree_pane.add(workspace_pane, JSplitPane.LEFT); tree_pane.add(collection_pane, JSplitPane.RIGHT); tree_pane.setDividerLocation(TREE_SIZE.width - 10); file_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); file_pane.setLayout(new BorderLayout()); file_pane.add(file_status, BorderLayout.CENTER); file_pane.add(stop_action, BorderLayout.EAST); progress_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); progress_pane.setLayout(new BorderLayout()); progress_pane.add(progress_bar, BorderLayout.CENTER); inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,10,10,10), BorderFactory.createLoweredBevelBorder())); inner_pane.setLayout(new GridLayout(2,1)); inner_pane.add(file_pane); inner_pane.add(progress_pane); button_pane.add(new_folder); button_pane.add(recycle_bin); control_pane.setLayout(new BorderLayout()); control_pane.add(inner_pane, BorderLayout.CENTER); control_pane.add(button_pane, BorderLayout.EAST); this.setLayout(new BorderLayout()); this.add(tree_pane, BorderLayout.CENTER); this.add(control_pane, BorderLayout.SOUTH); } /** Called to inform this control panel that it has just gained focus as an effect of the user clicking on its tab. */ public void gainFocus() { // Update the meta-audit view to show the current selection, if any. Gatherer.g_man.meta_audit.setRecords(getCollectionTreeSelection()); } /** Retrieve a list of the currently selected file records in the collection tree. */ private CollectionTreeNode[] getCollectionTreeSelection() { TreePath paths[] = collection_tree.getSelectionPaths(); CollectionTreeNode records[] = null; if (paths != null) { records = new CollectionTreeNode[paths.length]; for (int i = 0; i < records.length; i++) { records[i] = (CollectionTreeNode) paths[i].getLastPathComponent(); } } return records; } /** Called whenever the detail mode changes to ensure the filters are at an appropriate level (ie only editable by those that understand regular expression matching) * @param mode the mode level as an int */ public void modeChanged(int mode) { collection_filter.setEditable(mode > Configuration.LIBRARIAN_MODE); workspace_filter.setEditable(mode > Configuration.LIBRARIAN_MODE); } /** Refresh this pane, depending on what has just happened (refresh_reason). */ public void refresh(int refresh_reason, boolean collection_loaded) { if (collection_loaded) { // Update collection label Dictionary.registerText(collection_label, "Collection.Collection"); collection_label.setBackground(Configuration.getColor("coloring.collection_heading_background", false)); collection_label.setForeground(Configuration.getColor("coloring.collection_heading_foreground", false)); // Update collection tree if (refresh_reason == Gatherer.COLLECTION_OPENED) { collection_tree.setModel(Gatherer.c_man.getCollectionTreeModel()); } // Update collection filter collection_filter.setBackground(Configuration.getColor("coloring.collection_heading_background", false)); } else { // Update collection label String[] args = new String[1]; args[0] = Dictionary.get("Collection.No_Collection"); Dictionary.registerText(collection_label, "Collection.Collection", args); collection_label.setBackground(Color.lightGray); collection_label.setForeground(Color.black); // Update collection tree collection_tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Error"))); // Update collection filter collection_filter.setBackground(Color.lightGray); } // Enable or disable the controls workspace_tree.setEnabled(true); collection_tree.setEnabled(collection_loaded); collection_filter.setEnabled(collection_loaded); new_folder.setEnabled(collection_loaded); // Ensure that this collection tree view is synchronized with all others collection_tree_sync.add(collection_tree); } public void refreshCollectionTree(int refresh_reason) { collection_tree.refresh(null); } public void refreshWorkspaceTree(int refresh_reason) { workspace_tree.refresh(refresh_reason); } }