source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/gui/GatherPane.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 18.6 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import java.util.*;
43import javax.swing.*;
44import javax.swing.event.*;
45import javax.swing.tree.*;
46import org.greenstone.gatherer.Configuration;
47import org.greenstone.gatherer.DebugStream;
48import org.greenstone.gatherer.Dictionary;
49import org.greenstone.gatherer.Gatherer;
50import org.greenstone.gatherer.collection.CollectionTree;
51import org.greenstone.gatherer.collection.CollectionTreeNode;
52import org.greenstone.gatherer.file.FileNode;
53import org.greenstone.gatherer.file.FileOpenActionListener;
54import org.greenstone.gatherer.file.FileQueue;
55import org.greenstone.gatherer.file.FileSystemModel;
56import org.greenstone.gatherer.file.RecycleBin;
57import org.greenstone.gatherer.file.WorkspaceTree;
58import org.greenstone.gatherer.file.WorkspaceTreeNode;
59import org.greenstone.gatherer.gui.tree.DragTree;
60import org.greenstone.gatherer.util.DragComponent;
61import org.greenstone.gatherer.util.DragGroup;
62import org.greenstone.gatherer.util.JarTools;
63import org.greenstone.gatherer.util.Utility;
64
65
66/** 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.
67 * @author John Thompson, Greenstone Digital Library, University of Waikato
68 * @version 2.3
69 */
70public class GatherPane
71 extends JPanel
72 implements ActionListener
73{
74 private CardLayout card_layout = null;
75 private JPanel card_pane = null;
76 /** The name of the panel containing the "collection loaded" (collection tree) card. */
77 private String COLLECTION_LOADED_CARD = "";
78 /** The name of the panel containing the "no collection loaded" placeholder */
79 private String NO_COLLECTION_LOADED_CARD = "No collection loaded";
80 /** 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. */
81 private DragGroup group = null;
82 /** The tree showing the files within the collection. */
83 private CollectionTree collection_tree = null;
84 /** The threaded queue that handles the actually movement of files, so that the gui remains responsive. */
85 private FileQueue file_queue = null;
86 /** The filter currently applied to the collection tree. */
87 private Filter collection_filter = null;
88 /** The filter currently applied to the workspace tree. */
89 private Filter workspace_filter = null;
90 /** The button used to cancel all pending file queue jobs. */
91 private JButton stop_action = null;
92 /** The button used to create a new folder in the collection tree. */
93 private JButton new_folder = null;
94 /** The label shown at the top of the collection tree. */
95 private JLabel collection_label = null;
96 /** The label shown in the status area explaining the file apon which action is taking place. */
97 private JLabel filename_label = null;
98 /** The label shown explaining the current state of the file queue thread. */
99 private JLabel status_label = null;
100 /** The label at the top of the workspace tree. */
101 private JLabel workspace_label = null;
102 /** The panel that contains the collection tree. */
103 private JPanel collection_pane = null;
104 /** The panel that contains the various controls including the status area. */
105 private JPanel control_pane = null;
106 /** The panel that contains the workspace tree. */
107 private JPanel workspace_pane = null;
108 /** The scrollable area into which the collection tree is placed. */
109 private JScrollPane collection_scroll = null;
110 /** The scrollable area into which the workspace tree is placed. */
111 private JScrollPane workspace_scroll = null;
112 /** A split pane seperating the two trees, allowing for the screen real-estate for each to be changed. */
113 private JSplitPane tree_pane = null;
114 /** The minimum size a gui component can become. */
115 static private Dimension MIN_SIZE = new Dimension( 90, 90);
116 /** The default size of the status area. */
117 static private Dimension STATUS_SIZE = new Dimension(450, 120);
118 /** The initial size of the trees. */
119 static private Dimension TREE_SIZE = new Dimension(400, 430);
120
121 /** The tree showing the available source workspace. */
122 public WorkspaceTree workspace_tree = null;
123
124
125 public GatherPane()
126 {
127 this.group = new DragGroup();
128 this.file_queue = Gatherer.f_man.getQueue();
129 this.setComponentOrientation(org.greenstone.gatherer.Dictionary.getOrientation());
130 // Create components.
131 stop_action = new GLIButton(Dictionary.get("Collection.Stop"), Dictionary.get("Collection.Stop_Tooltip"));
132 stop_action.addActionListener(this);
133 stop_action.setEnabled(false);
134 file_queue.registerStopButton(stop_action);
135
136 new_folder = new GLIButton(JarTools.getImage("folder.gif"), Dictionary.get("Collection.New_Folder_Tooltip"));
137 new_folder.addActionListener(this);
138 new_folder.setEnabled(false);
139 new_folder.setMinimumSize(MIN_SIZE);
140 new_folder.setPreferredSize(MIN_SIZE);
141
142 }
143
144 /** 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. */
145 public void actionPerformed(ActionEvent event) {
146 // If a user has clicked on the bin button directly remove whatever
147 // files are selected in the active tree.
148 if (event.getSource() == Gatherer.recycle_bin) {
149 if (!Gatherer.recycle_bin.ignore()) {
150 // Find the active tree (you've made selections in).
151 DragTree tree = (DragTree) group.getActive();
152 if (tree != null) { // if something has indeed been selected
153 // Fudge things a bit
154 group.setSource(tree);
155 // Determine the selection.
156 TreePath paths[] = tree.getSelectionPaths();
157 if(paths != null) {
158 FileNode[] source_nodes = new FileNode[paths.length];
159 for(int i = 0; i < paths.length; i++) {
160 source_nodes[i] = (FileNode)(paths[i].getLastPathComponent());
161 }
162 Gatherer.f_man.action(tree, source_nodes, Gatherer.recycle_bin, null);
163 }
164 }
165 }
166 }
167 // If a user has clicked on new_folder create a new folder under
168 // whatever node is selected.
169 else if(event.getSource() == new_folder && collection_tree != null) {
170 int count = collection_tree.getSelectionCount();
171 boolean error = false;
172 if(count == 1) {
173 TreePath path = collection_tree.getSelectionPath();
174 CollectionTreeNode node = (CollectionTreeNode) path.getLastPathComponent();
175 if (node.getAllowsChildren()) {
176 Gatherer.f_man.newFolder(collection_tree, node);
177 }
178 else {
179 // try the parent
180 CollectionTreeNode parent = (CollectionTreeNode) node.getParent();
181 if (parent!=null && parent.getAllowsChildren()) {
182 Gatherer.f_man.newFolder(collection_tree, parent);
183 } else {
184 error = true;
185 }
186 }
187 }
188 else {
189 error = true;
190 }
191 if(error) {
192 // instead of an error, we now create a new folder at the root
193 CollectionTreeNode node = (CollectionTreeNode) collection_tree.getModel().getRoot();
194 Gatherer.f_man.newFolder(collection_tree, node);
195 }
196 }
197 else if(event.getSource() == stop_action) {
198 file_queue.cancelAction();
199 }
200 }
201
202
203 /** Generates the pane on controls used to 'collect' files into the collection. Resposible for creating, connecting and laying out these controls. */
204 public void display()
205 {
206 // Workspace Tree
207 workspace_pane = new JPanel();
208 workspace_pane.setMinimumSize(MIN_SIZE);
209 workspace_pane.setPreferredSize(TREE_SIZE);
210 workspace_pane.setSize(TREE_SIZE);
211 workspace_pane.setComponentOrientation(Dictionary.getOrientation());
212
213 workspace_label = new JLabel(Dictionary.get("Collection.Workspace"));
214 workspace_label.setOpaque(true);
215 workspace_label.setBackground(Configuration.getColor("coloring.workspace_heading_background", false));
216 workspace_label.setForeground(Configuration.getColor("coloring.workspace_heading_foreground", false));
217 workspace_label.setComponentOrientation(Dictionary.getOrientation());
218
219 workspace_tree = new WorkspaceTree();
220 workspace_tree.setComponentOrientation(Dictionary.getOrientation());
221 group.add(workspace_tree);
222 workspace_scroll = new JScrollPane(workspace_tree);
223 workspace_scroll.setComponentOrientation(Dictionary.getOrientation());
224 workspace_filter = workspace_tree.getFilter();
225 workspace_filter.setComponentOrientation(Dictionary.getOrientation());
226
227 card_layout = new CardLayout();
228
229 // Collection Tree
230 collection_pane = new JPanel();
231 collection_pane.setMinimumSize(MIN_SIZE);
232 collection_pane.setPreferredSize(TREE_SIZE);
233 collection_pane.setSize(TREE_SIZE);
234 collection_pane.setComponentOrientation(Dictionary.getOrientation());
235
236 collection_label = new JLabel(Dictionary.get("Collection.Collection"));
237 collection_label.setOpaque(true);
238 collection_label.setComponentOrientation(Dictionary.getOrientation());
239
240 collection_tree = Gatherer.c_man.getCollectionTree();
241 collection_tree.setEnabled(Gatherer.c_man.getCollectionTreeModel() != null);
242 group.add(collection_tree);
243 collection_filter = collection_tree.getFilter();
244
245 tree_pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
246 tree_pane.setComponentOrientation(Dictionary.getOrientation());
247 // No collection loaded pane
248 JPanel no_collection_pane = new JPanel();
249 no_collection_pane.setBackground(Color.lightGray);
250 no_collection_pane.setComponentOrientation(Dictionary.getOrientation());
251
252 JLabel no_collection_label = new JLabel(Dictionary.get("Collection.Collection"));
253 no_collection_label.setBackground(Color.lightGray);
254 no_collection_label.setForeground(Color.black);
255 no_collection_label.setOpaque(true);
256 no_collection_label.setComponentOrientation(Dictionary.getOrientation());
257
258 JPanel no_collection_loaded_panel = new JPanel();
259 no_collection_loaded_panel.setBorder(BorderFactory.createLineBorder(Color.black));
260 no_collection_loaded_panel.setBackground(Color.lightGray);
261 no_collection_loaded_panel.setComponentOrientation(Dictionary.getOrientation());
262
263 JLabel no_collection_loaded_label = new JLabel(Dictionary.get("Collection.No_Collection_Loaded"));
264 no_collection_loaded_label.setHorizontalAlignment(JLabel.CENTER);
265 no_collection_loaded_label.setVerticalAlignment(JLabel.CENTER);
266 no_collection_loaded_label.setComponentOrientation(Dictionary.getOrientation());
267
268 // Status pane
269 control_pane = new JPanel();
270 control_pane.setComponentOrientation(Dictionary.getOrientation());
271
272 JPanel inner_pane = new JPanel();
273 inner_pane.setSize(STATUS_SIZE);
274 inner_pane.setComponentOrientation(Dictionary.getOrientation());
275
276 card_pane = new JPanel();
277 card_pane.setComponentOrientation(Dictionary.getOrientation());
278
279 JPanel file_pane = new JPanel();
280 file_pane.setComponentOrientation(Dictionary.getOrientation());
281
282 JPanel progress_pane = new JPanel();
283 progress_pane.setComponentOrientation(Dictionary.getOrientation());
284
285 JLabel file_status = file_queue.getFileStatus();
286 file_status.setComponentOrientation(Dictionary.getOrientation());
287
288 JProgressBar progress_bar = file_queue.getProgressBar();
289 progress_bar.setComponentOrientation(Dictionary.getOrientation());
290
291 JPanel button_pane = new JPanel();
292 button_pane.setComponentOrientation(Dictionary.getOrientation());
293 RecycleBin recycle_bin = Gatherer.recycle_bin;
294 recycle_bin.addActionListener(this);
295 recycle_bin.setMinimumSize(MIN_SIZE);
296 recycle_bin.setPreferredSize(MIN_SIZE);
297 recycle_bin.setToolTipText(Dictionary.get("Collection.Delete_Tooltip"));
298 group.add(recycle_bin);
299
300 // Layout Components.
301 workspace_pane.setLayout(new BorderLayout());
302 workspace_pane.add(workspace_label, BorderLayout.NORTH);
303 workspace_pane.add(workspace_scroll, BorderLayout.CENTER);
304 workspace_pane.add(workspace_filter, BorderLayout.SOUTH);
305
306 collection_pane.setLayout(new BorderLayout());
307 collection_pane.add(collection_label, BorderLayout.NORTH);
308
309 no_collection_loaded_panel.setLayout(new BorderLayout());
310 no_collection_loaded_panel.add(no_collection_loaded_label, BorderLayout.CENTER);
311
312 no_collection_pane.setLayout(new BorderLayout());
313 no_collection_pane.add(no_collection_label, BorderLayout.NORTH);
314 no_collection_pane.add(no_collection_loaded_panel, BorderLayout.CENTER);
315
316 card_pane.setLayout(card_layout);
317 card_pane.add(no_collection_pane, NO_COLLECTION_LOADED_CARD);
318 card_pane.add(collection_pane, COLLECTION_LOADED_CARD);
319
320 if (Dictionary.getOrientation().isLeftToRight()){
321 tree_pane.add(workspace_pane, JSplitPane.LEFT);
322 tree_pane.add(card_pane, JSplitPane.RIGHT);
323 }else{
324 tree_pane.add(workspace_pane, JSplitPane.RIGHT);
325 tree_pane.add(card_pane, JSplitPane.LEFT);
326 }
327
328
329 tree_pane.setDividerLocation(TREE_SIZE.width - 10);
330
331 file_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
332 file_pane.setLayout(new BorderLayout());
333 file_pane.add(file_status, BorderLayout.CENTER);
334 file_pane.add(stop_action, BorderLayout.LINE_END);
335
336 progress_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
337 progress_pane.setLayout(new BorderLayout());
338 progress_pane.add(progress_bar, BorderLayout.CENTER);
339
340 inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,10,10,10), BorderFactory.createLoweredBevelBorder()));
341 inner_pane.setLayout(new GridLayout(2,1));
342 inner_pane.add(file_pane);
343 inner_pane.add(progress_pane);
344
345 button_pane.add(new_folder);
346 button_pane.add(recycle_bin);
347
348 control_pane.setLayout(new BorderLayout());
349 control_pane.add(inner_pane, BorderLayout.CENTER);
350 control_pane.add(button_pane, BorderLayout.LINE_END);
351
352 this.setLayout(new BorderLayout());
353 this.add(tree_pane, BorderLayout.CENTER);
354 this.add(control_pane, BorderLayout.SOUTH);
355 }
356
357
358 /** Called to inform this control panel that it has just gained focus as an effect of the user clicking on its tab.
359 */
360 public void gainFocus()
361 {
362 // Add the collection tree and filter back into this pane
363 collection_scroll = new JScrollPane(collection_tree);
364 collection_pane.add(collection_scroll, BorderLayout.CENTER);
365 collection_pane.add(collection_filter, BorderLayout.SOUTH);
366 }
367
368
369 /** Called to inform this pane that it has just lost focus as an effect of the user clicking on another tab
370 */
371 public void loseFocus()
372 {
373 // Remove the collection tree and filter from this pane so it can be added to the Enrich pane
374 collection_pane.remove(collection_scroll);
375 collection_pane.remove(collection_filter);
376 }
377
378
379 /** Retrieve a list of the currently selected file records in the collection tree. */
380 private CollectionTreeNode[] getCollectionTreeSelection()
381 {
382 TreePath paths[] = collection_tree.getSelectionPaths();
383 CollectionTreeNode records[] = null;
384 if (paths != null) {
385 records = new CollectionTreeNode[paths.length];
386 for (int i = 0; i < records.length; i++) {
387 records[i] = (CollectionTreeNode) paths[i].getLastPathComponent();
388 }
389 }
390 return records;
391 }
392
393
394 /** 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)
395 * @param mode the mode level as an int
396 */
397 public void modeChanged(int mode) {
398 collection_filter.setEditable(mode >= Configuration.LIBRARIAN_MODE);
399 workspace_filter.setEditable(mode >= Configuration.LIBRARIAN_MODE);
400 }
401
402
403 /** Refresh this pane, depending on what has just happened (refresh_reason). */
404 public void refresh(int refresh_reason, boolean collection_loaded)
405 {
406 if (collection_loaded) {
407 // Update collection tree
408 if (refresh_reason == Gatherer.COLLECTION_OPENED) {
409 collection_tree.setModel(Gatherer.c_man.getCollectionTreeModel());
410 }
411
412 card_layout.show(card_pane, COLLECTION_LOADED_CARD);
413 }
414 else {
415 // Update collection tree
416 collection_tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Error")));
417
418 card_layout.show(card_pane, NO_COLLECTION_LOADED_CARD);
419 }
420
421 // File sizes turned on/off
422 if (refresh_reason == Gatherer.PREFERENCES_CHANGED) {
423 refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED);
424 refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED);
425 }
426
427 // Enable or disable the controls
428 collection_tree.setEnabled(collection_loaded);
429 collection_filter.setEnabled(collection_loaded);
430 new_folder.setEnabled(collection_loaded);
431 }
432
433
434 public void refreshCollectionTree(int refresh_reason) {
435 collection_tree.refresh(null);
436 }
437
438
439 public void refreshWorkspaceTree(int refresh_reason) {
440 workspace_tree.refresh(refresh_reason);
441 }
442}
Note: See TracBrowser for help on using the repository browser.