Ignore:
Timestamp:
2003-05-27T15:40:47+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fixed tabbing.

File:
1 edited

Legend:

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

    r4293 r4364  
    4646 */
    4747public class GImportProgressMonitor
    48     implements GShellProgressMonitor {
    49     /** Indicates if the GUI has asked the process this object monitors to stop. */
    50     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;
    53     /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */
    54     private int num_docs = 0;
    55     /** The progress bar this monitor updates. */
    56     private JProgressBar progress_bar;
    57     /** The maximum value for this progress bar. */
    58     static final private int MAX = 1000000;
    59     /** The minimum value for this progress bar. */
    60     static final private int MIN = 0;
    61     /** A String fragment which is used to determine if the current output process line is referring to the number of documents actually processed by the import script. */
    62     static final private String NUM_DOCS_PROCESSED = "processed and included in the collection";
    63     /** 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     public GImportProgressMonitor() {
    66           progress_bar = new JProgressBar();
    67           progress_bar.setMaximum(MAX);
    68           progress_bar.setMinimum(MIN);
    69           progress_bar.setValue(MIN);
    70     }
    71     /** Method to register a new progress bar with this monitor.
     48    implements GShellProgressMonitor {
     49    /** Indicates if the GUI has asked the process this object monitors to stop. */
     50    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;
     53    /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */
     54    private int num_docs = 0;
     55    /** The progress bar this monitor updates. */
     56    private JProgressBar progress_bar;
     57    /** The maximum value for this progress bar. */
     58    static final private int MAX = 1000000;
     59    /** The minimum value for this progress bar. */
     60    static final private int MIN = 0;
     61    /** A String fragment which is used to determine if the current output process line is referring to the number of documents actually processed by the import script. */
     62    static final private String NUM_DOCS_PROCESSED = "processed and included in the collection";
     63    /** 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    public GImportProgressMonitor() {
     66    progress_bar = new JProgressBar();
     67    progress_bar.setMaximum(MAX);
     68    progress_bar.setMinimum(MIN);
     69    progress_bar.setValue(MIN);
     70    }
     71    /** Method to register a new progress bar with this monitor.
    7272      * @param progress_bar The new <strong>JProgressBar</strong>.
    7373      */     
    74     public void addProgressBar(JProgressBar progress_bar) {
    75           this.progress_bar = progress_bar;
    76           progress_bar.setMaximum(MAX);
    77           progress_bar.setMinimum(MIN);
    78           progress_bar.setValue(MIN);
    79     }
    80     /** 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.
     74    public void addProgressBar(JProgressBar progress_bar) {
     75    this.progress_bar = progress_bar;
     76    progress_bar.setMaximum(MAX);
     77    progress_bar.setMinimum(MIN);
     78    progress_bar.setValue(MIN);
     79    }
     80    /** 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.
    8181      * @return A <i>int</i> with a value of zero if and only if the script was successful.
    8282      */
    83     public int exitValue() {
    84           if(num_docs > 0) {
    85                 return 0;
    86           }
    87           return 1;
    88     }
    89     /** Retrieve the number of documents recorded by the import monitor during the execution of the import scripts.
     83    public int exitValue() {
     84    if(num_docs > 0) {
     85        return 0;
     86    }
     87    return 1;
     88    }
     89    /** Retrieve the number of documents recorded by the import monitor during the execution of the import scripts.
    9090      * @return An <i>int</i> giving the document number.
    9191      */
    92     public int getNumberOfDocuments() {
    93           return num_docs;
    94     }
     92    public int getNumberOfDocuments() {
     93    return num_docs;
     94    }
    9595
    96     /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later.
     96    /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later.
    9797      * @return A <strong>Component</strong> on which the progress of the process is being displayed.
    9898      */
    99     public Component getProgress() {
    100           return progress_bar;
    101     }
    102     /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
     99    public Component getProgress() {
     100    return progress_bar;
     101    }
     102    /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
    103103      * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
    104104      */
    105     public boolean hasSignalledStop() {
    106           return stop;
    107     }
    108     /** 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. */
    109     public void increment() {
    110           if(num_docs > 0) {
    111                 progress_bar.setValue(progress_bar.getValue() + ((MAX / 5) / num_docs));
    112           }
    113           else {
    114                 progress_bar.setIndeterminate(true);
    115           }
    116     }
    117     /** This method is used to 'feed in' a line of text captured from the process.
     105    public boolean hasSignalledStop() {
     106    return stop;
     107    }
     108    /** 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. */
     109    public void increment() {
     110    if(num_docs > 0) {
     111        progress_bar.setValue(progress_bar.getValue() + ((MAX / 5) / num_docs));
     112    }
     113    else {
     114        progress_bar.setIndeterminate(true);
     115    }
     116    }
     117    /** This method is used to 'feed in' a line of text captured from the process.
    118118      * @param line A <strong>String</strong> of text captured from either standard out or standard error.
    119119      * TODO Everthing.
    120120      */
    121     public void parse(String line_raw) {
    122           String line = line_raw.toLowerCase();
    123           if(line.indexOf(SENTINEL) != -1) {
     121    public void parse(String line_raw) {
     122    String line = line_raw.toLowerCase();
     123    if(line.indexOf(SENTINEL) != -1) {
    124124                ///ystem.err.println("Sentinal value detected: ");
    125                 if(num_dirs > 0) {
    126                      ///ystem.err.println(count + " of " + num_dirs);
    127                      ///ystem.err.println("Value before: " + progress_bar.getValue());
    128                      progress_bar.setValue(progress_bar.getValue() + ((4 * (MAX / 5)) / num_dirs));
    129                      ///ystem.err.println("Value after:  " + progress_bar.getValue());
    130                 }
    131                 else {
    132                      progress_bar.setIndeterminate(true);
    133                 }
    134           }
    135           else if(line.indexOf(NUM_DOCS_PROCESSED) != -1) {
     125        if(num_dirs > 0) {
     126        ///ystem.err.println(count + " of " + num_dirs);
     127        ///ystem.err.println("Value before: " + progress_bar.getValue());
     128        progress_bar.setValue(progress_bar.getValue() + ((4 * (MAX / 5)) / num_dirs));
     129        ///ystem.err.println("Value after:  " + progress_bar.getValue());
     130        }
     131        else {
     132        progress_bar.setIndeterminate(true);
     133        }
     134    }
     135    else if(line.indexOf(NUM_DOCS_PROCESSED) != -1) {
    136136                // Increment the import because we have finished a directory
    137137               
    138                 num_docs = -1;
    139                 StringTokenizer tokenizer = new StringTokenizer(line);
    140                 while(num_docs == -1 && tokenizer.hasMoreTokens()) {
    141                      String pos_num_docs_str = tokenizer.nextToken();
    142                      try {
    143                           num_docs = Integer.parseInt(pos_num_docs_str);
    144                      }
    145                      catch (Exception error) {
    146                      }
    147                 }
     138        num_docs = -1;
     139        StringTokenizer tokenizer = new StringTokenizer(line);
     140        while(num_docs == -1 && tokenizer.hasMoreTokens()) {
     141        String pos_num_docs_str = tokenizer.nextToken();
     142        try {
     143            num_docs = Integer.parseInt(pos_num_docs_str);
     144        }
     145        catch (Exception error) {
     146        }
     147        }
    148148                ///ystem.err.println("Parsed num_docs to be " + num_docs);
    149           }
    150     }
    151     /** 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.
     149    }
     150    }
     151    /** 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.
    152152      * @param state The desired state of the stop flag as a <strong>boolean</strong>.
    153153      */
    154     public void setStop(boolean state) {
    155           stop = state;
    156           progress_bar.setIndeterminate(false);
    157     }
    158     /** This method resets this monitor to the start, reseting the process parsing and progress bar.
     154    public void setStop(boolean state) {
     155    stop = state;
     156    progress_bar.setIndeterminate(false);
     157    }
     158    /** This method resets this monitor to the start, reseting the process parsing and progress bar.
    159159      * TODO Everthing.
    160160      */
    161     public void start() {
    162           num_dirs = Gatherer.c_man.getCollection().getFolderCount();
    163           progress_bar.setValue(MIN);
    164           System.err.println("Number of directories is " + num_dirs);
    165     }
    166     /** This method indicates the process is complete.
     161    public void start() {
     162    num_dirs = Gatherer.c_man.getCollection().getFolderCount();
     163    progress_bar.setValue(MIN);
     164    System.err.println("Number of directories is " + num_dirs);
     165    }
     166    /** This method indicates the process is complete.
    167167      * TODO Everthing.
    168168      */
    169     public void stop() {
    170           progress_bar.setIndeterminate(false);
    171           progress_bar.setValue(MAX);
    172     }
     169    public void stop() {
     170    progress_bar.setIndeterminate(false);
     171    progress_bar.setValue(MAX);
     172    }
    173173}
Note: See TracChangeset for help on using the changeset viewer.