Ignore:
Timestamp:
2004-01-16T15:52:11+13:00 (20 years ago)
Author:
jmt12
Message:

Finished the design of a new 'simple' creating/progress pane, including merging the two progress bars into one

Location:
trunk/gli/src/org/greenstone/gatherer/shell
Files:
5 edited

Legend:

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

    r6388 r6533  
    8282    return this;
    8383    }
     84
     85    public JProgressBar getSharedProgress() {
     86    return null;
     87    }
     88
    8489    /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
    8590     * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
  • trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java

    r6388 r6533  
    121121    /** The progress bar this monitor updates. */
    122122    private JProgressBar progress_bar;
     123    /** A progress bar that is shared between this this listener and the Import monitor. */
     124    private JProgressBar shared_progress_bar;
    123125
    124126    /** Construct a new GBuildProgressMonitor. */
    125     public GBuildProgressMonitor() {
     127    public GBuildProgressMonitor(JProgressBar shared_progress_bar) {
     128    this.shared_progress_bar = shared_progress_bar;
    126129    progress_bar = new JProgressBar();
    127130    progress_bar.setMaximum(MAX);
    128131    progress_bar.setMinimum(MIN);
    129     progress_bar.setValue(MIN);
     132    progress_bar.setString(null);
     133    progress_bar.setStringPainted(true);
     134    setValue(MIN);
    130135    }
    131136
     
    137142    progress_bar.setMaximum(MAX);
    138143    progress_bar.setMinimum(MIN);
    139     progress_bar.setValue(MIN);
     144    progress_bar.setStringPainted(false);
     145    progress_bar.setString(null);
     146    setValue(MIN);
    140147    }
    141148
     
    155162    return progress_bar;
    156163    }
     164
     165    public JProgressBar getSharedProgress() {
     166    return shared_progress_bar;
     167    }
     168
    157169    /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
    158170     * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
    159171     */
    160     public boolean hasSignalledStop() {
     172    public synchronized boolean hasSignalledStop() {
    161173    return stop;
    162174    }
     
    193205            state = BUILD;
    194206            // Produce a lower detail message if required
    195             if(Gatherer.config.getMode() <= threshold) {
     207            if(Gatherer.config.getMode() <= threshold && !stop) {
    196208            queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildBegun1"), event.getStatus()));
    197209            }
     
    254266        else if(name.equals(BUILD_ELEMENT) && element.isClosed()) {
    255267            progress_bar.setIndeterminate(false);
    256             progress_bar.setValue(MAX);
     268            setValue(MAX);
    257269            state = BASE;
    258270            if(Gatherer.config.getMode() <= threshold) {
     
    279291            // One third complete
    280292            progress_bar.setIndeterminate(false);
    281             progress_bar.setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages);
     293            setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages);
    282294            }
    283295            else if(value.equals(COMPRESSINGTEXT_VALUE)) {
    284296            // Two thirds complete
    285297            progress_bar.setIndeterminate(false);
    286             progress_bar.setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
     298                setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
    287299            }
    288300            else {
     
    302314            current_stages++;
    303315            progress_bar.setIndeterminate(false);
    304             progress_bar.setValue((current_stages * MAX) / expected_stages);
     316            setValue((current_stages * MAX) / expected_stages);
    305317            state = BUILD;
    306318        }
     
    323335            // One fifth complete
    324336            progress_bar.setIndeterminate(false);
    325             progress_bar.setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages);
     337            setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages);
    326338            }
    327339            else if(value.equals(CREATETHEWEIGHTS_VALUE)) {
    328340            // Two fifths complete
    329341            progress_bar.setIndeterminate(false);
    330             progress_bar.setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages);
     342            setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages);
    331343            }
    332344            else if(value.equals(CREATESTEMMEDDIC_VALUE)) {
    333345            // Three fifths complete
    334346            progress_bar.setIndeterminate(false);
    335             progress_bar.setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
     347            setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
    336348            }
    337349            else if(value.equals(CREATINGSTEMINDX_VALUE)) {
    338350            // Four fifths complete
    339351            progress_bar.setIndeterminate(false);
    340             progress_bar.setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages);
     352            setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages);
    341353            }
    342354            else {
     
    359371            current_stages++;
    360372            progress_bar.setIndeterminate(false);
    361             progress_bar.setValue((current_stages * MAX) / expected_stages);
     373            setValue((current_stages * MAX) / expected_stages);
    362374            state = BUILD;
    363375        }
     
    379391            // One sixth complete
    380392            progress_bar.setIndeterminate(false);
    381             progress_bar.setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages);
     393            setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages);
    382394            }
    383395            else if(value.equals(SORTANDRENUMBER_VALUE)) {
    384396            // Two sixths complete
    385397            progress_bar.setIndeterminate(false);
    386             progress_bar.setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages);
     398                setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages);
    387399            }
    388400            else if(value.equals(PHRASEDATABASES_VALUE)) {
    389401            // Three sixths complete
    390402            progress_bar.setIndeterminate(false);
    391             progress_bar.setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages);
     403                setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages);
    392404            }
    393405            else if(value.equals(WORDLEVELINDEXES_VALUE)) {
    394406            // Four sixths complete
    395407            progress_bar.setIndeterminate(false);
    396             progress_bar.setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages);
     408            setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages);
    397409            }
    398410            else if(value.equals(DOCINFODATABASES_VALUE)) {
    399411            // Five sixths complete
    400412            progress_bar.setIndeterminate(false);
    401             progress_bar.setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages);
     413            setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages);
    402414            }
    403415            else {
     
    412424            current_stages++;
    413425            progress_bar.setIndeterminate(false);
    414             progress_bar.setValue((current_stages * MAX) / expected_stages);
     426            setValue((current_stages * MAX) / expected_stages);
    415427            state = BUILD;
    416428        }
     
    429441            current_stages++;
    430442            progress_bar.setIndeterminate(false);
    431             progress_bar.setValue((current_stages * MAX) / expected_stages);
     443            setValue((current_stages * MAX) / expected_stages);
    432444            state = BUILD;
    433445        }
     
    455467    expected_stages = 0;
    456468    progress_bar.setIndeterminate(false);
    457     progress_bar.setString(StaticStrings.SPACE_CHARACTER);
    458     progress_bar.setValue(MIN);
     469    progress_bar.setString(null);
     470    setValue(MIN);
    459471    state = BASE;
    460     stop = false;
    461472    progress_bar.updateUI();
    462473    }
    463474
    464475    public void saving() {
     476    }
     477
     478    public void setSharedProgressBar(JProgressBar shared_progress_bar) {
     479    this.shared_progress_bar = shared_progress_bar;
    465480    }
    466481
     
    468483     * @param state The desired state of the stop flag as a <strong>boolean</strong>.
    469484     */
    470     public void setStop(boolean state) {
    471     stop = state;
     485    public synchronized void setStop(boolean state) {
     486    this.stop = state;
    472487    progress_bar.setIndeterminate(false);
    473488    }
     
    476491     */
    477492    public void start() {
    478     progress_bar.setValue(MIN);
     493    stop = false;
     494    setValue(MIN);
    479495    expected_stages = 3; // Always compress text, create info database and auxiliary creation
    480496    // Retrieve cdm.
     
    507523    public void stop() {
    508524    progress_bar.setIndeterminate(false);
    509     progress_bar.setValue(MAX);
     525    setValue(MAX);
     526    }
     527
     528    private void setValue(int value) {
     529    progress_bar.setValue(value);
     530    // Incrementing the shared progress bar is a little more problematic as we may very well be trying to set it to MIN but instead set it to halfway if we're not careful.
     531    if(value > MIN) {
     532        shared_progress_bar.setValue(MAX + value);
     533    }
    510534    }
    511535}
  • trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java

    r6388 r6533  
    7272    /** The progress bar this monitor updates. */
    7373    private JProgressBar progress_bar;
     74
     75    /** The progress bar that is shared with build monitor. */
     76    private JProgressBar shared_progress_bar;
     77
    7478    /** */
    7579    static final private String BLOCKED_ATTRIBUTE = "blocked";
     
    102106    progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED);
    103107    progress_bar.setMinimum(MIN);
    104     progress_bar.setString(StaticStrings.SPACE_CHARACTER);
     108    progress_bar.setString(null);
    105109    progress_bar.setStringPainted(true);
     110    next_progress_value = CALCULATION;
     111    shared_progress_bar = new JProgressBar();
     112    shared_progress_bar.setIndeterminate(false);
     113    shared_progress_bar.setMaximum((CALCULATION + PROCESSED + EXTRACTED) * 2);
     114    shared_progress_bar.setMinimum(MIN);
     115    shared_progress_bar.setString(null); // Default string
     116    shared_progress_bar.setStringPainted(true);
    106117    setValue(MIN);
    107     next_progress_value = CALCULATION;
    108118    }
    109119
     
    143153    }
    144154
     155    public JProgressBar getSharedProgress() {
     156    return shared_progress_bar;
     157    }
     158
    145159    /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
    146160     * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
    147161     */
    148     public boolean hasSignalledStop() {
     162    public synchronized boolean hasSignalledStop() {
    149163    return stop;
    150164    }
     
    168182    line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1);
    169183    line = line.trim();
     184    ///ystem.err.println("Process: " + line);
    170185    if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) {
    171186        // No original event is passed on, even in the lower modes
     
    174189        GShellElement element = new GShellElement(line);
    175190        String name = element.getElementName();
     191        ///ystem.err.println("Gatherer tag: " + name);
    176192        // We may be reading a file. Remember we have to offset process as we recieve this message 'before' a document is processed. Hence the use of 'next_progress_value'
    177193        if(name.equals(IMPORT_ELEMENT)) {
     194        ///ystem.err.println("#Import");
    178195        // We're into parsing output, so we don't need the 'calculating file size' etc string.
    179196        if(showing_string) {
    180             progress_bar.setString("");
     197            progress_bar.setString(null);
    181198            showing_string = false;
    182199        }
     
    186203        }
    187204        else if(name.equals(FILE_ELEMENT)) {
     205        ///ystem.err.println("#File");
    188206        file_count++;
    189207        // Set the next progress
     
    197215        // Or we're being told what plugin is actually processing the file
    198216        else if(name.equals(FILEPROCESSING_ELEMENT)) {
     217        ///ystem.err.println("#FileProcessing");
    199218        // If we are at lower mode settings fire a new 'dumbed down' event
    200219        if(Gatherer.config.getMode() <= threshold) {
     
    243262            num_docs = 0;
    244263            }
     264
    245265            processed_str = null;
    246266            // The number of documents blocked
     
    278298            queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete3"), event.getStatus()));
    279299        }
     300        else {
     301            // Try to set num docs
     302            String processed_str = element.getAttribute(PROCESSED_ATTRIBUTE);
     303            try {
     304            num_docs = Integer.parseInt(processed_str);
     305            }
     306            catch(Exception exception) {
     307            num_docs = 0;
     308            }
     309        }
    280310        }
    281311        else {
     
    291321    public void reset() {
    292322    setValue(MIN);
    293     progress_bar.setString(StaticStrings.SPACE_CHARACTER);
     323    progress_bar.setString(null);
    294324    progress_bar.updateUI();
    295325    }
     
    303333     * @param state The desired state of the stop flag as a <strong>boolean</strong>.
    304334     */
    305     public void setStop(boolean state) {
    306     stop = state;
     335    public synchronized void setStop(boolean state) {
     336    this.stop = state;
    307337    }
    308338
     
    310340     */
    311341    public void start() {
     342    stop = false;
    312343    setValue(MIN);
    313344    progress_bar.setString(Dictionary.get("FileActions.Calculating_Size"));
     
    329360    private void setValue(int value) {
    330361    progress_bar.setValue(value);
     362    shared_progress_bar.setValue(value);
    331363    if(value != 0 && value < previous_value) {
    332364        Gatherer.println("Progress is decreasing! " + previous_value + " -> " + value);
  • trunk/gli/src/org/greenstone/gatherer/shell/GShell.java

    r6388 r6533  
    4242import javax.swing.event.*;
    4343import javax.swing.tree.*;
     44import org.greenstone.gatherer.Configuration;
    4445import org.greenstone.gatherer.Dictionary;
    4546import org.greenstone.gatherer.Gatherer;
     
    228229        }
    229230        }
    230        
    231         // Of course, just because the process is finished doesn't mean the incoming streams are empty. Unfortunately I've got no chance of preserving order, so I'll process the error stream first, then the out stream
    232         while(eisr.ready()) {
    233         int c = eisr.read();
    234         ///atherer.println("eisr: '" + (char) c + "'");
    235         if(c == '\n' || c == '\r') {
    236             if(eline_buffer.length() > 0) {
    237             String eline = eline_buffer.toString();
    238             ///atherer.println("* " + eline + " *");
    239             fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
    240             eline = null;
    241             eline_buffer = new StringBuffer();
    242             }
    243         }
    244         else {
    245             eline_buffer.append((char)c);
    246         }
    247         }
    248         while(stdisr.ready()) {
    249         int c = stdisr.read();
    250         ///atherer.println("eisr: '" + (char) c + "'");
    251         if(c == '\n' || c == '\r') {
    252             if(stdline_buffer.length() > 0) {
    253             String stdline = stdline_buffer.toString();
    254             ///atherer.println("+ " + stdline + " +");
    255             fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
    256             stdline = null;
    257             stdline_buffer = new StringBuffer();
    258             }
    259         }
    260         else {
    261             stdline_buffer.append((char)c);
    262         }
    263         }
    264        
    265         // Ensure that any messages still remaining in the string buffers are fired off.
    266         if(eline_buffer.length() > 0) {
    267         String eline = eline_buffer.toString();
    268         ///atherer.println("Last bit of eline: " + eline);
    269         fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
    270         eline = null;
    271         }
    272        
    273         if(stdline_buffer.length() > 0) {
    274         String stdline = stdline_buffer.toString();
    275         ///atherer.println("Last bit of stdline: " + stdline);
    276         fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
    277         stdline = null;
     231        if(!hasSignalledStop()) {
     232        // Of course, just because the process is finished doesn't mean the incoming streams are empty. Unfortunately I've got no chance of preserving order, so I'll process the error stream first, then the out stream
     233        while(eisr.ready()) {
     234            int c = eisr.read();
     235            ///atherer.println("eisr: '" + (char) c + "'");
     236            if(c == '\n' || c == '\r') {
     237            if(eline_buffer.length() > 0) {
     238                String eline = eline_buffer.toString();
     239                ///atherer.println("* " + eline + " *");
     240                fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
     241                eline = null;
     242                eline_buffer = new StringBuffer();
     243            }
     244            }
     245            else {
     246            eline_buffer.append((char)c);
     247            }
     248        }
     249        while(stdisr.ready()) {
     250            int c = stdisr.read();
     251            ///atherer.println("eisr: '" + (char) c + "'");
     252            if(c == '\n' || c == '\r') {
     253            if(stdline_buffer.length() > 0) {
     254                String stdline = stdline_buffer.toString();
     255                ///atherer.println("+ " + stdline + " +");
     256                fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
     257                stdline = null;
     258                stdline_buffer = new StringBuffer();
     259            }
     260            }
     261            else {
     262            stdline_buffer.append((char)c);
     263            }
     264        }
     265       
     266        // Ensure that any messages still remaining in the string buffers are fired off.
     267        if(eline_buffer.length() > 0) {
     268            String eline = eline_buffer.toString();
     269            ///atherer.println("Last bit of eline: " + eline);
     270            fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
     271            eline = null;
     272        }
     273       
     274        if(stdline_buffer.length() > 0) {
     275            String stdline = stdline_buffer.toString();
     276            ///atherer.println("Last bit of stdline: " + stdline);
     277            fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
     278            stdline = null;
     279        }
     280        }
     281        else {
     282        System.err.println("We've been asked to stop.");
    278283        }
    279284       
     
    312317        fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Complete"), status, null);
    313318    }
     319    if(hasSignalledStop()) {
     320        status = CANCELLED;
     321    }
    314322    // We're done.
    315323    fireProcessComplete(type, status);
     
    388396     */
    389397    protected void fireProcessComplete(int type, int status) {
    390     // Tidy up by stopping the progress bar.
    391     if(progress != null) {
     398    // Tidy up by stopping the progress bar. If it was cancelled then the cancel command has arrived via the progress bars and they don't need to be told again (it actually causes problems).
     399    if(progress != null && status != CANCELLED) {
    392400        progress.stop();
     401    }
     402   
     403    // If we were cancelled, and we are lower details modes, fire off one last message.
     404    if(status == CANCELLED && Gatherer.config.getMode() <= Configuration.SYSTEMS_MODE) {
     405        GShellEvent current_event = new GShellEvent(this, 0, type, Dictionary.get("GShell.Build.BuildCancelled"), status);
     406        Object[] concerned = listeners.getListenerList();
     407        for(int i = 0; i < concerned.length ; i++) {
     408        if(concerned[i] == GShellListener.class) {
     409            ((GShellListener)concerned[i+1]).message(current_event);
     410        }
     411        }
     412        concerned = null;
    393413    }
    394414    // And firing off an event
     
    408428    boolean has_signalled_stop = false;
    409429    if(progress != null) {
    410         return progress.hasSignalledStop();
     430        has_signalled_stop = progress.hasSignalledStop();
    411431    }
    412432    return has_signalled_stop;
  • trunk/gli/src/org/greenstone/gatherer/shell/GShellProgressMonitor.java

    r6388 r6533  
    6666    public int exitValue();
    6767
     68    public JProgressBar getSharedProgress();
     69
    6870    /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>JProgressBar</strong> but there may be others implemented later.
    6971     * @return A <strong>Component</strong> on which the progress of the process is being displayed.
Note: See TracChangeset for help on using the changeset viewer.