- Timestamp:
- 2003-06-16T10:47:06+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java
r4596 r4675 51 51 import org.greenstone.gatherer.util.Utility; 52 52 import org.w3c.dom.*; 53 /** 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>. 53 /** 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>. 54 54 * @author John Thompson, Greenstone Digital Library, University of Waikato 55 55 * @version 2.2 … … 75 75 static final public char UNSUCCESSFUL = 'u'; 76 76 static final public char CANCELLED = 'c'; 77 77 78 78 static private int BUILD = 0; 79 79 static private int IMPORT = 1; … … 85 85 static private Dimension SPINNER_SIZE = new Dimension(100, 25); 86 86 static private String DESCRIPTION_SEP = " + "; 87 88 87 88 89 89 /** 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. */ 90 90 public OptionsPane(JTextArea log, BuildOptions build_options) { … … 95 95 } 96 96 97 /** creates a new log from the text in log. The new file is named 97 /** creates a new log from the text in log. The new file is named 98 98 * build_log.<current time>.txt. A new FileEntry is added to teh log list 99 99 * and made selected. A fresh listener is added to teh document */ 100 100 public void addNewLog(char success) { 101 101 ///ystem.out.println("add new log"); 102 102 103 103 // create the file name 104 104 long time = System.currentTimeMillis(); … … 153 153 } 154 154 return pane; 155 } 155 } 156 156 /** This method creates the panel with all the import only options on it. 157 157 * @return A <strong>JPanel</strong> which can be used to display all the import only options. … … 189 189 if (log_pane == null) { 190 190 log_pane = new JPanel(new BorderLayout()); 191 191 192 192 // Build a list of the log files available, ordering by last modified. Log files are like build_log.date.txt 193 193 DefaultListModel contents = new DefaultListModel(); … … 213 213 } 214 214 } 215 216 log_list = new JList(contents); 215 216 log_list = new JList(contents); 217 217 log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 218 218 log_list.setLayoutOrientation(JList.VERTICAL); 219 219 log_list.setVisibleRowCount(3); 220 220 log_list.addListSelectionListener(new LogListListener()); 221 221 222 222 JScrollPane list_scroller = new JScrollPane(log_list); 223 223 224 224 // If log is not empty and we have something in displayed_log - make that element selected 225 225 if (log_display.getText().length()>0 && displayed_log != null) { … … 228 228 log_list.setSelectedIndex(index); 229 229 } 230 230 231 231 } 232 232 log_pane.add(new JScrollPane(log_display), BorderLayout.CENTER); … … 261 261 return Gatherer.dictionary.get(key, args); 262 262 } 263 /** Attempts to discover the latest document count. 263 /** Attempts to discover the latest document count. 264 264 * @return An <strong>int</strong> detailing the number of documents in this collection. 265 265 */ … … 273 273 return 1; 274 274 } 275 275 276 276 /** Loads a new log into the log text - saves the currently showing one, 277 277 * and loads the new one, adding a fresh listener to the document 278 * Note, we need to remove any listener before making the changes, then 279 * add a listener back in 278 * Note, we need to remove any listener before making the changes, then 279 * add a listener back in 280 280 */ 281 281 public void loadSelectedLog(FileEntry fe) { … … 286 286 log_display.getDocument().removeDocumentListener(log_change_listener); 287 287 } 288 288 289 289 displayed_log = fe; 290 290 if (fe != null) { … … 295 295 is_log_changed=false; 296 296 log_display.getDocument().addDocumentListener(log_change_listener); 297 297 298 298 } 299 299 300 300 /** Neutralizes the log list - saves any unsaved changes to the current log 301 * clears the log text, unselects the log list, and adds a fresh listener 302 * to the log's document 303 * Note, we need to remove any listener before making the changes, then 301 * clears the log text, unselects the log list, and adds a fresh listener 302 * to the log's document 303 * Note, we need to remove any listener before making the changes, then 304 304 * add a listener back in */ 305 305 public void resetLogList() { … … 317 317 is_log_changed=false; 318 318 log_display.getDocument().addDocumentListener(log_change_listener); 319 319 320 320 } 321 321 322 322 /** saves the current text in log to the File specified */ 323 323 public void saveLogFile(File file) { 324 324 325 325 try { 326 326 BufferedWriter out = new BufferedWriter(new FileWriter(file)); // uses the default encoding … … 331 331 String token = t.nextToken(); 332 332 if (token.equals("\n")) { 333 out.newLine(); 333 out.newLine(); 334 334 } else { 335 335 out.write(token, 0, token.length()); 336 336 } 337 337 338 338 } 339 339 out.close(); 340 340 341 341 } catch(Exception e) { 342 342 System.out.println("Error in saving log file: "+file.toString()); 343 343 e.printStackTrace(); 344 344 } 345 346 345 346 347 347 } 348 348 … … 550 550 /** Constructor. */ 551 551 public EnabledListener(JComponent target) { 552 this.target = target; 552 this.target = target; 553 553 } 554 554 /** Any implementation of ActionListener must include this method so that we can be informed when an action has been performed on or registered check box, prompting us to change the state of the other controls as per the users request. … … 587 587 588 588 /** holds a File which has a particular naming convention 589 * build_log.date.txt 589 * build_log.date.txt 590 590 * also keeps a Date corresponding to the date in its name*/ 591 591 private class FileEntry { 592 592 593 593 private Date date=null; 594 594 private File file=null; … … 598 598 this.date = getDateFromFileName(); 599 599 this.display = createDisplayText(); 600 600 601 601 } 602 602 … … 606 606 return date.compareTo(d); 607 607 } 608 608 609 609 public Date getDate() { 610 610 return this.date; … … 622 622 BufferedReader in = new BufferedReader(new FileReader(this.file)); 623 623 String line; 624 624 625 625 while ((line = in.readLine()) != null) { 626 626 contents.append(line); … … 632 632 } catch (IOException ioe) { 633 633 System.err.println("Error: exception occurred when trying to read in file "+this.file.toString()+", "+ioe.getMessage()); 634 635 } 636 634 635 } 636 637 637 return contents.toString(); 638 638 } 639 639 /** we only want the date out of the file name, not the whole path */ 640 640 public String toString() { 641 return this.display; 641 return this.display; 642 642 } 643 643 /** creates the display text for the list */ … … 645 645 StringBuffer d = new StringBuffer(); 646 646 d.append(date.toString()); 647 char success= this.file.getName().charAt(23); 648 switch (success) { 649 case OptionsPane.SUCCESSFUL: 650 d.append(get("Successful")); 651 break; 652 case OptionsPane.UNSUCCESSFUL: 653 d.append(get("Unsuccessful")); 654 break; 655 case OptionsPane.CANCELLED: 656 d.append(get("Cancelled")); 657 break; 658 } 647 //char success= this.file.getName().charAt(23); 648 String filename = this.file.getName(); 649 int index = filename.lastIndexOf(".") - 1; 650 if(index >= 0) { 651 char success = filename.charAt(index); 652 switch (success) { 653 case OptionsPane.SUCCESSFUL: 654 d.append(get("Successful")); 655 break; 656 case OptionsPane.UNSUCCESSFUL: 657 d.append(get("Unsuccessful")); 658 break; 659 case OptionsPane.CANCELLED: 660 d.append(get("Cancelled")); 661 break; 662 } 663 } 659 664 return d.toString(); 660 665 } … … 675 680 } 676 681 677 682 678 683 } 679 684 680 685 /** A DocumentListener that listens for changes in the log_display document 681 686 * if a change is registered, the flag is_log_changed is set to true, 682 * and the listener removes itself from log_display 687 * and the listener removes itself from log_display 683 688 * Because we only want to register user's changes, the listener must be removed before the system makes any changes, and then put back. For example, each time we switchlogs to display, a remove event and an insert event are sent. We dont want to register these as changes to the document, so the listener must be removed before the switch, and added back afterwards */ 684 689 private class LogChangeListener implements DocumentListener { … … 703 708 } 704 709 } 705 706 /** a ListSelectionListener that triggers the load of a newly selected 710 711 /** a ListSelectionListener that triggers the load of a newly selected 707 712 log */ 708 713 private class LogListListener implements ListSelectionListener { 709 714 710 715 public void valueChanged(ListSelectionEvent e) { 711 if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one) 716 if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one) 712 717 JList source = (JList)e.getSource(); 713 718 FileEntry fe = (FileEntry) source.getSelectedValue();
Note:
See TracChangeset
for help on using the changeset viewer.