source: trunk/gli/src/org/greenstone/gatherer/gui/CreatePane.java@ 4551

Last change on this file since 4551 was 4551, checked in by mdewsnip, 21 years ago

Fixed a bug where a new OptionsPane was being created whenever a collection was built, causing a NPE because the log list starts off null. Now a new OptionsPane is only created for a new collection.

  • Property svn:keywords set to Author Date Id Revision
File size: 27.4 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.event.*;
40import javax.swing.*;
41import javax.swing.event.*;
42import javax.swing.tree.*;
43import org.greenstone.gatherer.Gatherer;
44import org.greenstone.gatherer.collection.BuildOptions;
45import org.greenstone.gatherer.collection.Collection;
46import org.greenstone.gatherer.gui.OptionsPane;
47import org.greenstone.gatherer.shell.GBasicProgressMonitor;
48import org.greenstone.gatherer.shell.GBuildProgressMonitor;
49import org.greenstone.gatherer.shell.GImportProgressMonitor;
50import org.greenstone.gatherer.shell.GShell;
51import org.greenstone.gatherer.shell.GShellEvent;
52import org.greenstone.gatherer.shell.GShellListener;
53import org.greenstone.gatherer.shell.GShellProgressMonitor;
54/** This class provides a GUI view showing some statistics on your current collection, and options for building it. As the collection is built this initial view is replaced with one showing progress bars and a message log of the creation process. This log can be later accessed via the options tree located in the center of the initial pane. This class is also responsible for creating the GShellProgressMonitors that are then attatched to external shell processes, and calling the methods in the CollectionManager for actually importing and building the collection. <br><BR>
55 * <center><table width=80% border=2 cellspacing=0 cellpadding=2><tr><td align=center colspan=4>
56 * The (i)mport and/or (b)uild options supported:</td></tr>
57 * <tr background=black><font color=white><td>Script</td><td>Associated Argument</td><td>Control</td><td>Comments</td></font></tr>
58 * <tr><td>b</td><td>-allclassifications</td><td>JCheckBox</td><td>&nbsp;</td></tr>
59 * <tr><td>i/b</td><td>-archivedir</td><td>JTextField</td><td>&nbsp;</td></tr>
60 * <tr><td>b</td><td>-builddir</td><td>JTextField</td><td>&nbsp;</td></tr>
61 * <tr><td>i/b</td><td>-debug</td><td>JCheckBox</td><td>&nbsp;</td></tr>
62 * <tr><td>i/b</td><td>-collectdir</td><td>JTextField</td><td>&nbsp;</td></tr>
63 * <tr><td>b</td><td>-create_images</td><td>JCheckBox</td><td>&nbsp;</td></tr>
64 * <tr><td>i</td><td>-groupsize</td><td>JSpinner </td><td>&nbsp;</td></tr>
65 * <tr><td>i</td><td>-gzip</td><td>JCheckBox</td><td>&nbsp;</td></tr>
66 * <tr><td>i</td><td>-importdir</td><td>JTextField</td><td>&nbsp;</td></tr>
67 * <tr><td>b</td><td>-index</td><td>GCheckList</td><td>&nbsp;</td></tr>
68 * <tr><td>i/b</td><td>-keepold</td><td>JCheckBox</td><td>sanity check removeold</td></tr>
69 * <tr><td>i/b</td><td>-maxdocs</td><td>JSpinner</td><td>&nbsp;</td></tr>
70 * <tr><td>b</td><td>-mode</td><td>JComboBox</td><td>"all", "compress_text", "infodb", "build_index"</td></tr>
71 * <tr><td>b</td><td>-no_text</td><td>JCheckBox</td><td>&nbsp;</td></tr>
72 * <tr><td>i</td><td>-OIDtype</td><td>JComboBox</td><td>"hash","incremental"</td></tr>
73 * <tr><td>i/b</td><td>-out</td><td>JTextField</td><td>&nbsp;</td></tr>
74 * <tr><td>i</td><td>-removeold</td><td>JCheckBox</td><td>sanity check keepold</td></tr>
75 * <tr><td>i</td><td>-sortmeta</td><td>JComboBox</td><td>&nbsp;</td></tr>
76 * <tr><td>i/b</td><td>-verbosity</td><td>JSpinner</td><td>1, 3</td></tr>
77 * </table></center>
78 * @author John Thompson, Greenstone Digital Library, University of Waikato
79 * @version 2.3
80 */
81public class CreatePane
82 extends JPanel
83 implements GShellListener {
84 /** Determines the current view that should be shown for this pane. */
85 public boolean processing = false;
86 /** The options pane generates all the various option sheet configuations. */
87 public OptionsPane options_pane = null;
88 /** A card layout is used to store the separate configuration and progress panes. */
89 private CardLayout card_layout = null;
90 /** Stores a reference to the current collection. */
91 private Collection previous_collection = null;
92 /** This monitor tracks the build processes progress. */
93 private GShellProgressMonitor build_monitor = null;
94 /** This monitor tracks the copy processes progress. */
95 private GShellProgressMonitor copy_monitor = null;
96 /** This monitor tracks the import processes progress. */
97 private GShellProgressMonitor import_monitor = null;
98 /** The button for begining the building processes. */
99 private JButton build_button = null;
100 /** The button for stopping the building processes. */
101 private JButton cancel_button = null;
102 /** The label displaying the number of documents in this collection. */
103 private JLabel document_count = null;
104 /** The label alongside the build progress bar gets some special treatment so... */
105 private JLabel progress_build_label = null;
106 /** The label alongside the copy progress bar gets some special treatment so... */
107 private JLabel progress_copy_label = null;
108 /** The label alongside the import progress bar gets some special treatment so... */
109 private JLabel progress_import_label = null;
110 /** The pane which contains the controls for configuration. */
111 private JPanel control_pane = null;
112 /** The pane which has the card layout as its manager. */
113 private JPanel main_pane = null;
114 /** The pane which contains the progress information. */
115 private JPanel progress_pane = null;
116 /** the pane on the right-hand side - shows the requested options view */
117 private JPanel right = null;
118 /** This pane is the one that is updated to show the requested options view. */
119 //private JPanel target_pane = null;
120 /** The scrolling pane the log is inside. */
121 private JScrollPane scroll_log = null;
122 /** the scrolling pane the righthand side is inside - only used for import and build options. the log and log list are not inside a scrollpane */
123 private JScrollPane scroll_pane;
124 /** The log for the current process. */
125 private JTextArea process_log = null;
126 /** The message log for the entire session. */
127 private JTextArea message_log = new JTextArea();
128 /** A tree used to display the currently available option views. */
129 private OptionTree tree = null;
130 /** An array used to pass arguments with dictionary calls. */
131 private String args[] = null;
132 /** The size of the buttons at the bottom of the screen. */
133 static private Dimension BUTTON_SIZE = new Dimension(386, 50);
134 /** The size of the labels on the progress pane. */
135 static private Dimension LABEL_SIZE = new Dimension(140, 25);
136 /** An identifier for the control panel within the card layout. */
137 static private String CONTROL = "Control";
138 /** An identifier for the progress panel within the card layout. */
139 static private String PROGRESS = "Progress";
140 /** The constructor creates important helper classes, and initializes all the components.
141 * @see org.greenstone.gatherer.collection.CollectionManager
142 * @see org.greenstone.gatherer.gui.BuildOptions
143 * @see org.greenstone.gatherer.gui.CreatePane.BuildButtonListener
144 * @see org.greenstone.gatherer.gui.CreatePane.CancelButtonListener
145 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
146 * @see org.greenstone.gatherer.gui.OptionsPane
147 * @see org.greenstone.gatherer.shell.GBasicProgressMonitor
148 * @see org.greenstone.gatherer.shell.GBuildProgressMonitor
149 * @see org.greenstone.gatherer.shell.GImportProgressMonitor
150 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
151 */
152 public CreatePane() {
153 //this.target_pane = new JPanel(new BorderLayout());
154 Collection collection = Gatherer.c_man.getCollection();
155 //if(collection != null) {
156 // this.options_pane = new OptionsPane(message_log, collection.build_options);
157 // }
158 // Create components
159 card_layout = new CardLayout();
160 // Control Pane
161 control_pane = new JPanel();
162 args = new String[1];
163 args[0] = "0";
164 document_count = new JLabel(get("Document_Count", args));
165 tree = new OptionTree();
166 // Progress Pane
167 progress_pane = new JPanel();
168
169 progress_copy_label = new JLabel(get("Copy_Progress"));
170 progress_copy_label.setForeground(Color.black);
171 progress_copy_label.setHorizontalAlignment(JLabel.LEFT);
172 progress_copy_label.setPreferredSize(LABEL_SIZE);
173 progress_copy_label.setMinimumSize(LABEL_SIZE);
174 progress_copy_label.setSize(LABEL_SIZE);
175
176 copy_monitor = new GBasicProgressMonitor();
177 Gatherer.c_man.registerCopyMonitor(copy_monitor);
178
179 progress_import_label = new JLabel(get("Import_Progress"));
180 progress_import_label.setForeground(Color.black);
181 progress_import_label.setHorizontalAlignment(JLabel.LEFT);
182 progress_import_label.setPreferredSize(LABEL_SIZE);
183 progress_import_label.setMinimumSize(LABEL_SIZE);
184 progress_import_label.setSize(LABEL_SIZE);
185
186 import_monitor = new GImportProgressMonitor(); //GBasicProgressMonitor();
187 Gatherer.c_man.registerImportMonitor(import_monitor);
188
189 progress_build_label = new JLabel(get("Build_Progress"));
190 progress_build_label.setForeground(Color.black);
191 progress_build_label.setHorizontalAlignment(JLabel.LEFT);
192 progress_build_label.setPreferredSize(LABEL_SIZE);
193 progress_build_label.setMinimumSize(LABEL_SIZE);
194 progress_build_label.setSize(LABEL_SIZE);
195
196 build_monitor = new GBuildProgressMonitor((GImportProgressMonitor)import_monitor); //GBasicProgressMonitor();
197 Gatherer.c_man.registerBuildMonitor(build_monitor);
198
199 // Buttons.
200 build_button = new JButton(get("Build_Collection"));
201 build_button.addActionListener(new BuildButtonListener());
202 build_button.setPreferredSize(BUTTON_SIZE);
203 cancel_button = new JButton(get("Cancel_Build"));
204 cancel_button.addActionListener(new CancelButtonListener());
205 cancel_button.setEnabled(false);
206 cancel_button.setPreferredSize(BUTTON_SIZE);
207 }
208 /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating.
209 * @param ready A <strong>boolean</strong> indicating if a collection is currently available.
210 * @see org.greenstone.gatherer.Gatherer
211 * @see org.greenstone.gatherer.collection.CollectionManager
212 * @see org.greenstone.gatherer.gui.BuildOptions
213 * @see org.greenstone.gatherer.gui.OptionsPane
214 */
215 public void collectionChanged(boolean ready) {
216 ///ystem.err.println("Collection changed... ");
217 if(Gatherer.c_man != null && Gatherer.c_man.ready()) {
218
219 if (!processing &&this.options_pane!=null) {
220 // we only do this if we are not processing - if we are processing, then we haven't added the new entry yet, and it will be added by another method
221 this.options_pane.resetLogList(); // saves any residual message
222 }
223 Collection current_collection = Gatherer.c_man.getCollection();
224 if (current_collection != previous_collection) {
225 this.options_pane = new OptionsPane(message_log, current_collection.build_options);
226 previous_collection = current_collection;
227 }
228 tree.valueChanged(null);
229 }
230 }
231 /** This method is called to actually layout the components.
232 * @see org.greenstone.gatherer.Configuration
233 * @see org.greenstone.gatherer.Gatherer
234 */
235 public void display() {
236 // Build control_pane
237 JPanel stats_area = new JPanel();
238 stats_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(get("Statistics_Title"))));
239 stats_area.setLayout(new GridLayout(1,1));
240 stats_area.add(document_count);
241
242 JPanel left = new JPanel();
243 left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
244 left.setLayout(new BorderLayout());
245 left.add(tree, BorderLayout.CENTER);
246
247 right = new JPanel();
248 right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
249 right.setLayout(new BorderLayout());
250 //scroll_pane = new JScrollPane(target_pane);
251 //right.add(scroll_pane, BorderLayout.CENTER);
252
253 JPanel options_area = new JPanel();
254 options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(get("Options_Title"))));
255 options_area.setLayout(new BorderLayout());
256 options_area.add(left, BorderLayout.WEST);
257 options_area.add(right, BorderLayout.CENTER);
258
259 control_pane.setLayout(new BorderLayout());
260 control_pane.add(options_area, BorderLayout.CENTER);
261 //control_pane.add(stats_area, BorderLayout.SOUTH);
262
263 // Build progress_pane
264 JPanel copy_pane = new JPanel();
265 copy_pane.setLayout(new BorderLayout());
266 copy_pane.add(progress_copy_label, BorderLayout.WEST);
267 copy_pane.add(copy_monitor.getProgress(), BorderLayout.CENTER);
268
269 JPanel import_pane = new JPanel();
270 import_pane.setLayout(new BorderLayout());
271 import_pane.add(progress_import_label, BorderLayout.WEST);
272 import_pane.add(import_monitor.getProgress(), BorderLayout.CENTER);
273
274 JPanel build_pane = new JPanel();
275 build_pane.setLayout(new BorderLayout());
276 build_pane.add(progress_build_label, BorderLayout.WEST);
277 build_pane.add(build_monitor.getProgress(), BorderLayout.CENTER);
278
279 JPanel bar_area = new JPanel();
280 bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10));
281
282 bar_area.setLayout(new GridLayout(2,2,10,5));
283 bar_area.add(import_pane);
284 bar_area.add(build_pane);
285
286
287 progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
288 progress_pane.setLayout(new BorderLayout());
289 progress_pane.add(bar_area, BorderLayout.NORTH);
290
291 // Main pane
292 main_pane = new JPanel(card_layout);
293 main_pane.add(control_pane, CONTROL);
294 main_pane.add(progress_pane, PROGRESS);
295
296 // Buttons
297 JPanel button_pane = new JPanel();
298 button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10));
299 button_pane.setLayout(new GridLayout(1,2));
300 button_pane.add(build_button);
301 button_pane.add(cancel_button);
302
303 this.setLayout(new BorderLayout());
304 this.add(main_pane, BorderLayout.CENTER);
305 this.add(button_pane, BorderLayout.SOUTH);
306 }
307 /** This method is called whenever the 'Create' tab is selected from the view bar. It allows this view to perform any preactions required prior to display. In this case this entails gathering up to date information about the status of the collection including number of documents etc.
308 * @see org.greenstone.gatherer.Gatherer
309 * @see org.greenstone.gatherer.collection.CollectionManager
310 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
311 */
312 public void gainFocus() {
313 if(!processing) {
314 card_layout.show(main_pane, CONTROL);
315 //args = new String[1];
316 //if(Gatherer.c_man.ready()) {
317 // args[0] = String.valueOf(Gatherer.c_man.getCollection().getDocumentCount());
318 //}
319 //else {
320 //args[0] = "0";
321 //}
322 //document_count.setText(get("Document_Count", args));
323 }
324 // Refresh the set of controls.
325 TreePath path = tree.getSelectionPath();
326 tree.clearSelection();
327 tree.setSelectionPath(path);
328 }
329 /** Method to acquire the progress monitor associated with builds.
330 * @return The build <strong>GShellProgressMonitor</strong>.
331 */
332 public GShellProgressMonitor getBuildProgress() {
333 return build_monitor;
334 }
335 /** Method to acquire the progress monitor associated with copying.
336 * @return The copying <strong>GShellProgressMonitor</strong>.
337 */
338 public GShellProgressMonitor getCopyProgress() {
339 return copy_monitor;
340 }
341 /** Method to acquire the progress monitor associated with import.
342 * @return The import <strong>GShellProgressMonitor</strong>.
343 */
344 public GShellProgressMonitor getImportProgress() {
345 return import_monitor;
346 }
347
348 /** We are informed when this view pane loses focus so we can update build options. */
349 public void loseFocus() {
350 tree.valueChanged(null);
351 }
352
353 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
354 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
355 */
356 public synchronized void message(GShellEvent event) {
357 ///ystem.err.println("Recieved message: " + event.getMessage());
358 String text = event.getMessage();
359 message_log.append(text + "\n");
360 if(process_log != null) {
361 process_log.append(text + "\n");
362 process_log.setCaretPosition(process_log.getCaretPosition() + text.length() + 1);
363 //scroll_log.getVerticalScrollBar().setValue(process_log.getHeight() - process_log.getVisibleRect().height);
364 }
365 }
366 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used.
367 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
368 */
369 public synchronized void processBegun(GShellEvent event) {
370 // We don't care. We'll get a more acurate start from the progress monitors.
371 }
372 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
373 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
374 */
375 public synchronized void processComplete(GShellEvent event) {
376 if(event.getType() == GShell.BUILD) {
377 processing = false;
378 cancel_button.setEnabled(false);
379 build_button.setEnabled(true);
380 int status = event.getStatus();
381 if (status == GShell.OK) {
382 options_pane.addNewLog(OptionsPane.SUCCESSFUL);
383 } else {
384 options_pane.addNewLog(OptionsPane.UNSUCCESSFUL);
385 }
386 card_layout.show(main_pane, CONTROL);
387 }
388 }
389 /** This method retrieves a phrase from the dictionary based apon the key.
390 * @param key A <strong>String</strong> used as a reference to the correct phrase.
391 * @return A phrase, matching the key, as a <strong>String</strong>.
392 */
393 private String get(String key) {
394 return get(key, null);
395 }
396 /** This method retrieves a phrase from the dictionary based apon the key and arguments.
397 * @param key A <strong>String</strong> used as a reference to the correct phrase.
398 * @param args A <strong>String[]</strong> whose contents are often substituted into the phrase before it is returned.
399 * @return A phrase, matching the key and constructed using the arguments, as a <strong>String</strong>.
400 * @see org.greenstone.gatherer.Dictionary
401 * @see org.greenstone.gatherer.Gatherer
402 */
403 private String get(String key, String args[]) {
404 if(key.indexOf(".") == -1) {
405 key = "CreatePane." + key;
406 }
407 return Gatherer.dictionary.get(key, args);
408 }
409 /** This class serves as the listener for actions on the build button. */
410 private class BuildButtonListener
411 implements ActionListener {
412 /** This method causes a call to be made to CollectionManager.importCollection(), which then imports and builds the collection as necessary.
413 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
414 * @see org.greenstone.gatherer.Gatherer
415 * @see org.greenstone.gatherer.collection.CollectionManager
416 * @see org.greenstone.gatherer.gui.BuildOptions
417 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
418 */
419 public void actionPerformed(ActionEvent event) {
420 // First we force the build options to be updated if we haven't already.
421 tree.valueChanged(null);
422 // Now go about building.
423 build_button.setEnabled(false);
424 cancel_button.setEnabled(true);
425 // Create a new process log, and place it.
426 if(scroll_log != null) {
427 progress_pane.remove(scroll_log);
428 }
429 process_log = new JTextArea();
430 scroll_log = new JScrollPane(process_log);
431 progress_pane.add(scroll_log, BorderLayout.CENTER);
432 // clear the log list and message_log
433 options_pane.resetLogList();
434 // Change the view.
435 processing = true;
436 card_layout.show(main_pane, PROGRESS);
437 // Reset the stop flag in all the process monitors, just incase.
438 ((GBuildProgressMonitor)build_monitor).reset();
439 copy_monitor.setStop(false);
440 import_monitor.setStop(false);
441 // Set removeold automatically.
442 if(Gatherer.c_man.ready() && !Gatherer.c_man.built()) {
443 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
444 }
445 // Call CollectionManagers method to build collection.
446 Gatherer.c_man.importCollection();
447 }
448 }
449 /** This class serves as the listener for actions on the cancel button. */
450 private class CancelButtonListener
451 implements ActionListener {
452 /** This method attempts to cancel the current GShell task. It does this by first telling CollectionManager not to carry out any further action. This it turn tells the GShell to break from the current job immediately, without waiting for the processEnded message, and then kills the thread in an attempt to stop the process. The results of such an action are debatable.
453 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
454 * @see org.greenstone.gatherer.Gatherer
455 * @see org.greenstone.gatherer.collection.CollectionManager
456 * @see org.greenstone.gatherer.gui.BuildOptions
457 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
458 */
459 public void actionPerformed(ActionEvent event) {
460 build_button.setEnabled(true);
461 cancel_button.setEnabled(false);
462 processing = false;
463 options_pane.addNewLog(OptionsPane.CANCELLED);
464 card_layout.show(main_pane, CONTROL);
465 // Set the stop flag in all the process monitor.
466 build_monitor.setStop(true);
467 copy_monitor.setStop(true);
468 import_monitor.setStop(true);
469 // Set removeold automatically.
470 if(Gatherer.c_man.ready()) { // and it should be.
471 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
472 }
473 // Remove the collection lock.
474 Gatherer.g_man.lockCollection(false, false);
475 }
476 }
477 /** The OptionTree is simply a tree structure that has a root node labelled "Options" and then has a child node for each available options screen. These screens are either combinations of the available import and build arguments, or a message log detailing the shell processes progress. */
478 private class OptionTree
479 extends JTree
480 implements TreeSelectionListener {
481 /** The model behind the tree. */
482 private DefaultTreeModel model = null;
483 /** The previous options view displayed, which is sometimes needed to refresh properly. */
484 private JPanel previous_pane = null;
485 /** The node corresponding to the building options view. */
486 private OptionTreeNode building = null;
487 /** The node corresponding to the importing options view. */
488 private OptionTreeNode importing = null;
489 /** The node corresponding to the log view. */
490 private OptionTreeNode log = null;
491 /** The root node of the options tree, which has no associated options view. */
492 private OptionTreeNode options = null;
493 /** Constructor.
494 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
495 */
496 public OptionTree() {
497 super();
498 addTreeSelectionListener(this);
499 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
500 setRootVisible(false);
501 setToggleClickCount(1);
502 // Create tree.
503 building = new OptionTreeNode(get("Build"));
504 importing = new OptionTreeNode(get("Import"));
505 log = new OptionTreeNode(get("Log"));
506 options = new OptionTreeNode(get("Options"));
507
508 model = new DefaultTreeModel(options);
509 setModel(model);
510 model.insertNodeInto(importing, options, 0);
511 model.insertNodeInto(building, options, 1);
512 model.insertNodeInto(log, options, 2);
513 // Expand the root node
514 expandPath(new TreePath(options));
515 }
516 /** Any implementation of TreeSelectionListener must include this method to allow this listener to know when the selection has changed. Here we swap the options view depending on the selected OptionTreeNode.
517 * @param event A <Strong>TreeSelectionEvent</strong> which contains all the information garnered when the event occured.
518 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
519 */
520 public void valueChanged(TreeSelectionEvent event) {
521 TreePath path = null;
522 OptionTreeNode node = null;
523 //if(event != null) {
524 //path = event.getPath();
525 path = getSelectionPath();
526 if(path != null) {
527 node = (OptionTreeNode)path.getLastPathComponent();
528 }
529 //}
530 if(previous_pane != null) {
531 //target_pane.remove(previous_pane);
532 options_pane.update(previous_pane);
533 if(scroll_pane != null) {
534 right.remove(scroll_pane);
535 }
536 else {
537 right.remove(previous_pane);
538 }
539 previous_pane = null;
540 scroll_pane = null;
541 }
542 if(node != null && node.equals(building)) {
543 previous_pane = options_pane.buildBuild();
544 scroll_pane = new JScrollPane(previous_pane);
545 right.add(scroll_pane, BorderLayout.CENTER);
546 //target_pane.add(previous_pane, BorderLayout.CENTER);
547 }
548 else if(node != null && node.equals(importing)) {
549 previous_pane = options_pane.buildImport();
550 scroll_pane = new JScrollPane(previous_pane);
551 right.add(scroll_pane, BorderLayout.CENTER);
552 //target_pane.add(previous_pane, BorderLayout.CENTER);
553 }
554 else {
555 previous_pane = options_pane.buildLog();
556 right.add(previous_pane, BorderLayout.CENTER);
557 right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time
558 ///ystem.err.println("I've added the log back to the right pane again.");
559 //target_pane.add(previous_pane, BorderLayout.CENTER);
560 }
561 //scroll_pane.setViewportView(previous_pane);
562 previous_pane.validate();
563 }
564 }
565 /** The <strong>OptionTree</strong> is built from these nodes, each of which has several methods used in creating the option panes.
566 */
567 private class OptionTreeNode
568 extends DefaultMutableTreeNode
569 implements Comparable {
570 /** The text label given to this node in the tree. */
571 private String title = null;
572 /** Constructor.
573 * @param title The <strong>String</strong> which serves as this nodes title.
574 */
575 public OptionTreeNode(String title) {
576 super();
577 this.title = title;
578 }
579 /** This method compares two nodes for ordering.
580 * @param obj The <strong>Object</strong> to compare to.
581 * @return An <strong>int</strong> of one of the possible values -1, 0 or 1 indicating if this node is less than, equal to or greater than the target node respectively.
582 */
583 public int compareTo(Object obj) {
584 return title.compareTo(obj.toString());
585 }
586 /** This method checks if two nodes are equivelent.
587 * @param obj The <strong>Object</strong> to be tested against.
588 * @return A <strong>boolean</strong> which is <i>true</i> if the objects are equal, <i>false</i> otherwise.
589 */
590 public boolean equals(Object obj) {
591 if(compareTo(obj) == 0) {
592 return true;
593 }
594 return false;
595 }
596 /** Method to translate this node into a textual representation.
597 * @return A <strong>String</strong> which in this case is the title.
598 */
599 public String toString() {
600 return title;
601 }
602 }
603}
Note: See TracBrowser for help on using the repository browser.