Ignore:
Timestamp:
2005-02-18T12:31:54+13:00 (19 years ago)
Author:
mdewsnip
Message:

GLI applet: collection building is now much happier about being cancelled. By Matthew Whyte.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r9045 r9095  
    4949import org.greenstone.gatherer.DebugStream;
    5050import org.greenstone.gatherer.Dictionary;
     51import org.greenstone.gatherer.shell.GShell;
    5152// Don't even think about adding import org.greenstone.gatherer.Gatherer in here!
    5253// The functions in this class should be independent of the Gatherer class. Put your function somewhere else buster!
     
    601602    }
    602603
    603     static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip)
     604    static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source)
    604605    {
    605606    // Using try is required because of file io.
    606607    try {
     608        // Exit if pressed cancel.
     609        if (source != null && source.hasSignalledStop()) {
     610        return;
     611        }
    607612        // Create a Zip Entry and put it into the archive (no data yet).
    608613
     
    624629        // to the zip output stream until the bis has been entirely read.
    625630        while ((byteCount = bis.read(data, 0, 1024)) > -1) {
     631        //Check for cancell
     632        if(source != null) {
     633            if(source.hasSignalledStop()) {
     634            break;
     635            }
     636        }
    626637        zos.write(data, 0, byteCount);
    627638        }
     
    634645    }
    635646
    636     static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip)
     647    static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source)
    637648    {
    638649    File dirObj = new File(dir_name);
     
    645656        // Loop through File array and display.
    646657        for (int i = 0; i < fileList.length; i++) {
     658            if(source != null) {
     659            if(source.hasSignalledStop()) {
     660                break;
     661            }
     662            }
    647663            File file = fileList[i];
    648664            if (file.isDirectory()) {
     
    661677            }
    662678
    663             dirFunc(zos,dir_path,prefix_strip);
     679            dirFunc(zos,dir_path,prefix_strip, source);
    664680            } else if (file.isFile()) {
    665681            // Call the zipFunc function
    666682            String file_path = fileList[i].getPath();
    667             zipFunc(zos,file_path,prefix_strip);
     683            zipFunc(zos,file_path,prefix_strip, source);
    668684            }
    669685        }
     
    680696
    681697
    682     static public void zipup(String col_dir, String col_name, String dir_or_file)
     698    static public void zipup(String col_dir, String col_name, String dir_or_file, GShell source)
    683699    {
    684700    int prefix_strip = col_dir.length();
     
    695711        if (zip_dof.isDirectory()) {
    696712            String zip_dir = zip_dir_or_file;
    697             dirFunc(zos,zip_dir,prefix_strip);
     713            dirFunc(zos,zip_dir,prefix_strip, source);
    698714        }
    699715        else {
     
    714730            }
    715731            }
    716             zipFunc(zos,zip_full_file,prefix_strip);
     732            zipFunc(zos,zip_full_file,prefix_strip, source);
    717733        }
    718734        }
     
    728744    catch (IOException exception) {
    729745        DebugStream.printStackTrace(exception);
    730     } 
     746    }
    731747    }
    732748   
Note: See TracChangeset for help on using the changeset viewer.