1 | /* |
---|
2 | * $Id: CLTransformColorMap.java,v 1.5 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 | */ |
---|
12 | package gov.noaa.pmel.sgt; |
---|
13 | |
---|
14 | import gov.noaa.pmel.util.Range2D; |
---|
15 | import gov.noaa.pmel.util.Debug; |
---|
16 | |
---|
17 | import java.awt.*; |
---|
18 | import java.beans.PropertyChangeListener; |
---|
19 | import java.beans.PropertyChangeSupport; |
---|
20 | import java.beans.PropertyChangeEvent; |
---|
21 | |
---|
22 | /** |
---|
23 | * <code>CLTransformColorMap</code> provides a mapping from a value |
---|
24 | * to a <code>Color</code> via a <code>ContourLevel</code> object. |
---|
25 | * |
---|
26 | * @author Donald Denbo |
---|
27 | * @version $Revision: 1.5 $, $Date: 2002/06/12 18:47:26 $ |
---|
28 | * @since 2.0 |
---|
29 | */ |
---|
30 | public class CLTransformColorMap extends ColorMap |
---|
31 | implements Cloneable, PropertyChangeListener, TransformColor, ContourLevelsAccess { |
---|
32 | /** |
---|
33 | * Red Transform |
---|
34 | |
---|
35 | * @supplierCardinality 0..1 |
---|
36 | * @clientRole rTrans_ |
---|
37 | * @link aggregationByValue |
---|
38 | */ |
---|
39 | private Transform rTrans_ = null; |
---|
40 | /** |
---|
41 | * Green Transform |
---|
42 | |
---|
43 | * @supplierCardinality 0..1 |
---|
44 | * @clientRole gTrans_ |
---|
45 | * @link aggregationByValue |
---|
46 | */ |
---|
47 | private Transform gTrans_ = null; |
---|
48 | /** |
---|
49 | * Blue Transform |
---|
50 | |
---|
51 | * @supplierCardinality 0..1 |
---|
52 | * @clientRole bTrans_ |
---|
53 | * @link aggregationByValue |
---|
54 | */ |
---|
55 | private Transform bTrans_ = null; |
---|
56 | /** |
---|
57 | * if not null use LEVEL_INDEXED or LEVEL_TRANSFORM |
---|
58 | * @shapeType AggregationLink |
---|
59 | * @label cl |
---|
60 | */ |
---|
61 | private ContourLevels cl_ = null; |
---|
62 | /** |
---|
63 | * Initialize the color map to use red, green, and blue transforms. |
---|
64 | * Each <code>Transform</code> should have identical user |
---|
65 | * ranges. The physical range will be set to 0.0 to 1.0 for each |
---|
66 | * color component. |
---|
67 | * |
---|
68 | * @see Transform |
---|
69 | */ |
---|
70 | public CLTransformColorMap(Transform rTrans,Transform gTrans,Transform bTrans) { |
---|
71 | rTrans_ = rTrans; |
---|
72 | rTrans_.setRangeP(0.0, 1.0); |
---|
73 | gTrans_ = gTrans; |
---|
74 | gTrans_.setRangeP(0.0, 1.0); |
---|
75 | bTrans_ = bTrans; |
---|
76 | bTrans_.setRangeP(0.0, 1.0); |
---|
77 | } |
---|
78 | /** |
---|
79 | * Create a copy of the <code>ColorMap</code> object. |
---|
80 | */ |
---|
81 | public ColorMap copy() { |
---|
82 | ColorMap newMap; |
---|
83 | try { |
---|
84 | newMap = (ColorMap)clone(); |
---|
85 | } catch (CloneNotSupportedException e) { |
---|
86 | newMap = null; |
---|
87 | } |
---|
88 | return newMap; |
---|
89 | } |
---|
90 | /** |
---|
91 | * Get a <code>Color</code>. |
---|
92 | * |
---|
93 | * @param val Value |
---|
94 | * @return Color |
---|
95 | * |
---|
96 | */ |
---|
97 | public Color getColor(double val) { |
---|
98 | double ival = val; |
---|
99 | int indx; |
---|
100 | ival = (double)cl_.getIndex(ival)/(double)cl_.getMaximumIndex(); |
---|
101 | float red = (float)rTrans_.getTransP(ival); |
---|
102 | float green = (float)gTrans_.getTransP(ival); |
---|
103 | float blue = (float)bTrans_.getTransP(ival); |
---|
104 | return new Color(red, green, blue); |
---|
105 | } |
---|
106 | /** |
---|
107 | * Get the current user range for the <code>Transform</code>s. |
---|
108 | * |
---|
109 | * @return user range |
---|
110 | */ |
---|
111 | public Range2D getRange() { |
---|
112 | return cl_.getRange(); |
---|
113 | } |
---|
114 | /** |
---|
115 | * Set the color <code>Transform</code>s. |
---|
116 | * <BR><B>Property Change:</B> <code>redColorTransform</code>, |
---|
117 | * <code>greenColorTransform</code>, and |
---|
118 | * <code>blueColorTransform</code>. |
---|
119 | * |
---|
120 | * @param rTrans red <code>Transform</code> |
---|
121 | * @param gTrans green <code>Transform</code> |
---|
122 | * @param bTrans blue <code>Transform</code> |
---|
123 | */ |
---|
124 | public void setColorTransforms(Transform rTrans, |
---|
125 | Transform gTrans, |
---|
126 | Transform bTrans) { |
---|
127 | if(!rTrans_.equals(rTrans) || |
---|
128 | !gTrans_.equals(gTrans) || |
---|
129 | !bTrans_.equals(bTrans)) { |
---|
130 | if(rTrans_ != null) rTrans_.removePropertyChangeListener(this); |
---|
131 | if(gTrans_ != null) gTrans_.removePropertyChangeListener(this); |
---|
132 | if(bTrans_ != null) bTrans_.removePropertyChangeListener(this); |
---|
133 | |
---|
134 | Transform tempOld = rTrans_; |
---|
135 | rTrans_ = rTrans; |
---|
136 | rTrans_.setRangeP(0.0, 1.0); |
---|
137 | firePropertyChange("redColorTransform", |
---|
138 | tempOld, |
---|
139 | rTrans_); |
---|
140 | tempOld = gTrans_; |
---|
141 | gTrans_ = gTrans; |
---|
142 | gTrans_.setRangeP(0.0, 1.0); |
---|
143 | firePropertyChange("greenColorTransform", |
---|
144 | tempOld, |
---|
145 | gTrans_); |
---|
146 | tempOld = bTrans_; |
---|
147 | bTrans_ = bTrans; |
---|
148 | bTrans_.setRangeP(0.0, 1.0); |
---|
149 | firePropertyChange("blueColorTransform", |
---|
150 | tempOld, |
---|
151 | bTrans_); |
---|
152 | |
---|
153 | rTrans_.addPropertyChangeListener(this); |
---|
154 | gTrans_.addPropertyChangeListener(this); |
---|
155 | bTrans_.addPropertyChangeListener(this); |
---|
156 | } |
---|
157 | } |
---|
158 | /** |
---|
159 | * Set the red transform. |
---|
160 | */ |
---|
161 | public void setRedTransform(Transform red) { |
---|
162 | rTrans_ = red; |
---|
163 | } |
---|
164 | /** |
---|
165 | * Get the red color <code>Transform</code>. |
---|
166 | * |
---|
167 | * @return red <code>Transform</code> |
---|
168 | */ |
---|
169 | public Transform getRedTransform() { |
---|
170 | return rTrans_; |
---|
171 | } |
---|
172 | /** |
---|
173 | * Set the green transform. |
---|
174 | */ |
---|
175 | public void setGreenTransform(Transform green) { |
---|
176 | gTrans_ = green; |
---|
177 | } |
---|
178 | /** |
---|
179 | * Get the green color <code>Transform</code>. |
---|
180 | * |
---|
181 | * @return green <code>Transform</code> |
---|
182 | */ |
---|
183 | public Transform getGreenTransform() { |
---|
184 | return gTrans_; |
---|
185 | } |
---|
186 | /** |
---|
187 | * Set the blue transform. |
---|
188 | */ |
---|
189 | public void setBlueTransform(Transform blue) { |
---|
190 | bTrans_ = blue; |
---|
191 | } |
---|
192 | /** |
---|
193 | * Get the blue color <code>Transform</code>. |
---|
194 | * |
---|
195 | * @return blue <code>Transform</code> |
---|
196 | */ |
---|
197 | public Transform getBlueTransform() { |
---|
198 | return bTrans_; |
---|
199 | } |
---|
200 | /** |
---|
201 | * Set <code>ContourLevels</code>. |
---|
202 | * <BR><B>Property Change:</B> <code>contourLevels</code>. |
---|
203 | * |
---|
204 | * @param cl <code>ContourLevels</code> |
---|
205 | */ |
---|
206 | public void setContourLevels(ContourLevels cl) { |
---|
207 | if(!cl_.equals(cl)) { |
---|
208 | ContourLevels tempOld = cl_; |
---|
209 | cl_ = cl; |
---|
210 | firePropertyChange("contourLevels", |
---|
211 | tempOld, |
---|
212 | cl_); |
---|
213 | } |
---|
214 | } |
---|
215 | /** |
---|
216 | * Get <code>ContourLevels</code> for the color mappings. |
---|
217 | * |
---|
218 | * @return <code>ContourLevels</code> |
---|
219 | */ |
---|
220 | public ContourLevels getContourLevels() { |
---|
221 | return cl_; |
---|
222 | } |
---|
223 | /** |
---|
224 | * Test for color map equality |
---|
225 | */ |
---|
226 | public boolean equals(ColorMap cm) { |
---|
227 | if(cm == null || !(cm instanceof CLTransformColorMap)) return false; |
---|
228 | if(!cl_.equals(((CLTransformColorMap)cm).cl_)) return false; |
---|
229 | if(!(rTrans_.equals(((CLTransformColorMap)cm).rTrans_) && |
---|
230 | gTrans_.equals(((CLTransformColorMap)cm).gTrans_) && |
---|
231 | bTrans_.equals(((CLTransformColorMap)cm).bTrans_))) return false; |
---|
232 | return true; |
---|
233 | } |
---|
234 | } |
---|