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

Last change on this file since 4939 was 4685, checked in by kjdon, 21 years ago

cleared the message log when coll changed

  • 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 && ready) {
218 ///ystem.out.println("create coll changed");
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 message_log.setText(null);
226 this.options_pane = new OptionsPane(message_log, current_collection.build_options);
227 previous_collection = current_collection;
228 }
229 tree.valueChanged(null);
230 }
231 }
232 /** This method is called to actually layout the components.
233 * @see org.greenstone.gatherer.Configuration
234 * @see org.greenstone.gatherer.Gatherer
235 */
236 public void display() {
237 // Build control_pane
238 JPanel stats_area = new JPanel();
239 stats_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(get("Statistics_Title"))));
240 stats_area.setLayout(new GridLayout(1,1));
241 stats_area.add(document_count);
242
243 JPanel left = new JPanel();
244 left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
245 left.setLayout(new BorderLayout());
246 left.add(tree, BorderLayout.CENTER);
247
248 right = new JPanel();
249 right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
250 right.setLayout(new BorderLayout());
251 //scroll_pane = new JScrollPane(target_pane);
252 //right.add(scroll_pane, BorderLayout.CENTER);
253
254 JPanel options_area = new JPanel();
255 options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(get("Options_Title"))));
256 options_area.setLayout(new BorderLayout());
257 options_area.add(left, BorderLayout.WEST);
258 options_area.add(right, BorderLayout.CENTER);
259
260 control_pane.setLayout(new BorderLayout());
261 control_pane.add(options_area, BorderLayout.CENTER);
262 //control_pane.add(stats_area, BorderLayout.SOUTH);
263
264 // Build progress_pane
265 JPanel copy_pane = new JPanel();
266 copy_pane.setLayout(new BorderLayout());
267 copy_pane.add(progress_copy_label, BorderLayout.WEST);
268 copy_pane.add(copy_monitor.getProgress(), BorderLayout.CENTER);
269
270 JPanel import_pane = new JPanel();
271 import_pane.setLayout(new BorderLayout());
272 import_pane.add(progress_import_label, BorderLayout.WEST);
273 import_pane.add(import_monitor.getProgress(), BorderLayout.CENTER);
274
275 JPanel build_pane = new JPanel();
276 build_pane.setLayout(new BorderLayout());
277 build_pane.add(progress_build_label, BorderLayout.WEST);
278 build_pane.add(build_monitor.getProgress(), BorderLayout.CENTER);
279
280 JPanel bar_area = new JPanel();
281 bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10));
282
283 bar_area.setLayout(new GridLayout(2,2,10,5));
284 bar_area.add(import_pane);
285 bar_area.add(build_pane);
286
287
288 progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
289 progress_pane.setLayout(new BorderLayout());
290 progress_pane.add(bar_area, BorderLayout.NORTH);
291
292 // Main pane
293 main_pane = new JPanel(card_layout);
294 main_pane.add(control_pane, CONTROL);
295 main_pane.add(progress_pane, PROGRESS);
296
297 // Buttons
298 JPanel button_pane = new JPanel();
299 button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10));
300 button_pane.setLayout(new GridLayout(1,2));
301 button_pane.add(build_button);
302 button_pane.add(cancel_button);
303
304 this.setLayout(new BorderLayout());
305 this.add(main_pane, BorderLayout.CENTER);
306 this.add(button_pane, BorderLayout.SOUTH);
307 }
308 /** 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.
309 * @see org.greenstone.gatherer.Gatherer
310 * @see org.greenstone.gatherer.collection.CollectionManager
311 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
312 */
313 public void gainFocus() {
314 if(!processing) {
315 card_layout.show(main_pane, CONTROL);
316 //args = new String[1];
317 //if(Gatherer.c_man.ready()) {
318 // args[0] = String.valueOf(Gatherer.c_man.getCollection().getDocumentCount());
319 //}
320 //else {
321 //args[0] = "0";
322 //}
323 //document_count.setText(get("Document_Count", args));
324 }
325 // Refresh the set of controls.
326 TreePath path = tree.getSelectionPath();
327 tree.clearSelection();
328 tree.setSelectionPath(path);
329 }
330 /** Method to acquire the progress monitor associated with builds.
331 * @return The build <strong>GShellProgressMonitor</strong>.
332 */
333 public GShellProgressMonitor getBuildProgress() {
334 return build_monitor;
335 }
336 /** Method to acquire the progress monitor associated with copying.
337 * @return The copying <strong>GShellProgressMonitor</strong>.
338 */
339 public GShellProgressMonitor getCopyProgress() {
340 return copy_monitor;
341 }
342 /** Method to acquire the progress monitor associated with import.
343 * @return The import <strong>GShellProgressMonitor</strong>.
344 */
345 public GShellProgressMonitor getImportProgress() {
346 return import_monitor;
347 }
348
349 /** We are informed when this view pane loses focus so we can update build options. */
350 public void loseFocus() {
351 tree.valueChanged(null);
352 }
353
354 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
355 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
356 */
357 public synchronized void message(GShellEvent event) {
358 ///ystem.err.println("Recieved message: " + event.getMessage());
359 String text = event.getMessage();
360 message_log.append(text + "\n");
361 if(process_log != null) {
362 process_log.append(text + "\n");
363 process_log.setCaretPosition(process_log.getCaretPosition() + text.length() + 1);
364 //scroll_log.getVerticalScrollBar().setValue(process_log.getHeight() - process_log.getVisibleRect().height);
365 }
366 }
367 /** 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.
368 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
369 */
370 public synchronized void processBegun(GShellEvent event) {
371 // We don't care. We'll get a more acurate start from the progress monitors.
372 }
373 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
374 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
375 */
376 public synchronized void processComplete(GShellEvent event) {
377 if(event.getType() == GShell.BUILD) {
378 processing = false;
379 cancel_button.setEnabled(false);
380 build_button.setEnabled(true);
381 int status = event.getStatus();
382 if (status == GShell.OK) {
383 options_pane.addNewLog(OptionsPane.SUCCESSFUL);
384 } else {
385 options_pane.addNewLog(OptionsPane.UNSUCCESSFUL);
386 }
387 card_layout.show(main_pane, CONTROL);
388 }
389 }
390 /** This method retrieves a phrase from the dictionary based apon the key.
391 * @param key A <strong>String</strong> used as a reference to the correct phrase.
392 * @return A phrase, matching the key, as a <strong>String</strong>.
393 */
394 private String get(String key) {
395 return get(key, null);
396 }
397 /** This method retrieves a phrase from the dictionary based apon the key and arguments.
398 * @param key A <strong>String</strong> used as a reference to the correct phrase.
399 * @param args A <strong>String[]</strong> whose contents are often substituted into the phrase before it is returned.
400 * @return A phrase, matching the key and constructed using the arguments, as a <strong>String</strong>.
401 * @see org.greenstone.gatherer.Dictionary
402 * @see org.greenstone.gatherer.Gatherer
403 */
404 private String get(String key, String args[]) {
405 if(key.indexOf(".") == -1) {
406 key = "CreatePane." + key;
407 }
408 return Gatherer.dictionary.get(key, args);
409 }
410 /** This class serves as the listener for actions on the build button. */
411 private class BuildButtonListener
412 implements ActionListener {
413 /** This method causes a call to be made to CollectionManager.importCollection(), which then imports and builds the collection as necessary.
414 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
415 * @see org.greenstone.gatherer.Gatherer
416 * @see org.greenstone.gatherer.collection.CollectionManager
417 * @see org.greenstone.gatherer.gui.BuildOptions
418 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
419 */
420 public void actionPerformed(ActionEvent event) {
421 // First we force the build options to be updated if we haven't already.
422 tree.valueChanged(null);
423 // Now go about building.
424 build_button.setEnabled(false);
425 cancel_button.setEnabled(true);
426 // Create a new process log, and place it.
427 if(scroll_log != null) {
428 progress_pane.remove(scroll_log);
429 }
430 process_log = new JTextArea();
431 scroll_log = new JScrollPane(process_log);
432 progress_pane.add(scroll_log, BorderLayout.CENTER);
433 // clear the log list and message_log
434 options_pane.resetLogList();
435 // Change the view.
436 processing = true;
437 card_layout.show(main_pane, PROGRESS);
438 // Reset the stop flag in all the process monitors, just incase.
439 ((GBuildProgressMonitor)build_monitor).reset();
440 copy_monitor.setStop(false);
441 import_monitor.setStop(false);
442 // Set removeold automatically.
443 if(Gatherer.c_man.ready() && Gatherer.c_man.built()) {
444 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
445 }
446 // Call CollectionManagers method to build collection.
447 Gatherer.c_man.importCollection();
448 }
449 }
450 /** This class serves as the listener for actions on the cancel button. */
451 private class CancelButtonListener
452 implements ActionListener {
453 /** 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.
454 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
455 * @see org.greenstone.gatherer.Gatherer
456 * @see org.greenstone.gatherer.collection.CollectionManager
457 * @see org.greenstone.gatherer.gui.BuildOptions
458 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
459 */
460 public void actionPerformed(ActionEvent event) {
461 build_button.setEnabled(true);
462 cancel_button.setEnabled(false);
463 processing = false;
464 options_pane.addNewLog(OptionsPane.CANCELLED);
465 card_layout.show(main_pane, CONTROL);
466 // Set the stop flag in all the process monitor.
467 build_monitor.setStop(true);
468 copy_monitor.setStop(true);
469 import_monitor.setStop(true);
470 // Set removeold automatically.
471 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
472 // Remove the collection lock.
473 //Gatherer.g_man.lockCollection(false, false);
474 }
475 }
476 /** 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. */
477 private class OptionTree
478 extends JTree
479 implements TreeSelectionListener {
480 /** The model behind the tree. */
481 private DefaultTreeModel model = null;
482 /** The previous options view displayed, which is sometimes needed to refresh properly. */
483 private JPanel previous_pane = null;
484 /** The node corresponding to the building options view. */
485 private OptionTreeNode building = null;
486 /** The node corresponding to the importing options view. */
487 private OptionTreeNode importing = null;
488 /** The node corresponding to the log view. */
489 private OptionTreeNode log = null;
490 /** The root node of the options tree, which has no associated options view. */
491 private OptionTreeNode options = null;
492 /** Constructor.
493 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
494 */
495 public OptionTree() {
496 super();
497 addTreeSelectionListener(this);
498 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
499 setRootVisible(false);
500 setToggleClickCount(1);
501 // Create tree.
502 building = new OptionTreeNode(get("Build"));
503 importing = new OptionTreeNode(get("Import"));
504 log = new OptionTreeNode(get("Log"));
505 options = new OptionTreeNode(get("Options"));
506
507 model = new DefaultTreeModel(options);
508 setModel(model);
509 model.insertNodeInto(importing, options, 0);
510 model.insertNodeInto(building, options, 1);
511 model.insertNodeInto(log, options, 2);
512 // Expand the root node
513 expandPath(new TreePath(options));
514 }
515 /** 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.
516 * @param event A <Strong>TreeSelectionEvent</strong> which contains all the information garnered when the event occured.
517 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
518 */
519 public void valueChanged(TreeSelectionEvent event) {
520 TreePath path = null;
521 OptionTreeNode node = null;
522 //if(event != null) {
523 //path = event.getPath();
524 path = getSelectionPath();
525 if(path != null) {
526 node = (OptionTreeNode)path.getLastPathComponent();
527 }
528 //}
529 if(previous_pane != null) {
530 //target_pane.remove(previous_pane);
531 options_pane.update(previous_pane);
532 if(scroll_pane != null) {
533 right.remove(scroll_pane);
534 }
535 else {
536 right.remove(previous_pane);
537 }
538 previous_pane = null;
539 scroll_pane = null;
540 }
541 if(node != null && node.equals(building)) {
542 previous_pane = options_pane.buildBuild();
543 scroll_pane = new JScrollPane(previous_pane);
544 right.add(scroll_pane, BorderLayout.CENTER);
545 //target_pane.add(previous_pane, BorderLayout.CENTER);
546 }
547 else if(node != null && node.equals(importing)) {
548 previous_pane = options_pane.buildImport();
549 scroll_pane = new JScrollPane(previous_pane);
550 right.add(scroll_pane, BorderLayout.CENTER);
551 //target_pane.add(previous_pane, BorderLayout.CENTER);
552 }
553 else {
554 previous_pane = options_pane.buildLog();
555 right.add(previous_pane, BorderLayout.CENTER);
556 right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time
557 ///ystem.err.println("I've added the log back to the right pane again.");
558 //target_pane.add(previous_pane, BorderLayout.CENTER);
559 }
560 //scroll_pane.setViewportView(previous_pane);
561 previous_pane.validate();
562 }
563 }
564 /** The <strong>OptionTree</strong> is built from these nodes, each of which has several methods used in creating the option panes.
565 */
566 private class OptionTreeNode
567 extends DefaultMutableTreeNode
568 implements Comparable {
569 /** The text label given to this node in the tree. */
570 private String title = null;
571 /** Constructor.
572 * @param title The <strong>String</strong> which serves as this nodes title.
573 */
574 public OptionTreeNode(String title) {
575 super();
576 this.title = title;
577 }
578 /** This method compares two nodes for ordering.
579 * @param obj The <strong>Object</strong> to compare to.
580 * @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.
581 */
582 public int compareTo(Object obj) {
583 return title.compareTo(obj.toString());
584 }
585 /** This method checks if two nodes are equivelent.
586 * @param obj The <strong>Object</strong> to be tested against.
587 * @return A <strong>boolean</strong> which is <i>true</i> if the objects are equal, <i>false</i> otherwise.
588 */
589 public boolean equals(Object obj) {
590 if(compareTo(obj) == 0) {
591 return true;
592 }
593 return false;
594 }
595 /** Method to translate this node into a textual representation.
596 * @return A <strong>String</strong> which in this case is the title.
597 */
598 public String toString() {
599 return title;
600 }
601 }
602}
Note: See TracBrowser for help on using the repository browser.