Changeset 3333


Ignore:
Timestamp:
10/31/07 08:03:53 (12 years ago)
Author:
melissa
Message:

Slicer now implements PlugInFilter, preventing an exception when there are no open images.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/plugins/Slicer.java

    r3305 r3333  
    2828import ij.*; 
    2929import ij.gui.GenericDialog; 
    30 import ij.plugin.PlugIn; 
     30import ij.plugin.filter.PlugInFilter; 
     31import ij.process.ImageProcessor; 
    3132import loci.formats.FormatTools; 
    3233 
    33 public class Slicer implements PlugIn { 
     34public class Slicer implements PlugInFilter { 
    3435 
    3536  // -- Fields -- 
     
    3839  public boolean canceled; 
    3940 
    40   // -- PlugIn API methods -- 
     41  /** Plugin options. */ 
     42  private String arg; 
    4143 
    42   /** Executes the plugin. */ 
    43   public void run(String arg) { 
     44  /** Current image stack. */ 
     45  private ImagePlus imp; 
     46 
     47  // -- PlugInFilter API methods -- 
     48 
     49  public int setup(String arg, ImagePlus imp) { 
     50    this.arg = arg; 
     51    this.imp = imp; 
     52    return DOES_ALL + NO_CHANGES; 
     53  } 
     54 
     55  public void run(ImageProcessor ip) { 
    4456    boolean sliceZ = false; 
    4557    boolean sliceC = false; 
     
    8092    } 
    8193 
    82     ImagePlus current = WindowManager.getCurrentImage(); 
    83     ImageStack stack = current.getImageStack(); 
     94    ImageStack stack = imp.getImageStack(); 
    8495 
    85     if (current instanceof CompositeImage) return; 
     96    if (imp instanceof CompositeImage) return; 
    8697 
    87     int sizeZ = current.getNSlices(); 
    88     int sizeC = current.getNChannels(); 
    89     int sizeT = current.getNFrames(); 
     98    int sizeZ = imp.getNSlices(); 
     99    int sizeC = imp.getNChannels(); 
     100    int sizeT = imp.getNFrames(); 
    90101 
    91     if (current instanceof CustomImage) sliceC = false; 
     102    if (imp instanceof CustomImage) sliceC = false; 
    92103 
    93104    int slicesPerStack = stack.getSize(); 
     
    114125 
    115126    for (int i=0; i<newStacks.length; i++) { 
    116       ImagePlus ip = new ImagePlus(current.getTitle(), newStacks[i]); 
    117       ip.setDimensions(sliceC ? 1 : sizeC, sliceZ ? 1 : sizeZ, 
     127      ImagePlus p = new ImagePlus(imp.getTitle(), newStacks[i]); 
     128      p.setDimensions(sliceC ? 1 : sizeC, sliceZ ? 1 : sizeZ, 
    118129        sliceT ? 1 : sizeT); 
    119       if (current instanceof CustomImage) { 
    120         CustomImage c = new CustomImage(ip, stackOrder, sliceZ ? 1 : sizeZ, 
     130      if (imp instanceof CustomImage) { 
     131        CustomImage c = new CustomImage(p, stackOrder, sliceZ ? 1 : sizeZ, 
    121132          sliceT ? 1 : sizeT, sliceC ? 1 : sizeC, true); 
    122133        c.show(); 
    123134      } 
    124       else ip.show(); 
     135      else p.show(); 
    125136    } 
    126     if (!keepOriginal) current.close(); 
     137    if (!keepOriginal) imp.close(); 
    127138  } 
    128139 
Note: See TracChangeset for help on using the changeset viewer.