Changeset 1408


Ignore:
Timestamp:
09/01/06 17:32:58 (14 years ago)
Author:
curtis
Message:

Make ImageReader's file filters also call isThisType(id, false). This results
in the file chooser being lightning fast, but unfortunately disables the
"smarter" filtering behavior for the constituent filters--I will fix this
problem on Monday.

Location:
trunk/loci/formats
Files:
7 edited

Legend:

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

    r1388 r1408  
    4949    System.arraycopy(filters, 0, filts, 0, filters.length); 
    5050    desc = description; 
     51  } 
     52 
     53  // -- ComboFileFilter API methods -- 
     54 
     55  /** Gets the list of file filters forming this filter combination. */ 
     56  public FileFilter[] getFilters() { 
     57    FileFilter[] ff = new FileFilter[filts.length]; 
     58    System.arraycopy(filts, 0, ff, 0, filts.length); 
     59    return ff; 
    5160  } 
    5261 
     
    111120  public String getDescription() { return desc; } 
    112121 
     122  // -- Object API methods -- 
     123 
     124  /** Gets a string representation of this file filter. */ 
     125  public String toString() { 
     126    StringBuffer sb = new StringBuffer("ComboFileFilter: "); 
     127    sb.append(desc); 
     128    for (int i=0; i<filts.length; i++) { 
     129      sb.append("\n\t"); 
     130      sb.append(filts[i].toString()); 
     131    } 
     132    return sb.toString(); 
     133  } 
     134 
    113135  // -- Comparable API methods -- 
    114136 
  • trunk/loci/formats/ExtensionFileFilter.java

    r1388 r1408  
    4141  private String desc; 
    4242 
    43  
    4443  // -- Constructors -- 
    4544 
     
    7069  } 
    7170 
     71  // -- ExtensionFileFilter API methods -- 
     72 
     73  /** Gets the filter's first valid extension. */ 
     74  public String getExtension() { return exts[0]; } 
     75 
     76  /** Gets the filter's valid extensions. */ 
     77  public String[] getExtensions() { return exts; } 
    7278 
    7379  // -- FileFilter API methods -- 
     
    8894  } 
    8995 
    90   /** Gets the filter's first valid extension. */ 
    91   public String getExtension() { return exts[0]; } 
    92  
    93   /** Gets the filter's valid extensions. */ 
    94   public String[] getExtensions() { return exts; } 
    95  
    9696  /** Gets the filter's description. */ 
    9797  public String getDescription() { return desc; } 
    9898 
     99  // -- Object API methods -- 
     100 
     101  /** Gets a string representation of this file filter. */ 
     102  public String toString() { return "ExtensionFileFilter: " + desc; } 
    99103 
    100104  // -- Comparable API methods -- 
  • trunk/loci/formats/FormatFileFilter.java

    r1406 r1408  
    7272 
    7373  /** Gets whether it is allowed to open a file to determine its type. */ 
    74   public boolean  isOpenAllowed() { return allowOpen; } 
     74  public boolean isOpenAllowed() { return allowOpen; } 
    7575 
    7676  // -- FileFilter API methods -- 
     
    8585  public String getDescription() { return desc; } 
    8686 
     87  // -- Object API methods -- 
     88 
     89  /** Gets a string representation of this file filter. */ 
     90  public String toString() { return "FormatFileFilter: " + desc; } 
     91 
    8792  // -- Comparable API methods -- 
    8893 
  • trunk/loci/formats/ImageReader.java

    r1406 r1408  
    456456   */ 
    457457  public JFileChooser getFileChooser() { 
    458     return FormatHandler.buildFileChooser(getFileFilters()); 
     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; 
    459471  } 
    460472 
     
    474486   * @see loci.formats.IFormatHandler#getFormat() 
    475487   */ 
    476   public String getFormat() { 
    477     return readers[index].getFormat(); 
    478   } 
     488  public String getFormat() { return readers[index].getFormat(); } 
    479489 
    480490  /* (non-Javadoc) 
    481491   * @see loci.formats.IFormatHandler#getSuffixes() 
    482492   */ 
    483   public String[] getSuffixes() { 
    484     return suffixes; 
    485   } 
     493  public String[] getSuffixes() { return suffixes; } 
    486494 
    487495  /** 
     
    546554  private IFormatReader currentReader() { return readers[index]; } 
    547555 
     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 
    548568  // -- Main method -- 
    549569 
  • trunk/loci/formats/in/AndorReader.java

    r1406 r1408  
    136136   */ 
    137137  public boolean isThisType(String name, boolean open) { 
    138     String lname = name.toLowerCase(); 
    139     if (!lname.endsWith(".tif") && !lname.endsWith(".tiff")) return false; 
     138    if (!super.isThisType(name, open)) return false; 
    140139 
    141140    // just checking the filename isn't enough to differentiate between 
  • trunk/loci/formats/in/FluoviewReader.java

    r1406 r1408  
    130130   */ 
    131131  public boolean isThisType(String name, boolean open) { 
    132     String lname = name.toLowerCase(); 
    133     if (!lname.endsWith(".tif") && !lname.endsWith(".tiff")) return false; 
     132    if (!super.isThisType(name, open)) return false; 
    134133 
    135134    // just checking the filename isn't enough to differentiate between 
  • trunk/loci/formats/in/OpenlabReader.java

    r1406 r1408  
    9393   */ 
    9494  public boolean isThisType(String name, boolean open) { 
    95     String lname = name.toLowerCase(); 
    96     if (lname.endsWith(".liff")) return true; 
     95    if (super.isThisType(name, open)) return true; 
    9796 
    9897    if (open) { 
     
    101100      return checkBytes(name, 8); 
    102101    } 
    103     else return lname.indexOf(".") < 0; // file appears to have no extension 
     102    else { 
     103      String lname = name.toLowerCase(); 
     104      return lname.indexOf(".") < 0; // file appears to have no extension 
     105    } 
    104106  } 
    105107 
Note: See TracChangeset for help on using the changeset viewer.