Changeset 7213


Ignore:
Timestamp:
11/16/10 20:29:03 (9 years ago)
Author:
aivar
Message:

Added new method to generate a color bar. Added javadoc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/maven/projects/slim-plugin/src/main/java/loci/slim/colorizer/ThreeColorColorize.java

    r7060 r7213  
    3838 
    3939/** 
    40  * TODO 
     40 * Colorizes data based on a sequence of three colors. 
    4141 * 
    42  * <dl><dt><b>Source code:</b></dt> 
    43  * <dd><a href="http://dev.loci.wisc.edu/trac/java/browser/trunk/projects/slim-plugin/src/main/java/loci/colorizer/ThreeColorColorize.java">Trac</a>, 
    44  * <a href="http://dev.loci.wisc.edu/svn/java/trunk/projects/slim-plugin/src/main/java/loci/colorizer/ThreeColorColorize.java">SVN</a></dd></dl> 
    45  * 
    46  * @author Aivar Grislis grislis at wisc.edu 
     42 * @author Aivar Grislis 
    4743 */ 
    48 public class ThreeColorColorize implements IColorize { 
     44public class ThreeColorColorize extends MultiColorColorize implements IColorize { 
    4945    Color m_color1; 
    5046    Color m_color2; 
    5147    Color m_color3; 
    5248 
     49    /** 
     50     * Constructor.  Specifies the sequence of three colors. 
     51     * 
     52     * @param color1 
     53     * @param color2 
     54     * @param color3 
     55     */ 
    5356    public ThreeColorColorize(Color color1, Color color2, Color color3) { 
    5457        m_color1 = color1; 
     
    5760    } 
    5861 
     62    /** 
     63     * Colorizes a data value. 
     64     * 
     65     * @param start value associated with starting color 
     66     * @param stop value associated with ending color 
     67     * @param value to colorize 
     68     * @return interpolated Color value 
     69     */ 
    5970    public Color colorize(double start, double stop, double value) { 
    6071        Color returnColor = Color.BLACK; 
     
    7485        return returnColor; 
    7586    } 
    76  
    77     private Color interpolateColor(Color start, Color end, double blend) { 
    78         int startRed   = start.getRed(); 
    79         int startGreen = start.getGreen(); 
    80         int startBlue  = start.getBlue(); 
    81         int endRed   = end.getRed(); 
    82         int endGreen = end.getGreen(); 
    83         int endBlue  = end.getBlue(); 
    84         int red   = interpolateColorComponent(startRed, endRed, blend); 
    85         int green = interpolateColorComponent(startGreen, endGreen, blend); 
    86         int blue  = interpolateColorComponent(startBlue, endBlue, blend); 
    87         Color returnColor = Color.BLACK; 
    88         try { 
    89             returnColor = new Color(red, green, blue); 
    90         } 
    91         catch (Exception e) { 
    92             System.out.println("Exception " + e + " " + red + " " + green + " " + blue); 
    93         } 
    94         return returnColor; 
    95     } 
    96  
    97     private int interpolateColorComponent(int start, int end, double blend) { 
    98         return (int)(blend * (end - start) + start); 
    99     } 
    100  
    10187} 
Note: See TracChangeset for help on using the changeset viewer.