Changeset 2453


Ignore:
Timestamp:
03/14/07 16:11:24 (13 years ago)
Author:
curtis
Message:

Add event for listening to status updates from format readers and writers.

  • Interested parties can register status listeners with FormatHandler.addStatusListener(StatusListener).
  • Format handlers can report status updates by calling the FormatHandler.status() methods.
  • But no concrete format implementations report any status events, yet.
Location:
trunk/loci/formats
Files:
2 added
10 edited

Legend:

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

    r2442 r2453  
    719719  public JFileChooser getFileChooser() { 
    720720    return reader.getFileChooser(); 
     721  } 
     722 
     723  /* @see IFormatHandler#addStatusListener(StatusListener) */ 
     724  public void addStatusListener(StatusListener l) { 
     725    for (int i=0; i<readers.length; i++) readers[i].addStatusListener(l); 
     726  } 
     727 
     728  /* @see IFormatHandler#removeStatusListener(StatusListener) */ 
     729  public void removeStatusListener(StatusListener l) { 
     730    for (int i=0; i<readers.length; i++) readers[i].removeStatusListener(l); 
     731  } 
     732 
     733  /* @see IFormatHandler#getStatusListeners() */ 
     734  public StatusListener[] getStatusListeners() { 
     735    return reader.getStatusListeners(); 
    721736  } 
    722737 
  • trunk/loci/formats/FormatHandler.java

    r2178 r2453  
    2525package loci.formats; 
    2626 
    27 import java.lang.reflect.InvocationTargetException; 
     27import java.util.Vector; 
    2828import javax.swing.JFileChooser; 
    29 import javax.swing.SwingUtilities; 
    3029import javax.swing.filechooser.FileFilter; 
    3130 
     
    4746  protected JFileChooser chooser; 
    4847 
     48  /** List of status listeners. */ 
     49  protected Vector statusListeners = new Vector(); 
     50 
    4951  /** Name of current file. */ 
    5052  protected String currentId; 
     
    6163    this.format = format; 
    6264    this.suffixes = suffixes == null ? new String[0] : suffixes; 
     65  } 
     66 
     67  // -- Internal FormatHandler methods -- 
     68 
     69  /** Fires a status update event. */ 
     70  protected void status(String message) { 
     71    status(new StatusEvent(message)); 
     72  } 
     73 
     74  /** Fires a status update event. */ 
     75  protected void status(int progress, int maximum, String message) { 
     76    status(new StatusEvent(progress, maximum, message)); 
     77  } 
     78 
     79  /** Fires a status update event. */ 
     80  protected void status(StatusEvent e) { 
     81    StatusListener[] l = getStatusListeners(); 
     82    for (int i=0; i<l.length; i++) l[i].statusUpdated(e); 
    6383  } 
    6484 
     
    104124  /* @see IFormatHandler#getFileChooser() */ 
    105125  public JFileChooser getFileChooser() { 
    106     if (chooser == null) chooser = buildFileChooser(getFileFilters()); 
     126    if (chooser == null) { 
     127      chooser = FormatTools.buildFileChooser(getFileFilters()); 
     128    } 
    107129    return chooser; 
    108130  } 
    109131 
    110   // -- Utility methods -- 
     132  /* @see IFormatHandler#addStatusListener(StatusListener) */ 
     133  public void addStatusListener(StatusListener l) { 
     134    synchronized (statusListeners) { 
     135      if (!statusListeners.contains(l)) statusListeners.add(l); 
     136    } 
     137  } 
    111138 
    112   /** 
    113    * Builds a file chooser with the given file filters, 
    114    * as well as an "All supported file types" combo filter. 
    115    */ 
    116   public static JFileChooser buildFileChooser(final FileFilter[] filters) { 
    117     // NB: must construct JFileChooser in the 
    118     // AWT worker thread, to avoid deadlocks 
    119     final JFileChooser[] jfc = new JFileChooser[1]; 
    120     Runnable r = new Runnable() { 
    121       public void run() { 
    122         JFileChooser fc = new JFileChooser(System.getProperty("user.dir")); 
    123         FileFilter[] ff = ComboFileFilter.sortFilters(filters); 
    124         FileFilter combo = null; 
    125         if (ff.length > 1) { 
    126           // By default, some readers might need to open a file to determine 
    127           // if it is the proper type, when the extension alone isn't enough 
    128           // to distinguish. 
    129           // 
    130           // We want to disable that behavior for the "All supported file 
    131           // types" combination filter, because otherwise it is too slow. 
    132           // 
    133           // Also, most of the formats that do this are TIFF-based, and the 
    134           // TIFF reader will already green-light anything with .tif 
    135           // extension, making more thorough checks redundant. 
    136           combo = new ComboFileFilter(ff, "All supported file types", false); 
    137           fc.addChoosableFileFilter(combo); 
    138         } 
    139         for (int i=0; i<ff.length; i++) fc.addChoosableFileFilter(ff[i]); 
    140         if (combo != null) fc.setFileFilter(combo); 
    141         jfc[0] = fc; 
    142       } 
    143     }; 
    144     if (Thread.currentThread().getName().startsWith("AWT-EventQueue")) { 
    145       // current thread is the AWT event queue thread; just execute the code 
    146       r.run(); 
     139  /* @see IFormatHandler#removeStatusListener(StatusListener) */ 
     140  public void removeStatusListener(StatusListener l) { 
     141    synchronized (statusListeners) { 
     142      statusListeners.remove(l); 
    147143    } 
    148     else { 
    149       // execute the code with the AWT event thread 
    150       try { 
    151         SwingUtilities.invokeAndWait(r); 
    152       } 
    153       catch (InterruptedException exc) { return null; } 
    154       catch (InvocationTargetException exc) { return null; } 
     144  } 
     145 
     146  /* @see IFormatHandler#getStatusListeners() */ 
     147  public StatusListener[] getStatusListeners() { 
     148    synchronized (statusListeners) { 
     149      StatusListener[] l = new StatusListener[statusListeners.size()]; 
     150      statusListeners.copyInto(l); 
     151      return l; 
    155152    } 
    156     return jfc[0]; 
    157153  } 
    158154 
  • trunk/loci/formats/FormatReader.java

    r2430 r2453  
    7171 
    7272  /** Whether or not we're doing channel stat calculation (no by default). */ 
    73   protected boolean enableChannelStatCalculation = false; 
     73  protected boolean enableChannelStats = false; 
    7474 
    7575  /** List of image indices that have been read. */ 
     
    167167  } 
    168168 
     169  /** 
     170   * Updates min/max values based on the given BufferedImage. 
     171   * Should be called by each format reader's openImage method. 
     172   */ 
     173  protected void updateMinMax(BufferedImage b, int ndx) 
     174    throws FormatException, IOException 
     175  { 
     176    if (b == null || !enableChannelStats) return; 
     177    Integer ii = new Integer(ndx); 
     178    if (imagesRead[series].contains(ii)) return; 
     179    if (channelMinMax == null) { 
     180      channelMinMax = 
     181        new double[getSeriesCount(currentId)][getSizeC(currentId)][2]; 
     182    } 
     183    if (planeMinMax == null) { 
     184      planeMinMax = new double[getSeriesCount(currentId)][ 
     185        getSizeZ(currentId) * getSizeC(currentId) * getSizeT(currentId)][2]; 
     186    } 
     187 
     188    imagesRead[series].add(ii); 
     189    int[] coords = getZCTCoords(currentId, ndx); 
     190    int numRGB = getRGBChannelCount(currentId); 
     191    WritableRaster pixels = b.getRaster(); 
     192    for (int x=0; x<b.getWidth(); x++) { 
     193      for (int y=0; y<b.getHeight(); y++) { 
     194        for (int c=0; c<numRGB; c++) { 
     195          double value = pixels.getSampleDouble(x, y, c); 
     196          if (value > channelMinMax[series][coords[1]*numRGB + c][MAX]) { 
     197            channelMinMax[series][coords[1]*numRGB + c][MAX] = value; 
     198          } 
     199          if (value < channelMinMax[series][coords[1]*numRGB + c][MIN]) { 
     200            channelMinMax[series][coords[1]*numRGB + c][MIN] = value; 
     201          } 
     202          if (value > planeMinMax[series][ndx*numRGB + c][MAX]) { 
     203            planeMinMax[series][ndx*numRGB + c][MAX] = value; 
     204          } 
     205          if (value < planeMinMax[series][ndx*numRGB + c][MIN]) { 
     206            planeMinMax[series][ndx*numRGB + c][MIN] = value; 
     207          } 
     208        } 
     209      } 
     210    } 
     211 
     212    if (imagesRead[series].size() == getImageCount(currentId)) { 
     213      minMaxFinished[series] = true; 
     214    } 
     215  } 
     216 
     217  /** 
     218   * Updates min/max values based on given byte array. 
     219   * Should be called by each format reader's openBytes method. 
     220   */ 
     221  protected void updateMinMax(byte[] b, int ndx) 
     222    throws FormatException, IOException 
     223  { 
     224    if (b == null || !enableChannelStats) return; 
     225    Integer ii = new Integer(ndx); 
     226    if (imagesRead[series].contains(ii)) return; 
     227    if (channelMinMax == null) { 
     228      channelMinMax = 
     229        new double[getSeriesCount(currentId)][getSizeC(currentId)][2]; 
     230    } 
     231    if (planeMinMax == null) { 
     232      planeMinMax = new double[getSeriesCount(currentId)][ 
     233        getSizeZ(currentId) * getSizeC(currentId) * getSizeT(currentId)][2]; 
     234    } 
     235 
     236    boolean little = isLittleEndian(currentId); 
     237    int bytes = FormatTools.getBytesPerPixel(getPixelType(currentId)); 
     238    int numRGB = getRGBChannelCount(currentId); 
     239    int pixels = getSizeX(currentId) * getSizeY(currentId); 
     240    boolean interleaved = isInterleaved(currentId); 
     241 
     242    byte[] value = new byte[bytes]; 
     243    int[] coords = getZCTCoords(currentId, ndx); 
     244 
     245    for (int i=0; i<pixels; i++) { 
     246      for (int c=0; c<numRGB; c++) { 
     247        int idx = interleaved ? i*numRGB + c : c*pixels + i; 
     248        idx *= bytes; 
     249        System.arraycopy(b, idx, value, 0, bytes); 
     250        double v = 
     251          Double.longBitsToDouble(DataTools.bytesToLong(value, little)); 
     252        if (v > channelMinMax[series][coords[1]*numRGB + c][MAX]) { 
     253          channelMinMax[series][coords[1]*numRGB + c][MAX] = v; 
     254        } 
     255        if (v < channelMinMax[series][coords[1]*numRGB + c][MIN]) { 
     256          channelMinMax[series][coords[1]*numRGB + c][MIN] = v; 
     257        } 
     258        if (v > planeMinMax[series][ndx*numRGB + c][MAX]) { 
     259          planeMinMax[series][ndx*numRGB + c][MAX] = v; 
     260        } 
     261        if (v < planeMinMax[series][ndx*numRGB + c][MIN]) { 
     262          planeMinMax[series][ndx*numRGB + c][MIN] = v; 
     263        } 
     264      } 
     265    } 
     266  } 
     267 
     268  /** Returns true if the given file name is in the used files list. */ 
     269  protected boolean isUsedFile(String id, String file) 
     270    throws FormatException, IOException 
     271  { 
     272    String[] usedFiles = getUsedFiles(id); 
     273    for (int i=0; i<usedFiles.length; i++) { 
     274      if (usedFiles[i].equals(file) || 
     275        usedFiles[i].equals(new Location(file).getAbsolutePath())) 
     276      { 
     277        return true; 
     278      } 
     279    } 
     280    return false; 
     281  } 
     282 
    169283  /** Adds an entry to the metadata table. */ 
    170284  protected void addMeta(String key, Object value) { 
     
    276390      throw new FormatException("Invalid channel index: " + theC); 
    277391    } 
    278     if (enableChannelStatCalculation && minMaxFinished[series]) { 
     392    if (enableChannelStats && minMaxFinished[series]) { 
    279393      return new Double(channelMinMax[series][theC][MIN]); 
    280394    } 
     
    290404      throw new FormatException("Invalid channel index: " + theC); 
    291405    } 
    292     if (enableChannelStatCalculation && minMaxFinished[series]) { 
     406    if (enableChannelStats && minMaxFinished[series]) { 
    293407      return new Double(channelMinMax[series][theC][MAX]); 
    294408    } 
     
    301415  { 
    302416    if (!id.equals(currentId)) initFile(id); 
    303     if (enableChannelStatCalculation) { 
     417    if (enableChannelStats) { 
    304418      return new Double(channelMinMax[series][theC][MIN]); 
    305419    } 
     
    312426  { 
    313427    if (!id.equals(currentId)) initFile(id); 
    314     if (enableChannelStatCalculation) { 
     428    if (enableChannelStats) { 
    315429      return new Double(channelMinMax[series][theC][MAX]); 
    316430    } 
     
    323437  { 
    324438    if (!id.equals(currentId)) initFile(id); 
    325     if (enableChannelStatCalculation && 
     439    if (enableChannelStats && 
    326440      imagesRead[series].contains(new Integer(no))) 
    327441    { 
     
    343457  { 
    344458    if (!id.equals(currentId)) initFile(id); 
    345     if (enableChannelStatCalculation && 
     459    if (enableChannelStats && 
    346460      imagesRead[series].contains(new Integer(no))) 
    347461    { 
     
    404518        "Warning: setChannelStatCalculation called with open file."); 
    405519    } 
    406     enableChannelStatCalculation = on; 
     520    enableChannelStats = on; 
    407521  } 
    408522 
    409523  /* @see IFormatReader#getChannelStatCalculationStatus() */ 
    410524  public boolean getChannelStatCalculationStatus() { 
    411     return enableChannelStatCalculation; 
     525    return enableChannelStats; 
    412526  } 
    413527 
     
    647761  } 
    648762 
    649   // -- Helper methods -- 
    650  
    651   /** 
    652    * Updates min/max values based on the given BufferedImage. 
    653    * Should be called by each format reader's openImage method. 
    654    */ 
    655   protected void updateMinMax(BufferedImage b, int ndx) 
    656     throws FormatException, IOException 
    657   { 
    658     Integer ii = new Integer(ndx); 
    659     if (!imagesRead[series].contains(ii) && enableChannelStatCalculation) { 
    660       if (channelMinMax == null) { 
    661         channelMinMax = 
    662           new double[getSeriesCount(currentId)][getSizeC(currentId)][2]; 
    663       } 
    664       if (planeMinMax == null) { 
    665         planeMinMax = new double[getSeriesCount(currentId)][ 
    666           getSizeZ(currentId) * getSizeC(currentId) * getSizeT(currentId)][2]; 
    667       } 
    668  
    669       imagesRead[series].add(ii); 
    670       int[] coords = getZCTCoords(currentId, ndx); 
    671       int numRGB = getRGBChannelCount(currentId); 
    672       WritableRaster pixels = b.getRaster(); 
    673       for (int x=0; x<b.getWidth(); x++) { 
    674         for (int y=0; y<b.getHeight(); y++) { 
    675           for (int c=0; c<numRGB; c++) { 
    676             double value = pixels.getSampleDouble(x, y, c); 
    677             if (value > channelMinMax[series][coords[1]*numRGB + c][MAX]) { 
    678               channelMinMax[series][coords[1]*numRGB + c][MAX] = value; 
    679             } 
    680             if (value < channelMinMax[series][coords[1]*numRGB + c][MIN]) { 
    681               channelMinMax[series][coords[1]*numRGB + c][MIN] = value; 
    682             } 
    683             if (value > planeMinMax[series][ndx*numRGB + c][MAX]) { 
    684               planeMinMax[series][ndx*numRGB + c][MAX] = value; 
    685             } 
    686             if (value < planeMinMax[series][ndx*numRGB + c][MIN]) { 
    687               planeMinMax[series][ndx*numRGB + c][MIN] = value; 
    688             } 
    689           } 
    690         } 
    691       } 
    692  
    693       if (imagesRead[series].size() == getImageCount(currentId)) { 
    694         minMaxFinished[series] = true; 
    695       } 
    696     } 
    697   } 
    698  
    699   /** 
    700    * Updates min/max values based on given byte array. 
    701    * Should be called by each format reader's openBytes method. 
    702    */ 
    703   protected void updateMinMax(byte[] b, int ndx) 
    704     throws FormatException, IOException 
    705   { 
    706     if (b == null) return; 
    707     Integer ii = new Integer(ndx); 
    708     if (!imagesRead[series].contains(ii) && enableChannelStatCalculation) { 
    709       if (channelMinMax == null) { 
    710         channelMinMax = 
    711           new double[getSeriesCount(currentId)][getSizeC(currentId)][2]; 
    712       } 
    713       if (planeMinMax == null) { 
    714         planeMinMax = new double[getSeriesCount(currentId)][ 
    715           getSizeZ(currentId) * getSizeC(currentId) * getSizeT(currentId)][2]; 
    716       } 
    717  
    718       boolean little = isLittleEndian(currentId); 
    719       int bytes = FormatTools.getBytesPerPixel(getPixelType(currentId)); 
    720       int numRGB = getRGBChannelCount(currentId); 
    721       int pixels = getSizeX(currentId) * getSizeY(currentId); 
    722       boolean interleaved = isInterleaved(currentId); 
    723  
    724       byte[] value = new byte[bytes]; 
    725       int[] coords = getZCTCoords(currentId, ndx); 
    726  
    727       for (int i=0; i<pixels; i++) { 
    728         for (int c=0; c<numRGB; c++) { 
    729           int idx = interleaved ? i*numRGB + c : c*pixels + i; 
    730           idx *= bytes; 
    731           System.arraycopy(b, idx, value, 0, bytes); 
    732           double v = 
    733             Double.longBitsToDouble(DataTools.bytesToLong(value, little)); 
    734           if (v > channelMinMax[series][coords[1]*numRGB + c][MAX]) { 
    735             channelMinMax[series][coords[1]*numRGB + c][MAX] = v; 
    736           } 
    737           if (v < channelMinMax[series][coords[1]*numRGB + c][MIN]) { 
    738             channelMinMax[series][coords[1]*numRGB + c][MIN] = v; 
    739           } 
    740           if (v > planeMinMax[series][ndx*numRGB + c][MAX]) { 
    741             planeMinMax[series][ndx*numRGB + c][MAX] = v; 
    742           } 
    743           if (v < planeMinMax[series][ndx*numRGB + c][MIN]) { 
    744             planeMinMax[series][ndx*numRGB + c][MIN] = v; 
    745           } 
    746         } 
    747       } 
    748     } 
    749   } 
    750  
    751   /** Returns true if the given file name is in the used files list. */ 
    752   protected boolean isUsedFile(String id, String file) 
    753     throws FormatException, IOException 
    754   { 
    755     String[] usedFiles = getUsedFiles(id); 
    756     for (int i=0; i<usedFiles.length; i++) { 
    757       if (usedFiles[i].equals(file) || 
    758         usedFiles[i].equals(new Location(file).getAbsolutePath())) 
    759       { 
    760         return true; 
    761       } 
    762     } 
    763     return false; 
    764   } 
    765  
    766763} 
  • trunk/loci/formats/FormatTools.java

    r2443 r2453  
    2525package loci.formats; 
    2626 
     27import java.awt.Image; 
    2728import java.awt.image.BufferedImage; 
    2829import java.io.IOException; 
     30import java.lang.reflect.InvocationTargetException; 
    2931import java.lang.reflect.Method; 
    3032import java.util.Arrays; 
    3133import java.util.Hashtable; 
     34import javax.swing.JFileChooser; 
     35import javax.swing.SwingUtilities; 
     36import javax.swing.filechooser.FileFilter; 
    3237 
    3338/** A utility class for format reader and writer implementations. */ 
     
    7883  private FormatTools() { } 
    7984 
    80   // -- Utility methods -- 
     85  // -- Utility methods - testing -- 
    8186 
    8287  /** 
     
    446451  } 
    447452 
    448   // -- Dimensional positions -- 
     453  /** A utility method for converting a file from the command line. */ 
     454  public static boolean testConvert(IFormatWriter writer, String[] args) 
     455    throws FormatException, IOException 
     456  { 
     457    String className = writer.getClass().getName(); 
     458    if (args == null || args.length < 2) { 
     459      System.out.println("To convert a file to " + writer.getFormat() + 
     460        " format, run:"); 
     461      System.out.println("  java " + className + " in_file out_file"); 
     462      return false; 
     463    } 
     464    String in = args[0]; 
     465    String out = args[1]; 
     466    System.out.print(in + " -> " + out + " "); 
     467 
     468    ImageReader reader = new ImageReader(); 
     469    long start = System.currentTimeMillis(); 
     470    int num = reader.getImageCount(in); 
     471    long mid = System.currentTimeMillis(); 
     472    long read = 0, write = 0; 
     473    for (int i=0; i<num; i++) { 
     474      long s = System.currentTimeMillis(); 
     475      Image image = reader.openImage(in, i); 
     476      long m = System.currentTimeMillis(); 
     477      writer.save(out, image, i == num - 1); 
     478      long e = System.currentTimeMillis(); 
     479      System.out.print("."); 
     480      read += m - s; 
     481      write += e - m; 
     482    } 
     483    long end = System.currentTimeMillis(); 
     484    System.out.println(" [done]"); 
     485 
     486    // output timing results 
     487    float sec = (end - start) / 1000f; 
     488    long initial = mid - start; 
     489    float readAvg = (float) read / num; 
     490    float writeAvg = (float) write / num; 
     491    System.out.println(sec + "s elapsed (" + 
     492      readAvg + "+" + writeAvg + "ms per image, " + initial + "ms overhead)"); 
     493 
     494    return true; 
     495  } 
     496 
     497  // -- Utility methods - dimensional positions -- 
    449498 
    450499  /** 
     
    641690  } 
    642691 
    643   // -- Pixel types -- 
     692  // -- Utility methods - pixel types -- 
    644693 
    645694  /** 
     
    691740  } 
    692741 
     742  // -- Utility methods - GUI -- 
     743 
     744  /** 
     745   * Builds a file chooser with the given file filters, 
     746   * as well as an "All supported file types" combo filter. 
     747   */ 
     748  public static JFileChooser buildFileChooser(final FileFilter[] filters) { 
     749    // NB: must construct JFileChooser in the 
     750    // AWT worker thread, to avoid deadlocks 
     751    final JFileChooser[] jfc = new JFileChooser[1]; 
     752    Runnable r = new Runnable() { 
     753      public void run() { 
     754        JFileChooser fc = new JFileChooser(System.getProperty("user.dir")); 
     755        FileFilter[] ff = ComboFileFilter.sortFilters(filters); 
     756        FileFilter combo = null; 
     757        if (ff.length > 1) { 
     758          // By default, some readers might need to open a file to determine 
     759          // if it is the proper type, when the extension alone isn't enough 
     760          // to distinguish. 
     761          // 
     762          // We want to disable that behavior for the "All supported file 
     763          // types" combination filter, because otherwise it is too slow. 
     764          // 
     765          // Also, most of the formats that do this are TIFF-based, and the 
     766          // TIFF reader will already green-light anything with .tif 
     767          // extension, making more thorough checks redundant. 
     768          combo = new ComboFileFilter(ff, "All supported file types", false); 
     769          fc.addChoosableFileFilter(combo); 
     770        } 
     771        for (int i=0; i<ff.length; i++) fc.addChoosableFileFilter(ff[i]); 
     772        if (combo != null) fc.setFileFilter(combo); 
     773        jfc[0] = fc; 
     774      } 
     775    }; 
     776    if (Thread.currentThread().getName().startsWith("AWT-EventQueue")) { 
     777      // current thread is the AWT event queue thread; just execute the code 
     778      r.run(); 
     779    } 
     780    else { 
     781      // execute the code with the AWT event thread 
     782      try { 
     783        SwingUtilities.invokeAndWait(r); 
     784      } 
     785      catch (InterruptedException exc) { return null; } 
     786      catch (InvocationTargetException exc) { return null; } 
     787    } 
     788    return jfc[0]; 
     789  } 
     790 
    693791} 
  • trunk/loci/formats/FormatWriter.java

    r2430 r2453  
    3333  implements IFormatWriter 
    3434{ 
     35 
     36  // -- Constants -- 
     37 
     38  /** Debugging flag. */ 
     39  public static boolean debug = false; 
     40 
     41  /** Debugging level. 1=basic, 2=extended, 3=everything, 4=insane. */ 
     42  public static int debugLevel = 1; 
     43 
    3544 
    3645  // -- Fields -- 
     
    118127    throws FormatException, IOException 
    119128  { 
    120     return testConvert(this, args); 
    121   } 
    122  
    123   // -- Utility methods -- 
    124  
    125   /** A utility method for converting a file from the command line. */ 
    126   public static boolean testConvert(IFormatWriter writer, String[] args) 
    127     throws FormatException, IOException 
    128   { 
    129     String className = writer.getClass().getName(); 
    130     if (args == null || args.length < 2) { 
    131       System.out.println("To convert a file to " + writer.getFormat() + 
    132         " format, run:"); 
    133       System.out.println("  java " + className + " in_file out_file"); 
    134       return false; 
    135     } 
    136     String in = args[0]; 
    137     String out = args[1]; 
    138     System.out.print(in + " -> " + out + " "); 
    139  
    140     ImageReader reader = new ImageReader(); 
    141     long start = System.currentTimeMillis(); 
    142     int num = reader.getImageCount(in); 
    143     long mid = System.currentTimeMillis(); 
    144     long read = 0, write = 0; 
    145     for (int i=0; i<num; i++) { 
    146       long s = System.currentTimeMillis(); 
    147       Image image = reader.openImage(in, i); 
    148       long m = System.currentTimeMillis(); 
    149       writer.save(out, image, i == num - 1); 
    150       long e = System.currentTimeMillis(); 
    151       System.out.print("."); 
    152       read += m - s; 
    153       write += e - m; 
    154     } 
    155     long end = System.currentTimeMillis(); 
    156     System.out.println(" [done]"); 
    157  
    158     // output timing results 
    159     float sec = (end - start) / 1000f; 
    160     long initial = mid - start; 
    161     float readAvg = (float) read / num; 
    162     float writeAvg = (float) write / num; 
    163     System.out.println(sec + "s elapsed (" + 
    164       readAvg + "+" + writeAvg + "ms per image, " + initial + "ms overhead)"); 
    165  
    166     return true; 
     129    return FormatTools.testConvert(this, args); 
    167130  } 
    168131 
  • trunk/loci/formats/IFormatHandler.java

    r2178 r2453  
    5252  /** Gets a JFileChooser that recognizes accepted file types. */ 
    5353  JFileChooser getFileChooser(); 
     54 
     55  /** Adds a listener for status update events. */ 
     56  void addStatusListener(StatusListener l); 
     57 
     58  /** Removes a listener for status update events. */ 
     59  void removeStatusListener(StatusListener l); 
     60 
     61  /** Gets a list of all registered status update listeners. */ 
     62  StatusListener[] getStatusListeners(); 
     63 
    5464} 
  • trunk/loci/formats/IFormatReader.java

    r2320 r2453  
    7373  int getEffectiveSizeC(String id) throws FormatException, IOException; 
    7474 
    75   /** Get the number of channels per RGB image (if not RGB, this returns 1). */ 
     75  /** Gets the number of channels per RGB image (if not RGB, this returns 1). */ 
    7676  int getRGBChannelCount(String id) throws FormatException, IOException; 
    7777 
  • trunk/loci/formats/ImageReader.java

    r2430 r2453  
    7979        if (FormatReader.debug) err.printStackTrace(); 
    8080      } 
    81       if (c == null || !FormatReader.class.isAssignableFrom(c)) { 
     81      if (c == null || !IFormatReader.class.isAssignableFrom(c)) { 
    8282        System.err.println("Error: \"" + line + 
    8383          "\" is not a valid format reader."); 
     
    332332  /* @see IFormatReader#getChannelStatCalculationStatus() */ 
    333333  public boolean getChannelStatCalculationStatus() { 
    334     // NB: all readers should have the same status 
     334    // NB: all readers should have the same channel calculation status 
    335335    return readers[0].getChannelStatCalculationStatus(); 
    336336  } 
     
    410410  /* @see IFormatReader#isColorTableIgnored() */ 
    411411  public boolean isColorTableIgnored() { 
     412    // NB: all readers should have the same color tables setting 
    412413    return readers[0].isColorTableIgnored(); 
    413414  } 
     
    420421  /* @see IFormatReader#isNormalized() */ 
    421422  public boolean isNormalized() { 
     423    // NB: all readers should have the same normalization setting 
    422424    return readers[0].isNormalized(); 
    423425  } 
     
    478480  /* @see IFormatReader#isMetadataFiltered() */ 
    479481  public boolean isMetadataFiltered() { 
     482    // NB: all readers should have the same metadata filtering setting 
    480483    return readers[0].isNormalized(); 
    481484  } 
     
    556559      Vector v = new Vector(); 
    557560      for (int i=0; i<readers.length; i++) { 
    558         javax.swing.filechooser.FileFilter[] ff = readers[i].getFileFilters(); 
     561        FileFilter[] ff = readers[i].getFileFilters(); 
    559562        for (int j=0; j<ff.length; j++) v.add(ff[j]); 
    560563      } 
     
    567570  public JFileChooser getFileChooser() { 
    568571    if (chooser == null) { 
    569       chooser = FormatHandler.buildFileChooser(getFileFilters()); 
     572      chooser = FormatTools.buildFileChooser(getFileFilters()); 
    570573    } 
    571574    return chooser; 
     575  } 
     576 
     577  /* @see IFormatHandler#addStatusListener(StatusListener) */ 
     578  public void addStatusListener(StatusListener l) { 
     579    for (int i=0; i<readers.length; i++) readers[i].addStatusListener(l); 
     580  } 
     581 
     582  /* @see IFormatHandler#removeStatusListener(StatusListener) */ 
     583  public void removeStatusListener(StatusListener l) { 
     584    for (int i=0; i<readers.length; i++) readers[i].removeStatusListener(l); 
     585  } 
     586 
     587  /* @see IFormatHandler#getStatusListeners() */ 
     588  public StatusListener[] getStatusListeners() { 
     589    // NB: all readers should have the same status listeners 
     590    return readers[0].getStatusListeners(); 
    572591  } 
    573592 
  • trunk/loci/formats/ImageWriter.java

    r2320 r2453  
    7070      Class c = null; 
    7171      try { c = Class.forName(line); } 
    72       catch (ClassNotFoundException exc) { } 
    73       if (c == null || !FormatWriter.class.isAssignableFrom(c)) { 
     72      catch (ClassNotFoundException exc) { 
     73        if (FormatWriter.debug) exc.printStackTrace(); 
     74      } 
     75      catch (NoClassDefFoundError err) { 
     76        if (FormatWriter.debug) err.printStackTrace(); 
     77      } 
     78      catch (ExceptionInInitializerError err) { 
     79        if (FormatWriter.debug) err.printStackTrace(); 
     80      } 
     81      if (c == null || !IFormatWriter.class.isAssignableFrom(c)) { 
    7482        System.err.println("Error: \"" + line + 
    7583          "\" is not a valid format writer."); 
     
    270278      System.out.println("[" + getFormat(args[1]) + "]"); 
    271279    } 
    272     return FormatWriter.testConvert(this, args); 
     280    return FormatTools.testConvert(this, args); 
    273281  } 
    274282 
     
    297305  public String[] getSuffixes() { 
    298306    if (suffixes == null) { 
    299       HashSet set = new HashSet(); 
     307      HashSet suffixSet = new HashSet(); 
    300308      for (int i=0; i<writers.length; i++) { 
    301         String[] s = writers[i].getSuffixes(); 
    302         for (int j=0; j<s.length; j++) set.add(s[j]); 
    303       } 
    304       suffixes = new String[set.size()]; 
    305       set.toArray(suffixes); 
     309        String[] suf = writers[i].getSuffixes(); 
     310        for (int j=0; j<suf.length; j++) suffixSet.add(suf[j]); 
     311      } 
     312      suffixes = new String[suffixSet.size()]; 
     313      suffixSet.toArray(suffixes); 
    306314      Arrays.sort(suffixes); 
    307315    } 
     
    325333  public JFileChooser getFileChooser() { 
    326334    if (chooser == null) { 
    327       chooser = FormatHandler.buildFileChooser(getFileFilters()); 
     335      chooser = FormatTools.buildFileChooser(getFileFilters()); 
    328336    } 
    329337    return chooser; 
     338  } 
     339 
     340  /* @see IFormatHandler#addStatusListener(StatusListener) */ 
     341  public void addStatusListener(StatusListener l) { 
     342    for (int i=0; i<writers.length; i++) writers[i].addStatusListener(l); 
     343  } 
     344 
     345  /* @see IFormatHandler#removeStatusListener(StatusListener) */ 
     346  public void removeStatusListener(StatusListener l) { 
     347    for (int i=0; i<writers.length; i++) writers[i].removeStatusListener(l); 
     348  } 
     349 
     350  /* @see IFormatHandler#getStatusListeners() */ 
     351  public StatusListener[] getStatusListeners() { 
     352    // NB: all writers should have the same status listeners 
     353    return writers[0].getStatusListeners(); 
    330354  } 
    331355 
  • trunk/loci/formats/ReaderWrapper.java

    r2382 r2453  
    332332  } 
    333333 
     334  public void addStatusListener(StatusListener l) { 
     335    reader.addStatusListener(l); 
     336  } 
     337 
     338  public void removeStatusListener(StatusListener l) { 
     339    reader.removeStatusListener(l); 
     340  } 
     341 
     342  public StatusListener[] getStatusListeners() { 
     343    return reader.getStatusListeners(); 
     344  } 
     345 
    334346} 
Note: See TracChangeset for help on using the changeset viewer.