source: ether_megapoli/trunk/applets/src/gov/noaa/pmel/sgt/VectorAttribute.java @ 174

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

Applets _ récupération des sources

File size: 15.9 KB
Line 
1/*
2 * $Id: VectorAttribute.java,v 1.12 2003/09/17 20:32:10 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
13package  gov.noaa.pmel.sgt;
14
15import  java.awt.*;
16import java.beans.PropertyChangeListener;
17import java.beans.PropertyChangeSupport;
18
19/**
20 * Sets the rendering style for line data.
21 * <code>Color</code>, width, and dash characteristics are
22 * <code>VectorAttribute</code> properties.
23 * <BR><FONT color="#FF0000">Warning: The SGT implementation of
24 * Vectors requires Java2D. To use Vectors you must be using jdk1.2 or
25 * newer.</FONT>
26 *
27 * @author Donald Denbo
28 * @version $Revision: 1.12 $, $Date: 2003/09/17 20:32:10 $
29 * @since 2.1
30 * @see LineCartesianRenderer
31 * @see ContourLevels
32 */
33public class VectorAttribute
34  implements Attribute, Cloneable, java.io.Serializable {
35
36  protected transient PropertyChangeSupport changes_ = new PropertyChangeSupport(this);
37  private boolean batch_ = false;
38  private boolean local_ = true;
39  private boolean modified_ = false;
40  private String id_ = null;
41  private int vectorStyle_ = HEAD;
42  private Color vectorColor_ = Color.black;
43  private double vectorScale_ = 0.01;  // User units to physical
44  private double vectorMaxSize_ = 100.0;
45  private double offsetAngle_ = 0.0;
46
47  private double headScale_ = 1.0;  // User units to physical
48  private double headMaxSize_ = 100.0;
49  private double headMinSize_ = 0.05;
50  private double headFixedSize_ = 0.2;  // Physical units
51
52  private int originStyle_ = NO_MARK;
53  private Color markColor_ = Color.black;
54  private int mark_ = 1;
55  private double markHeightP_ = 0.2;
56
57  private float width_ = 1.0f;
58  private int capStyle_ = LineAttribute.CAP_SQUARE;
59  private int miterStyle_ = LineAttribute.JOIN_MITER;
60  private float miterLimit_ = 10.0f;
61  /**
62   * Vector head style, None.  No arrow head will be drawn.
63   */
64  public static final int NO_HEAD = 0;
65  /**
66   * Vector head style, Un-scaled (default).  Head will be drawn a
67   * constant size.
68   */
69  public static final int HEAD = 1;
70  /**
71   * Vector head style, Scaled.  The size of the head will be
72   * proportional to the length of the vector.
73   */
74  public static final int SCALED_HEAD = 2;
75  /**
76   * Vector origin style, no mark (default).  The origin of the vector
77   * will be drawn without a plot mark.
78   */
79  public static final int NO_MARK = 0;
80  /**
81   * Vector origin style, Mark.  A plot mark will be drawn at the
82   * origin of the vector.
83   */
84  public static final int MARK = 1;
85  /**
86   * Default constructor.  Default vector style is HEAD,
87   * default color is red, and scale = 1.0;
88   **/
89  public VectorAttribute() {
90    this(1.0, Color.red);
91  }
92  /**
93   * <code>VectorAttribute</code> constructor.  Default vector style
94   * is HEAD.
95   *
96   * @param scale vector scale
97   * @param color vector <code>Color</code>
98   * @see java.awt.Color
99   **/
100  public VectorAttribute(double scale, Color color) {
101    vectorStyle_ = HEAD;
102    vectorScale_ = scale;
103    vectorColor_ = color;
104  }
105  /**
106   * <code>VectorAttribute</code> constructor.
107   *
108   * @param style vector style
109   * @param scale vector scale
110   * @param color vector <code>Color</code>
111   * @param head_scale scale of vector head
112   * @see java.awt.Color
113   **/
114  public VectorAttribute(int style, double scale, Color color,
115                         double head_scale) {
116    vectorStyle_ = style;
117    vectorScale_ = scale;
118    vectorColor_ = color;
119    headScale_ = head_scale;
120  }
121  /**
122   * Copy the <code>VectorAttribute</code>.
123   *
124   * @return new <code>VectorAttribute</code>
125   */
126  public Object copy() {
127    VectorAttribute newVector;
128    try {
129      newVector = (VectorAttribute)clone();
130    } catch (CloneNotSupportedException e) {
131      newVector = new VectorAttribute();
132    }
133    return newVector;
134  }
135  /**
136   * Change the head style.  Options include <code>NO_HEAD</code>,
137   * <code>HEAD</code>, and <code>SCALED_HEAD</code>.
138   * <BR><B>Property Change:</B> <code>vectorStyle</code>.
139   *
140   * @see #setVectorColor(java.awt.Color)
141   * @see #setVectorMaxSize(double)
142   * @see #setVectorScale(double)
143   * @see #setOffsetAngle(double)
144   *
145   */
146  public void setVectorStyle(int style) {
147    if(vectorStyle_ != style) {
148      Integer tempOld = new Integer(vectorStyle_);
149      vectorStyle_ = style;
150      firePropertyChange("vectorStyle",
151                                  tempOld,
152                                  new Integer(vectorStyle_));
153    }
154  }
155  /** Get the vector head style. */
156  public int getVectorStyle() {
157    return vectorStyle_;
158  }
159  /**
160   * Change the vector color.
161   * <BR><B>Property Change:</B> <code>vectorColor</code>.
162   *
163   */
164  public void setVectorColor(Color color) {
165    if(!vectorColor_.equals(color)) {
166      Color tempOld = vectorColor_;
167      vectorColor_ = color;
168      firePropertyChange("vectorColor",
169                                  tempOld,
170                                  vectorColor_);
171    }
172  }
173  /** Get the vector color. */
174  public Color getVectorColor() {
175    return vectorColor_;
176  }
177  /**
178   * Change the vector scale.  The vector length is determined
179   * by the data value times the vector scale.  The
180   * vector length is bounded by the maximum allowed
181   * vector length.
182   * <BR><B>Property Change:</B> <code>vectorScale</code>.
183   *
184   * @see #setVectorMaxSize(double)
185   *
186   */
187  public void setVectorScale(double scale) {
188    if(vectorScale_ != scale) {
189      Double tempOld = new Double(vectorScale_);
190      vectorScale_ = scale;
191      firePropertyChange("vectorScale",
192                                  tempOld,
193                                  new Double(vectorScale_));
194    }
195  }
196  /** Geth the vector head scale. */
197  public double getVectorScale() {
198    return vectorScale_;
199  }
200  /**
201   * Set the maximum size for a vector.
202   * <BR><B>Property Change:</B> <code>vectorMaxSize</code>.
203   *
204   */
205  public void setVectorMaxSize(double size) {
206    if(vectorMaxSize_ != size) {
207      Double tempOld = new Double(vectorMaxSize_);
208      vectorMaxSize_ = size;
209      firePropertyChange("vectorMaxSize",
210                                  tempOld,
211                                  new Double(vectorMaxSize_));
212    }
213  }
214  /** Get the maximum vector length allowed. */
215  public double getVectorMaxSize() {
216    return vectorMaxSize_;
217  }
218  /**
219   * Set the angle (clockwize positive) to rotate the vector.
220   * <BR><B>Property Change:</B> <code>offsetAngle</code>.
221   * @param angle in degrees
222   */
223  public void setOffsetAngle(double angle) {
224    if(offsetAngle_ != angle) {
225      Double tempOld = new Double(offsetAngle_);
226      offsetAngle_ = angle;
227      firePropertyChange("offsetAngle",
228                                  tempOld,
229                                  new Double(offsetAngle_));
230    }
231  }
232  /** Get the vector rotation angle. */
233  public double getOffsetAngle() {
234    return offsetAngle_;
235  }
236  /**
237   * Change the vector head scale.  The vector head size is determined
238   * by the length of the vector times the vector head scale.  The
239   * vector head size is bounded by the minimum and maximum allowed
240   * head size.
241   * <BR><B>Property Change:</B> <code>headScale</code>.
242   *
243   * @see #setHeadMinSize(double)
244   * @see #setHeadMaxSize(double)
245   *
246   */
247  public void setHeadScale(double scale) {
248    if(headScale_ != scale) {
249      Double tempOld = new Double(headScale_);
250      headScale_ = scale;
251      firePropertyChange("headScale",
252                                  tempOld,
253                                  new Double(headScale_));
254    }
255  }
256  /** Get the vector head scale. */
257  public double getHeadScale() {
258    return headScale_;
259  }
260  /**
261   * Set the maximum size for a scaled vector head.
262   * <BR><B>Property Change:</B> <code>headMaxSize</code>.
263   *
264   */
265  public void setHeadMaxSize(double size) {
266    if(headMaxSize_ != size) {
267      Double tempOld = new Double(headMaxSize_);
268      headMaxSize_ = size;
269      firePropertyChange("headMaxSize",
270                                  tempOld,
271                                  new Double(headMaxSize_));
272    }
273  }
274  /** Get the maximum vector head size. */
275  public double getHeadMaxSize() {
276    return headMaxSize_;
277  }
278  /**
279   * Set the minimum size for a scaled vector head.
280   * <BR><B>Property Change:</B> <code>headMinSize</code>.
281   *
282   */
283  public void setHeadMinSize(double size) {
284    if(headMinSize_ != size) {
285      Double tempOld = new Double(headMinSize_);
286      headMinSize_ = size;
287      firePropertyChange("headMinSize",
288                                  tempOld,
289                                  new Double(headMinSize_));
290    }
291  }
292  /** Get the minimum vector head size. */
293  public double getHeadMinSize() {
294    return headMinSize_;
295  }
296  /**
297   * Set the fixed size for a unscaled vector head.
298   * <BR><B>Property Change:</B> <code>headFixedSize</code>.
299   *
300   */
301  public void setHeadFixedSize(double size) {
302    if(headFixedSize_ != size) {
303      Double tempOld = new Double(headFixedSize_);
304      headFixedSize_ = size;
305      firePropertyChange("headFixedSize",
306                                  tempOld,
307                                  new Double(headFixedSize_));
308    }
309  }
310  /** Get the fixed vector head size. */
311  public double getHeadFixedSize() {
312    return headFixedSize_;
313  }
314  /**
315   * Set the vector origin style.  Options are <code>NO_MARK</code>
316   * and <code>MARK</code>.
317   * <BR><B>Property Change:</B> <code>originStyle</code>.
318   *
319   * @see #setMarkColor(java.awt.Color)
320   * @see #setMark(int)
321   * @see #setMarkHeightP(double)
322   */
323  public void setOriginStyle(int style) {
324    if(originStyle_ != style) {
325      Integer tempOld = new Integer(originStyle_);
326      originStyle_ = style;
327      firePropertyChange("originStyle",
328                                  tempOld,
329                                  new Integer(originStyle_));
330    }
331  }
332  /** Get vector origin style. */
333  public int getOriginStyle() {
334    return originStyle_;
335  }
336  /**
337   * Set the color for the origin mark.
338   * <BR><B>Property Change:</B> <code>markColor</code>.
339   */
340  public void setMarkColor(Color color) {
341    if(!markColor_.equals(color)) {
342      Color tempOld = markColor_;
343      markColor_ = color;
344      firePropertyChange("markColor",
345                                  tempOld,
346                                  markColor_);
347    }
348  }
349  /** Get the color for the origin mark. */
350  public Color getMarkColor() {
351    return markColor_;
352  }
353  /**
354   * Set the mark for the origin.
355   * <BR><B>Property Change:</B> <code>mark</code>.
356   *
357   * @param mark the plot mark
358   * @see PlotMark
359   */
360  public void setMark(int mark) {
361    if(mark_ != mark) {
362      Integer tempOld = new Integer(mark_);
363      if(mark <= 0) mark = 1;
364      if(mark > 51) mark = 51;
365      mark_ = mark;
366      firePropertyChange("mark",
367                                  tempOld,
368                                  new Integer(mark_));
369    }
370  }
371  /**
372   * Get plot mark for the origin.
373   *
374   * @return plot mark
375   **/
376  public int getMark() {
377    return mark_;
378  }
379  /**
380   * Set mark height for the origin.
381   * <BR><B>Property Change:</B> <code>markHeightP</code>.
382   *
383   * @param markh mark height
384   **/
385  public void setMarkHeightP(double markh) {
386    if(markHeightP_ != markh) {
387      Double tempOld = new Double(markHeightP_);
388      markHeightP_ = markh;
389      firePropertyChange("markHeightP",
390                                  tempOld,
391                                  new Double(markHeightP_));
392    }
393  }
394  /**
395   * Get mark height for the origin.
396   *
397   * @return mark height
398   **/
399  public double getMarkHeightP() {
400    return markHeightP_;
401  }
402  /**
403   * Set the line width in physical units.
404   * <BR><B>Property Change:</B> <code>width</code>.
405   *
406   * @param t line width
407   **/
408  public void setWidth(float t) {
409    if(width_ != t) {
410      Float tempOld = new Float(width_);
411      width_ = t;
412      firePropertyChange("width",
413                                  tempOld,
414                                  new Float(width_));
415    }
416  }
417  /**
418   * Get line width.
419   *
420   * @return line width in physcial coordinates.
421   **/
422  public float getWidth() {
423    return width_;
424  }
425  /**
426   * Set the line Cap Style.  Styles include
427   * <code>LineAttribute.CAP_BUTT</code>,
428   * <code>LineAttribute.CAP_ROUND</code>, and
429   * <code>LineAttribute.CAP_SQUARE</code>.
430   * <BR><B>Property Change:</B> <code>capStyle</code>.
431   *
432   * @see LineAttribute#CAP_BUTT
433   * @see LineAttribute#CAP_ROUND
434   * @see LineAttribute#CAP_SQUARE
435   */
436  public void setCapStyle(int style) {
437    if(capStyle_ != style) {
438      Integer tempOld = new Integer(capStyle_);
439      capStyle_ = style;
440      firePropertyChange("capStyle",
441                                  tempOld,
442                                  new Integer(capStyle_));
443    }
444  }
445  /** Get the line cap style. */
446  public int getCapStyle() {
447    return capStyle_;
448  }
449  /**
450   * Set the line miter style.  Styles include
451   * <code>LineAttribute.JOIN_BEVEL</code>,
452   * <code>LineAttribute.JOIN_MITER</code>, and
453   * <code>LineAttribute.JOIN_ROUND</code>.
454   * <BR><B>Property Change:</B> <code>miterStyle</code>.
455   *
456   * @see LineAttribute#JOIN_BEVEL
457   * @see LineAttribute#JOIN_MITER
458   * @see LineAttribute#JOIN_ROUND
459   */
460  public void setMiterStyle(int style) {
461    if(miterStyle_ != style) {
462      Integer tempOld = new Integer(miterStyle_);
463      miterStyle_ = style;
464      firePropertyChange("miterStyle",
465                                  tempOld,
466                                  new Integer(miterStyle_));
467    }
468
469  }
470  /** Get the line miter sytle. */
471  public int getMiterStyle() {
472    return miterStyle_;
473  }
474  /**
475   * Set the line miter limit.
476   * <BR><B>Property Change:</B> <code>miterLimit</code>.
477   */
478  public void setMiterLimit(float limit) {
479    if(miterLimit_ != limit) {
480      Float tempOld = new Float(miterLimit_);
481      miterLimit_ = limit;
482      firePropertyChange("miterLimit",
483                                  tempOld,
484                                  new Float(miterLimit_));
485    }
486  }
487  /** Get the line miter limit. */
488  public float getMiterLimit() {
489    return miterLimit_;
490  }
491
492  /**
493   * Get a <code>String</code> representation of the
494   * <code>VectorAttribute</code>.
495   *
496   * @return <code>String</code> representation
497   */
498  public String toString() {
499    String name = getClass().getName();
500    return name.substring(name.lastIndexOf(".")+1);
501  }
502  /**
503   * Add listener to changes in <code>VectorAttribute</code> properties.
504   */
505  public void addPropertyChangeListener(PropertyChangeListener listener) {
506    if(changes_ == null) changes_ = new PropertyChangeSupport(this);
507    changes_.addPropertyChangeListener(listener);
508  }
509  public void removePropertyChangeListener(PropertyChangeListener listener) {
510    changes_.removePropertyChangeListener(listener);
511  }
512  /**
513   * @since 3.0
514   */
515  public void setId(String id) {
516    id_ = id;
517  }
518  /**
519   * @since 3.0
520   */
521  public String getId() {
522    return id_;
523  }
524
525  protected void firePropertyChange(String name, Object oldValue, Object newValue) {
526    if(batch_) {
527      modified_ = true;
528      return;
529    }
530    AttributeChangeEvent ace = new AttributeChangeEvent(this, name,
531                                                        oldValue, newValue,
532                                                        local_);
533    changes_.firePropertyChange(ace);
534    modified_ = false;
535  }
536  /**
537   * @since 3.0
538   */
539  public void setBatch(boolean batch) {
540    setBatch(batch, true);
541  }
542  /**
543   * @since 3.0
544   */
545  public void setBatch(boolean batch, boolean local) {
546    local_ = local;
547    batch_ = batch;
548    if(!batch && modified_) firePropertyChange("batch", Boolean.TRUE, Boolean.FALSE);
549  }
550  /**
551   * @since 3.0
552   */
553  public boolean isBatch() {
554    return batch_;
555  }
556}
Note: See TracBrowser for help on using the repository browser.