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

Last change on this file since 6540 was 6533, checked in by jmt12, 20 years ago

Finished the design of a new 'simple' creating/progress pane, including merging the two progress bars into one

  • Property svn:keywords set to Author Date Id Revision
File size: 38.0 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.Configuration;
47import org.greenstone.gatherer.Dictionary;
48import org.greenstone.gatherer.Gatherer;
49import org.greenstone.gatherer.cdm.SearchTypeManager;
50import org.greenstone.gatherer.collection.BuildOptions;
51import org.greenstone.gatherer.collection.Collection;
52import org.greenstone.gatherer.gui.GLIButton;
53import org.greenstone.gatherer.gui.OptionsPane;
54import org.greenstone.gatherer.shell.GBasicProgressMonitor;
55import org.greenstone.gatherer.shell.GBuildProgressMonitor;
56import org.greenstone.gatherer.shell.GImportProgressMonitor;
57import org.greenstone.gatherer.shell.GShell;
58import org.greenstone.gatherer.shell.GShellEvent;
59import org.greenstone.gatherer.shell.GShellListener;
60import org.greenstone.gatherer.shell.GShellProgressMonitor;
61import org.greenstone.gatherer.util.AppendLineOnlyFileDocument;
62import org.greenstone.gatherer.util.StaticStrings;
63
64/** 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>
65 * <center><table width=80% border=2 cellspacing=0 cellpadding=2><tr><td align=center colspan=4>
66 * The (i)mport and/or (b)uild options supported:</td></tr>
67 * <tr background=black><font color=white><td>Script</td><td>Associated Argument</td><td>Control</td><td>Comments</td></font></tr>
68 * <tr><td>b</td><td>-allclassifications</td><td>JCheckBox</td><td>&nbsp;</td></tr>
69 * <tr><td>i/b</td><td>-archivedir</td><td>JTextField</td><td>&nbsp;</td></tr>
70 * <tr><td>b</td><td>-builddir</td><td>JTextField</td><td>&nbsp;</td></tr>
71 * <tr><td>i/b</td><td>-debug</td><td>JCheckBox</td><td>&nbsp;</td></tr>
72 * <tr><td>i/b</td><td>-collectdir</td><td>JTextField</td><td>&nbsp;</td></tr>
73 * <tr><td>b</td><td>-create_images</td><td>JCheckBox</td><td>&nbsp;</td></tr>
74 * <tr><td>i</td><td>-groupsize</td><td>JSpinner </td><td>&nbsp;</td></tr>
75 * <tr><td>i</td><td>-gzip</td><td>JCheckBox</td><td>&nbsp;</td></tr>
76 * <tr><td>i</td><td>-importdir</td><td>JTextField</td><td>&nbsp;</td></tr>
77 * <tr><td>b</td><td>-index</td><td>GCheckList</td><td>&nbsp;</td></tr>
78 * <tr><td>i/b</td><td>-keepold</td><td>JCheckBox</td><td>sanity check removeold</td></tr>
79 * <tr><td>i/b</td><td>-maxdocs</td><td>JSpinner</td><td>&nbsp;</td></tr>
80 * <tr><td>b</td><td>-mode</td><td>JComboBox</td><td>"all", "compress_text", "infodb", "build_index"</td></tr>
81 * <tr><td>b</td><td>-no_text</td><td>JCheckBox</td><td>&nbsp;</td></tr>
82 * <tr><td>i</td><td>-OIDtype</td><td>JComboBox</td><td>"hash","incremental"</td></tr>
83 * <tr><td>i/b</td><td>-out</td><td>JTextField</td><td>&nbsp;</td></tr>
84 * <tr><td>i</td><td>-removeold</td><td>JCheckBox</td><td>sanity check keepold</td></tr>
85 * <tr><td>i</td><td>-sortmeta</td><td>JComboBox</td><td>&nbsp;</td></tr>
86 * <tr><td>i/b</td><td>-verbosity</td><td>JSpinner</td><td>1, 3</td></tr>
87 * </table></center>
88 * @author John Thompson, Greenstone Digital Library, University of Waikato
89 * @version 2.3
90 */
91public class CreatePane
92 extends JPanel
93 implements GShellListener {
94
95 static private Dimension ARGUMENT_SIZE = new Dimension(800,90);
96 /** The size of the buttons at the bottom of the screen. */
97 static private Dimension BUTTON_SIZE = new Dimension (256, 40);//(386, 50);
98 /** The size of the labels on the progress pane. */
99 static private Dimension LABEL_SIZE = new Dimension(140, 25);
100 /** The threshold for when the simple view is replaced by the complex one. */
101 static private final int THRESHOLD = Configuration.EXPERT_MODE;
102 /** An identifier for the control panel within the card layout. */
103 static private String CONTROL = "Control";
104 /** An identifier for the progress panel within the card layout. */
105 static private String PROGRESS = "Progress";
106 /** An identifier for the simple panel within the card layout. */
107 static private String SIMPLE = "Simple";
108
109 /** Determines the current view that should be shown for this pane. */
110 public boolean processing = false;
111 /** The options pane generates all the various option sheet configuations. */
112 public OptionsPane options_pane = null;
113 private AppendLineOnlyFileDocument document;
114 /** A card layout is used to store the separate configuration and progress panes. */
115 private CardLayout card_layout = null;
116 /** Stores a reference to the current collection. */
117 private Collection previous_collection = null;
118 /** This monitor tracks the build processes progress. */
119 private GShellProgressMonitor build_monitor = null;
120 /** This monitor tracks the copy processes progress. */
121 private GShellProgressMonitor copy_monitor = null;
122 /** This monitor tracks the import processes progress. */
123 private GShellProgressMonitor import_monitor = null;
124 /** The button for begining the building processes. */
125 private JButton build_button = null;
126 /** The button for stopping the building processes. */
127 private JButton cancel_button = null;
128 /** The button for viewing the collection. */
129 private JButton preview_button = null;
130 private JButton simple_build_button;
131 private JButton simple_cancel_button;
132 private JButton simple_preview_button;
133 /** The label displaying the number of documents in this collection. */
134 private JLabel document_count = null;
135 /** The label alongside the build progress bar gets some special treatment so... */
136 private JLabel progress_build_label = null;
137 /** The label alongside the copy progress bar gets some special treatment so... */
138 private JLabel progress_copy_label = null;
139 /** The label alongside the import progress bar gets some special treatment so... */
140 private JLabel progress_import_label = null;
141 private JPanel bar_area;
142 /** The panel on which buttons are rendered on higher detail modes. */
143 private JPanel button_pane;
144 /** The pane which contains the controls for configuration. */
145 private JPanel control_pane = null;
146 /** The pane which has the card layout as its manager. */
147 private JPanel main_pane = null;
148 /** The pane which contains the progress information. */
149 private JPanel progress_pane = null;
150 /** The pane on the right-hand side - shows the requested options view */
151 private JPanel right = null;
152 /** The simple panel on which all of the available arguments are rendered. */
153 private JPanel sargument_configuration_panel;
154 /** The panel on which buttons are rendered on lower details modes. */
155 private JPanel sbutton_panel;
156 /** A simplified version for lower detail modes containing both the control and progress panes smooshed together. */
157 private JPanel simple_panel;
158 /** The inner panel of the simple pane which is global so that the bar_area can be added and removed from it. */
159 private JPanel sinner_panel;
160 /** The outer panel of the simple pane which is global so that the arguments pane can be added and removed from it. */
161 private JPanel souter_panel;
162 /** The scrolling pane for the log. */
163 private JScrollPane log_scroll;
164 /** The scrolling pane the simple arguments are rendered within. */
165 private JScrollPane sargument_configuration_scroll;
166 /** 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 */
167 private JScrollPane scroll_pane;
168 /** The message log for the entire session. */
169 private JTextArea log_textarea;
170 /** A tree used to display the currently available option views. */
171 private OptionTree tree = null;
172 /** An array used to pass arguments with dictionary calls. */
173 private String args[] = null;
174 /** The homepage address of the current collection */
175 private String homepage = null;
176
177
178 /** The constructor creates important helper classes, and initializes all the components.
179 * @see org.greenstone.gatherer.collection.CollectionManager
180 * @see org.greenstone.gatherer.gui.BuildOptions
181 * @see org.greenstone.gatherer.gui.CreatePane.BuildButtonListener
182 * @see org.greenstone.gatherer.gui.CreatePane.CancelButtonListener
183 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
184 * @see org.greenstone.gatherer.gui.OptionsPane
185 * @see org.greenstone.gatherer.shell.GBasicProgressMonitor
186 * @see org.greenstone.gatherer.shell.GBuildProgressMonitor
187 * @see org.greenstone.gatherer.shell.GImportProgressMonitor
188 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
189 */
190 public CreatePane() {
191 Collection collection = Gatherer.c_man.getCollection();
192 log_textarea = new JTextArea();
193 log_scroll = new JScrollPane(log_textarea);
194
195 // Create components
196 card_layout = new CardLayout();
197 // Control Pane
198 control_pane = new JPanel();
199 tree = new OptionTree();
200 button_pane = new JPanel();
201
202 // Progress Pane
203 progress_pane = new JPanel(); // One owner of the bar component
204 bar_area = new JPanel(); // This component will be shared about
205
206 progress_copy_label = new JLabel();
207 progress_copy_label.setForeground(Color.black);
208 progress_copy_label.setHorizontalAlignment(JLabel.LEFT);
209 progress_copy_label.setPreferredSize(LABEL_SIZE);
210 progress_copy_label.setMinimumSize(LABEL_SIZE);
211 progress_copy_label.setSize(LABEL_SIZE);
212 Dictionary.registerText(progress_copy_label, "CreatePane.Copy_Progress");
213
214 copy_monitor = new GBasicProgressMonitor();
215 Gatherer.c_man.registerCopyMonitor(copy_monitor);
216
217 progress_import_label = new JLabel();
218 progress_import_label.setForeground(Color.black);
219 progress_import_label.setHorizontalAlignment(JLabel.LEFT);
220 progress_import_label.setPreferredSize(LABEL_SIZE);
221 progress_import_label.setMinimumSize(LABEL_SIZE);
222 progress_import_label.setSize(LABEL_SIZE);
223 Dictionary.registerText(progress_import_label, "CreatePane.Import_Progress");
224
225 import_monitor = new GImportProgressMonitor(); //GBasicProgressMonitor();
226 Gatherer.c_man.registerImportMonitor(import_monitor);
227
228 progress_build_label = new JLabel();
229 progress_build_label.setForeground(Color.black);
230 progress_build_label.setHorizontalAlignment(JLabel.LEFT);
231 progress_build_label.setPreferredSize(LABEL_SIZE);
232 progress_build_label.setMinimumSize(LABEL_SIZE);
233 progress_build_label.setSize(LABEL_SIZE);
234 Dictionary.registerText(progress_build_label, "CreatePane.Build_Progress");
235
236 build_monitor = new GBuildProgressMonitor(import_monitor.getSharedProgress()); //GBasicProgressMonitor();
237 Gatherer.c_man.registerBuildMonitor(build_monitor);
238
239 // And the simple panel
240 simple_panel = new JPanel();
241 sbutton_panel = new JPanel();
242 sinner_panel = new JPanel();
243
244 // Buttons
245 BuildButtonListener bbl = new BuildButtonListener();
246 CancelButtonListener cbl = new CancelButtonListener();
247 PreviewButtonListener pbl = new PreviewButtonListener();
248
249 build_button = new GLIButton();
250 build_button.addActionListener(bbl);
251 build_button.setMnemonic(KeyEvent.VK_B);
252 build_button.setPreferredSize(BUTTON_SIZE);
253 Dictionary.registerBoth(build_button, "CreatePane.Build_Collection", "CreatePane.Build_Collection_Tooltip");
254
255 cancel_button = new GLIButton();
256 cancel_button.addActionListener(cbl);
257 cancel_button.setEnabled(false);
258 cancel_button.setMnemonic(KeyEvent.VK_C);
259 cancel_button.setPreferredSize(BUTTON_SIZE);
260 Dictionary.registerBoth(cancel_button, "CreatePane.Cancel_Build", "CreatePane.Cancel_Build_Tooltip");
261
262 preview_button = new GLIButton();
263 preview_button.addActionListener(pbl);
264 if(Gatherer.c_man != null) {
265 preview_button.setEnabled(Gatherer.c_man.built());
266 }
267 else {
268 preview_button.setEnabled(false);
269 }
270 preview_button.setMnemonic(KeyEvent.VK_P);
271 preview_button.setPreferredSize(BUTTON_SIZE);
272 Dictionary.registerBoth(preview_button, "CreatePane.Preview_Collection", "CreatePane.Preview_Collection_Tooltip");
273
274 simple_build_button = new GLIButton();
275 simple_build_button.addActionListener(bbl);
276 simple_build_button.setMnemonic(KeyEvent.VK_B);
277 simple_build_button.setPreferredSize(BUTTON_SIZE);
278 Dictionary.registerBoth(simple_build_button, "CreatePane.Build_Collection", "CreatePane.Build_Collection_Tooltip");
279
280 simple_cancel_button = new GLIButton();
281 simple_cancel_button.addActionListener(cbl);
282 simple_cancel_button.setEnabled(false);
283 simple_cancel_button.setMnemonic(KeyEvent.VK_C);
284 simple_cancel_button.setPreferredSize(BUTTON_SIZE);
285 Dictionary.registerBoth(simple_cancel_button, "CreatePane.Cancel_Build", "CreatePane.Cancel_Build_Tooltip");
286
287 simple_preview_button = new GLIButton();
288 simple_preview_button.addActionListener(pbl);
289 if(Gatherer.c_man != null) {
290 simple_preview_button.setEnabled(Gatherer.c_man.built());
291 }
292 else {
293 simple_preview_button.setEnabled(false);
294 }
295 simple_preview_button.setMnemonic(KeyEvent.VK_P);
296 simple_preview_button.setPreferredSize(BUTTON_SIZE);
297 Dictionary.registerBoth(simple_preview_button, "CreatePane.Preview_Collection", "CreatePane.Preview_Collection_Tooltip");
298
299 bbl = null;
300 cbl = null;
301 pbl = null;
302 }
303
304 /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating.
305 * @param ready A <strong>boolean</strong> indicating if a collection is currently available.
306 * @see org.greenstone.gatherer.Gatherer
307 * @see org.greenstone.gatherer.collection.CollectionManager
308 * @see org.greenstone.gatherer.gui.BuildOptions
309 * @see org.greenstone.gatherer.gui.OptionsPane
310 */
311 public void collectionChanged(boolean ready) {
312 ///ystem.err.println("Collection changed... ");
313 if(Gatherer.c_man == null || !ready) {
314 return;
315 }
316 Collection current_collection = Gatherer.c_man.getCollection();
317 if (current_collection != previous_collection && !Gatherer.c_man.isImporting()) {
318 this.options_pane = new OptionsPane(current_collection.build_options);
319 previous_collection = current_collection;
320 }
321 // If we are in simple mode, we have to rebuild the simple arguments list
322 if(Gatherer.config.getMode() < THRESHOLD) {
323 souter_panel.remove(sargument_configuration_scroll);
324 souter_panel.remove(sinner_panel);
325 sargument_configuration_panel = options_pane.buildImport(null);
326 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
327 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
328 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
329 souter_panel.add(sargument_configuration_scroll);
330 souter_panel.add(sinner_panel);
331 }
332 tree.valueChanged(null);
333
334 // now do the preview stuff
335 if (!Gatherer.c_man.built() || Gatherer.config.exec_address == null) {
336 preview_button.setEnabled(false);
337 simple_preview_button.setEnabled(false);
338 } else {
339 preview_button.setEnabled(true);
340 simple_preview_button.setEnabled(true);
341 }
342 }
343
344 public void destroy() {
345 if(document != null) {
346 document.destroy();
347 }
348 }
349
350 /** This method is called to actually layout the components.
351 * @see org.greenstone.gatherer.Configuration
352 * @see org.greenstone.gatherer.Gatherer
353 */
354 public void display() {
355
356 int current_mode = Gatherer.config.getMode();
357
358 // Build control_pane
359 JPanel left = new JPanel();
360 left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
361 left.setLayout(new BorderLayout());
362 left.add(tree, BorderLayout.CENTER);
363
364 right = new JPanel();
365 right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
366 right.setLayout(new BorderLayout());
367
368 JPanel options_area = new JPanel();
369 options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(Dictionary.get("CreatePane.Options_Title"))));
370 options_area.setLayout(new BorderLayout());
371 options_area.add(left, BorderLayout.WEST);
372 options_area.add(right, BorderLayout.CENTER);
373
374 button_pane = new JPanel();
375 button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10));
376 button_pane.setLayout(new GridLayout(1,3));
377 button_pane.add(build_button);
378 button_pane.add(cancel_button);
379 button_pane.add(preview_button);
380
381 control_pane.setLayout(new BorderLayout());
382 control_pane.add(options_area, BorderLayout.CENTER);
383 control_pane.add(button_pane, BorderLayout.SOUTH);
384
385 // Build progress_pane
386 JPanel copy_pane = new JPanel();
387 copy_pane.setLayout(new BorderLayout());
388 copy_pane.add(progress_copy_label, BorderLayout.WEST);
389 copy_pane.add(copy_monitor.getProgress(), BorderLayout.CENTER);
390
391 JPanel import_pane = new JPanel();
392 import_pane.setLayout(new BorderLayout());
393 import_pane.add(progress_import_label, BorderLayout.WEST);
394 import_pane.add(import_monitor.getProgress(), BorderLayout.CENTER);
395
396 JPanel build_pane = new JPanel();
397 build_pane.setLayout(new BorderLayout());
398 build_pane.add(progress_build_label, BorderLayout.WEST);
399 build_pane.add(build_monitor.getProgress(), BorderLayout.CENTER);
400
401 bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10));
402
403 bar_area.setLayout(new GridLayout(2,2,10,5));
404 bar_area.add(import_pane);
405 bar_area.add(build_pane);
406
407 progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
408 progress_pane.setLayout(new BorderLayout());
409 progress_pane.add(bar_area, BorderLayout.NORTH);
410 if(current_mode >= THRESHOLD) {
411 progress_pane.add(log_scroll, BorderLayout.CENTER);
412 }
413
414 // Simple panel
415 sbutton_panel.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
416 sbutton_panel.setLayout(new GridLayout(3,1));
417 sbutton_panel.add(simple_build_button);
418 sbutton_panel.add(simple_cancel_button);
419 sbutton_panel.add(simple_preview_button);
420
421 JPanel simple_bar_area = new JPanel(new GridLayout(3,1));
422 simple_bar_area.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
423 simple_bar_area.add(import_monitor.getSharedProgress());
424
425 sinner_panel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
426 sinner_panel.setLayout(new BorderLayout());
427 sinner_panel.add(sbutton_panel, BorderLayout.WEST);
428 sinner_panel.add(simple_bar_area, BorderLayout.CENTER);
429
430 if(options_pane != null) {
431 sargument_configuration_panel = options_pane.buildImport(null);
432 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
433 }
434 else {
435 sargument_configuration_panel = new JPanel();
436 }
437 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
438 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
439 souter_panel = new JPanel();
440 souter_panel.setSize(new Dimension(400,800));
441 souter_panel.setLayout(new GridLayout(2,1));
442 souter_panel.add(sargument_configuration_scroll);
443 souter_panel.add(sinner_panel);
444
445 simple_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
446 simple_panel.setLayout(new BorderLayout());
447 simple_panel.add(souter_panel, BorderLayout.NORTH);
448 if(current_mode < THRESHOLD) {
449 simple_panel.add(log_scroll, BorderLayout.CENTER);
450 }
451
452 // Main pane
453 main_pane = new JPanel(card_layout);
454 if(current_mode < THRESHOLD) { // Simple mode - add first
455 main_pane.add(simple_panel, SIMPLE);
456 }
457 main_pane.add(control_pane, CONTROL);
458 main_pane.add(progress_pane, PROGRESS);
459 if(current_mode >= THRESHOLD) { // Expert mode - add last
460 main_pane.add(simple_panel, SIMPLE);
461 }
462
463 this.setLayout(new BorderLayout());
464 this.add(main_pane, BorderLayout.CENTER);
465 }
466
467 /** 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.
468 * @see org.greenstone.gatherer.Gatherer
469 * @see org.greenstone.gatherer.collection.CollectionManager
470 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
471 */
472 public void gainFocus() {
473 if(Gatherer.config.getMode() < THRESHOLD) {
474 card_layout.show(main_pane, SIMPLE);
475 }
476 else if(!processing) {
477 // Move the buttons to control
478 control_pane.add(button_pane, BorderLayout.SOUTH);
479 card_layout.show(main_pane, CONTROL);
480 }
481 else {
482 // Move the buttons to progress
483 progress_pane.add(button_pane, BorderLayout.SOUTH);
484 card_layout.show(main_pane, PROGRESS);
485 }
486 // Refresh the set of controls.
487 TreePath path = tree.getSelectionPath();
488 tree.clearSelection();
489 tree.setSelectionPath(path);
490 }
491
492 /** We are informed when this view pane loses focus so we can update build options. */
493 public void loseFocus() {
494 tree.valueChanged(null);
495 }
496
497 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
498 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
499 */
500 public synchronized void message(GShellEvent event) {
501 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
502 if (event.getMessage().startsWith("import.pl> RecPlug - ")) {
503 return;
504 }
505 document.appendLine(event.getMessage());
506 log_textarea.setCaretPosition(document.getLengthToNearestLine());
507 }
508
509 /** Called when the detail mode has changed which in turn may cause several import/build configuration arguments to be available/hidden
510 * @param mode the new mode as an int
511 */
512 public void modeChanged(int mode) {
513 // If we are below the complexity threshold ensure the simple controls are being shown
514 if(Gatherer.config.getMode() < THRESHOLD) {
515 // Update the arguments
516 souter_panel.remove(sargument_configuration_scroll);
517 souter_panel.remove(sinner_panel);
518 if(options_pane != null) {
519 sargument_configuration_panel = options_pane.buildImport(null);
520 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
521 }
522 else {
523 sargument_configuration_panel = new JPanel();
524 }
525 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
526 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
527 souter_panel.add(sargument_configuration_scroll);
528 souter_panel.add(sinner_panel);
529 // Remove the shared components from the expert panels
530 progress_pane.remove(log_scroll);
531 // And add to simple one
532 simple_panel.add(log_scroll, BorderLayout.CENTER);
533 // And bring the card to the front
534 card_layout.show(main_pane, SIMPLE);
535 }
536 // And if we are above the threshold change to the complex controls
537 else {
538 // Remove the shared components from the simple panel
539 simple_panel.remove(log_scroll);
540 // And add then to the expert ones
541 progress_pane.add(log_scroll, BorderLayout.CENTER);
542 // And bring the appropriate card to the front
543 if(!processing) {
544 control_pane.add(button_pane, BorderLayout.SOUTH);
545 card_layout.show(main_pane, CONTROL);
546 }
547 else {
548 progress_pane.add(button_pane, BorderLayout.SOUTH);
549 card_layout.show(main_pane, PROGRESS);
550 }
551 }
552 tree.valueChanged(null); // Ensure tree argument panels are rebuilt
553 }
554
555 /** 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.
556 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
557 */
558 public synchronized void processBegun(GShellEvent event) {
559 // We don't care. We'll get a more acurate start from the progress monitors.
560 }
561 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
562 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
563 */
564 public synchronized void processComplete(GShellEvent event) {
565 if(event.getStatus() == GShell.OK) {
566 if(event.getType() == GShell.BUILD) {
567 processing = false;
568 build_button.setEnabled(true);
569 cancel_button.setEnabled(false);
570 preview_button.setEnabled(true);
571 simple_build_button.setEnabled(true);
572 simple_cancel_button.setEnabled(false);
573 simple_preview_button.setEnabled(true);
574 int status = event.getStatus();
575 document.setSpecialCharacter(OptionsPane.SUCCESSFUL);
576 options_pane.resetFileEntry();
577 build_monitor.reset();
578 import_monitor.reset();
579 if(Gatherer.config.getMode() >= THRESHOLD) {
580 control_pane.add(button_pane, BorderLayout.SOUTH);
581 card_layout.show(main_pane, CONTROL);
582 }
583 }
584 // Otherwise its completed import but still got build to go
585 }
586 else {
587 processing = false;
588 cancel_button.setEnabled(false);
589 build_button.setEnabled(true);
590 // The build may have failed, but a previous index may still be in place
591 preview_button.setEnabled(Gatherer.c_man.built());
592
593 simple_build_button.setEnabled(true);
594 simple_cancel_button.setEnabled(false);
595 simple_preview_button.setEnabled(Gatherer.c_man.built());
596 if(event.getStatus() == GShell.CANCELLED) {
597 document.setSpecialCharacter(OptionsPane.CANCELLED);
598 }
599 else {
600 document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL);
601 }
602 options_pane.resetFileEntry();
603 if(Gatherer.config.getMode() >= THRESHOLD) {
604 control_pane.add(button_pane, BorderLayout.SOUTH);
605 card_layout.show(main_pane, CONTROL);
606 }
607 }
608 }
609
610 private void configureHomeURL() {
611 // set up the home page for the current collection
612 Collection current_collection = Gatherer.c_man.getCollection();
613 String extra_args = "";
614 SearchTypeManager st_man = current_collection.cdm.searchtype_manager;
615 if (st_man.isMGPPEnabled()) {
616 // we need some more args on the url
617 String search_types = st_man.getSearchTypes();
618 if (search_types.equals("")) {
619 extra_args = "&ct=1&qt=0&qto=3";
620 } else if (search_types.equals("plain")) {
621 extra_args = "&ct=1&qt=0&qto=1";
622 } else if (search_types.equals("form")) {
623 extra_args = "&ct=1&qt=1&qto=2";
624 } else if (search_types.equals("plain,form")) {
625 extra_args = "&ct=1&qt=0&qto=3";
626 } else if (search_types.equals("form,plain")) {
627 extra_args = "&ct=1&qt=1&qto=3";
628 }
629 }
630 // Remember to add unique timestamp
631 homepage = Gatherer.config.exec_address.toString() + "?a=p&p=about&c=" + current_collection.getName()+extra_args + StaticStrings.TIMESTAMP_ARGUMENT + System.currentTimeMillis();
632
633 }
634
635
636 /** This class serves as the listener for actions on the build button. */
637 private class BuildButtonListener
638 implements ActionListener {
639 /** This method causes a call to be made to CollectionManager.importCollection(), which then imports and builds the collection as necessary.
640 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
641 * @see org.greenstone.gatherer.Gatherer
642 * @see org.greenstone.gatherer.collection.CollectionManager
643 * @see org.greenstone.gatherer.gui.BuildOptions
644 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
645 */
646 public void actionPerformed(ActionEvent event) {
647 // First we force the build options to be updated if we haven't already.
648 tree.valueChanged(null);
649
650 // Remember that for lower thresholds the above doesn't work, so try this instead
651 if(Gatherer.config.getMode() < THRESHOLD) {
652 options_pane.update(sargument_configuration_panel);
653 }
654
655 // Now go about building.
656 build_button.setEnabled(false);
657 cancel_button.setEnabled(true);
658 preview_button.setEnabled(false);
659
660 simple_build_button.setEnabled(false);
661 simple_cancel_button.setEnabled(true);
662 simple_preview_button.setEnabled(false);
663
664 document = options_pane.createNewLogDocument();
665 log_textarea.setDocument(document);
666 options_pane.log_textarea.setDocument(document);
667 // Change the view.
668 processing = true;
669 if(Gatherer.config.getMode() >= THRESHOLD) {
670 progress_pane.add(button_pane, BorderLayout.SOUTH);
671 card_layout.show(main_pane, PROGRESS);
672 }
673 // Reset the stop flag in all the process monitors, just incase.
674 ((GBuildProgressMonitor)build_monitor).reset();
675 copy_monitor.setStop(false);
676 import_monitor.setStop(false);
677 // Set removeold automatically.
678 if(Gatherer.c_man.ready() && Gatherer.c_man.built()) {
679 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
680 }
681 // Call CollectionManagers method to build collection.
682 Gatherer.c_man.importCollection();
683 }
684 }
685 /** This class serves as the listener for actions on the cancel button. */
686 private class CancelButtonListener
687 implements ActionListener {
688 /** 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.
689 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
690 * @see org.greenstone.gatherer.Gatherer
691 * @see org.greenstone.gatherer.collection.CollectionManager
692 * @see org.greenstone.gatherer.gui.BuildOptions
693 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
694 */
695 public void actionPerformed(ActionEvent event) {
696 build_button.setEnabled(true);
697 cancel_button.setEnabled(false);
698 preview_button.setEnabled(false);
699
700 simple_build_button.setEnabled(true);
701 simple_cancel_button.setEnabled(false);
702 simple_preview_button.setEnabled(false);
703
704 processing = false;
705 document.setSpecialCharacter(OptionsPane.CANCELLED);
706 if(Gatherer.config.getMode() >= THRESHOLD) {
707 control_pane.add(button_pane, BorderLayout.SOUTH);
708 card_layout.show(main_pane, CONTROL);
709 }
710 // Set the stop flag in all the process monitor.
711 import_monitor.setStop(true);
712 import_monitor.reset();
713 build_monitor.setStop(true);
714 build_monitor.reset();
715 // Set removeold automatically.
716 Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
717 // Remove the collection lock.
718 //Gatherer.g_man.lockCollection(false, false);
719 }
720 }
721
722 private class PreviewButtonListener
723 implements ActionListener {
724
725 public void actionPerformed(ActionEvent event) {
726 configureHomeURL();
727 Gatherer.self.spawnBrowser(homepage);
728
729 }
730 }
731
732 /** 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. */
733 private class OptionTree
734 extends JTree
735 implements TreeSelectionListener {
736 /** The model behind the tree. */
737 private DefaultTreeModel model = null;
738 /** The previous options view displayed, which is sometimes needed to refresh properly. */
739 private JPanel previous_pane = null;
740 /** The node corresponding to the building options view. */
741 private OptionTreeNode building = null;
742 /** The node corresponding to the importing options view. */
743 private OptionTreeNode importing = null;
744 /** The node corresponding to the log view. */
745 private OptionTreeNode log = null;
746 /** The root node of the options tree, which has no associated options view. */
747 private OptionTreeNode options = null;
748 /** Constructor.
749 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
750 */
751 public OptionTree() {
752 super();
753
754 ToolTipManager.sharedInstance().registerComponent(this);
755 addTreeSelectionListener(this);
756 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
757 setCellRenderer(new ToolTipTreeCellRenderer());
758 setRootVisible(false);
759 setToggleClickCount(1);
760
761 // Create tree.
762 building = new OptionTreeNode(Dictionary.get("CreatePane.Build"));
763 building.setToolTipText(Dictionary.get("CreatePane.Build_Tooltip"));
764 importing = new OptionTreeNode(Dictionary.get("CreatePane.Import"));
765 importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip"));
766 log = new OptionTreeNode(Dictionary.get("CreatePane.Log"));
767 log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip"));
768 options = new OptionTreeNode(Dictionary.get("CreatePane.Options"));
769
770 model = new DefaultTreeModel(options);
771 setModel(model);
772 model.insertNodeInto(importing, options, 0);
773 model.insertNodeInto(building, options, 1);
774 model.insertNodeInto(log, options, 2);
775 // Expand the root node
776 expandPath(new TreePath(options));
777 }
778 /** 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.
779 * @param event A <Strong>TreeSelectionEvent</strong> which contains all the information garnered when the event occured.
780 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
781 */
782 public void valueChanged(TreeSelectionEvent event) {
783 TreePath path = null;
784 OptionTreeNode node = null;
785 //if(event != null) {
786 //path = event.getPath();
787 path = getSelectionPath();
788 if(path != null) {
789 node = (OptionTreeNode)path.getLastPathComponent();
790 }
791 //}
792 if(previous_pane != null) {
793 //target_pane.remove(previous_pane);
794 options_pane.update(previous_pane);
795 if(scroll_pane != null) {
796 right.remove(scroll_pane);
797 }
798 else {
799 right.remove(previous_pane);
800 }
801 previous_pane = null;
802 scroll_pane = null;
803 }
804 if(node != null && node.equals(building)) {
805 previous_pane = options_pane.buildBuild(null);
806 scroll_pane = new JScrollPane(previous_pane);
807 right.add(scroll_pane, BorderLayout.CENTER);
808 //target_pane.add(previous_pane, BorderLayout.CENTER);
809 }
810 else if(node != null && node.equals(importing)) {
811 previous_pane = options_pane.buildImport(null);
812 scroll_pane = new JScrollPane(previous_pane);
813 right.add(scroll_pane, BorderLayout.CENTER);
814 //target_pane.add(previous_pane, BorderLayout.CENTER);
815 }
816 else {
817 previous_pane = options_pane.buildLog();
818 right.add(previous_pane, BorderLayout.CENTER);
819 right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time
820 ///ystem.err.println("I've added the log back to the right pane again.");
821 //target_pane.add(previous_pane, BorderLayout.CENTER);
822 }
823 //scroll_pane.setViewportView(previous_pane);
824 //previous_pane.validate();
825 right.validate();
826 //System.err.println("Current pane size: " + previous_pane.getSize());
827 //System.err.println("While its preferred size is: " + previous_pane.getPreferredSize());
828 }
829 }
830
831 /** The <strong>OptionTree</strong> is built from these nodes, each of which has several methods used in creating the option panes.
832 */
833 private class OptionTreeNode
834 extends DefaultMutableTreeNode
835 implements Comparable {
836 /** The text label given to this node in the tree. */
837 private String title = null;
838 /** a tool tip to be used for this node in the tree */
839 private String tool_tip = null;
840 /** Constructor.
841 * @param title The <strong>String</strong> which serves as this nodes title.
842 */
843 public OptionTreeNode(String title) {
844 super();
845 this.title = title;
846 }
847
848 /** This method compares two nodes for ordering.
849 * @param obj The <strong>Object</strong> to compare to.
850 * @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.
851 */
852 public int compareTo(Object obj) {
853 return title.compareTo(obj.toString());
854 }
855
856 /** This method checks if two nodes are equivalent.
857 * @param obj The <strong>Object</strong> to be tested against.
858 * @return A <strong>boolean</strong> which is <i>true</i> if the objects are equal, <i>false</i> otherwise.
859 */
860 public boolean equals(Object obj) {
861 if(compareTo(obj) == 0) {
862 return true;
863 }
864 return false;
865 }
866
867 /** get the tool tip */
868 public String getToolTipText() {
869 return tool_tip;
870 }
871
872 /** set the tool tip */
873 public void setToolTipText(String tip) {
874 tool_tip = tip;
875 }
876
877 /** Method to translate this node into a textual representation.
878 * @return A <strong>String</strong> which in this case is the title.
879 */
880 public String toString() {
881 return title;
882 }
883 }
884
885 // Adds tooltips to the tree nodes
886 private class ToolTipTreeCellRenderer
887 extends DefaultTreeCellRenderer {
888
889 public Component getTreeCellRendererComponent(JTree tree,
890 Object value,
891 boolean sel,
892 boolean expanded,
893 boolean leaf,
894 int row,
895 boolean hasFocus) {
896
897 super.getTreeCellRendererComponent(tree, value, sel,
898 expanded, leaf, row,
899 hasFocus);
900 if (value instanceof OptionTreeNode) {
901 String tip = ((OptionTreeNode) value).getToolTipText();
902 if (tip != null) {
903 setToolTipText(tip);
904 }
905 }
906 return this;
907 }
908 }
909}
Note: See TracBrowser for help on using the repository browser.