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

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

Changed calls to the Dictionary.

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