Changeset 5292 for trunk


Ignore:
Timestamp:
2003-08-27T14:58:06+12:00 (21 years ago)
Author:
mdewsnip
Message:

Improved the accuracy of the progress bar, especially when importing one folder containing many documents.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java

    r5035 r5292  
    4949    /** Indicates if the GUI has asked the process this object monitors to stop. */
    5050    private boolean stop = false;
    51     /** The number of directories that are expected to be scanned by this import process. May not be correct for various reasons, such as a custom RecPlug setup, but its seems the most reliable for general cases. */
    52     private int num_dirs = 0;
     51    private int file_num = 0;
     52    /** The number of files expected to be scanned by this import process. */
     53    private int num_files = 0;
    5354    /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */
    5455    private int num_docs = 0;
     
    6263    static final private String NUM_DOCS_PROCESSED = "processed and included in the collection";
    6364    /** The Sentinel value is the String fragment an output process line must start with to be considered a milestone. In this case we are counting directories, so the fragment refers to a directory scan. */
    64     static final private String SENTINEL = "recplug: getting directory ";
     65    static final private String SENTINEL = "recplug - ";
     66
    6567    public GImportProgressMonitor() {
    6668    progress_bar = new JProgressBar();
     
    7072    progress_bar.setValue(MIN);
    7173    }
     74
    7275    /** Method to register a new progress bar with this monitor.
    73       * @param progress_bar The new <strong>JProgressBar</strong>.
    74       */     
     76     * @param progress_bar The new <strong>JProgressBar</strong>.
     77     */
    7578    public void addProgressBar(JProgressBar progress_bar) {
    7679    this.progress_bar = progress_bar;
     
    7982    progress_bar.setValue(MIN);
    8083    }
     84
    8185    /** Determine the script exit value according to the progress monitor. This gets around a problem where several script failures actually result with a successful exit value.
    82       * @return A <i>int</i> with a value of zero if and only if the script was successful.
    83       */
     86     * @return A <i>int</i> with a value of zero if and only if the script was successful.
     87     */
    8488    public int exitValue() {
    8589    if(num_docs > 0) {
     
    8892    return 1;
    8993    }
     94
    9095    /** Retrieve the number of documents recorded by the import monitor during the execution of the import scripts.
    91       * @return An <i>int</i> giving the document number.
    92       */
     96     * @return An <i>int</i> giving the document number.
     97     */
    9398    public int getNumberOfDocuments() {
    9499    return num_docs;
     
    96101
    97102    /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later.
    98       * @return A <strong>Component</strong> on which the progress of the process is being displayed.
    99       */
     103     * @return A <strong>Component</strong> on which the progress of the process is being displayed.
     104     */
    100105    public Component getProgress() {
    101106    return progress_bar;
    102107    }
     108
    103109    /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
    104       * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
    105       */
     110     * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
     111     */
    106112    public boolean hasSignalledStop() {
    107113    return stop;
    108114    }
     115
    109116    /** Inform the progress bar that it should programatically increment progress by one step. This is only called during the metadata archive extraction so each step should be (100 / 5) / num_docs. */
    110117    public void increment() {
     
    116123    }
    117124    }
     125
    118126    /** This method is used to 'feed in' a line of text captured from the process.
    119       * @param line A <strong>String</strong> of text captured from either standard out or standard error.
    120       * TODO Everthing.
    121       */
     127     * @param line A <strong>String</strong> of text captured from either standard out or standard error.
     128     * TODO Everthing.
     129     */
    122130    public void parse(String line_raw) {
    123131    progress_bar.setString("");
    124132    String line = line_raw.toLowerCase();
    125     if(line.indexOf(SENTINEL) != -1) {
    126                 ///ystem.err.println("Sentinal value detected: ");
    127         if(num_dirs > 0) {
    128         ///ystem.err.println(count + " of " + num_dirs);
    129         ///ystem.err.println("Value before: " + progress_bar.getValue());
    130         progress_bar.setValue(progress_bar.getValue() + ((4 * (MAX / 5)) / num_dirs));
    131         ///ystem.err.println("Value after:  " + progress_bar.getValue());
    132         }
    133         else {
    134         progress_bar.setIndeterminate(true);
     133    if (line.indexOf(SENTINEL) == 0) {
     134        file_num = file_num + 1;
     135        ///ystem.err.println("Done " + file_num + " of " + num_files + "...");
     136        if (num_files > 0) {
     137        progress_bar.setValue((4 * MAX * file_num) / (5 * num_files));
    135138        }
    136139    }
    137     else if(line.indexOf(NUM_DOCS_PROCESSED) != -1) {
    138                 // Increment the import because we have finished a directory
    139                
     140    else if (line.indexOf(NUM_DOCS_PROCESSED) != -1) {
    140141        num_docs = -1;
    141142        StringTokenizer tokenizer = new StringTokenizer(line);
     
    148149        }
    149150        }
    150                 ///ystem.err.println("Parsed num_docs to be " + num_docs);
     151        ///ystem.err.println("Parsed num_docs to be " + num_docs);
    151152    }
    152153    }
     
    158159
    159160    /** Since the creator of this process monitor is actually in the GUI, this class provides the simpliest way to send a cancel process message between the two.
    160       * @param state The desired state of the stop flag as a <strong>boolean</strong>.
    161       */
     161     * @param state The desired state of the stop flag as a <strong>boolean</strong>.
     162     */
    162163    public void setStop(boolean state) {
    163164    stop = state;
    164165    progress_bar.setIndeterminate(false);
    165166    }
     167
    166168    /** This method resets this monitor to the start, reseting the process parsing and progress bar.
    167169     * TODO Everthing.
     
    171173    progress_bar.setString(Gatherer.dictionary.get("FileActions.Calculating_Size", (String)null));
    172174    progress_bar.setIndeterminate(false);
    173     num_dirs = Gatherer.c_man.getCollection().getFolderCount();
    174175    progress_bar.setValue(MIN);
    175     Gatherer.println("Number of directories is " + num_dirs);
     176    num_files = Gatherer.c_man.getCollection().getDocumentCount();
     177    ///ystem.err.println("Number of files: " + num_files);
     178    file_num = 0;
    176179    }
     180
    177181    /** This method indicates the process is complete.
    178182     * TODO Everthing.
Note: See TracChangeset for help on using the changeset viewer.