Changeset 4871


Ignore:
Timestamp:
03/01/09 13:48:14 (11 years ago)
Author:
melissa
Message:

The custom colorize option is now recorded correctly by the macro recorder.

Location:
trunk/components/loci-plugins/src/loci/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/loci-plugins/src/loci/plugins/Colorizer.java

    r4852 r4871  
    3333import ij.plugin.filter.PlugInFilter; 
    3434import ij.process.*; 
    35 import java.awt.Color; 
     35import ij.util.*; 
     36import java.awt.*; 
     37import java.awt.event.*; 
    3638import java.awt.image.IndexColorModel; 
    3739import java.io.ByteArrayOutputStream; 
    3840import java.io.PrintStream; 
    3941import java.util.Arrays; 
     42import java.util.Vector; 
    4043import loci.common.ReflectException; 
    4144import loci.common.ReflectedUniverse; 
     
    8487  private String mergeOption; 
    8588 
     89  private int series = 0; 
     90 
    8691  // -- PlugInFilter API methods -- 
    8792 
     
    121126    } 
    122127    else { 
     128      series = Integer.parseInt(Macro.getValue(arg, "series", "0")); 
    123129      stackOrder = Macro.getValue(arg, "stack_order", "XYCZT"); 
    124130      merge = 
     
    392398 
    393399  private void promptForColor(int channel) { 
    394     ColorChooser chooser = new ColorChooser( 
    395       "Color Chooser - Channel " + channel, Color.BLACK, false); 
     400    CustomColorChooser chooser = new CustomColorChooser( 
     401      "Color Chooser - Channel " + channel, null, series, channel); 
    396402 
    397403    Color color = chooser.getColor(); 
     
    409415  } 
    410416 
     417  // -- Helper class -- 
     418 
     419  /** 
     420   * Adapted from ij.gui.ColorChooser.  ColorChooser is not used because 
     421   * there is no way to change the slider labels - this means that we can't 
     422   * record macros in which custom colors are chosen for multiple channels. 
     423   */ 
     424  class CustomColorChooser implements TextListener { 
     425    Vector colors; 
     426    ColorPanel panel; 
     427    Color initialColor; 
     428    int red, green, blue; 
     429    String title; 
     430 
     431    private int series, channel; 
     432 
     433    public CustomColorChooser(String title, Color initialColor, int series, 
     434      int channel) 
     435    { 
     436        this.title = title; 
     437        if (initialColor == null) initialColor = Color.BLACK; 
     438        this.initialColor = initialColor; 
     439        red = initialColor.getRed(); 
     440        green = initialColor.getGreen(); 
     441        blue = initialColor.getBlue(); 
     442        this.series = series; 
     443        this.channel = channel; 
     444    } 
     445 
     446    // -- ColorChooser API methods -- 
     447 
     448    /** 
     449     * Displays a color selection dialog and returns the color 
     450     *  selected by the user. 
     451     */ 
     452    public Color getColor() { 
     453      GenericDialog gd = new GenericDialog(title); 
     454      gd.addSlider(makeLabel("Red:"), 0, 255, red); 
     455      gd.addSlider(makeLabel("Green:"), 0, 255, green); 
     456      gd.addSlider(makeLabel("Blue:"), 0, 255, blue); 
     457      panel = new ColorPanel(initialColor); 
     458      gd.addPanel(panel, GridBagConstraints.CENTER, new Insets(10, 0, 0, 0)); 
     459      colors = gd.getNumericFields(); 
     460      for (int i=0; i<colors.size(); i++) { 
     461        ((TextField) colors.elementAt(i)).addTextListener(this); 
     462      } 
     463      gd.showDialog(); 
     464      if (gd.wasCanceled()) return null; 
     465      int red = (int) gd.getNextNumber(); 
     466      int green = (int) gd.getNextNumber(); 
     467      int blue = (int) gd.getNextNumber(); 
     468      return new Color(red, green, blue); 
     469    } 
     470 
     471    public void textValueChanged(TextEvent e) { 
     472      int red = getColorValue(0); 
     473      int green = getColorValue(1); 
     474      int blue = getColorValue(2); 
     475      panel.setColor(new Color(red, green, blue)); 
     476      panel.repaint(); 
     477    } 
     478 
     479    // -- Helper methods -- 
     480 
     481    private int getColorValue(int index) { 
     482      int color = 
     483        (int) Tools.parseDouble(((TextField) colors.get(index)).getText()); 
     484      if (color < 0) color = 0; 
     485      if (color > 255) color = 255; 
     486      return color; 
     487    } 
     488 
     489    private String makeLabel(String baseLabel) { 
     490      return "Series_" + series + "_Channel_" + channel + "_" + baseLabel; 
     491    } 
     492  } 
     493 
     494  class ColorPanel extends Panel { 
     495    private static final int WIDTH = 100, HEIGHT = 50; 
     496    private Color c; 
     497 
     498    public ColorPanel(Color c) { 
     499      this.c = c; 
     500    } 
     501 
     502    public Dimension getPreferredSize() { 
     503      return new Dimension(WIDTH, HEIGHT); 
     504    } 
     505 
     506    void setColor(Color c) { this.c = c; } 
     507 
     508    public Dimension getMinimumSize() { 
     509      return new Dimension(WIDTH, HEIGHT); 
     510    } 
     511 
     512    public void paint(Graphics g) { 
     513      g.setColor(c); 
     514      g.fillRect(0, 0, WIDTH, HEIGHT); 
     515      g.setColor(Color.black); 
     516      g.drawRect(0, 0, WIDTH-1, HEIGHT-1); 
     517    } 
     518 
     519  } 
     520 
    411521} 
  • trunk/components/loci-plugins/src/loci/plugins/Importer.java

    r4852 r4871  
    774774        IJ.runPlugIn("loci.plugins.Colorizer", "stack_order=" + stackOrder + 
    775775          " merge=true merge_option=[" + options.getMergeOption() + "] " + 
    776           "hyper_stack=" + options.isViewHyperstack() + " "); 
     776          "series=" + r.getSeries() + " hyper_stack=" + 
     777          options.isViewHyperstack() + " "); 
    777778      } 
    778779      else if (mergeChannels) { 
    779780        IJ.runPlugIn("loci.plugins.Colorizer", "stack_order=" + stackOrder + 
    780           " merge=true hyper_stack=" + options.isViewHyperstack() + " "); 
     781          " merge=true series=" + r.getSeries() + " hyper_stack=" + 
     782          options.isViewHyperstack() + " "); 
    781783      } 
    782784    } 
     
    864866                IJ.runPlugIn("loci.plugins.Colorizer", 
    865867                  "stack_order=" + stackOrder + " merge=false colorize=true" + 
    866                   " ndx=" + channelIndex + " hyper_stack=" + 
    867                   options.isViewHyperstack() + " "); 
     868                  " ndx=" + channelIndex + " series=" + r.getSeries() + 
     869                  " hyper_stack=" + options.isViewHyperstack() + " "); 
    868870              } 
    869871              else { 
    870872                IJ.runPlugIn("loci.plugins.Colorizer", "stack_order=" + 
    871873                  stackOrder + " merge=false colorize=true ndx=" + 
    872                   (customColorize ? "-1" : "0") + " hyper_stack=" + 
    873                   options.isViewHyperstack() + " "); 
     874                  (customColorize ? "-1" : "0") + " series=" + r.getSeries() + 
     875                  " hyper_stack=" + options.isViewHyperstack() + " "); 
    874876              } 
    875877            } 
     
    879881          IJ.runPlugIn("loci.plugins.Colorizer", "stack_order=" + stackOrder + 
    880882            " merge=false colorize=true ndx=" + (customColorize ? "-1" : "0") + 
    881             " hyper_stack=" + options.isViewHyperstack() + " "); 
     883            " series=" + r.getSeries() + " hyper_stack=" + 
     884            options.isViewHyperstack() + " "); 
    882885        } 
    883886        else if (colorModels != null && !virtual) { 
    884887          Colorizer colorizer = new Colorizer(); 
    885888          String arg = "stack_order=" + stackOrder + " merge=false " + 
    886             "colorize=true hyper_stack=" + options.isViewHyperstack() + " "; 
     889            "colorize=true series=" + r.getSeries() + " hyper_stack=" + 
     890            options.isViewHyperstack() + " "; 
    887891          colorizer.setup(arg, imp); 
    888892          for (int channel=0; channel<colorModels.length; channel++) { 
  • trunk/components/loci-plugins/src/loci/plugins/ImporterOptions.java

    r4852 r4871  
    13841384 
    13851385    for (int n=0; n<r.getSeriesCount(); n++) { 
     1386      if (!series[n]) continue; 
    13861387      r.setSeries(n); 
    13871388      String z = gd.getNextChoice(); 
Note: See TracChangeset for help on using the changeset viewer.