1 | /* |
---|
2 | * $Id: GridAttribute.java,v 1.19 2003/08/22 23:02:32 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 | |
---|
13 | package gov.noaa.pmel.sgt; |
---|
14 | |
---|
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 | * Sets the rendering style for grid data. <code>ColorMap</code>, |
---|
24 | * <code>ContourLevels</code> are <code>GridAttribute</code> properties. |
---|
25 | * |
---|
26 | * @author Donald Denbo |
---|
27 | * @version $Revision: 1.19 $, $Date: 2003/08/22 23:02:32 $ |
---|
28 | * @since 1.0 |
---|
29 | * @see GridCartesianRenderer |
---|
30 | * @see ContourLevels |
---|
31 | */ |
---|
32 | public class GridAttribute implements Attribute, |
---|
33 | Cloneable, |
---|
34 | PropertyChangeListener { |
---|
35 | private transient PropertyChangeSupport changes_ = new PropertyChangeSupport(this); |
---|
36 | // serial version ref 1.18 |
---|
37 | private static final long serialVersionUID = 3822340406728567524L; |
---|
38 | private boolean batch_ = false; |
---|
39 | private boolean local_ = true; |
---|
40 | private boolean modified_ = false; |
---|
41 | private String id_ = null; |
---|
42 | /**@shapeType AggregationLink |
---|
43 | * @label cmap*/ |
---|
44 | private ColorMap cmap_; |
---|
45 | /**@shapeType AggregationLink |
---|
46 | * @label clev*/ |
---|
47 | private ContourLevels clev_; |
---|
48 | private int style_; |
---|
49 | /** |
---|
50 | * Raster style. |
---|
51 | */ |
---|
52 | public static final int RASTER = 0; |
---|
53 | /** |
---|
54 | * Area fill style. |
---|
55 | **/ |
---|
56 | public static final int AREA_FILL = 1; |
---|
57 | /** |
---|
58 | * Contour line style. |
---|
59 | */ |
---|
60 | public static final int CONTOUR = 2; |
---|
61 | /** |
---|
62 | * Raster and Contour style. |
---|
63 | * @since 2.0 |
---|
64 | */ |
---|
65 | public static final int RASTER_CONTOUR = 3; |
---|
66 | /** |
---|
67 | * Area fill and Contour style. |
---|
68 | * @since 2.0 |
---|
69 | */ |
---|
70 | public static final int AREA_FILL_CONTOUR = 4; |
---|
71 | /** |
---|
72 | * Default constructor. Default style is <code>RASTER</code> and |
---|
73 | * default <code>ColorMap</code> is null. |
---|
74 | **/ |
---|
75 | public GridAttribute() { |
---|
76 | this(RASTER, null); |
---|
77 | } |
---|
78 | /** |
---|
79 | * <code>GridAttribute</code> constructor for <code>RASTER</code> and |
---|
80 | * <code>AREA_FILL</code> styles. |
---|
81 | * |
---|
82 | * @param style grid style |
---|
83 | * @param cmap <code>ColorMap</code> |
---|
84 | **/ |
---|
85 | public GridAttribute(int style,ColorMap cmap) { |
---|
86 | style_ = style; |
---|
87 | cmap_ = cmap; |
---|
88 | if(cmap_ != null) cmap_.addPropertyChangeListener(this); |
---|
89 | } |
---|
90 | /** |
---|
91 | * <code>GridAttribute</code> constructor for <code>CONTOUR</code> style. |
---|
92 | * |
---|
93 | * @param clev <code>ContourLevels</code> |
---|
94 | */ |
---|
95 | public GridAttribute(ContourLevels clev) { |
---|
96 | style_ = CONTOUR; |
---|
97 | cmap_ = null; |
---|
98 | clev_ = clev; |
---|
99 | } |
---|
100 | /** |
---|
101 | * Set the <code>ContourLevels</code>. |
---|
102 | * <BR><B>Property Change:</B> <code>contourLevels</code>. |
---|
103 | * |
---|
104 | * @param clev <code>ContourLevels</code> |
---|
105 | */ |
---|
106 | public void setContourLevels(ContourLevels clev) { |
---|
107 | if(clev_ == null || !clev_.equals(clev)) { |
---|
108 | ContourLevels tempOld = clev_; |
---|
109 | clev_ = clev; |
---|
110 | firePropertyChange("contourLevels", |
---|
111 | tempOld, |
---|
112 | clev_); |
---|
113 | } |
---|
114 | } |
---|
115 | /** |
---|
116 | * Get the <code>ContourLevels</code>. |
---|
117 | * |
---|
118 | * @return <code>ContourLevels</code> |
---|
119 | */ |
---|
120 | public ContourLevels getContourLevels() { |
---|
121 | return clev_; |
---|
122 | } |
---|
123 | /** |
---|
124 | * Copy the <code>GridAttribute</code>. |
---|
125 | * |
---|
126 | * @return new <code>GridAttribute</code> |
---|
127 | */ |
---|
128 | public GridAttribute copy() { |
---|
129 | GridAttribute newGrid; |
---|
130 | try { |
---|
131 | newGrid = (GridAttribute)clone(); |
---|
132 | } catch (CloneNotSupportedException e) { |
---|
133 | newGrid = new GridAttribute(); |
---|
134 | } |
---|
135 | return newGrid; |
---|
136 | } |
---|
137 | /** |
---|
138 | * Set the grid style. |
---|
139 | * <BR><B>Property Change:</B> <code>style</code>. |
---|
140 | * |
---|
141 | * @param st grid style |
---|
142 | **/ |
---|
143 | public void setStyle(int st) { |
---|
144 | if(style_ != st) { |
---|
145 | Integer tempOld = new Integer(style_); |
---|
146 | style_ = st; |
---|
147 | firePropertyChange("style", |
---|
148 | tempOld, |
---|
149 | new Integer(style_)); |
---|
150 | } |
---|
151 | } |
---|
152 | /** |
---|
153 | * Get grid style. |
---|
154 | * |
---|
155 | * @return grid style |
---|
156 | **/ |
---|
157 | public int getStyle() { |
---|
158 | return style_; |
---|
159 | } |
---|
160 | /** |
---|
161 | * Tests if <code>GridAttribute</code> style is either |
---|
162 | * RASTER or RASTER_CONTOUR. |
---|
163 | * @since 2.0 |
---|
164 | */ |
---|
165 | public boolean isRaster() { |
---|
166 | return (style_ == RASTER || |
---|
167 | style_ == RASTER_CONTOUR); |
---|
168 | } |
---|
169 | /** |
---|
170 | * Tests if <code>GridAttribute</code> style is either |
---|
171 | * CONTOUR, RASTER_CONTOUR, or AREA_FILL_CONTOUR. |
---|
172 | * @since 2.0 |
---|
173 | */ |
---|
174 | public boolean isContour() { |
---|
175 | return (style_ == CONTOUR || |
---|
176 | style_ == RASTER_CONTOUR || |
---|
177 | style_ == AREA_FILL_CONTOUR); |
---|
178 | } |
---|
179 | /** |
---|
180 | * Tests if <code>GridAttribute</code> style is eigther |
---|
181 | * AREA_FILL or AREA_FILL_CONTOUR. |
---|
182 | * @since 2.0 |
---|
183 | */ |
---|
184 | public boolean isAreaFill() { |
---|
185 | return (style_ == AREA_FILL || |
---|
186 | style_ == AREA_FILL_CONTOUR); |
---|
187 | } |
---|
188 | /** |
---|
189 | * Get the <code>ColorMap</code>. |
---|
190 | * |
---|
191 | * @return the <code>ColorMap</code> |
---|
192 | **/ |
---|
193 | public ColorMap getColorMap() { |
---|
194 | return cmap_; |
---|
195 | } |
---|
196 | /** |
---|
197 | * Set the <code>ColorMap</code>. |
---|
198 | * <BR><B>Property Change:</B> <code>colorMap</code>. |
---|
199 | * |
---|
200 | * @param cmap the <code>ColorMap</code> |
---|
201 | */ |
---|
202 | public void setColorMap(ColorMap cmap) { |
---|
203 | if(cmap_ == null && cmap == null) { |
---|
204 | return; |
---|
205 | } else { |
---|
206 | if(cmap_ != null) cmap_.removePropertyChangeListener(this); |
---|
207 | if(cmap_ == null || !cmap_.equals(cmap)) { |
---|
208 | ColorMap tempOld = cmap_; |
---|
209 | cmap_ = cmap; |
---|
210 | firePropertyChange("colorMap", |
---|
211 | tempOld, |
---|
212 | cmap_); |
---|
213 | cmap_.addPropertyChangeListener(this); |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | /** |
---|
218 | * Get a <code>String</code> representation of the |
---|
219 | * <code>GridAttribute</code>. |
---|
220 | * |
---|
221 | * @return <code>String</code> representation |
---|
222 | */ |
---|
223 | public String toString() { |
---|
224 | String name = getClass().getName(); |
---|
225 | return name.substring(name.lastIndexOf(".")+1); |
---|
226 | } |
---|
227 | /** |
---|
228 | * Add listener to changes in <code>GridAttribute</code> properties. |
---|
229 | */ |
---|
230 | public void addPropertyChangeListener(PropertyChangeListener listener) { |
---|
231 | if(changes_ == null) changes_ = new PropertyChangeSupport(this); |
---|
232 | changes_.addPropertyChangeListener(listener); |
---|
233 | } |
---|
234 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
---|
235 | changes_.removePropertyChangeListener(listener); |
---|
236 | } |
---|
237 | |
---|
238 | public void propertyChange(PropertyChangeEvent evt) { |
---|
239 | if(Debug.EVENT) { |
---|
240 | System.out.println("GridAttribute: " + evt); |
---|
241 | System.out.println(" " + evt.getPropertyName()); |
---|
242 | } |
---|
243 | changes_.firePropertyChange(evt); |
---|
244 | } |
---|
245 | /** |
---|
246 | * @since 3.0 |
---|
247 | */ |
---|
248 | public void setId(String id) { |
---|
249 | id_ = id; |
---|
250 | } |
---|
251 | /** |
---|
252 | * @since 3.0 |
---|
253 | */ |
---|
254 | public String getId() { |
---|
255 | return id_; |
---|
256 | } |
---|
257 | |
---|
258 | protected void firePropertyChange(String name, Object oldValue, Object newValue) { |
---|
259 | if(batch_) { |
---|
260 | modified_ = true; |
---|
261 | return; |
---|
262 | } |
---|
263 | AttributeChangeEvent ace = new AttributeChangeEvent(this, name, |
---|
264 | oldValue, newValue, |
---|
265 | local_); |
---|
266 | changes_.firePropertyChange(ace); |
---|
267 | modified_ = false; |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * @since 3.0 |
---|
272 | */ |
---|
273 | public void setBatch(boolean batch) { |
---|
274 | setBatch(batch, true); |
---|
275 | } |
---|
276 | |
---|
277 | /** |
---|
278 | * @since 3.0 |
---|
279 | */ |
---|
280 | public void setBatch(boolean batch, boolean local) { |
---|
281 | local_ = local; |
---|
282 | batch_ = batch; |
---|
283 | if(!batch && modified_) firePropertyChange("batch", Boolean.TRUE, Boolean.FALSE); |
---|
284 | } |
---|
285 | |
---|
286 | /** |
---|
287 | * @since 3.0 |
---|
288 | */ |
---|
289 | public boolean isBatch() { |
---|
290 | return batch_; |
---|
291 | } |
---|
292 | } |
---|