Changeset 2555


Ignore:
Timestamp:
04/04/07 06:12:05 (13 years ago)
Author:
curtis
Message:
  • Centralize all dependencies on ij.* into loci.visbio.util.ImageJUtil.
  • Eliminate MathUtil raster/position methods in favor of FormatTools.
  • Use loci.formats.gui package for file chooser stuff.
Location:
trunk/loci/visbio
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/data/DataCache.java

    r1989 r2555  
    2525 
    2626import java.util.Hashtable; 
    27 import loci.visbio.util.MathUtil; 
     27import loci.formats.FormatTools; 
    2828import visad.Data; 
    2929 
     
    102102  public synchronized void dump(DataTransform trans, String append) { 
    103103    int[] lengths = trans.getLengths(); 
    104     int len = MathUtil.getRasterLength(lengths); 
     104    int len = FormatTools.getRasterLength(lengths); 
    105105    for (int i=0; i<len; i++) { 
    106       int[] pos = MathUtil.rasterToPosition(lengths, i); 
     106      int[] pos = FormatTools.rasterToPosition(lengths, i); 
    107107      dump(getKey(trans, pos, append)); 
    108108    } 
  • trunk/loci/visbio/data/ExportPane.java

    r1989 r2555  
    218218          int[] lengths = trans.getLengths(); 
    219219          for (int i=0; i<numFiles; i++) { 
    220             int[] pos = MathUtil.rasterToPosition(plen, i); 
     220            int[] pos = FormatTools.rasterToPosition(plen, i); 
    221221            int[] npos = new int[lengths.length]; 
    222222            for (int j=0; j<stars; j++) npos[maps[j]] = pos[j]; 
  • trunk/loci/visbio/data/SendToIJPane.java

    r1989 r2555  
    2727import com.jgoodies.forms.layout.CellConstraints; 
    2828import com.jgoodies.forms.layout.FormLayout; 
    29 import ij.ImagePlus; 
    30 import ij.ImageStack; 
    31 import ij.process.ImageProcessor; 
    3229import loci.visbio.*; 
    3330import loci.visbio.view.BioSlideWidget; 
     
    107104          } 
    108105 
    109           // convert FlatFields into ImagePlus object 
     106          // send FlatFields to ImageJ 
    110107          task.setStatus("Sending data to ImageJ"); 
    111           ImagePlus image; 
    112           String name = trans.getName() + " (from VisBio)"; 
    113           if (data.length > 1) { 
    114             // create image stack 
    115             ImageStack is = null; 
    116             for (int i=0; i<data.length; i++) { 
    117               ImageProcessor ips = ImageJUtil.extractImage(data[i]); 
    118               if (is == null) { 
    119                 is = new ImageStack(ips.getWidth(), ips.getHeight(), 
    120                   ips.getColorModel()); 
    121               } 
    122               is.addSlice("" + i, ips); 
    123             } 
    124             image = new ImagePlus(name, is); 
    125           } 
    126           else { 
    127             // create single image 
    128             image = new ImagePlus(name, ImageJUtil.extractImage(data[0])); 
    129           } 
    130  
    131           // send ImagePlus object to ImageJ 
     108          String title = trans.getName() + " (from VisBio)"; 
     109          ImageJUtil.sendToImageJ(title, data, bio); 
    132110          task.setCompleted(); 
    133           ImageJUtil.sendToImageJ(image, bio); 
    134111        } 
    135112        catch (VisADException exc) { 
  • trunk/loci/visbio/data/ThumbnailHandler.java

    r1989 r2555  
    2525 
    2626import java.rmi.RemoteException; 
     27import loci.formats.FormatTools; 
    2728import loci.visbio.BioTask; 
    2829import loci.visbio.TaskManager; 
     
    8485  /** Gets the thumbnail at the given dimensional position. */ 
    8586  public FlatField getThumb(int[] pos) { 
    86     int ndx = MathUtil.positionToRaster(data.getLengths(), pos); 
     87    int ndx = FormatTools.positionToRaster(data.getLengths(), pos); 
    8788    return ndx >= 0 && ndx < thumbs.length ? thumbs[ndx] : null; 
    8889  } 
     
    9091  /** Sets the thumbnail at the given dimensional position. */ 
    9192  public void setThumb(int[] pos, FlatField thumb) { 
    92     int ndx = MathUtil.positionToRaster(data.getLengths(), pos); 
     93    int ndx = FormatTools.positionToRaster(data.getLengths(), pos); 
    9394    if (ndx >= 0 && ndx < thumbs.length) thumbs[ndx] = thumb; 
    9495  } 
     
    131132      on = oldOn; 
    132133    } 
    133     thumbs = new FlatField[MathUtil.getRasterLength(data.getLengths())]; 
     134    thumbs = new FlatField[FormatTools.getRasterLength(data.getLengths())]; 
    134135    count = 0; 
    135136    if (on) startGeneration(); 
     
    154155    int[] lengths = data.getLengths(); 
    155156    String id = data.getCacheId( 
    156       MathUtil.rasterToPosition(lengths, i), global); 
     157      FormatTools.rasterToPosition(lengths, i), global); 
    157158 
    158159    // attempt to grab thumbnail from the disk cache 
     
    168169    if (!cached) { 
    169170      // compute thumbnail from data object 
    170       thumbs[i] = computeThumb(MathUtil.rasterToPosition(lengths, i)); 
     171      thumbs[i] = computeThumb(FormatTools.rasterToPosition(lengths, i)); 
    171172      if (cache != null && thumbs[i] != null) cache.store(id, thumbs[i]); 
    172173    } 
  • trunk/loci/visbio/overlays/OverlayIO.java

    r2534 r2555  
    3131import javax.swing.JComponent; 
    3232import javax.swing.JOptionPane; 
     33import loci.formats.FormatTools; 
    3334import loci.visbio.VisBio; 
    3435import loci.visbio.util.*; 
     
    155156 
    156157          // initialize replacement overlay lists 
    157           loadedOverlays = new Vector[MathUtil.getRasterLength(lengths)]; 
     158          loadedOverlays = new Vector[FormatTools.getRasterLength(lengths)]; 
    158159          for (int i=0; i<loadedOverlays.length; i++) { 
    159160            loadedOverlays[i] = new Vector(); 
     
    273274          if (obj instanceof OverlayNodedObject) loadedNodedObjects.add(obj); 
    274275 
    275           int r = MathUtil.positionToRaster(lengths, pos); 
     276          int r = FormatTools.positionToRaster(lengths, pos); 
    276277          //System.out.print("["); // TEMP 
    277278          //for (int i=0; i< pos.length; i++) System.out.print(i + " "); // TEMP 
     
    392393    // overlays table 
    393394    for (int i=0; i<overlays.length; i++) { 
    394       int[] pos = MathUtil.rasterToPosition(lengths, i); 
     395      int[] pos = FormatTools.rasterToPosition(lengths, i); 
    395396      StringBuffer sb = new StringBuffer(); 
    396397      // add 1 to shift indices for humans 
     
    561562    // overlays table 
    562563    for (int i=0; i<overlays.length; i++) { 
    563       int[] pos = MathUtil.rasterToPosition(lengths, i); 
     564      int[] pos = FormatTools.rasterToPosition(lengths, i); 
    564565       
    565566      for (int j=0; j<overlays[i].size(); j++) { 
  • trunk/loci/visbio/overlays/OverlayTransform.java

    r2477 r2555  
    3232import javax.swing.JComponent; 
    3333import javax.swing.JOptionPane; 
     34import loci.formats.FormatTools; 
    3435import loci.visbio.data.*; 
    3536import loci.visbio.state.Dynamic; 
    36 import loci.visbio.util.*; 
     37import loci.visbio.util.DisplayUtil; 
     38import loci.visbio.util.ObjectUtil; 
    3739import loci.visbio.view.DisplayWindow; 
    3840import org.apache.poi.hssf.usermodel.HSSFWorkbook; 
     
    152154  /** Adds an overlay object at the given dimensional position. */ 
    153155  public void addObject(OverlayObject obj, int[] pos) { 
    154     int ndx = MathUtil.positionToRaster(lengths, pos); 
     156    int ndx = FormatTools.positionToRaster(lengths, pos); 
    155157    if (ndx < 0 || ndx >= overlays.length) return; 
    156158    synchronized (overlays) { 
     
    166168  /** Removes an overlay object at the given dimensional position. */ 
    167169  public void removeObject(OverlayObject obj, int[] pos) { 
    168     int ndx = MathUtil.positionToRaster(lengths, pos); 
     170    int ndx = FormatTools.positionToRaster(lengths, pos); 
    169171    if (ndx < 0 || ndx >= overlays.length) return; 
    170172    synchronized (overlays) { 
     
    186188  /** Removes selected overlay objects at the given dimensional position. */ 
    187189  public void removeSelectedObjects(int[] pos) { 
    188     int ndx = MathUtil.positionToRaster(lengths, pos); 
     190    int ndx = FormatTools.positionToRaster(lengths, pos); 
    189191    if (ndx < 0 || ndx >= overlays.length) return; 
    190192    boolean anyRemoved = false; 
     
    217219   */ 
    218220  public void copySelectedObjects(int[] pos) { 
    219     int ndx = MathUtil.positionToRaster(lengths, pos); 
     221    int ndx = FormatTools.positionToRaster(lengths, pos); 
    220222    if (ndx < 0 || ndx >= overlays.length) return; 
    221223    synchronized (overlays) { 
     
    235237  /** Pastes copied objects at the given dimensional position. */ 
    236238  public void pasteObjects(int[] pos) { 
    237     int ndx = MathUtil.positionToRaster(lengths, pos); 
     239    int ndx = FormatTools.positionToRaster(lengths, pos); 
    238240    if (ndx < 0 || ndx >= overlays.length) return; 
    239241    synchronized (overlays) { 
     
    283285   */ 
    284286  public String distributeObjects(int[] pos) { 
    285     int ndx = MathUtil.positionToRaster(lengths, pos); 
     287    int ndx = FormatTools.positionToRaster(lengths, pos); 
    286288    if (ndx < 0 || ndx >= overlays.length) { 
    287289      return "Invalid dimensional position."; 
     
    356358      for (int i=1; i<distance; i++) { 
    357359        p[diffIndex] = pos[diffIndex] + i * inc; 
    358         ndx = MathUtil.positionToRaster(lengths, p); 
     360        ndx = FormatTools.positionToRaster(lengths, p); 
    359361 
    360362        OverlayObject obj = OverlayIO.createOverlay(className, this); 
     
    389391  /** Gets the overlay objects at the given dimensional position. */ 
    390392  public OverlayObject[] getObjects(int[] pos) { 
    391     int ndx = MathUtil.positionToRaster(lengths, pos); 
     393    int ndx = FormatTools.positionToRaster(lengths, pos); 
    392394    if (ndx < 0 || ndx >= overlays.length) return null; 
    393395    OverlayObject[] oo = new OverlayObject[overlays[ndx].size()]; 
     
    500502  public boolean isTextDrawn() { return drawText; } 
    501503 
     504  /** Gets whether the current tool has changed since last mouse gesture. */ 
     505  public boolean hasToolChanged() { return toolChanged; } 
     506 
    502507  // -- Static DataTransform API methods -- 
    503508 
     
    538543      return null; 
    539544    } 
    540     int q = MathUtil.positionToRaster(lengths, pos); 
     545    int q = FormatTools.positionToRaster(lengths, pos); 
    541546    if (q < 0 || q >= overlays.length) return null; 
    542547    synchronized (overlays) { 
     
    758763      else { 
    759764        // update selected text objects 
    760         int ndx = MathUtil.positionToRaster(lengths, pos); 
     765        int ndx = FormatTools.positionToRaster(lengths, pos); 
    761766        if (ndx < 0 || ndx >= overlays.length) return; 
    762767        Vector objs = overlays[ndx]; 
     
    794799  } 
    795800 
    796   /** Helper method for Display Changed -- releases left mouse button */ 
    797   protected void releaseLeft(DisplayEvent e, 
    798     DisplayImpl display, OverlayTool tool) 
    799   { 
    800     mouseDownLeft = false; 
    801     updatePosition(display); 
    802     if (tool != null) { 
    803       int px = e.getX(), py = e.getY(); 
    804       double[] coords = DisplayUtil.pixelToDomain(display, px, py); 
    805       tool.mouseUp(e, px, py, 
    806         (float) coords[0], (float) coords[1], pos, e.getModifiers()); 
    807     } 
    808   } 
    809  
    810801  // -- Dynamic API methods -- 
    811802 
     
    845836    makeLabels(); 
    846837 
    847     int len = MathUtil.getRasterLength(lengths); 
     838    int len = FormatTools.getRasterLength(lengths); 
    848839    Vector[] v = new Vector[len]; 
    849840    int minLen = 0; 
     
    894885   * the current state of the given display. 
    895886   */ 
    896   public void updatePosition(DisplayImpl display) { 
     887  protected void updatePosition(DisplayImpl display) { 
    897888    DisplayWindow window = DisplayWindow.getDisplayWindow(display); 
    898889    setPos(window.getTransformHandler().getPos(this)); 
    899890  } 
    900891 
    901   /**  
    902    * Returns whether the current tool has changed 
    903    */ 
    904   public boolean hasToolChanged() { return toolChanged; } 
     892  /** Helper method that handles left mouse button releases. */ 
     893  protected void releaseLeft(DisplayEvent e, 
     894    DisplayImpl display, OverlayTool tool) 
     895  { 
     896    mouseDownLeft = false; 
     897    updatePosition(display); 
     898    if (tool != null) { 
     899      int px = e.getX(), py = e.getY(); 
     900      double[] coords = DisplayUtil.pixelToDomain(display, px, py); 
     901      tool.mouseUp(e, px, py, 
     902        (float) coords[0], (float) coords[1], pos, e.getModifiers()); 
     903    } 
     904  } 
    905905 
    906906} 
  • trunk/loci/visbio/overlays/OverlayWidget.java

    r2500 r2555  
    3737import javax.swing.event.*; 
    3838import javax.swing.text.Document; 
    39 import loci.formats.ExtensionFileFilter; 
     39import loci.formats.gui.ExtensionFileFilter; 
    4040import loci.visbio.data.*; 
    4141import loci.visbio.util.*; 
  • trunk/loci/visbio/state/StateManager.java

    r2506 r2555  
    2828import java.util.*; 
    2929import javax.swing.*; 
    30 import loci.formats.ExtensionFileFilter; 
     30import loci.formats.gui.ExtensionFileFilter; 
    3131import loci.visbio.*; 
    3232import loci.visbio.util.XMLUtil; 
  • trunk/loci/visbio/util/ImageJUtil.java

    r1390 r2555  
    2727import ij.process.*; 
    2828import java.awt.Component; 
     29import java.awt.Image; 
    2930import java.io.File; 
    3031import javax.swing.JOptionPane; 
     
    137138 
    138139  /** 
    139    * Displays the given ImageJ image object within ImageJ, 
    140    * launching ImageJ if necessary. 
    141    */ 
    142   public static void sendToImageJ(ImagePlus image) { 
    143     sendToImageJ(image, null); 
    144   } 
    145  
    146   /** 
    147    * Displays the given ImageJ image object within ImageJ, 
    148    * launching ImageJ if necessary. 
    149    */ 
    150   public static void sendToImageJ(ImagePlus image, VisBioFrame bio) { 
     140   * Displays the given image object within ImageJ, 
     141   * launching ImageJ if necessary. 
     142   */ 
     143  public static void sendToImageJ(String title, Image image) { 
     144    sendToImageJ(title, image, null); 
     145  } 
     146 
     147  /** 
     148   * Displays the given image object within ImageJ, 
     149   * launching ImageJ if necessary. 
     150   */ 
     151  public static void sendToImageJ(String title, Image image, VisBioFrame bio) { 
     152    sendToImageJ(new ImagePlus(title, image), bio); 
     153  } 
     154 
     155  /** 
     156   * Displays the given FlatFields as an image stack within ImageJ, 
     157   * launching ImageJ if necessary. 
     158   */ 
     159  public static void sendToImageJ(String title, FlatField[] data, 
     160    VisBioFrame bio) throws VisADException 
     161  { 
     162    ImagePlus imp; 
     163    if (data.length > 1) { 
     164      // create image stack 
     165      ImageStack is = null; 
     166      for (int i=0; i<data.length; i++) { 
     167        ImageProcessor ips = extractImage(data[i]); 
     168        if (is == null) { 
     169          is = new ImageStack(ips.getWidth(), ips.getHeight(), 
     170            ips.getColorModel()); 
     171        } 
     172        is.addSlice("" + i, ips); 
     173      } 
     174      imp = new ImagePlus(title, is); 
     175    } 
     176    else { 
     177      // create single image 
     178      imp = new ImagePlus(title, ImageJUtil.extractImage(data[0])); 
     179    } 
     180    sendToImageJ(imp, bio); 
     181  } 
     182 
     183  /** 
     184   * Displays the given image object within ImageJ, launching ImageJ if 
     185   * necessary. If ImageJ is launched, and a suitable VisBio frame is given, 
     186   * the user is warned to save their work in ImageJ before quitting VisBio. 
     187   */ 
     188  public static void sendToImageJ(ImagePlus imp, VisBioFrame bio) { 
     189    boolean ijPopped = sendToImageJ(imp); 
     190    if (bio != null && ijPopped) { 
     191      // display ImageJ warning 
     192      OptionManager om = (OptionManager) bio.getManager(OptionManager.class); 
     193      om.checkWarning(bio, DisplayManager.WARN_IMAGEJ, false, 
     194        "Quitting VisBio will also shut down ImageJ, with no\n" + 
     195        "warning or opportunity to save your work. Please remember\n" + 
     196        "to save your work in ImageJ before closing VisBio."); 
     197    } 
     198  } 
     199 
     200  /** 
     201   * Displays the given image object within ImageJ, 
     202   * launching ImageJ if necessary. 
     203   * @return true if ImageJ needed to be launched 
     204   */ 
     205  public static boolean sendToImageJ(ImagePlus imp) { 
    151206    ImageJ ij = IJ.getInstance(); 
     207    boolean ijPopped = false; 
    152208    if (ij == null || (ij != null && !ij.isShowing())) { 
    153209      // create new ImageJ instance 
     
    157213      new ImageJ(null); 
    158214      System.setProperty("user.dir", dir.getPath()); 
    159  
    160       if (bio != null) { 
    161         // display ImageJ warning 
    162         OptionManager om = (OptionManager) bio.getManager(OptionManager.class); 
    163         om.checkWarning(ij, DisplayManager.WARN_IMAGEJ, false, 
    164           "Quitting VisBio will also shut down ImageJ, with no\n" + 
    165           "warning or opportunity to save your work. Please remember\n" + 
    166           "to save your work in ImageJ before closing VisBio."); 
    167       } 
    168     } 
    169     image.show(); 
     215      ijPopped = true; 
     216    } 
     217    imp.show(); 
     218    return ijPopped; 
    170219  } 
    171220 
  • trunk/loci/visbio/util/MathUtil.java

    r2250 r2555  
    246246  } 
    247247 
    248   /** 
    249    * Computes a unique 1-D index corresponding to the multidimensional 
    250    * position given in the pos array, using the specified lengths array 
    251    * as the maximum value at each positional dimension. 
    252    */ 
    253   public static int positionToRaster(int[] lengths, int[] pos) { 
    254     int[] offsets = new int[lengths.length]; 
    255     if (offsets.length > 0) offsets[0] = 1; 
    256     for (int i=1; i<offsets.length; i++) { 
    257       offsets[i] = offsets[i - 1] * lengths[i - 1]; 
    258     } 
    259     int raster = 0; 
    260     for (int i=0; i<pos.length; i++) raster += offsets[i] * pos[i]; 
    261     return raster; 
    262   } 
    263  
    264   /** 
    265    * Computes a unique 3-D position corresponding to the given raster 
    266    * value, using the specified lengths array as the maximum value at 
    267    * each positional dimension. 
    268    */ 
    269   public static int[] rasterToPosition(int[] lengths, int raster) { 
    270     int[] offsets = new int[lengths.length]; 
    271     if (offsets.length > 0) offsets[0] = 1; 
    272     for (int i=1; i<offsets.length; i++) { 
    273       offsets[i] = offsets[i - 1] * lengths[i - 1]; 
    274     } 
    275     int[] pos = new int[lengths.length]; 
    276     for (int i=0; i<pos.length; i++) { 
    277       int q = i < pos.length - 1 ? raster % offsets[i + 1] : raster; 
    278       pos[i] = q / offsets[i]; 
    279       raster -= q; 
    280     } 
    281     return pos; 
    282   } 
    283  
    284   /** 
    285    * Computes the maximum raster value of a positional array with 
    286    * the given maximum values. 
    287    */ 
    288   public static int getRasterLength(int[] lengths) { 
    289     int len = 1; 
    290     for (int i=0; i<lengths.length; i++) len *= lengths[i]; 
    291     return len; 
    292   } 
    293  
    294248  /** Units for use with getProductWithUnit method. */ 
    295249  private static final String[] UNITS = { 
  • trunk/loci/visbio/util/SwingUtil.java

    r2506 r2555  
    3737import javax.swing.tree.TreePath; 
    3838import loci.formats.ImageReader; 
     39import loci.formats.gui.GUITools; 
    3940 
    4041/** SwingUtil contains useful Swing functions. */ 
     
    246247  } 
    247248 
    248   /** ImageReader for JFileChooser filtering. */ 
    249   protected static ImageReader reader; 
     249  protected static JFileChooser chooser; 
    250250 
    251251  /** Constructs a JFileChooser that recognizes accepted VisBio file types. */ 
    252252  public static JFileChooser getVisBioFileChooser() { 
    253     if (reader == null) reader = new ImageReader(); 
    254     return reader.getFileChooser(); 
     253    if (chooser == null) chooser = GUITools.buildFileChooser(new ImageReader()); 
     254    return chooser; 
    255255  } 
    256256 
  • trunk/loci/visbio/view/CaptureHandler.java

    r1989 r2555  
    2424package loci.visbio.view; 
    2525 
    26 import ij.*; 
    27 import ij.io.FileSaver; 
    2826import java.awt.image.BufferedImage; 
    2927import java.io.IOException; 
     
    3432import javax.swing.filechooser.FileFilter; 
    3533import loci.formats.*; 
     34import loci.formats.gui.ExtensionFileFilter; 
    3635import loci.visbio.SystemManager; 
    3736import loci.visbio.WindowManager; 
     
    144143 
    145144    // save file in a separate thread 
    146     final String filename = file; 
     145    final String id = file; 
    147146    final boolean isTiff = tiff, isJpeg = jpeg; 
    148147    new Thread("VisBio-SnapshotThread-" + window.getName()) { 
    149148      public void run() { 
    150         FileSaver saver = new FileSaver(new ImagePlus("null", getSnapshot())); 
    151         if (isTiff) saver.saveAsTiff(filename); 
    152         else if (isJpeg) saver.saveAsJpeg(filename); 
     149        ImageWriter writer = new ImageWriter(); 
     150        try { 
     151          writer.save(id, getSnapshot(), true); 
     152          writer.close(); 
     153        } 
     154        catch (FormatException exc) { exc.printStackTrace(); } 
     155        catch (IOException exc) { exc.printStackTrace(); } 
    153156      } 
    154157    }.start(); 
     
    159162    new Thread("VisBio-SendToImageJThread-" + window.getName()) { 
    160163      public void run() { 
    161         ImageJUtil.sendToImageJ(new ImagePlus( 
    162           window.getName() + " snapshot", getSnapshot()), window.getVisBio()); 
     164        ImageJUtil.sendToImageJ(window.getName() + " snapshot", 
     165          getSnapshot(), window.getVisBio()); 
    163166      } 
    164167    }.start(); 
  • trunk/loci/visbio/view/ColorPane.java

    r1989 r2555  
    3535import javax.swing.border.TitledBorder; 
    3636import javax.swing.event.*; 
    37 import loci.formats.ExtensionFileFilter; 
     37import loci.formats.gui.ExtensionFileFilter; 
    3838import loci.visbio.util.*; 
    3939import visad.*; 
Note: See TracChangeset for help on using the changeset viewer.