1 | /* |
---|
2 | * $Id: DefaultContourLineAttribute.java,v 1.8 2001/12/13 19:07:04 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 java.awt.*; |
---|
16 | import java.lang.CloneNotSupportedException; |
---|
17 | |
---|
18 | /** |
---|
19 | * Sets the default rendering style for contour line data. |
---|
20 | * <code>Color</code>, width, and dash characteristics are |
---|
21 | * <code>DefaultContourLineAttribute</code> properties. For individual |
---|
22 | * contour lines, the characteristics can be overridden by |
---|
23 | * <code>ContourLineAttribute</code> when used with |
---|
24 | * <code>ContourLevels</code>. |
---|
25 | * |
---|
26 | * @author Donald Denbo |
---|
27 | * @version $Revision: 1.8 $, $Date: 2001/12/13 19:07:04 $ |
---|
28 | * @since 2.0 |
---|
29 | * @see GridCartesianRenderer |
---|
30 | * @see ContourLevels |
---|
31 | * @see ContourLineAttribute |
---|
32 | */ |
---|
33 | public class DefaultContourLineAttribute extends LineAttribute { |
---|
34 | /** |
---|
35 | * @label attr |
---|
36 | */ |
---|
37 | private ContourLineAttribute attr_; |
---|
38 | private boolean labelEnabled_ = true; |
---|
39 | private Color labelColor_; |
---|
40 | private Font labelFont_; |
---|
41 | private double labelHeightP_; |
---|
42 | private int sigDigits_; |
---|
43 | private String labelFormat_; |
---|
44 | /** |
---|
45 | * Default constructor. Defaults are: |
---|
46 | * <pre> |
---|
47 | * labelColor = <code>Color.black</code> |
---|
48 | * labelHeightP = 0.16 |
---|
49 | * labelFont = null |
---|
50 | * labelFormat = "" |
---|
51 | * sigDigits = 2 |
---|
52 | * </pre> |
---|
53 | */ |
---|
54 | public DefaultContourLineAttribute() { |
---|
55 | super(SOLID, Color.black); |
---|
56 | labelColor_ = Color.black; |
---|
57 | labelHeightP_ = 0.16; |
---|
58 | labelFont_ = null; |
---|
59 | sigDigits_ = 2; |
---|
60 | labelFormat_ = ""; |
---|
61 | } |
---|
62 | /** |
---|
63 | * Set the <code>ContourLineAttribute</code> that will potentially |
---|
64 | * override attributes. |
---|
65 | */ |
---|
66 | public DefaultContourLineAttribute setContourLineAttribute(ContourLineAttribute attr) { |
---|
67 | attr_ = attr; |
---|
68 | return this; |
---|
69 | } |
---|
70 | /** |
---|
71 | * Get the associated <code>ContourLineAttribute</code> |
---|
72 | */ |
---|
73 | public ContourLineAttribute getContourLineAttribute() { |
---|
74 | return attr_; |
---|
75 | } |
---|
76 | /** |
---|
77 | * Set label text for associated <code>ContourLineAttribute</code>. |
---|
78 | */ |
---|
79 | public void setLabelText(String label) { |
---|
80 | if(attr_ != null) attr_.setLabelText(label); |
---|
81 | } |
---|
82 | /** |
---|
83 | * Return label text from associated |
---|
84 | * <code>ContourLineAttribute</code>, if none return empty string. |
---|
85 | */ |
---|
86 | public String getLabelText() { |
---|
87 | if(attr_ != null) { |
---|
88 | return attr_.getLabelText(); |
---|
89 | } else { |
---|
90 | return ""; |
---|
91 | } |
---|
92 | } |
---|
93 | /** |
---|
94 | * Enable/disable the contour label. |
---|
95 | * <BR><B>Property Change:</B> <code>labelEnabled</code>. |
---|
96 | */ |
---|
97 | public void setLabelEnabled(boolean sle) { |
---|
98 | if(labelEnabled_ != sle) { |
---|
99 | Boolean tempOld = new Boolean(labelEnabled_); |
---|
100 | labelEnabled_ = sle; |
---|
101 | changes_.firePropertyChange("labelEnabled", |
---|
102 | tempOld, |
---|
103 | new Boolean(labelEnabled_)); |
---|
104 | } |
---|
105 | } |
---|
106 | /** |
---|
107 | * Test if the contour label is enabled. Use associated |
---|
108 | * <code>ContourLineAttribute</code> if it exists and has |
---|
109 | * labelEnabledOverrideen set to <code>false</code>. |
---|
110 | */ |
---|
111 | public boolean isLabelEnabled() { |
---|
112 | if(attr_ != null && attr_.isLabelEnabledOverridden()) { |
---|
113 | return attr_.isLabelEnabled(); |
---|
114 | } else { |
---|
115 | return labelEnabled_; |
---|
116 | } |
---|
117 | } |
---|
118 | /** |
---|
119 | * Set the default contour label color |
---|
120 | * <BR><B>Property Change:</B> <code>labelColor</code>. |
---|
121 | */ |
---|
122 | public void setLabelColor(Color color) { |
---|
123 | if(!labelColor_.equals(color)) { |
---|
124 | Color tempOld = labelColor_; |
---|
125 | labelColor_ = color; |
---|
126 | changes_.firePropertyChange("labelColor", |
---|
127 | tempOld, |
---|
128 | labelColor_); |
---|
129 | } |
---|
130 | } |
---|
131 | /** |
---|
132 | * Get the contour label color. Use associated |
---|
133 | * <code>ContourLineAttribute</code> if it exists and has |
---|
134 | * labelColorOverrideen set to <code>false</code>. |
---|
135 | */ |
---|
136 | public Color getLabelColor() { |
---|
137 | if(attr_ != null && attr_.isLabelColorOverridden()) { |
---|
138 | return attr_.getLabelColor(); |
---|
139 | } else { |
---|
140 | return labelColor_; |
---|
141 | } |
---|
142 | } |
---|
143 | /** |
---|
144 | * Set the default contour label height. |
---|
145 | * <BR><B>Property Change:</B> <code>labelHeightP</code>. |
---|
146 | */ |
---|
147 | public void setLabelHeightP(double height) { |
---|
148 | if(labelHeightP_ != height) { |
---|
149 | Double tempOld = new Double(labelHeightP_); |
---|
150 | labelHeightP_ = height; |
---|
151 | changes_.firePropertyChange("labelHeightP", |
---|
152 | tempOld, |
---|
153 | new Double(labelHeightP_)); |
---|
154 | } |
---|
155 | } |
---|
156 | /** |
---|
157 | * Get the contour label height. Use associated |
---|
158 | * <code>ContourLineAttribute</code> if it exists and has |
---|
159 | * labelHeightPOverrideen set to <code>false</code>. |
---|
160 | */ |
---|
161 | public double getLabelHeightP() { |
---|
162 | if(attr_ != null && attr_.isLabelHeightPOverridden()) { |
---|
163 | return attr_.getLabelHeightP(); |
---|
164 | } else { |
---|
165 | return labelHeightP_; |
---|
166 | } |
---|
167 | } |
---|
168 | /** |
---|
169 | * Set the default contour label font. |
---|
170 | * <BR><B>Property Change:</B> <code>labelFont</code>. |
---|
171 | */ |
---|
172 | public void setLabelFont(Font font) { |
---|
173 | if(labelFont_ == null || !labelFont_.equals(font)) { |
---|
174 | Font tempOld = labelFont_; |
---|
175 | labelFont_ = font; |
---|
176 | changes_.firePropertyChange("labelFont", |
---|
177 | tempOld, |
---|
178 | labelFont_); |
---|
179 | } |
---|
180 | } |
---|
181 | /** |
---|
182 | * Get the contour label font. Use associated |
---|
183 | * <code>ContourLineAttribute</code> if it exists and has |
---|
184 | * labelFontOverrideen set to <code>false</code>. |
---|
185 | */ |
---|
186 | public Font getLabelFont() { |
---|
187 | if(attr_ != null && attr_.isLabelFontOverridden()) { |
---|
188 | return attr_.getLabelFont(); |
---|
189 | } else { |
---|
190 | return labelFont_; |
---|
191 | } |
---|
192 | } |
---|
193 | /** |
---|
194 | * Set the number of significant digits for auto labelling. |
---|
195 | * <BR><B>Property Change:</B> <code>significantDigits</code>. |
---|
196 | */ |
---|
197 | public void setSignificantDigits(int sig) { |
---|
198 | if(sigDigits_ != sig) { |
---|
199 | Integer tempOld = new Integer(sigDigits_); |
---|
200 | sigDigits_ = sig; |
---|
201 | changes_.firePropertyChange("significantDigits", |
---|
202 | tempOld, |
---|
203 | new Integer(sigDigits_)); |
---|
204 | } |
---|
205 | } |
---|
206 | /** |
---|
207 | * Get the number of significant digits for auto labelling. |
---|
208 | */ |
---|
209 | public int getSignificantDigits() { |
---|
210 | return sigDigits_; |
---|
211 | } |
---|
212 | /** |
---|
213 | * Set the default contour label format. |
---|
214 | * <BR><B>Property Change:</B> <code>labelFormat</code>. |
---|
215 | */ |
---|
216 | public void setLabelFormat(String format) { |
---|
217 | if(!labelFormat_.equals(format)) { |
---|
218 | String tempOld = labelFormat_; |
---|
219 | labelFormat_ = format; |
---|
220 | changes_.firePropertyChange("labelFormat", |
---|
221 | tempOld, |
---|
222 | labelFormat_); |
---|
223 | } |
---|
224 | } |
---|
225 | /** |
---|
226 | * Get the contour label format. Use associated |
---|
227 | * <code>ContourLineAttribute</code> if it exists and has |
---|
228 | * labelFormatOverrideen set to <code>false</code>. |
---|
229 | */ |
---|
230 | public String getLabelFormat() { |
---|
231 | if(attr_ != null && attr_.isLabelFormatOverridden()) { |
---|
232 | return attr_.getLabelFormat(); |
---|
233 | } else { |
---|
234 | return labelFormat_; |
---|
235 | } |
---|
236 | } |
---|
237 | /** |
---|
238 | * Test if auto label is enabled. Use associated |
---|
239 | * <code>ContourLineAttribute</code> if it exists otherwise always |
---|
240 | * returns <code>true</code>. |
---|
241 | */ |
---|
242 | public boolean isAutoLabel() { |
---|
243 | if(attr_ != null) { |
---|
244 | return attr_.isAutoLabel(); |
---|
245 | } else { |
---|
246 | return true; |
---|
247 | } |
---|
248 | } |
---|
249 | /** |
---|
250 | * Get dash array. Use associated |
---|
251 | * <code>ContourLineAttribute</code> if it exists and has |
---|
252 | * dashArrayOverrideen set to <code>false</code>. |
---|
253 | */ |
---|
254 | public float[] getDashArray() { |
---|
255 | if(attr_ != null && attr_.isDashArrayOverridden()) { |
---|
256 | return attr_.getDashArray(); |
---|
257 | } else { |
---|
258 | return super.getDashArray(); |
---|
259 | } |
---|
260 | } |
---|
261 | /** |
---|
262 | * Get the dash phase. Use associated |
---|
263 | * <code>ContourLineAttribute</code> if it exists and has |
---|
264 | * dashPhaseOverrideen set to <code>false</code>. |
---|
265 | */ |
---|
266 | public float getDashPhase() { |
---|
267 | if(attr_ != null && attr_.isDashPhaseOverridden()) { |
---|
268 | return attr_.getDashPhase(); |
---|
269 | } else { |
---|
270 | return super.getDashPhase(); |
---|
271 | } |
---|
272 | } |
---|
273 | /** |
---|
274 | * Override the default setStyle. Legal styles <em>do not</em> |
---|
275 | * include MARK or MARK_LINE. |
---|
276 | */ |
---|
277 | public void setStyle(int st) { |
---|
278 | if(st == MARK || st == MARK_LINE) return; |
---|
279 | super.setStyle(st); |
---|
280 | } |
---|
281 | /** |
---|
282 | * Get the contour line style. Use associated |
---|
283 | * <code>ContourLineAttribute</code> if it exists and has |
---|
284 | * styleOverrideen set to <code>false</code>. |
---|
285 | */ |
---|
286 | public int getStyle() { |
---|
287 | if(attr_ != null && attr_.isStyleOverridden()) { |
---|
288 | return attr_.getStyle(); |
---|
289 | } else { |
---|
290 | return super.getStyle(); |
---|
291 | } |
---|
292 | } |
---|
293 | /** |
---|
294 | * Get the contour line color. Use associated |
---|
295 | * <code>ContourLineAttribute</code> if it exists and has |
---|
296 | * colorOverrideen set to <code>false</code>. |
---|
297 | */ |
---|
298 | public Color getColor() { |
---|
299 | if(attr_ != null && attr_.isColorOverridden()) { |
---|
300 | return attr_.getColor(); |
---|
301 | } else { |
---|
302 | return super.getColor(); |
---|
303 | } |
---|
304 | } |
---|
305 | /** |
---|
306 | * Get the contour line width. Use associated |
---|
307 | * <code>ContourLineAttribute</code> if it exists and has |
---|
308 | * widthOverrideen set to <code>false</code>. |
---|
309 | */ |
---|
310 | public float getWidth() { |
---|
311 | if(attr_ != null && attr_.isWidthOverridden()) { |
---|
312 | return attr_.getWidth(); |
---|
313 | } else { |
---|
314 | return super.getWidth(); |
---|
315 | } |
---|
316 | } |
---|
317 | /** |
---|
318 | * Get the contour line cap style. Use associated |
---|
319 | * <code>ContourLineAttribute</code> if it exists and has |
---|
320 | * capStyleOverrideen set to <code>false</code>. |
---|
321 | */ |
---|
322 | public int getCapStyle() { |
---|
323 | if(attr_ != null && attr_.isCapStyleOverridden()) { |
---|
324 | return attr_.getCapStyle(); |
---|
325 | } else { |
---|
326 | return super.getCapStyle(); |
---|
327 | } |
---|
328 | } |
---|
329 | /** |
---|
330 | * Get the contour line miter style. Use associated |
---|
331 | * <code>ContourLineAttribute</code> if it exists and has |
---|
332 | * miterStyleOverrideen set to <code>false</code>. |
---|
333 | */ |
---|
334 | public int getMiterStyle() { |
---|
335 | if(attr_ != null && attr_.isMiterStyleOverridden()) { |
---|
336 | return attr_.getMiterStyle(); |
---|
337 | } else { |
---|
338 | return super.getMiterStyle(); |
---|
339 | } |
---|
340 | } |
---|
341 | /** |
---|
342 | * Get the contour line miter limit. Use associated |
---|
343 | * <code>ContourLineAttribute</code> if it exists and has |
---|
344 | * miterLimitOverrideen set to <code>false</code>. |
---|
345 | */ |
---|
346 | public float getMiterLimit() { |
---|
347 | if(attr_ != null && attr_.isMiterLimitOverridden()) { |
---|
348 | return attr_.getMiterLimit(); |
---|
349 | } else { |
---|
350 | return super.getMiterLimit(); |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | public String toString() { |
---|
355 | Color col = getColor(); |
---|
356 | int style = getStyle(); |
---|
357 | String sstyle; |
---|
358 | if(style == SOLID) { |
---|
359 | sstyle = "SOLID"; |
---|
360 | } else if(style == DASHED) { |
---|
361 | sstyle = "DASHED"; |
---|
362 | } else if(style == HEAVY) { |
---|
363 | sstyle = "HEAVY"; |
---|
364 | } else if(style == HIGHLIGHT) { |
---|
365 | sstyle = "HIGHLIGHT"; |
---|
366 | } else if(style == MARK) { |
---|
367 | sstyle = "MARK - unsupported"; |
---|
368 | } else if(style == MARK_LINE) { |
---|
369 | sstyle = "MARK_LINE - unsupported"; |
---|
370 | } else if(style == STROKE) { |
---|
371 | sstyle = "STROKE"; |
---|
372 | } else { |
---|
373 | sstyle = ""; |
---|
374 | } |
---|
375 | String scol = "[" + col.getRed() + "," + col.getGreen() + |
---|
376 | "," + col.getBlue() + "]"; |
---|
377 | return sstyle + ", " + scol + ", labelEnabled=" + labelEnabled_; |
---|
378 | } |
---|
379 | |
---|
380 | public Object copy() { |
---|
381 | DefaultContourLineAttribute newAttr; |
---|
382 | try { |
---|
383 | newAttr = (DefaultContourLineAttribute)clone(); |
---|
384 | } catch (CloneNotSupportedException e) { |
---|
385 | newAttr = new DefaultContourLineAttribute(); |
---|
386 | } |
---|
387 | return newAttr; |
---|
388 | } |
---|
389 | |
---|
390 | } |
---|