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

Last change on this file since 5181 was 5164, checked in by jmt12, 21 years ago

I can't remember what has changed, but I bet it was for the better

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