1 | /** |
---|
2 | * $Id: SimplePoint.java,v 1.14 2003/08/22 23:02:38 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.dm; |
---|
14 | |
---|
15 | import gov.noaa.pmel.sgt.SGLabel; |
---|
16 | import gov.noaa.pmel.sgt.InvalidMethodError; |
---|
17 | import gov.noaa.pmel.util.GeoDate; |
---|
18 | import gov.noaa.pmel.util.SoTRange; |
---|
19 | import gov.noaa.pmel.util.SoTPoint; |
---|
20 | import gov.noaa.pmel.util.SoTValue; |
---|
21 | |
---|
22 | import java.beans.PropertyChangeSupport; |
---|
23 | import java.beans.PropertyChangeListener; |
---|
24 | import java.io.Serializable; |
---|
25 | |
---|
26 | /** |
---|
27 | * <code>SimplePoint</code> provides an implementation of the |
---|
28 | * <code>SGTPoint</code> and <code>Cartesian</code> interfaces. |
---|
29 | * |
---|
30 | * @author Donald Denbo |
---|
31 | * @version $Revision: 1.14 $, $Date: 2003/08/22 23:02:38 $ |
---|
32 | * @since 1.0 |
---|
33 | * @see SGTPoint |
---|
34 | * @see Cartesian |
---|
35 | */ |
---|
36 | public class SimplePoint implements SGTPoint, Cartesian, Cloneable, Serializable { |
---|
37 | protected double xloc_ = Double.NaN; |
---|
38 | protected double yloc_ = Double.NaN; |
---|
39 | protected long tloc_; |
---|
40 | protected boolean xTime_ = false; |
---|
41 | protected boolean yTime_ = false; |
---|
42 | protected double value_; |
---|
43 | protected String title_; |
---|
44 | protected SGLabel keyTitle_ = null; |
---|
45 | protected String id_ = null; |
---|
46 | /**@shapeType AggregationLink |
---|
47 | * @clientRole value*/ |
---|
48 | protected SGTMetaData valueMetaData_; |
---|
49 | |
---|
50 | /** |
---|
51 | * @link aggregation |
---|
52 | * @clientRole x |
---|
53 | */ |
---|
54 | protected SGTMetaData xMetaData_; |
---|
55 | |
---|
56 | /** |
---|
57 | * @link aggregation |
---|
58 | * @clientRole y*/ |
---|
59 | protected SGTMetaData yMetaData_; |
---|
60 | protected boolean hasValue_ = false; |
---|
61 | private PropertyChangeSupport changes_ = new PropertyChangeSupport(this); |
---|
62 | /** |
---|
63 | * Default constructor. |
---|
64 | */ |
---|
65 | public SimplePoint() { |
---|
66 | } |
---|
67 | /** |
---|
68 | * Simple Point constructor. |
---|
69 | * |
---|
70 | * @param xloc X coordinate |
---|
71 | * @param yloc Y coordinate |
---|
72 | * @param title the title |
---|
73 | */ |
---|
74 | public SimplePoint(double xloc,double yloc,String title) { |
---|
75 | xloc_ = xloc; |
---|
76 | yloc_ = yloc; |
---|
77 | title_ = title; |
---|
78 | } |
---|
79 | /** |
---|
80 | * Simple Point constructor. |
---|
81 | * |
---|
82 | * @since 3.0 |
---|
83 | * |
---|
84 | * @param loc SoTPoint |
---|
85 | * @param title the title |
---|
86 | */ |
---|
87 | public SimplePoint(SoTPoint loc, String title) { |
---|
88 | xTime_ = loc.isXTime(); |
---|
89 | yTime_ = loc.isYTime(); |
---|
90 | if(xTime_) { |
---|
91 | tloc_ = loc.getX().getLongTime(); |
---|
92 | } else { |
---|
93 | xloc_ = ((Number)loc.getX().getObjectValue()).doubleValue(); |
---|
94 | } |
---|
95 | if(yTime_) { |
---|
96 | tloc_ = loc.getY().getLongTime(); |
---|
97 | } else { |
---|
98 | yloc_ = ((Number)loc.getY().getObjectValue()).doubleValue(); |
---|
99 | } |
---|
100 | title_ = title; |
---|
101 | } |
---|
102 | /** |
---|
103 | * Create a copy. |
---|
104 | * |
---|
105 | * @since 2.0 |
---|
106 | * @see SGTData |
---|
107 | */ |
---|
108 | public SGTData copy() { |
---|
109 | SGTPoint newPoint; |
---|
110 | try { |
---|
111 | newPoint = (SGTPoint)clone(); |
---|
112 | } catch (CloneNotSupportedException e) { |
---|
113 | newPoint = new SimplePoint(); |
---|
114 | } |
---|
115 | return (SGTData)newPoint; |
---|
116 | } |
---|
117 | /** |
---|
118 | * Get the X coordinate. |
---|
119 | */ |
---|
120 | public double getX() { |
---|
121 | return xloc_; |
---|
122 | } |
---|
123 | /** |
---|
124 | * Get the Y coordinate |
---|
125 | */ |
---|
126 | public double getY() { |
---|
127 | return yloc_; |
---|
128 | } |
---|
129 | /** |
---|
130 | * Get the associated value. |
---|
131 | */ |
---|
132 | public double getValue() { |
---|
133 | return value_; |
---|
134 | } |
---|
135 | /** |
---|
136 | * Is there an associated value? |
---|
137 | */ |
---|
138 | public boolean hasValue() { |
---|
139 | return hasValue_; |
---|
140 | } |
---|
141 | /** |
---|
142 | * Get the time coordinate. |
---|
143 | */ |
---|
144 | public GeoDate getTime() { |
---|
145 | return new GeoDate(tloc_); |
---|
146 | } |
---|
147 | /** |
---|
148 | * Get the time in <code>long</code> referenced |
---|
149 | * to 1970-01-01 |
---|
150 | * |
---|
151 | * @since 3.0 |
---|
152 | */ |
---|
153 | public long getLongTime() { |
---|
154 | return tloc_; |
---|
155 | } |
---|
156 | /** |
---|
157 | * Set the time coordinate |
---|
158 | * |
---|
159 | * @since 3.0 |
---|
160 | */ |
---|
161 | public void setTime(GeoDate date) { |
---|
162 | setTime(date.getTime()); |
---|
163 | } |
---|
164 | /** |
---|
165 | * @since 3.0 |
---|
166 | */ |
---|
167 | public void setTime(long t) { |
---|
168 | long old = tloc_; |
---|
169 | tloc_ = t; |
---|
170 | changes_.firePropertyChange("dataModified", |
---|
171 | new Long(old), |
---|
172 | new Long(tloc_)); |
---|
173 | } |
---|
174 | /** |
---|
175 | * Is the X coordinate Time? |
---|
176 | */ |
---|
177 | public boolean isXTime() { |
---|
178 | return xTime_; |
---|
179 | } |
---|
180 | /** |
---|
181 | * Is the Y coordinate Time? |
---|
182 | */ |
---|
183 | public boolean isYTime() { |
---|
184 | return yTime_; |
---|
185 | } |
---|
186 | /** |
---|
187 | * Get the title. |
---|
188 | */ |
---|
189 | public String getTitle() { |
---|
190 | return title_; |
---|
191 | } |
---|
192 | /** |
---|
193 | * Set the title. |
---|
194 | */ |
---|
195 | public void setTitle(String title) { |
---|
196 | title_ = title; |
---|
197 | } |
---|
198 | public SGLabel getKeyTitle() { |
---|
199 | return keyTitle_; |
---|
200 | } |
---|
201 | /** Set the title formatted for the <code>VectorKey</code>. */ |
---|
202 | public void setKeyTitle(SGLabel title) { |
---|
203 | keyTitle_ = title; |
---|
204 | } |
---|
205 | /** |
---|
206 | * Get the unique identifier. The presence of the identifier |
---|
207 | * is optional, but if it is present it should be unique. This |
---|
208 | * field is used to search for the layer that contains the data. |
---|
209 | * |
---|
210 | * @since 2.0 |
---|
211 | * @return unique identifier |
---|
212 | * @see gov.noaa.pmel.sgt.Pane |
---|
213 | * @see gov.noaa.pmel.sgt.Layer |
---|
214 | */ |
---|
215 | public String getId() { |
---|
216 | return id_; |
---|
217 | } |
---|
218 | /** |
---|
219 | * Set the unique identifier. |
---|
220 | */ |
---|
221 | public void setId(String ident) { |
---|
222 | id_ = ident; |
---|
223 | } |
---|
224 | /** |
---|
225 | * Get the associated value SGTMetaData. |
---|
226 | */ |
---|
227 | public SGTMetaData getValueMetaData() { |
---|
228 | return valueMetaData_; |
---|
229 | } |
---|
230 | /** |
---|
231 | * Set the X coordinate. |
---|
232 | * <BR><B>Property Change:</B> <code>dataModified</code>. |
---|
233 | */ |
---|
234 | public void setX(double xloc) { |
---|
235 | double old = xloc_; |
---|
236 | xloc_ = xloc; |
---|
237 | changes_.firePropertyChange("dataModified", |
---|
238 | new Double(old), |
---|
239 | new Double(xloc_)); |
---|
240 | } |
---|
241 | /** |
---|
242 | * Set the Y coordinate. |
---|
243 | * <BR><B>Property Change:</B> <code>dataModified</code>. |
---|
244 | */ |
---|
245 | public void setY(double yloc) { |
---|
246 | double old = yloc_; |
---|
247 | yloc_ = yloc; |
---|
248 | changes_.firePropertyChange("dataModified", |
---|
249 | new Double(old), |
---|
250 | new Double(yloc_)); |
---|
251 | } |
---|
252 | /** |
---|
253 | * The the associated value and basic metadata. |
---|
254 | * <BR><B>Property Change:</B> <code>associatedDataModified</code>. |
---|
255 | * |
---|
256 | * @param value associated data |
---|
257 | * @param name values name |
---|
258 | * @param units values units |
---|
259 | */ |
---|
260 | public void setValue(double value,String name,String units) { |
---|
261 | double old = value_; |
---|
262 | value_ = value; |
---|
263 | valueMetaData_ = new SGTMetaData(name, units); |
---|
264 | hasValue_ = true; |
---|
265 | changes_.firePropertyChange("associatedDataModified", |
---|
266 | new Double(old), |
---|
267 | new Double(value_)); |
---|
268 | } |
---|
269 | /** |
---|
270 | * Set the <code>SGTMetaData</code> associated with the x |
---|
271 | * coordinate |
---|
272 | * |
---|
273 | * @since 2.0 |
---|
274 | */ |
---|
275 | public void setXMetaData(SGTMetaData md) { |
---|
276 | xMetaData_ = md; |
---|
277 | } |
---|
278 | /** |
---|
279 | * Set the <code>SGTMetaData</code> associated with the y |
---|
280 | * coordinate |
---|
281 | * |
---|
282 | * @since 2.0 |
---|
283 | */ |
---|
284 | public void setYMetaData(SGTMetaData md) { |
---|
285 | yMetaData_ = md; |
---|
286 | } |
---|
287 | public SGTMetaData getXMetaData() { |
---|
288 | return xMetaData_; |
---|
289 | } |
---|
290 | public SGTMetaData getYMetaData() { |
---|
291 | return yMetaData_; |
---|
292 | } |
---|
293 | public SoTRange getXRange() { |
---|
294 | if(xTime_) { |
---|
295 | return new SoTRange.Time(tloc_, tloc_); |
---|
296 | } else { |
---|
297 | return new SoTRange.Double(xloc_, xloc_); |
---|
298 | } |
---|
299 | } |
---|
300 | public SoTRange getYRange() { |
---|
301 | if(yTime_) { |
---|
302 | return new SoTRange.Time(tloc_, tloc_); |
---|
303 | } else { |
---|
304 | return new SoTRange.Double(yloc_, yloc_); |
---|
305 | } |
---|
306 | } |
---|
307 | public void addPropertyChangeListener(PropertyChangeListener l) { |
---|
308 | changes_.addPropertyChangeListener(l); |
---|
309 | } |
---|
310 | public void removePropertyChangeListener(PropertyChangeListener l) { |
---|
311 | changes_.removePropertyChangeListener(l); |
---|
312 | } |
---|
313 | } |
---|