Changeset 1409


Ignore:
Timestamp:
09/05/06 10:38:17 (14 years ago)
Author:
curtis
Message:

More tweaking around with file filters, for speed and accuracy.
Now "All supported file types" does not permit file probing,
but individual file filters still do.

Location:
trunk/loci/formats
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/ComboFileFilter.java

    r1408 r1409  
    4242  private String desc; 
    4343 
     44  /** Whether it is ok to open a file to determine its type. */ 
     45  private boolean allowOpen; 
     46 
    4447  // -- Constructor -- 
    4548 
    4649  /** Constructs a new filter from a list of other filters. */ 
    4750  public ComboFileFilter(FileFilter[] filters, String description) { 
     51    this(filters, description, true); 
     52  } 
     53 
     54  /** Constructs a new filter from a list of other filters. */ 
     55  public ComboFileFilter(FileFilter[] filters, String description, 
     56    boolean openAllowed) 
     57  { 
    4858    filts = new FileFilter[filters.length]; 
    4959    System.arraycopy(filters, 0, filts, 0, filters.length); 
    5060    desc = description; 
     61    allowOpen = openAllowed; 
    5162  } 
    5263 
     
    112123  public boolean accept(File f) { 
    113124    for (int i=0; i<filts.length; i++) { 
    114       if (filts[i].accept(f)) return true; 
     125      if (filts[i] instanceof FormatFileFilter) { 
     126        if (((FormatFileFilter) filts[i]).accept(f, allowOpen)) return true; 
     127      } 
     128      else if (filts[i].accept(f)) return true; 
    115129    } 
    116130    return false; 
  • trunk/loci/formats/FormatFileFilter.java

    r1408 r1409  
    4141  private String desc; 
    4242 
    43   /** Whether it is ok to open a file to determine its type. */ 
    44   private boolean allowOpen = true; 
    45  
    4643  // -- Constructor -- 
    4744 
     
    6865  // -- FormatFileFilter API methods -- 
    6966 
    70   /** Sets whether it is allowed to open a file to determine its type. */ 
    71   public void setOpenAllowed(boolean openAllowed) { allowOpen = openAllowed; } 
    72  
    73   /** Gets whether it is allowed to open a file to determine its type. */ 
    74   public boolean isOpenAllowed() { return allowOpen; } 
     67  /** 
     68   * Accepts files in accordance with the file format reader. 
     69   * @param allowOpen whether it is ok to open a file to determine its type. 
     70   */ 
     71  public boolean accept(File f, boolean allowOpen) { 
     72    if (f.isDirectory()) return true; 
     73    return reader.isThisType(f.getPath(), allowOpen); 
     74  } 
    7575 
    7676  // -- FileFilter API methods -- 
    7777 
    7878  /** Accepts files in accordance with the file format reader. */ 
    79   public boolean accept(File f) { 
    80     if (f.isDirectory()) return true; 
    81     return reader.isThisType(f.getPath(), allowOpen); 
    82   } 
     79  public boolean accept(File f) { return accept(f, true); } 
    8380 
    8481  /** Gets the filter's description. */ 
  • trunk/loci/formats/FormatHandler.java

    r1406 r1409  
    127127    FileFilter combo = null; 
    128128    if (ff.length > 1) { 
    129       combo = new ComboFileFilter(ff, "All supported file types"); 
     129      // By default, some readers might need to open a file to determine if it 
     130      // is the proper type, when the extension alone isn't enough to 
     131      // distinguish. 
     132      // 
     133      // We want to disable that behavior for the "All supported file types" 
     134      // combination filter, because otherwise it is too slow. 
     135      // 
     136      // Also, most of the formats that do this are TIFF-based, and the TIFF 
     137      // reader will already green-light anything with .tif extension, making 
     138      // more thorough checks redundant. 
     139      combo = new ComboFileFilter(ff, "All supported file types", false); 
    130140      fc.addChoosableFileFilter(combo); 
    131141    } 
  • trunk/loci/formats/ImageReader.java

    r1408 r1409  
    456456   */ 
    457457  public JFileChooser getFileChooser() { 
    458     JFileChooser chooser = FormatHandler.buildFileChooser(getFileFilters()); 
    459  
    460     // By default, some readers might need to open a file to determine if it 
    461     // is the proper type, if the extension alone isn't enough to distinguish. 
    462     // 
    463     // We want to disable that behavior for ImageReader because it is slow. 
    464     // 
    465     // Also, most of the formats that do this are TIFF-based, and the TIFF 
    466     // reader will already green-light anything with .tif extension, making 
    467     // more thorough checks redundant. 
    468     disableOpen(chooser.getChoosableFileFilters()); 
    469  
    470     return chooser; 
     458    return FormatHandler.buildFileChooser(getFileFilters()); 
    471459  } 
    472460 
     
    554542  private IFormatReader currentReader() { return readers[index]; } 
    555543 
    556   /** Disables file probing to verify file type for the given filters. */ 
    557   private void disableOpen(FileFilter[] ff) { 
    558     for (int i=0; i<ff.length; i++) { 
    559       if (ff[i] instanceof FormatFileFilter) { 
    560         ((FormatFileFilter) ff[i]).setOpenAllowed(false); 
    561       } 
    562       else if (ff[i] instanceof ComboFileFilter) { 
    563         disableOpen(((ComboFileFilter) ff[i]).getFilters()); 
    564       } 
    565     } 
    566   } 
    567  
    568544  // -- Main method -- 
    569545 
Note: See TracChangeset for help on using the changeset viewer.