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

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

Fixed tabbing.

  • Property svn:keywords set to Author Date Id Revision
File size: 27.1 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 /** This monitor tracks the build processes progress. */
91 private GShellProgressMonitor build_monitor = null;
92 /** This monitor tracks the copy processes progress. */
93 private GShellProgressMonitor copy_monitor = null;
94 /** This monitor tracks the import processes progress. */
95 private GShellProgressMonitor import_monitor = null;
96 /** The button for begining the building processes. */
97 private JButton build_button = null;
98 /** The button for stopping the building processes. */
99 private JButton cancel_button = null;
100 /** The label displaying the number of documents in this collection. */
101 private JLabel document_count = null;
102 /** The label alongside the build progress bar gets some special treatment so... */
103 private JLabel progress_build_label = null;
104 /** The label alongside the copy progress bar gets some special treatment so... */
105 private JLabel progress_copy_label = null;
106 /** The label alongside the import progress bar gets some special treatment so... */
107 private JLabel progress_import_label = null;
108 /** The pane which contains the controls for configuration. */
109 private JPanel control_pane = null;
110 /** The pane which has the card layout as its manager. */
111 private JPanel main_pane = null;
112 /** The pane which contains the progress information. */
113 private JPanel progress_pane = null;
114 /** the pane on the right-hand side - shows the requested options view */
115 private JPanel right = null;
116 /** This pane is the one that is updated to show the requested options view. */
117 //private JPanel target_pane = null;
118 /** The scrolling pane the log is inside. */
119 private JScrollPane scroll_log = null;
120 /** 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 */
121 private JScrollPane scroll_pane;
122 /** The log for the current process. */
123 private JTextArea process_log = null;
124 /** The message log for the entire session. */
125 private JTextArea message_log = new JTextArea();
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 //this.target_pane = new JPanel(new BorderLayout());
152 Collection collection = Gatherer.c_man.getCollection();
153 //if(collection != null) {
154 // this.options_pane = new OptionsPane(message_log, collection.build_options);
155 // }
156 // Create components
157 card_layout = new CardLayout();
158 // Control Pane
159 control_pane = new JPanel();
160 args = new String[1];
161 args[0] = "0";
162 document_count = new JLabel(get("Document_Count", args));
163 tree = new OptionTree();
164 // Progress Pane
165 progress_pane = new JPanel();
166
167 progress_copy_label = new JLabel(get("Copy_Progress"));
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
174 copy_monitor = new GBasicProgressMonitor();
175 Gatherer.c_man.registerCopyMonitor(copy_monitor);
176
177 progress_import_label = new JLabel(get("Import_Progress"));
178 progress_import_label.setForeground(Color.black);
179 progress_import_label.setHorizontalAlignment(JLabel.LEFT);
180 progress_import_label.setPreferredSize(LABEL_SIZE);
181 progress_import_label.setMinimumSize(LABEL_SIZE);
182 progress_import_label.setSize(LABEL_SIZE);
183
184 import_monitor = new GImportProgressMonitor(); //GBasicProgressMonitor();
185 Gatherer.c_man.registerImportMonitor(import_monitor);
186
187 progress_build_label = new JLabel(get("Build_Progress"));
188 progress_build_label.setForeground(Color.black);
189 progress_build_label.setHorizontalAlignment(JLabel.LEFT);
190 progress_build_label.setPreferredSize(LABEL_SIZE);
191 progress_build_label.setMinimumSize(LABEL_SIZE);
192 progress_build_label.setSize(LABEL_SIZE);
193
194 build_monitor = new GBuildProgressMonitor((GImportProgressMonitor)import_monitor); //GBasicProgressMonitor();
195 Gatherer.c_man.registerBuildMonitor(build_monitor);
196
197 // Buttons.
198 build_button = new JButton(get("Build_Collection"));
199 build_button.addActionListener(new BuildButtonListener());
200 build_button.setPreferredSize(BUTTON_SIZE);
201 cancel_button = new JButton(get("Cancel_Build"));
202 cancel_button.addActionListener(new CancelButtonListener());
203 cancel_button.setEnabled(false);
204 cancel_button.setPreferredSize(BUTTON_SIZE);
205 }
206 /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating.
207 * @param ready A <strong>boolean</strong> indicating if a collection is currently available.
208 * @see org.greenstone.gatherer.Gatherer
209 * @see org.greenstone.gatherer.collection.CollectionManager
210 * @see org.greenstone.gatherer.gui.BuildOptions
211 * @see org.greenstone.gatherer.gui.OptionsPane
212 */
213 public void collectionChanged(boolean ready) {
214 ///ystem.err.println("Collection changed... ");
215 if(Gatherer.c_man != null && Gatherer.c_man.ready()) {
216
217 if (!processing &&this.options_pane!=null) {
218 // 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
219 this.options_pane.resetLogList(); // saves any residual message
220 }
221 this.options_pane = new OptionsPane(message_log, Gatherer.c_man.getCollection().build_options);
222 tree.valueChanged(null);
223 }
224 }
225 /** This method is called to actually layout the components.
226 * @see org.greenstone.gatherer.Configuration
227 * @see org.greenstone.gatherer.Gatherer
228 */
229 public void display() {
230 // Build control_pane
231 JPanel stats_area = new JPanel();
232 stats_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(get("Statistics_Title"))));
233 stats_area.setLayout(new GridLayout(1,1));
234 stats_area.add(document_count);
235
236 JPanel left = new JPanel();
237 left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
238 left.setLayout(new BorderLayout());
239 left.add(tree, BorderLayout.CENTER);
240
241 right = new JPanel();
242 right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
243 right.setLayout(new BorderLayout());
244 //scroll_pane = new JScrollPane(target_pane);
245 //right.add(scroll_pane, BorderLayout.CENTER);
246
247 JPanel options_area = new JPanel();
248 options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(get("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 //control_pane.add(stats_area, BorderLayout.SOUTH);
256
257 // Build progress_pane
258 JPanel copy_pane = new JPanel();
259 copy_pane.setLayout(new BorderLayout());
260 copy_pane.add(progress_copy_label, BorderLayout.WEST);
261 copy_pane.add(copy_monitor.getProgress(), BorderLayout.CENTER);
262
263 JPanel import_pane = new JPanel();
264 import_pane.setLayout(new BorderLayout());
265 import_pane.add(progress_import_label, BorderLayout.WEST);
266 import_pane.add(import_monitor.getProgress(), BorderLayout.CENTER);
267
268 JPanel build_pane = new JPanel();
269 build_pane.setLayout(new BorderLayout());
270 build_pane.add(progress_build_label, BorderLayout.WEST);
271 build_pane.add(build_monitor.getProgress(), BorderLayout.CENTER);
272
273 JPanel bar_area = new JPanel();
274 bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10));
275
276 bar_area.setLayout(new GridLayout(2,2,10,5));
277 bar_area.add(import_pane);
278 bar_area.add(build_pane);
279
280
281 progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
282 progress_pane.setLayout(new BorderLayout());
283 progress_pane.add(bar_area, BorderLayout.NORTH);
284
285 // Main pane
286 main_pane = new JPanel(card_layout);
287 main_pane.add(control_pane, CONTROL);
288 main_pane.add(progress_pane, PROGRESS);
289
290 // Buttons
291 JPanel button_pane = new JPanel();
292 button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10));
293 button_pane.setLayout(new GridLayout(1,2));
294 button_pane.add(build_button);
295 button_pane.add(cancel_button);
296
297 this.setLayout(new BorderLayout());
298 this.add(main_pane, BorderLayout.CENTER);
299 this.add(button_pane, BorderLayout.SOUTH);
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 //args = new String[1];
310 //if(Gatherer.c_man.ready()) {
311 // args[0] = String.valueOf(Gatherer.c_man.getCollection().getDocumentCount());
312 //}
313 //else {
314 //args[0] = "0";
315 //}
316 //document_count.setText(get("Document_Count", args));
317 }
318 // Refresh the set of controls.
319 TreePath path = tree.getSelectionPath();
320 tree.clearSelection();
321 tree.setSelectionPath(path);
322 }
323 /** Method to acquire the progress monitor associated with builds.
324 * @return The build <strong>GShellProgressMonitor</strong>.
325 */
326 public GShellProgressMonitor getBuildProgress() {
327 return build_monitor;
328 }
329 /** Method to acquire the progress monitor associated with copying.
330 * @return The copying <strong>GShellProgressMonitor</strong>.
331 */
332 public GShellProgressMonitor getCopyProgress() {
333 return copy_monitor;
334 }
335 /** Method to acquire the progress monitor associated with import.
336 * @return The import <strong>GShellProgressMonitor</strong>.
337 */
338 public GShellProgressMonitor getImportProgress() {
339 return import_monitor;
340 }
341
342 /** We are informed when this view pane loses focus so we can update build options. */
343 public void loseFocus() {
344 tree.valueChanged(null);
345 }
346
347 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
348 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
349 */
350 public synchronized void message(GShellEvent event) {
351 ///ystem.err.println("Recieved message: " + event.getMessage());
352 String text = event.getMessage();
353 message_log.append(text + "\n");
354 if(process_log != null) {
355 process_log.append(text + "\n");
356 process_log.setCaretPosition(process_log.getCaretPosition() + text.length() + 1);
357 //scroll_log.getVerticalScrollBar().setValue(process_log.getHeight() - process_log.getVisibleRect().height);
358 }
359 }
360 /** 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.
361 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
362 */
363 public synchronized void processBegun(GShellEvent event) {
364 // We don't care. We'll get a more acurate start from the progress monitors.
365 }
366 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
367 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
368 */
369 public synchronized void processComplete(GShellEvent event) {
370 if(event.getType() == GShell.BUILD) {
371 processing = false;
372 cancel_button.setEnabled(false);
373 build_button.setEnabled(true);
374 int status = event.getStatus();
375 if (status == GShell.OK) {
376 options_pane.addNewLog(OptionsPane.SUCCESSFUL);
377 } else {
378 options_pane.addNewLog(OptionsPane.UNSUCCESSFUL);
379 }
380 card_layout.show(main_pane, CONTROL);
381 }
382 }
383 /** This method retrieves a phrase from the dictionary based apon the key.
384 * @param key A <strong>String</strong> used as a reference to the correct phrase.
385 * @return A phrase, matching the key, as a <strong>String</strong>.
386 */
387 private String get(String key) {
388 return get(key, null);
389 }
390 /** This method retrieves a phrase from the dictionary based apon the key and arguments.
391 * @param key A <strong>String</strong> used as a reference to the correct phrase.
392 * @param args A <strong>String[]</strong> whose contents are often substituted into the phrase before it is returned.
393 * @return A phrase, matching the key and constructed using the arguments, as a <strong>String</strong>.
394 * @see org.greenstone.gatherer.Dictionary
395 * @see org.greenstone.gatherer.Gatherer
396 */
397 private String get(String key, String args[]) {
398 if(key.indexOf(".") == -1) {
399 key = "CreatePane." + key;
400 }
401 return Gatherer.dictionary.get(key, args);
402 }
403 /** This class serves as the listener for actions on the build button. */
404 private class BuildButtonListener
405 implements ActionListener {
406 /** This method causes a call to be made to CollectionManager.importCollection(), which then imports and builds the collection as necessary.
407 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
408 * @see org.greenstone.gatherer.Gatherer
409 * @see org.greenstone.gatherer.collection.CollectionManager
410 * @see org.greenstone.gatherer.gui.BuildOptions
411 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
412 */
413 public void actionPerformed(ActionEvent event) {
414 // First we force the build options to be updated if we haven't already.
415 tree.valueChanged(null);
416 // Now go about building.
417 build_button.setEnabled(false);
418 cancel_button.setEnabled(true);
419 // Create a new process log, and place it.
420 if(scroll_log != null) {
421 progress_pane.remove(scroll_log);
422 }
423 process_log = new JTextArea();
424 scroll_log = new JScrollPane(process_log);
425 progress_pane.add(scroll_log, BorderLayout.CENTER);
426 // clear the log list and message_log
427 options_pane.resetLogList();
428 // Change the view.
429 processing = true;
430 card_layout.show(main_pane, PROGRESS);
431 // Reset the stop flag in all the process monitors, just incase.
432 ((GBuildProgressMonitor)build_monitor).reset();
433 copy_monitor.setStop(false);
434 import_monitor.setStop(false);
435 // Set removeold automatically.
436 if(Gatherer.c_man.ready() && !Gatherer.c_man.built()) {
437 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
438 }
439 // Call CollectionManagers method to build collection.
440 Gatherer.c_man.importCollection();
441 }
442 }
443 /** This class serves as the listener for actions on the cancel button. */
444 private class CancelButtonListener
445 implements ActionListener {
446 /** 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.
447 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
448 * @see org.greenstone.gatherer.Gatherer
449 * @see org.greenstone.gatherer.collection.CollectionManager
450 * @see org.greenstone.gatherer.gui.BuildOptions
451 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
452 */
453 public void actionPerformed(ActionEvent event) {
454 build_button.setEnabled(true);
455 cancel_button.setEnabled(false);
456 processing = false;
457 options_pane.addNewLog(OptionsPane.CANCELLED);
458 card_layout.show(main_pane, CONTROL);
459 // Set the stop flag in all the process monitor.
460 build_monitor.setStop(true);
461 copy_monitor.setStop(true);
462 import_monitor.setStop(true);
463 // Set removeold automatically.
464 if(Gatherer.c_man.ready()) { // and it should be.
465 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
466 }
467 // Remove the collection lock.
468 Gatherer.g_man.lockCollection(false, false);
469 }
470 }
471 /** 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. */
472 private class OptionTree
473 extends JTree
474 implements TreeSelectionListener {
475 /** The model behind the tree. */
476 private DefaultTreeModel model = null;
477 /** The previous options view displayed, which is sometimes needed to refresh properly. */
478 private JPanel previous_pane = null;
479 /** The node corresponding to the building options view. */
480 private OptionTreeNode building = null;
481 /** The node corresponding to the importing options view. */
482 private OptionTreeNode importing = null;
483 /** The node corresponding to the log view. */
484 private OptionTreeNode log = null;
485 /** The root node of the options tree, which has no associated options view. */
486 private OptionTreeNode options = null;
487 /** Constructor.
488 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
489 */
490 public OptionTree() {
491 super();
492 addTreeSelectionListener(this);
493 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
494 setRootVisible(false);
495 setToggleClickCount(1);
496 // Create tree.
497 building = new OptionTreeNode(get("Build"));
498 importing = new OptionTreeNode(get("Import"));
499 log = new OptionTreeNode(get("Log"));
500 options = new OptionTreeNode(get("Options"));
501
502 model = new DefaultTreeModel(options);
503 setModel(model);
504 model.insertNodeInto(importing, options, 0);
505 model.insertNodeInto(building, options, 1);
506 model.insertNodeInto(log, options, 2);
507 // Expand the root node
508 expandPath(new TreePath(options));
509 }
510 /** 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.
511 * @param event A <Strong>TreeSelectionEvent</strong> which contains all the information garnered when the event occured.
512 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
513 */
514 public void valueChanged(TreeSelectionEvent event) {
515 TreePath path = null;
516 OptionTreeNode node = null;
517 //if(event != null) {
518 //path = event.getPath();
519 path = getSelectionPath();
520 if(path != null) {
521 node = (OptionTreeNode)path.getLastPathComponent();
522 }
523 //}
524 if(previous_pane != null) {
525 //target_pane.remove(previous_pane);
526 options_pane.update(previous_pane);
527 if(scroll_pane != null) {
528 right.remove(scroll_pane);
529 }
530 else {
531 right.remove(previous_pane);
532 }
533 previous_pane = null;
534 scroll_pane = null;
535 }
536 if(node != null && node.equals(building)) {
537 previous_pane = options_pane.buildBuild();
538 scroll_pane = new JScrollPane(previous_pane);
539 right.add(scroll_pane, BorderLayout.CENTER);
540 //target_pane.add(previous_pane, BorderLayout.CENTER);
541 }
542 else if(node != null && node.equals(importing)) {
543 previous_pane = options_pane.buildImport();
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 {
549 previous_pane = options_pane.buildLog();
550 right.add(previous_pane, BorderLayout.CENTER);
551 right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time
552 ///ystem.err.println("I've added the log back to the right pane again.");
553 //target_pane.add(previous_pane, BorderLayout.CENTER);
554 }
555 //scroll_pane.setViewportView(previous_pane);
556 previous_pane.validate();
557 }
558 }
559 /** The <strong>OptionTree</strong> is built from these nodes, each of which has several methods used in creating the option panes.
560 */
561 private class OptionTreeNode
562 extends DefaultMutableTreeNode
563 implements Comparable {
564 /** The text label given to this node in the tree. */
565 private String title = null;
566 /** Constructor.
567 * @param title The <strong>String</strong> which serves as this nodes title.
568 */
569 public OptionTreeNode(String title) {
570 super();
571 this.title = title;
572 }
573 /** This method compares two nodes for ordering.
574 * @param obj The <strong>Object</strong> to compare to.
575 * @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.
576 */
577 public int compareTo(Object obj) {
578 return title.compareTo(obj.toString());
579 }
580 /** This method checks if two nodes are equivelent.
581 * @param obj The <strong>Object</strong> to be tested against.
582 * @return A <strong>boolean</strong> which is <i>true</i> if the objects are equal, <i>false</i> otherwise.
583 */
584 public boolean equals(Object obj) {
585 if(compareTo(obj) == 0) {
586 return true;
587 }
588 return false;
589 }
590 /** Method to translate this node into a textual representation.
591 * @return A <strong>String</strong> which in this case is the title.
592 */
593 public String toString() {
594 return title;
595 }
596 }
597}
Note: See TracBrowser for help on using the repository browser.