source: ether_statistics/service/implementation/gov/noaa/pmel/sgt/beans/Legend.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 17.2 KB
Line 
1/*
2 * $Id: Legend.java,v 1.3 2003/09/18 21:01:14 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.beans;
14
15import gov.noaa.pmel.sgt.dm.SGTData;
16import gov.noaa.pmel.sgt.LayerChild;
17import gov.noaa.pmel.util.Rectangle2D;
18import gov.noaa.pmel.util.Point2D;
19import javax.swing.event.*;
20import java.util.*;
21import java.io.*;
22import java.beans.*;
23import java.awt.Color;
24import java.awt.Font;
25/**
26 * Encapsulates reference to <code>SGTData</code> and key.
27 *
28 * @author Donald Denbo
29 * @version $Revision: 1.3 $, $Date: 2003/09/18 21:01:14 $
30 * @since 3.0
31 **/
32public class Legend implements Serializable {
33  transient private ChangeEvent changeEvent_ = new ChangeEvent(this);
34  transient private PanelHolder pHolder_ = null;
35  // properties for all keys.
36  private String id = "";
37  private Rectangle2D.Double boundsP = new Rectangle2D.Double(0.0, 0.0, 0.0, 0.0);
38  private boolean visible = true;
39  private boolean instantiated = false;
40  // VectorKey, LineKey, PointCollectionKey specific properties
41  private double lineLength = 0.3;
42  private int columns = 1;
43  // ColorKey specific properties
44  private Color scaleColor = Color.black; //advanced
45  private double scaleLabelHeightP = 0.2;
46  private int scaleNumberSmallTics = 0; // advanced
47  private int scaleLabelInterval = 2;
48  private Font scaleLabelFont = new Font("Helvetica", Font.PLAIN, 10); //advanced
49  private double scaleLargeTicHeightP = 0.1; //advanced
50  private double scaleSmallTicHeightP = 0.05; //advanced
51  private boolean scaleVisible = true; //advanced
52  private int scaleSignificantDigits = 2;
53  private String scaleLabelFormat = ""; //advanced
54  private double keyLabelHeightP = 0.16; //advanced
55  //
56  private int borderStyle = NO_BORDER;
57  /**
58   * Plain line border style.
59   */
60  public static final int PLAIN_LINE = 0;
61  /**
62   * Raised line border style.
63   */
64  public static final int RAISED = 1;
65  /**
66   * No border line border style.
67   */
68  public static final int NO_BORDER = 2;
69
70  private int type = LINE;
71  /**
72   * LineKey legend type
73   */
74  public static final int LINE = 0;
75  /**
76   * ColorKey legend type
77   */
78  public static final int COLOR = 1;
79  /**
80   * VectorKey legend type
81   */
82  public static final int VECTOR = 2;
83  /**
84   * PointCollectionKey legend type
85   */
86  public static final int POINT = 3;
87
88  transient private Vector changeListeners;
89  static {
90    try {
91      BeanInfo info = Introspector.getBeanInfo(Legend.class);
92      PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
93      for(int i=0; i < descriptors.length; i++) {
94        PropertyDescriptor pd = descriptors[i];
95        if(pd.getName().equals("instantiated")) {
96          pd.setValue("transient", Boolean.TRUE);
97        } else if(pd.getName().equals("panelHolder")) {
98          pd.setValue("transient", Boolean.TRUE);
99        }
100      }
101    } catch (IntrospectionException ie) {
102     ie.printStackTrace();
103    }
104  }
105
106  /**
107   * Default constructor.  Legend id and bounds set to <code>null</code>.
108   */
109  public Legend() {
110    this(null, null);
111  }
112  /**
113   * Legend constructor.
114   * @param id legend identifier
115   * @param boundsP bounds in physical units
116   */
117  public Legend(String id, Rectangle2D.Double boundsP) {
118    this.id = id;
119    this.boundsP = boundsP;
120  }
121
122  /**
123   * Set legend identifier.
124   * @param id identifier
125   */
126  public void setId(String id) {
127    String saved = this.id;
128    this.id = id;
129    if(saved == null || !saved.equals(this.id)) fireStateChanged();
130  }
131  /**
132   * Get legend identifier
133   * @return ident
134   */
135  public String getId() {
136    return id;
137  }
138
139  /**
140   * Set legend bounds.
141   * @param boundsP bounds in physical coordinates
142   */
143  public void setBoundsP(Rectangle2D.Double boundsP) {
144    Rectangle2D.Double saved = this.boundsP;
145    this.boundsP = boundsP;
146    if(saved == null || !saved.equals(this.boundsP)) fireStateChanged();
147  }
148  /**
149   * Get Legend bounds.
150   * @return bounds
151   */
152  public Rectangle2D.Double getBoundsP() {
153    return boundsP;
154  }
155
156  /**
157   * Set the location of the TOP-LEFT corner
158   * @param locationP upper left corner in physical coordinates
159   */
160  public void setLocationP(Point2D.Double locationP) {
161    double x = boundsP.x;
162    double y = boundsP.y - boundsP.height;
163
164    boundsP.x = locationP.x;
165    boundsP.y = locationP.y;
166    if(x != boundsP.x || y != boundsP.y)
167      fireStateChanged();
168  }
169  /**
170   * Get the location of the upper left corner.
171   * @return upper left corner
172   */
173  public Point2D.Double getLocationP() {
174    return new Point2D.Double(boundsP.x, boundsP.y + boundsP.height);
175  }
176
177  /**
178   * Set legend height.
179   * @param heightP height on physical coordinates
180   */
181  public void setHeightP(double heightP) {
182    double saved = boundsP.height;
183    boundsP.height = (float)heightP;
184    if(boundsP.height != saved)
185      fireStateChanged();
186  }
187  /**
188   * Get legend height.
189   * @return height
190   */
191  public double getHeightP() {
192    return boundsP.height;
193  }
194
195  /**
196   * Set legend width
197   * @param widthP width in physcial coordinates
198   */
199  public void setWidthP(double widthP) {
200    double saved = boundsP.width;
201    boundsP.width = (float)widthP;
202    if(boundsP.width != saved)
203      fireStateChanged();
204  }
205  /**
206   * Get legend width
207   * @return width
208   */
209  public double getWidthP() {
210    return boundsP.width;
211  }
212
213  /**
214   * Remove change listener.
215   * @param l change listener
216   */
217  public synchronized void removeChangeListener(ChangeListener l) {
218    if (changeListeners != null && changeListeners.contains(l)) {
219      Vector v = (Vector) changeListeners.clone();
220      v.removeElement(l);
221      changeListeners = v;
222    }
223  }
224  /**
225   * Add change listener.
226   * @param l change listener
227   */
228  public synchronized void addChangeListener(ChangeListener l) {
229    if(Page.DEBUG) System.out.println("Legend.addChangeListener(" + l + ")");
230    Vector v = changeListeners == null ? new Vector(2) : (Vector) changeListeners.clone();
231    if (!v.contains(l)) {
232      v.addElement(l);
233      changeListeners = v;
234    }
235  }
236  /**
237   * Remove change listeners that implement <code>DesignListener</code>.
238   */
239  public synchronized void removeDesignChangeListeners() {
240    if(changeListeners != null) {
241      Vector v = (Vector) changeListeners.clone();
242      Iterator iter = v.iterator();
243      while(iter.hasNext()) {
244        Object obj = iter.next();
245        if(obj instanceof DesignListener) changeListeners.removeElement(obj);
246      }
247    }
248  }
249  /**
250   * Remove all change listeners.
251   */
252  public synchronized void removeAllChangeListeners() {
253    changeListeners = null;
254  }
255
256  protected void fireStateChanged() {
257    if (changeListeners != null) {
258      Vector listeners = changeListeners;
259      int count = listeners.size();
260      for (int i = 0; i < count; i++) {
261        ((ChangeListener) listeners.elementAt(i)).stateChanged(changeEvent_);
262      }
263    }
264  }
265
266  /**
267   * Set visibility for legend.
268   * @param visible visibility state
269   */
270  public void setVisible(boolean visible) {
271    boolean saved = this.visible;
272    this.visible = visible;
273    if(saved != this.visible) fireStateChanged();
274  }
275  /**
276   * Test if legend visible.
277   * @return true, if legend is visible
278   */
279  public boolean isVisible() {
280    return visible;
281  }
282
283  /**
284   * Set legend state to instatiated.  This is called internally when the
285   * property Key has been instatiated.
286   * @param instantiated instatiation state
287   */
288  public void setInstantiated(boolean instantiated) {
289    this.instantiated = instantiated;
290  }
291  /**
292   * Test if the key instantiated.
293   * @return true, if key has been instantiated
294   */
295  public boolean isInstantiated() {
296    return instantiated;
297  }
298  /**
299   * Test if legend of type COLOR.
300   * @return true, if legend is COLOR
301   */
302  public boolean isColor() {
303    return type == Legend.COLOR;
304  }
305
306  /**
307   * Get legend type.
308   * @return legend type.
309   */
310  public int getType() {
311    return type;
312  }
313  /**
314   * Set legend type.  Types include <code>COLOR</code>, <code>LINE</code>,
315   * <code>POINT</code>, and <code>VECTOR</code>.
316   * @param type legend type
317   */
318  public void setType(int type) {
319    this.type = type;
320  }
321
322  /**
323   * Get legend border style.
324   * @return border style
325   */
326  public int getBorderStyle() {
327    return borderStyle;
328  }
329  /**
330   * Set legend border style.  Border styles include: <code>PLAIN_LINE</code>,
331   * <code>RAISED</code>, and <code>NO_BORDER</code>.  Default = NO_BORDER.
332   * @param borderStyle border style
333   */
334  public void setBorderStyle(int borderStyle) {
335    int saved = this.borderStyle;
336    this.borderStyle = borderStyle;
337    if(saved != this.borderStyle) fireStateChanged();
338  }
339
340  /**
341   * Get number of columns. Not used with <code>COLOR</code> legends.
342   * @return number of columns
343   */
344  public int getColumns() {
345    return columns;
346  }
347  /**
348   * Set number of columns. Not used with <code>COLOR</code> legends. Default = 1.
349   * @param columns number of columns
350   */
351  public void setColumns(int columns) {
352    int saved = this.columns;
353    this.columns = columns;
354    if(saved != this.columns) fireStateChanged();
355  }
356
357  /**
358   * Get the legend line, or vector length in physical coordinages.
359   * Not used with <code>COLOR</code> legends.
360   * @return line or vector length
361   */
362  public double getLineLength() {
363    return lineLength;
364  }
365  /**
366   * Set the legend line or vector lenght in physical units.
367   * Not used with <code>COLOR</code> legends.
368   * Defautl = 0.3
369   * @param lineLength line or vector length
370   */
371  public void setLineLength(double lineLength) {
372    double saved = this.lineLength;
373    this.lineLength = lineLength;
374    if(saved != this.lineLength) fireStateChanged();
375  }
376
377  /**
378   * Get <code>COLOR</code> legend scale color. Only used with <code>COLOR</code>
379   * legends.
380   * @return scale color
381   */
382  public Color getScaleColor() {
383    return scaleColor;
384  }
385  /**
386   * Set <code>COLOR</code> legend scale color. Only used with <code>COLOR</code>
387   * legends.  Deault = black.
388   * @param scaleColor scale color
389   */
390  public void setScaleColor(Color scaleColor) {
391    Color saved = new Color(this.scaleColor.getRed(),
392                            this.scaleColor.getGreen(),
393                            this.scaleColor.getBlue(),
394                            this.scaleColor.getAlpha());
395    this.scaleColor = scaleColor;
396    if(!saved.equals(this.scaleColor)) fireStateChanged();
397  }
398
399  /**
400   * Get <code>COLOR</code> legend scale font. Only used with <code>COLOR</code>
401   * legends.
402   * @return scale font
403   */
404  public Font getScaleLabelFont() {
405    return scaleLabelFont;
406  }
407  /**
408   * Set <code>COLOR</code> legend scale font. Only used with <code>COLOR</code>
409   * legends.  Deault = ("Helvetica", PLAIN, 10).
410   * @param scaleLabelFont scale font
411   */
412  public void setScaleLabelFont(Font scaleLabelFont) {
413    Font saved = new Font(this.scaleLabelFont.getName(),
414                          this.scaleLabelFont.getStyle(),
415                          this.scaleLabelFont.getSize());
416    this.scaleLabelFont = scaleLabelFont;
417    if(!saved.equals(this.scaleLabelFont)) fireStateChanged();
418  }
419
420  /**
421   * Get <code>COLOR</code> legend scale label height in physical coordinates.
422   * Only used with <code>COLOR</code> legends.
423   * @return scale label height
424   */
425  public double getScaleLabelHeightP() {
426    return scaleLabelHeightP;
427  }
428  /**
429   * Set <code>COLOR</code> legend scale label heigth. Only used with <code>COLOR</code>
430   * legends.  Deault = 0.2.
431   * @param scaleLabelHeightP scale label height
432   */
433  public void setScaleLabelHeightP(double scaleLabelHeightP) {
434    double saved = this.scaleLargeTicHeightP;
435    this.scaleLabelHeightP = scaleLabelHeightP;
436    if(saved != this.scaleLabelHeightP) fireStateChanged();
437  }
438
439  /**
440   * Get <code>COLOR</code> legend scale label interval.
441   * Only used with <code>COLOR</code> legends.
442   * @return scale label interval
443   */
444  public int getScaleLabelInterval() {
445    return scaleLabelInterval;
446  }
447  /**
448   * Set <code>COLOR</code> legend scale label interval. Only used with <code>COLOR</code>
449   * legends.  Deault = 2.
450   * @param scaleLabelInterval scale label interval
451   */
452  public void setScaleLabelInterval(int scaleLabelInterval) {
453    int saved = this.scaleLabelInterval;
454    this.scaleLabelInterval = scaleLabelInterval;
455    if(saved != this.scaleLabelInterval) fireStateChanged();
456  }
457
458  /**
459   * Get <code>COLOR</code> legend scale number of small tics.
460   * Only used with <code>COLOR</code> legends.
461   * @return scale number of small tics
462   */
463  public int getScaleNumberSmallTics() {
464    return scaleNumberSmallTics;
465  }
466  /**
467   * Set <code>COLOR</code> legend scale number of small tics. Only used with <code>COLOR</code>
468   * legends.  Deault = 0.
469   * @param scaleNumberSmallTics scale number of small tics
470   */
471  public void setScaleNumberSmallTics(int scaleNumberSmallTics) {
472    int saved = this.scaleNumberSmallTics;
473    this.scaleNumberSmallTics = scaleNumberSmallTics;
474    if(saved != this.scaleNumberSmallTics) fireStateChanged();
475  }
476
477  /**
478   * Get <code>COLOR</code> legend scale label format.
479   * Only used with <code>COLOR</code> legends.
480   * @return scale label format
481   */
482  public String getScaleLabelFormat() {
483    return scaleLabelFormat;
484  }
485  /**
486   * Set <code>COLOR</code> legend scale label format. Only used with <code>COLOR</code>
487   * legends.  Deault = "".
488   * @param scaleLabelFormat scale label format
489   */
490  public void setScaleLabelFormat(String scaleLabelFormat) {
491    String saved = this.scaleLabelFormat;
492    this.scaleLabelFormat = scaleLabelFormat;
493    if(!saved.equals(this.scaleLabelFormat)) fireStateChanged();
494  }
495
496  /**
497   * Get <code>COLOR</code> legend scale large tick height.
498   * Only used with <code>COLOR</code> legends.
499   * @return scale large tick height
500   */
501  public double getScaleLargeTicHeightP() {
502    return scaleLargeTicHeightP;
503  }
504  /**
505   * Set <code>COLOR</code> legend scale large tick height in physical
506   * coordinates. Only used with <code>COLOR</code>
507   * legends.  Deault = 0.1.
508   * @param scaleLargeTicHeightP scale large tick height
509   */
510  public void setScaleLargeTicHeightP(double scaleLargeTicHeightP) {
511    double saved = this.scaleLargeTicHeightP;
512    this.scaleLargeTicHeightP = scaleLargeTicHeightP;
513    if(saved != this.scaleLargeTicHeightP) fireStateChanged();
514  }
515
516  /**
517   * Get <code>COLOR</code> legend scale significant digits.
518   * Only used with <code>COLOR</code> legends.
519   * @return scale significant digits
520   */
521  public int getScaleSignificantDigits() {
522    return scaleSignificantDigits;
523  }
524  /**
525   * Set <code>COLOR</code> legend scale significant digits. Only used with <code>COLOR</code>
526   * legends.  Deault = 2.
527   * @param scaleSignificantDigits scale significant digits
528   */
529  public void setScaleSignificantDigits(int scaleSignificantDigits) {
530    int saved = this.scaleSignificantDigits;
531    this.scaleSignificantDigits = scaleSignificantDigits;
532    if(saved != this.scaleSignificantDigits) fireStateChanged();
533  }
534
535  /**
536   * Get <code>COLOR</code> legend scale small tick height.
537   * Only used with <code>COLOR</code> legends.
538   * @return scale small tick height
539   */
540  public double getScaleSmallTicHeightP() {
541    return scaleSmallTicHeightP;
542  }
543  /**
544   * Set <code>COLOR</code> legend scale small tick height in physical
545   * coordinates. Only used with <code>COLOR</code>
546   * legends.  Deault = 0.05.
547   * @param scaleSmallTicHeightP scale small tick height
548   */
549  public void setScaleSmallTicHeightP(double scaleSmallTicHeightP) {
550    double saved = this.scaleSmallTicHeightP;
551    this.scaleSmallTicHeightP = scaleSmallTicHeightP;
552    if(saved != this.scaleSmallTicHeightP) fireStateChanged();
553  }
554
555  /**
556   * Test if <code>COLOR</code> legend scale visible.
557   * Only used with <code>COLOR</code> legends.
558   * @return true, if scale visible
559   */
560  public boolean isScaleVisible() {
561    return scaleVisible;
562  }
563  /**
564   * Set <code>COLOR</code> legend scale visible. Only used with <code>COLOR</code>
565   * legends.  Deault = true.
566   * @param scaleVisible scale visible
567   */
568  public void setScaleVisible(boolean scaleVisible) {
569    boolean saved = this.scaleVisible;
570    this.scaleVisible = scaleVisible;
571    if(saved != this.scaleVisible) fireStateChanged();
572  }
573
574  /**
575   * Get <code>PanelHolder</code> parent.
576   * @return panelholder
577   */
578  public PanelHolder getPanelHolder() {
579    return pHolder_;
580  }
581  /**
582   * Set <code>PanelHolder</code> parent.
583   * @param pHolder panelholder
584   */
585  public void setPanelHolder(PanelHolder pHolder) {
586    pHolder_ = pHolder;
587  }
588
589  /**
590   * Get key label height.
591   * @return key label height
592   */
593  public double getKeyLabelHeightP() {
594    return keyLabelHeightP;
595  }
596  /**
597   * Set key label height in physical coordinates.
598   * Default = 0.16.
599   * @param keyLabelHeightP key label height
600   */
601  public void setKeyLabelHeightP(double keyLabelHeightP) {
602    double saved = this.keyLabelHeightP;
603    this.keyLabelHeightP = keyLabelHeightP;
604    if(saved != this.keyLabelHeightP) fireStateChanged();
605  }
606}
Note: See TracBrowser for help on using the repository browser.