source: gli/trunk/src/org/greenstone/gatherer/gui/OptionsPane.java@ 20957

Last change on this file since 20957 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

  • Property svn:keywords set to Author Date Id Revision
File size: 25.9 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 java.util.*;
43import javax.swing.*;
44import javax.swing.event.*;
45import javax.swing.text.*;
46import org.greenstone.gatherer.Configuration;
47import org.greenstone.gatherer.DebugStream;
48import org.greenstone.gatherer.Dictionary;
49import org.greenstone.gatherer.Gatherer;
50import org.greenstone.gatherer.cdm.Argument;
51import org.greenstone.gatherer.cdm.ArgumentControl;
52import org.greenstone.gatherer.collection.ScriptOptions;
53import org.greenstone.gatherer.collection.Collection;
54import org.greenstone.gatherer.collection.CollectionManager;
55import org.greenstone.gatherer.util.AppendLineOnlyFileDocument;
56import org.greenstone.gatherer.util.AppendLineOnlyFileDocumentOwner;
57import org.greenstone.gatherer.util.StaticStrings;
58
59/** This class serves as the data holder for all subclasses of option panes, such as Import options or All options. It also contains methods for creating each of the option lines as they would appear in the subpane. Futhermore it has a method for considering all the arguments and generating a <strong>String[]</strong> to allow you to pass them to the <strong>GShell</strong>.
60 * @author John Thompson, Greenstone Digital Library, University of Waikato
61 * @version 2.2
62 */
63public class OptionsPane
64 extends JPanel
65 implements AppendLineOnlyFileDocumentOwner, MouseListener {
66
67 static final public char SUCCESSFUL = 's';
68 static final public char UNSUCCESSFUL = 'u';
69 static final public char CANCELLED = 'c';
70 static final public char UNKNOWN = 'x';
71 static final public char SCHEDULED = 'd';
72
73 static private int BUILD = 0;
74 static private int IMPORT = 1;
75 static private int SCHEDULE = 2;
76 static private int MINIMUM_ROWS = 15;
77
78 /** All process messages are written to this log text area. */
79 public JTextArea log_textarea = null;
80
81 private ArrayList current_controls;
82
83 /** The <strong>ScriptOptions</strong> data object contains all the option settings we wish to persist between Gatherer sessions (and thus is stored in <strong>Collection</strong>). */
84 private ScriptOptions build_options = null;
85 private ScriptOptions import_options = null;
86 private ScriptOptions schedule_options = null;
87
88 private FileEntry file_entry = null;
89
90 /** the log pane - we only create it once now, not each time */
91 private JPanel log_pane = null;
92 /** the list of previous log messages */
93 private JList log_list = null;
94 private Vector writing_documents;
95
96
97 /** The default constructor creates the few session length options, but either retrieves the rest from the current collection, or creates a default set of options. */
98 public OptionsPane(ScriptOptions import_options, ScriptOptions build_options, ScriptOptions schedule_options) {
99 this.build_options = build_options;
100 this.import_options = import_options;
101 this.schedule_options = schedule_options;
102 this.current_controls = new ArrayList();
103 this.writing_documents = new Vector();
104 this.setComponentOrientation(Dictionary.getOrientation());
105
106 // Have to do this here, not in display, as the message log view may not have been displayed yet.
107 log_textarea = new JTextArea();
108 log_textarea.setComponentOrientation(Dictionary.getOrientation());
109 log_textarea.setEditable(false);
110 }
111
112 /** This method creates the panel with all the build only options on it.
113 * @param pane a JPanel which already has previous arguments available on it, to allow for lower moes to concatenate all of the arguments together
114 * @return a JPanel which can be used to display all the build only options
115 * @see org.greenstone.gatherer.Configuration#EXPERT_MODE
116 * @see org.greenstone.gatherer.Configuration#getColor
117 * @see org.greenstone.gatherer.Configuration#getMode
118 * @see org.greenstone.gatherer.Gatherer#config
119 * @see org.greenstone.gatherer.cdm.Argument
120 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildArgument
121 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildArgumentCount
122 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildValue
123 * @see org.greenstone.gatherer.collection.BuildOptions#getBuildValueEnabled
124 * @see org.greenstone.gatherer.gui.OptionsPane.MyArgumentControl
125 */
126 public JPanel buildBuild(JPanel pane) {
127 // Reset the arguments
128 if(pane == null) {
129 current_controls.clear();
130 }
131 ArrayList build_arguments = new ArrayList();
132 int current_mode = Configuration.getMode();
133 int total_build_argument_count = build_options.getArgumentCount();
134
135 for(int i = 0; i < total_build_argument_count; i++) {
136 // Retrieve the argument so we know how to format the control.
137 Argument argument = build_options.getArgument(i);
138
139 //A hack to make the disable_OAI option visible in the GLI for Greenstone 3
140 if(argument.getName().equals(StaticStrings.DISABLEOAI_STR) && Gatherer.GS3) {
141 argument.setHiddenGLI(false);
142 }
143 if(!argument.isHiddenGLI() && argument.getModeLevel() <= current_mode) {
144 // Now attempt to retrieve any existing value for this argument.
145 boolean enabled = build_options.getValueEnabled(argument.getName());
146 String value = build_options.getValue(argument.getName());
147 MyArgumentControl argument_control = new MyArgumentControl(BUILD, argument, enabled, value);
148 build_arguments.add(argument_control);
149 }
150 }
151 current_controls.addAll(build_arguments);
152
153 // Now that we know how many arguments there are we can build the pane to view them on. Modes lower than EXPERT can provide a previous pane on which to add the arguments.
154 if(pane == null || current_mode >= Configuration.EXPERT_MODE) {
155 pane = new JPanel();
156 pane.setComponentOrientation(Dictionary.getOrientation());
157 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
158 pane.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
159 int argument_count = build_arguments.size();
160 // If in any of the higher detail modes, and assuming we don't want super phat argument controls, we better ensure there is a minimum number of lines in the grid layout
161 if(current_mode >= Configuration.EXPERT_MODE) {
162 if(argument_count < MINIMUM_ROWS) {
163 argument_count = MINIMUM_ROWS;
164 }
165 pane.setLayout(new GridLayout(argument_count, 1, 5, 5));
166 }
167 // Otherwise we're just going to throw them on one after another and chuck it in a scroll pane anyway
168 else {
169 // use GridLayout with 0 rows == as many rows as needed. Unfortunately, rows will
170 // grow fat if space too large, but we don't know how many rows we'll need yet.
171 pane.setLayout(new GridLayout(0, 1, 5, 5));
172 }
173 }
174
175 for(int j = 0; j < build_arguments.size(); j++) {
176 pane.add((JComponent)build_arguments.get(j));
177 }
178 pane.addMouseListener(this);
179 build_arguments = null;
180 return pane;
181 }
182
183 /**Wendy's attempt at writing a buildSchedule Jpanel. */
184 public JPanel buildSchedule(JPanel pane) {
185 //reset the arguments
186 if(pane == null) {
187 current_controls.clear();
188 }
189
190 ArrayList schedule_arguments = new ArrayList();
191 int current_mode = Configuration.getMode();
192
193 int total_schedule_argument_count = schedule_options.getArgumentCount();
194
195 for(int i = 0; i < total_schedule_argument_count; i++) {
196 // Retrieve the argument so we know how to format the control.
197 Argument argument = schedule_options.getArgument(i);
198
199 //A hack to make the disable_OAI option visible in the GLI for Greenstone 3
200 if(argument.getName().equals(StaticStrings.DISABLEOAI_STR) && Gatherer.GS3) {
201 argument.setHiddenGLI(false);
202 }
203 if(!argument.isHiddenGLI() && argument.getModeLevel() <= current_mode) {
204 // Now attempt to retrieve any existing value for this argument.
205 boolean enabled = schedule_options.getValueEnabled(argument.getName());
206 String value = schedule_options.getValue(argument.getName());
207 MyArgumentControl argument_control = new MyArgumentControl(SCHEDULE, argument, enabled, value);
208 schedule_arguments.add(argument_control);
209 }
210 }
211 current_controls.addAll(schedule_arguments);
212
213 // Now that we know how many arguments there are we can build the pane to view them on. Modes lower than EXPERT can provide a previous pane on which to add the arguments.
214 if(pane == null || current_mode >= Configuration.EXPERT_MODE) {
215 pane = new JPanel();
216 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
217 pane.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
218 int argument_count = schedule_arguments.size();
219 // If in any of the higher detail modes, and assuming we don't want super phat argument controls, we better ensure there is a minimum number of lines in the grid layout
220 if(current_mode >= Configuration.EXPERT_MODE) {
221 if(argument_count < MINIMUM_ROWS) {
222 argument_count = MINIMUM_ROWS;
223 }
224 pane.setLayout(new GridLayout(argument_count, 1, 5, 5));
225 }
226 // Otherwise we're just going to throw them on one after another and chuck it in a scroll pane anyway
227 else {
228 // use GridLayout with 0 rows == as many rows as needed. Unfortunately, rows will
229 // grow fat if space too large, but we don't know how many rows we'll need yet.
230 pane.setLayout(new GridLayout(0, 1, 5, 5));
231 }
232 }
233
234 for(int j = 0; j < schedule_arguments.size(); j++) {
235 pane.add((JComponent)schedule_arguments.get(j));
236 }
237 pane.addMouseListener(this);
238 schedule_arguments = null;
239 return pane;
240
241 }
242
243 /** This method creates the panel with all the import only options on it.
244 * @param pane a JPanel which already has previous arguments available on it, to allow for lower moes to concatenate all of the arguments together
245 * @return a JPanel which can be used to display all the build only options
246 * @see org.greenstone.gatherer.Configuration#EXPERT_MODE
247 * @see org.greenstone.gatherer.Configuration#getColor
248 * @see org.greenstone.gatherer.Configuration#getMode
249 * @see org.greenstone.gatherer.Gatherer#config
250 * @see org.greenstone.gatherer.cdm.Argument
251 * @see org.greenstone.gatherer.collection.BuildOptions#getImportArgument
252 * @see org.greenstone.gatherer.collection.BuildOptions#getImportArgumentCount
253 * @see org.greenstone.gatherer.collection.BuildOptions#getImportValue
254 * @see org.greenstone.gatherer.collection.BuildOptions#getImportValueEnabled
255 * @see org.greenstone.gatherer.gui.OptionsPane.ArgumentControl
256 */
257 public JPanel buildImport(JPanel pane) {
258 // Reset the arguments
259 if(pane == null) {
260 current_controls.clear();
261 }
262 ArrayList import_arguments = new ArrayList();
263 int current_mode = Configuration.getMode();
264 int total_import_argument_count = import_options.getArgumentCount();
265 for(int i = 0; i < total_import_argument_count; i++) {
266 // Retrieve the argument so we know how to format the control.
267 Argument argument = import_options.getArgument(i);
268 if(!argument.isHiddenGLI() && argument.getModeLevel() <= current_mode) {
269 // Now attempt to retrieve any existing value for this argument.
270 boolean enabled = import_options.getValueEnabled(argument.getName());
271 String value = import_options.getValue(argument.getName());
272 MyArgumentControl argument_control = new MyArgumentControl(IMPORT, argument, enabled, value);
273 import_arguments.add(argument_control);
274 }
275 }
276 current_controls.addAll(import_arguments);
277 // Now that we know how many arguments there are we can build the pane to view them on. Modes lower than EXPERT can provide a previous pane on which to add the arguments.
278 if(pane == null || current_mode >= Configuration.EXPERT_MODE) {
279 pane = new JPanel();
280 pane.setComponentOrientation(Dictionary.getOrientation());
281 pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
282 pane.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
283 int argument_count = import_arguments.size();
284 // If in any of the higher detail modes, and assuming we don't want super phat argument controls, we better ensure there is a minimum number of lines in the grid layout
285 if(current_mode >= Configuration.EXPERT_MODE) {
286 if(argument_count < MINIMUM_ROWS) {
287 argument_count = MINIMUM_ROWS;
288 }
289 pane.setLayout(new GridLayout(argument_count, 1, 5, 5));
290 }
291 // Otherwise we're just going to throw them on one after another and chuck it in a scroll pane anyway
292 else {
293 // use GridLayout with 0 rows == as many rows as needed. Unfortunately, rows will
294 // grow fat if space too large, but we don't know how many rows we'll need yet.
295 pane.setLayout(new GridLayout(0, 1, 5, 5));
296 }
297 }
298
299 for(int j = 0; j < import_arguments.size(); j++) {
300 pane.add((JComponent)import_arguments.get(j));
301 }
302 pane.addMouseListener(this);
303 import_arguments = null;
304 return pane;
305 }
306
307 /** This method is used to build a panel based on the message log, which is nothing like any of the other panels.
308 * @return A <strong>JPanel</strong> containing a scrollable text area which represents the shell process message log.
309 */
310 public JPanel buildLog() {
311 // we now save the log pane
312 if (log_pane == null) {
313 log_pane = new JPanel(new BorderLayout());
314 log_pane.setComponentOrientation(Dictionary.getOrientation());
315 // Build a list of the log files available, ordering by last modified. Log files are like build_log.date.txt
316 DefaultListModel contents = new DefaultListModel();
317 File log_directory = new File(CollectionManager.getLoadedCollectionLogDirectoryPath());
318 File children[] = log_directory.listFiles();
319 for(int i = 0; children != null && i < children.length; i++) {
320 String filename = children[i].getName();
321 if(filename.startsWith("build_log.") && filename.endsWith(".txt") ) {
322 String datestamp = filename.substring(filename.indexOf(".") + 1, filename.lastIndexOf(".")).toLowerCase();
323 if(datestamp.indexOf("s") == -1 && datestamp.indexOf("u") == -1 && datestamp.indexOf("c") == -1 && datestamp.indexOf("x") == -1) {
324 FileEntry entry = new FileEntry(children[i].getName(), children[i].getAbsolutePath());
325 // We are about to insert it. But where.
326 boolean found = false;
327 for(int j = 0; !found && j < contents.size(); j++) {
328 FileEntry sibling = (FileEntry) contents.getElementAt(j);
329 int order = entry.compareTo(sibling);
330 if(order > 0) {
331 contents.insertElementAt(entry, j);
332 found = true;
333 }
334 }
335 if(!found) {
336 contents.addElement(entry);
337 }
338 }
339 }
340 }
341
342 log_list = new JList(contents);
343 log_list.setComponentOrientation(Dictionary.getOrientation());
344 log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
345 log_list.setLayoutOrientation(JList.VERTICAL);
346 log_list.setPreferredSize(new Dimension(600, 100));
347 log_list.setVisibleRowCount(3);
348 log_list.addListSelectionListener(new LogListListener());
349
350 JLabel log_history_label = new JLabel(Dictionary.get("OptionsPane.LogHistory"));
351 log_history_label.setComponentOrientation(Dictionary.getOrientation());
352 JPanel log_history_pane = new JPanel();
353 log_history_pane.setComponentOrientation(Dictionary.getOrientation());
354 log_history_pane.setPreferredSize(new Dimension(600, 100));
355 log_history_pane.setLayout(new BorderLayout());
356 log_history_pane.add(log_history_label, BorderLayout.NORTH);
357 JScrollPane scrol_tmp=new JScrollPane(log_list);
358 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
359 log_history_pane.add(scrol_tmp, BorderLayout.CENTER);
360
361 scrol_tmp=new JScrollPane(log_textarea);
362 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
363 log_pane.add(scrol_tmp, BorderLayout.CENTER);
364 log_pane.add(log_history_pane, BorderLayout.SOUTH);
365 }
366 return log_pane;
367 }
368
369 public AppendLineOnlyFileDocument createNewLogDocument() {
370 long time = System.currentTimeMillis();
371 StringBuffer name = new StringBuffer();
372 name.append("build_log.");
373 name.append(time);
374 name.append(".txt");
375 // just in case there is no log directory
376 File file = new File(CollectionManager.getLoadedCollectionLogDirectoryPath() + name.toString());
377 File parent_file = file.getParentFile();
378 parent_file.mkdirs();
379 parent_file = null;
380 // create the file entry and add it to the list at pos 0 - it will always be the newest one created
381 file_entry = new FileEntry(name.toString(), file.getAbsolutePath());
382 ((DefaultListModel)log_list.getModel()).add(0, file_entry);
383 log_list.setSelectedIndex(0);
384 // Finally retrieve and return the document associated with this file entry
385 return file_entry.getDocument();
386 }
387
388
389 /** Attempts to discover the latest document count.
390 * @return An <strong>int</strong> detailing the number of documents in this collection.
391 */
392 public int getDocumentCount() {
393 if(Gatherer.c_man.ready()) {
394 int count = Gatherer.c_man.getCollection().getDocumentCount();
395 if(count != 0) {
396 return count;
397 }
398 }
399 return 1;
400 }
401
402 /** Called by our magic log documents after they have finished writing themselves to file, whereapon it is no longer necessary to hold a reference to them. */
403 public void remove(AppendLineOnlyFileDocument document) {
404 writing_documents.remove(document);
405 }
406
407 public void resetFileEntry() {
408 if(file_entry != null) {
409 file_entry.reset();
410 }
411 }
412
413 /** Given a panel containing ArgumentControls, update the values associated with them. */
414 public void update(JPanel panel) {
415 if(panel == log_pane) {
416 return;
417 }
418
419 for(int i = 0; i < panel.getComponentCount(); i++) {
420 Component component = panel.getComponent(i);
421 if(component instanceof MyArgumentControl) {
422 ((MyArgumentControl)component).update();
423 }
424 }
425 }
426
427 /** Implementation side-effect
428 * @param e a MouseEvent
429 */
430 public void mouseClicked(MouseEvent e) {}
431
432 /** Implementation side-effect
433 * @param e a MouseEvent
434 */
435 public void mouseEntered(MouseEvent e) {}
436
437 /** Implemented to ensure that, by the time the mouse pointer leaves the current build options screen, ang changes to the value the JSpinners have been commited
438 * @param e a MouseEvent
439 */
440 public void mouseExited(MouseEvent e) {
441 // Loop through the controls, and if the current control is a JSpinner, commit its current editing
442 for(int i = 0; i < current_controls.size(); i++) {
443 MyArgumentControl control = (MyArgumentControl) current_controls.get(i);
444 JComponent value_control = control.getValueControl();
445 if(value_control instanceof JSpinner) {
446 try {
447 ((JSpinner)value_control).commitEdit();
448 }
449 catch(Exception exception) {
450 DebugStream.println("Exception in OptionsPane.mouseExited() - unexpected");
451 DebugStream.printStackTrace(exception);
452 }
453 }
454 value_control = null;
455 control = null;
456 }
457 }
458
459 /** Implementation side-effect
460 * @param e a MouseEvent
461 */
462 public void mousePressed(MouseEvent e) {}
463
464 /** Implementation side-effect
465 * @param e a MouseEvent
466 */
467 public void mouseReleased(MouseEvent e) {}
468
469 private class MyArgumentControl
470 extends ArgumentControl {
471 private int type;
472
473 public MyArgumentControl(int type, Argument argument, boolean enable, String value) {
474 super(argument, enable, value);
475 this.type = type;
476 }
477
478 /** Update the values stored in the collection so as to remember the current state of this argument. */
479 public void update() {
480 String name = getArgumentName();
481 boolean enable = isEnabled();
482 String value = getValue();
483 // If this argument was a flag, but is now disabled, remove from the build options altogether
484 if(!enable && value == null) {
485 if(type == BUILD) {
486 build_options.removeValue(name);
487 }
488 else if(type == SCHEDULE) {
489 schedule_options.removeValue(name);
490 }
491 else {
492 import_options.removeValue(name);
493 }
494 }
495 // Otherwise update the argument value
496 else {
497 if(type == BUILD) {
498 build_options.setValue(name, enable, value);
499 }
500 else if(type == SCHEDULE) {
501 schedule_options.setValue(name, enable, value);
502 }
503 else {
504 import_options.setValue(name, enable, value);
505 }
506 }
507 }
508 }
509
510 /** Holds a File which has a particular naming convention build_log.date.txt also keeps a Date corresponding to the date in its name*/
511 private class FileEntry {
512
513 private AppendLineOnlyFileDocument current_document;
514 private Date date;
515 private long last_modified;
516 private String display;
517 private String filename;
518 private String filepath;
519
520 public FileEntry(String filename, String filepath) {
521 this.date = null;
522 this.display = null;
523 this.filename = filename;
524 this.filepath = filepath;
525 this.last_modified = 0L;
526 }
527
528 /** returns 0 if the dates are the same, -ve number if the current FileEntry is earlier than the fe FileEntry ...*/
529 public int compareTo(FileEntry file_entry) {
530 Date our_date = getDate();
531 Date other_date = file_entry.getDate();
532 return our_date.compareTo(other_date);
533 }
534
535 public Date getDate() {
536 if(date == null) {
537 // Need to exclude first '.'
538 int first_index = filename.indexOf(".") + 1;
539 // Need to exclude the last '.'
540 int last_index = filename.lastIndexOf(".");
541 if(first_index > 0 && last_index > 0 && first_index < last_index) {
542 String date_string = filename.substring(first_index, last_index);
543 date = new Date(Long.parseLong(date_string));
544 }
545 else {
546 date = new Date(); // Current date
547 }
548 }
549 return date;
550 }
551
552 public AppendLineOnlyFileDocument getDocument() {
553 if(current_document == null) {
554 current_document = new AppendLineOnlyFileDocument(filepath);
555 }
556 return current_document;
557 }
558
559 public void reset() {
560 display = null;
561 }
562
563 /** we only want the date out of the file name, not the whole path */
564 public String toString() {
565 File file = new File(filename);
566 if(display == null) {
567 last_modified = file.lastModified();
568 StringBuffer d = new StringBuffer();
569 Date date = getDate();
570 d.append(date.toString());
571 char success = UNKNOWN;
572 File the_file = new File(filepath);
573 if(the_file.exists()) {
574 try {
575 FileInputStream in = new FileInputStream(the_file);
576 success = (char) in.read();
577 in.close();
578 in = null;
579 }
580 catch(Exception error) {
581 ///ystem.err.println("Log '" + filepath + "' not found!");
582 ///atherer.printStackTrace(error);
583 }
584 }
585 the_file = null;
586 switch (success) {
587 case SUCCESSFUL:
588 d.append(Dictionary.get("OptionsPane.Successful"));
589 break;
590 case UNSUCCESSFUL:
591 d.append(Dictionary.get("OptionsPane.Unsuccessful"));
592 break;
593 case CANCELLED:
594 d.append(Dictionary.get("OptionsPane.Cancelled"));
595 break;
596 case SCHEDULED:
597 d.append(Dictionary.get("OptionsPane.Scheduled"));
598 break;
599 default:
600 d.append(Dictionary.get("OptionsPane.Unknown"));
601 }
602 display = d.toString();
603 }
604 return display;
605 }
606 }
607
608 /** a ListSelectionListener that triggers the load of a newly selected log */
609 private class LogListListener implements ListSelectionListener {
610
611 public void valueChanged(ListSelectionEvent e) {
612 if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one)
613 ///ystem.err.println("Log change detected.");
614 JList source = (JList)e.getSource();
615 file_entry = (FileEntry) source.getSelectedValue();
616 // First we determine if the old log has been completely written to file
617 Document document = log_textarea.getDocument();
618 ///ystem.err.println(" * current document: " + document);
619 ///ystem.err.println(" * new document: " + file_entry.getDocument());
620 // If we are dealing with the same document don't do anything.
621 if(document != file_entry.getDocument()) {
622 if(document instanceof AppendLineOnlyFileDocument) {
623 AppendLineOnlyFileDocument append_line_only_file_document = (AppendLineOnlyFileDocument) document;
624 if(append_line_only_file_document.isStillWriting()) {
625 ///ystem.err.println("Current log is still active... finishing.");
626 writing_documents.add(append_line_only_file_document); // We have to maintain a reference until they are all done.
627 append_line_only_file_document.setOwner(OptionsPane.this);
628 append_line_only_file_document.setExit();
629 }
630 else {
631 ///ystem.err.println("Current log is complete. Nothing to do.");
632 }
633 }
634 // Load the new log
635 log_textarea.setDocument(file_entry.getDocument());
636 }
637 }
638 }
639 }
640
641}
Note: See TracBrowser for help on using the repository browser.