Changeset 2571


Ignore:
Timestamp:
04/06/07 13:53:45 (13 years ago)
Author:
curtis
Message:

Change the way "allow open" stuff works, so that ComboFileFilter need not have
special knowledge about FormatFileFilter. Rather, whether open is allowed is
set in the FormatFileFilter constructor.

Location:
trunk/loci/formats/gui
Files:
3 edited

Legend:

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

    r2538 r2571  
    4242  private String desc; 
    4343 
    44   /** Whether it is ok to open a file to determine its type. */ 
    45   private boolean allowOpen; 
    46  
    4744  // -- Constructor -- 
    4845 
    4946  /** Constructs a new filter from a list of other filters. */ 
    5047  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   { 
    5848    filts = new FileFilter[filters.length]; 
    5949    System.arraycopy(filters, 0, filts, 0, filters.length); 
    6050    desc = description; 
    61     allowOpen = openAllowed; 
    6251  } 
    6352 
     
    123112  public boolean accept(File f) { 
    124113    for (int i=0; i<filts.length; i++) { 
    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; 
     114      if (filts[i].accept(f)) return true; 
    129115    } 
    130116    return false; 
  • trunk/loci/formats/gui/FormatFileFilter.java

    r2538 r2571  
    3939  private IFormatReader reader; 
    4040 
     41  /** Whether it is ok to open a file to determine its type. */ 
     42  private boolean allowOpen; 
     43 
    4144  /** Description. */ 
    4245  private String desc; 
    4346 
    44   // -- Constructor -- 
     47  // -- Constructors -- 
    4548 
    46   /** Constructs a new filter that accepts the given extension. */ 
     49  /** Constructs a new filter that accepts files of the given reader's type. */ 
    4750  public FormatFileFilter(IFormatReader reader) { 
     51    this(reader, true); 
     52  } 
     53 
     54  /** 
     55   * Constructs a new filter that accepts files of the given reader's type, 
     56   * allowing the reader to open files only if the allowOpen flag is set. 
     57   * @param reader The reader to use for verifying a file's type. 
     58   * @param allowOpen Whether it is ok to open a file to determine its type. 
     59   */ 
     60  public FormatFileFilter(IFormatReader reader, boolean allowOpen) { 
    4861    this.reader = reader; 
     62    this.allowOpen = allowOpen; 
    4963    StringBuffer sb = new StringBuffer(reader.getFormat()); 
    5064    String[] exts = reader.getSuffixes(); 
     
    6478  } 
    6579 
    66   // -- FormatFileFilter API methods -- 
     80  // -- FileFilter API methods -- 
    6781 
    68   /** 
    69    * Accepts files in accordance with the file format reader. 
    70    * @param allowOpen whether it is ok to open a file to determine its type. 
    71    */ 
    72   public boolean accept(File f, boolean allowOpen) { 
     82  /** Accepts files in accordance with the file format reader. */ 
     83  public boolean accept(File f) { 
    7384    if (f.isDirectory()) return true; 
    7485    return reader.isThisType(f.getPath(), allowOpen); 
    7586  } 
    76  
    77   // -- FileFilter API methods -- 
    78  
    79   /** Accepts files in accordance with the file format reader. */ 
    80   public boolean accept(File f) { return accept(f, true); } 
    8187 
    8288  /** Gets the filter's description. */ 
  • trunk/loci/formats/gui/GUITools.java

    r2538 r2571  
    3939public final class GUITools { 
    4040 
    41   // -- Static fields -- 
    42  
    43   //... 
    44  
    4541  // -- Constructor -- 
    4642 
     
    6864      Vector v = new Vector(); 
    6965      for (int i=0; i<readers.length; i++) { 
    70         v.add(new FormatFileFilter(readers[i])); 
     66        // NB: By default, some readers might need to open a file to 
     67        // determine if it is the proper type, when the extension alone 
     68        // isn't enough to distinguish. 
     69        // 
     70        // We want to disable that behavior for ImageReader, 
     71        // because otherwise the combination filter is too slow. 
     72        // 
     73        // Also, most of the formats that do this are TIFF-based, and the 
     74        // TIFF reader will already green-light anything with .tif 
     75        // extension, making more thorough checks redundant. 
     76        v.add(new FormatFileFilter(readers[i], false)); 
    7177      } 
    7278      ff = ComboFileFilter.sortFilters(v); 
     
    114120        FileFilter combo = null; 
    115121        if (ff.length > 1) { 
    116           // By default, some readers might need to open a file to determine 
    117           // if it is the proper type, when the extension alone isn't enough 
    118           // to distinguish. 
    119           // 
    120           // We want to disable that behavior for the "All supported file 
    121           // types" combination filter, because otherwise it is too slow. 
    122           // 
    123           // Also, most of the formats that do this are TIFF-based, and the 
    124           // TIFF reader will already green-light anything with .tif 
    125           // extension, making more thorough checks redundant. 
    126           combo = new ComboFileFilter(ff, "All supported file types", false); 
     122          combo = new ComboFileFilter(ff, "All supported file types"); 
    127123          fc.addChoosableFileFilter(combo); 
    128124        } 
Note: See TracChangeset for help on using the changeset viewer.