source: ether_megapoli/trunk/service/implementation/gov2/noaa/pmel/sgt/TransformColorMap.java @ 192

Last change on this file since 192 was 192, checked in by vmipsl, 13 years ago

Servlet _ Contour en cours _ package gov2

File size: 6.1 KB
Line 
1/*
2 * $Id: TransformColorMap.java,v 1.6 2002/06/12 18:47:26 dwd Exp $
3 *
4 * This software is provided by NOAA for full, free and open release.  It is
5 * understood by the recipient/user that NOAA assumes no liability for any
6 * errors contained in the code.  Although this software is released without
7 * conditions or restrictions in its use, it is expected that appropriate
8 * credit be given to its author and to the National Oceanic and Atmospheric
9 * Administration should the software be included by the recipient as an
10 * element in other product development.
11 */
12package gov.noaa.pmel.sgt;
13
14import gov.noaa.pmel.util.Range2D;
15import gov.noaa.pmel.util.Debug;
16
17import java.awt.*;
18import java.beans.PropertyChangeListener;
19import java.beans.PropertyChangeSupport;
20import java.beans.PropertyChangeEvent;
21
22/**
23 * <code>TransformColorMap</code> provides a mapping from a value
24 * to a <code>Color</code>.
25 *
26 * @author Donald Denbo
27 * @version $Revision: 1.6 $, $Date: 2002/06/12 18:47:26 $
28 * @since 2.0
29 */
30public class TransformColorMap extends ColorMap
31  implements Cloneable, PropertyChangeListener,
32             TransformColor, TransformAccess {
33  /**
34   * Red Transform
35
36   * @supplierCardinality 0..1
37   * @clientRole rTrans_
38   * @link aggregationByValue
39   */
40  private Transform rTrans_ = null;
41  /**
42   * Green Transform
43
44   * @supplierCardinality 0..1
45   * @clientRole gTrans_
46   * @link aggregationByValue
47   */
48  private Transform gTrans_ = null;
49  /**
50   * Blue Transform
51
52   * @supplierCardinality 0..1
53   * @clientRole bTrans_
54   * @link aggregationByValue
55   */
56  private Transform bTrans_ = null;
57  /**
58   * Initialize the color map to use red, green, and blue transforms. Sets up
59   * <code>ColorMap</code> for <code>TRANSFORM</code> access.
60   * Each <code>Transform</code> should have identical user
61   * ranges.  The physical range will be set to 0.0 to 1.0 for each
62   * color component.
63   *
64   * @see Transform
65   */
66  public TransformColorMap(Transform rTrans,Transform gTrans,Transform bTrans) {
67    rTrans_ = rTrans;
68    rTrans_.setRangeP(0.0, 1.0);
69    gTrans_ = gTrans;
70    gTrans_.setRangeP(0.0, 1.0);
71    bTrans_ = bTrans;
72    bTrans_.setRangeP(0.0, 1.0);
73  }
74  /**
75   * Create a copy of the <code>ColorMap</code> object.
76   */
77  public ColorMap copy() {
78    ColorMap newMap;
79    try {
80      newMap = (ColorMap)clone();
81    } catch (CloneNotSupportedException e) {
82      newMap = null;
83    }
84    return newMap;
85  }
86  /**
87   * Get a <code>Color</code>. Returns a <code>Color</code> by
88   * one of four methods. <code>INDEXED</code>, <code>TRANSFORM</code>,
89   * <code>LEVEL_INDEXED</code>, and <code>LEVEL_TRANSFORM</code>.
90   *
91   * @param val Value
92   * @return Color
93   *
94   */
95  public Color getColor(double val) {
96    double ival = val;
97    float red = (float)rTrans_.getTransP(ival);
98    float green = (float)gTrans_.getTransP(ival);
99    float blue = (float)bTrans_.getTransP(ival);
100    return new Color(red, green, blue);
101  }
102  /**
103   * Set the user range for all the <code>Transform</codes>s.
104   *
105   */
106  public void setRange(Range2D range) {
107    rTrans_.setRangeU(range);
108    gTrans_.setRangeU(range);
109    bTrans_.setRangeU(range);
110  }
111  /**
112   * Get the current user range for the <code>Transform</code>s.
113   *
114   * @return user range
115   */
116  public Range2D getRange() {
117    return rTrans_.getRangeU();
118  }
119  /**
120   * Set the color <code>Transform</code>s.
121   * <BR><B>Property Change:</B> <code>redColorTransform</code>,
122   * <code>greenColorTransform</code>, and
123   * <code>blueColorTransform</code>.
124   *
125   * @param rTrans red <code>Transform</code>
126   * @param gTrans green <code>Transform</code>
127   * @param bTrans blue <code>Transform</code>
128   */
129  public void setColorTransforms(Transform rTrans,
130                                 Transform gTrans,
131                                 Transform bTrans) {
132    if(!rTrans_.equals(rTrans) ||
133       !gTrans_.equals(gTrans) ||
134       !bTrans_.equals(bTrans)) {
135      if(rTrans_ != null) rTrans_.removePropertyChangeListener(this);
136      if(gTrans_ != null) gTrans_.removePropertyChangeListener(this);
137      if(bTrans_ != null) bTrans_.removePropertyChangeListener(this);
138
139      Transform tempOld = rTrans_;
140      rTrans_ = rTrans;
141      rTrans_.setRangeP(0.0, 1.0);
142      firePropertyChange("redColorTransform",
143                                  tempOld,
144                                  rTrans_);
145      tempOld = gTrans_;
146      gTrans_ = gTrans;
147      gTrans_.setRangeP(0.0, 1.0);
148      firePropertyChange("greenColorTransform",
149                                  tempOld,
150                                  gTrans_);
151      tempOld = bTrans_;
152      bTrans_ = bTrans;
153      bTrans_.setRangeP(0.0, 1.0);
154      firePropertyChange("blueColorTransform",
155                                  tempOld,
156                                  bTrans_);
157
158      rTrans_.addPropertyChangeListener(this);
159      gTrans_.addPropertyChangeListener(this);
160      bTrans_.addPropertyChangeListener(this);
161    }
162  }
163  /**
164   * Set the red color <code>Transform</code>
165   */
166  public void setRedTransform(Transform red) {
167    rTrans_ = red;
168  }
169  /**
170   * Get the red color <code>Transform</code>.
171   *
172   * @return red <code>Transform</code>
173   */
174  public Transform getRedTransform() {
175    return rTrans_;
176  }
177  /**
178   * Set the green color <code>Transform</code>
179   */
180  public void setGreenTransform(Transform green) {
181    gTrans_ = green;
182  }
183  /**
184   * Get the green color <code>Transform</code>.
185   *
186   * @return green <code>Transform</code>
187   */
188  public Transform getGreenTransform() {
189    return gTrans_;
190  }
191  /**
192   * Set the blue color <code>Transform</code>
193   */
194  public void setBlueTransform(Transform blue) {
195    bTrans_ = blue;
196  }
197  /**
198   * Get the blue color <code>Transform</code>.
199   *
200   * @return blue <code>Transform</code>
201   */
202  public Transform getBlueTransform() {
203    return bTrans_;
204  }
205
206  public boolean equals(ColorMap cm) {
207    if(cm == null || !(cm instanceof TransformColorMap)) return false;
208    if(!(rTrans_.equals(((TransformColorMap)cm).rTrans_) &&
209         gTrans_.equals(((TransformColorMap)cm).gTrans_) &&
210         bTrans_.equals(((TransformColorMap)cm).bTrans_))) return false;
211    return true;
212  }
213}
Note: See TracBrowser for help on using the repository browser.