Ignore:
Timestamp:
2003-06-16T10:47:06+12:00 (21 years ago)
Author:
jmt12
Message:

Sunday's work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java

    r4596 r4675  
    5151import org.greenstone.gatherer.util.Utility;
    5252import 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>.
    5454 * @author John Thompson, Greenstone Digital Library, University of Waikato
    5555 * @version 2.2
     
    7575    static final public char UNSUCCESSFUL = 'u';
    7676    static final public char CANCELLED = 'c';
    77    
     77
    7878    static private int BUILD = 0;
    7979    static private int IMPORT = 1;
     
    8585    static private Dimension SPINNER_SIZE = new Dimension(100, 25);
    8686    static private String DESCRIPTION_SEP = " + ";
    87    
    88    
     87
     88
    8989     /** 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. */
    9090    public OptionsPane(JTextArea log, BuildOptions build_options) {
     
    9595    }
    9696
    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
    9898     * build_log.<current time>.txt. A new FileEntry is added to teh log list
    9999     * and made selected. A fresh listener is added to teh document */
    100100    public void addNewLog(char success) {
    101101    ///ystem.out.println("add new log");
    102        
     102
    103103    // create the file name
    104104    long time = System.currentTimeMillis();
     
    153153    }
    154154    return pane;
    155     } 
     155    }
    156156    /** This method creates the panel with all the import only options on it.
    157157      * @return A <strong>JPanel</strong> which can be used to display all the import only options.
     
    189189    if (log_pane == null) {
    190190        log_pane = new JPanel(new BorderLayout());
    191          
     191
    192192        // Build a list of the log files available, ordering by last modified. Log files are like build_log.date.txt
    193193        DefaultListModel contents = new DefaultListModel();
     
    213213        }
    214214        }
    215          
    216         log_list = new JList(contents); 
     215
     216        log_list = new JList(contents);
    217217        log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    218218        log_list.setLayoutOrientation(JList.VERTICAL);
    219219        log_list.setVisibleRowCount(3);
    220220        log_list.addListSelectionListener(new LogListListener());
    221          
     221
    222222        JScrollPane list_scroller = new JScrollPane(log_list);
    223          
     223
    224224        // If log is not empty and we have something in displayed_log - make that element selected
    225225        if (log_display.getText().length()>0 && displayed_log != null) {
     
    228228            log_list.setSelectedIndex(index);
    229229        }
    230              
     230
    231231        }
    232232        log_pane.add(new JScrollPane(log_display), BorderLayout.CENTER);
     
    261261    return Gatherer.dictionary.get(key, args);
    262262    }
    263     /** Attempts to discover the latest document count. 
     263    /** Attempts to discover the latest document count.
    264264      * @return An <strong>int</strong> detailing the number of documents in this collection.
    265265     */
     
    273273    return 1;
    274274    }
    275    
     275
    276276    /** Loads a new log into the log text - saves the currently showing one,
    277277     * 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
    280280     */
    281281    public void loadSelectedLog(FileEntry fe) {
     
    286286        log_display.getDocument().removeDocumentListener(log_change_listener);
    287287    }
    288    
     288
    289289    displayed_log = fe;
    290290    if (fe != null) {
     
    295295    is_log_changed=false;
    296296    log_display.getDocument().addDocumentListener(log_change_listener);
    297    
     297
    298298    }
    299299
    300300    /** 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
    304304     * add a listener back in */
    305305    public void resetLogList() {
     
    317317    is_log_changed=false;
    318318    log_display.getDocument().addDocumentListener(log_change_listener);
    319    
     319
    320320    }
    321321
    322322    /** saves the current text in log to the File specified */
    323323    public void saveLogFile(File file) {
    324    
     324
    325325    try {
    326326        BufferedWriter out = new BufferedWriter(new FileWriter(file)); // uses the default encoding
     
    331331        String token = t.nextToken();
    332332        if (token.equals("\n")) {
    333             out.newLine(); 
     333            out.newLine();
    334334        } else {
    335335            out.write(token, 0, token.length());
    336336        }
    337        
     337
    338338        }
    339339        out.close();
    340        
     340
    341341    } catch(Exception e) {
    342342        System.out.println("Error in saving log file: "+file.toString());
    343343        e.printStackTrace();
    344344    }
    345    
    346    
     345
     346
    347347    }
    348348
     
    550550    /** Constructor. */
    551551    public EnabledListener(JComponent target) {
    552         this.target = target;   
     552        this.target = target;
    553553    }
    554554    /** 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.
     
    587587
    588588    /** holds a File which has a particular naming convention
    589      * build_log.date.txt 
     589     * build_log.date.txt
    590590     * also keeps a Date corresponding to the date in its name*/
    591591    private class FileEntry {
    592    
     592
    593593    private Date date=null;
    594594    private File file=null;
     
    598598        this.date = getDateFromFileName();
    599599        this.display = createDisplayText();
    600        
     600
    601601    }
    602602
     
    606606        return date.compareTo(d);
    607607    }
    608    
     608
    609609    public Date getDate() {
    610610        return this.date;
     
    622622        BufferedReader in = new BufferedReader(new FileReader(this.file));
    623623        String line;
    624        
     624
    625625        while ((line = in.readLine()) != null) {
    626626            contents.append(line);
     
    632632        } catch (IOException ioe) {
    633633        System.err.println("Error: exception occurred when trying to read in file "+this.file.toString()+", "+ioe.getMessage());
    634        
    635         }
    636        
     634
     635        }
     636
    637637        return contents.toString();
    638638    }
    639639    /** we only want the date out of the file name, not the whole path */
    640640    public String toString() {
    641         return this.display; 
     641        return this.display;
    642642    }
    643643    /** creates the display text for the list */
     
    645645        StringBuffer d = new StringBuffer();
    646646        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        }
    659664        return d.toString();
    660665    }
     
    675680    }
    676681
    677    
     682
    678683    }
    679684
    680685    /** A DocumentListener that listens for changes in the log_display document
    681686     * 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
    683688     * 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 */
    684689    private class LogChangeListener implements DocumentListener {
     
    703708    }
    704709    }
    705    
    706     /** a ListSelectionListener that triggers the load of a newly selected 
     710
     711    /** a ListSelectionListener that triggers the load of a newly selected
    707712    log */
    708713    private class LogListListener implements ListSelectionListener {
    709714
    710715    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)
    712717        JList source  = (JList)e.getSource();
    713718        FileEntry fe = (FileEntry) source.getSelectedValue();
Note: See TracChangeset for help on using the changeset viewer.