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

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

Nouveau projet

File size: 11.5 KB
Line 
1/*
2 * $Id: DataGroup.java,v 1.2 2003/08/22 23:02:33 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 java.awt.Insets;
16import java.awt.Point;
17import java.awt.Rectangle;
18import java.awt.Graphics;
19import java.awt.Color;
20
21import gov.noaa.pmel.sgt.AxisTransform;
22import gov.noaa.pmel.sgt.Axis;
23import gov.noaa.pmel.sgt.PlainAxis;
24import gov.noaa.pmel.sgt.TimeAxis;
25import gov.noaa.pmel.sgt.LinearTransform;
26import gov.noaa.pmel.util.SoTPoint;
27import gov.noaa.pmel.util.SoTRange;
28import gov.noaa.pmel.util.Range2D;
29import gov.noaa.pmel.util.Rectangle2D;
30import javax.swing.event.*;
31import java.util.*;
32import java.io.*;
33import java.beans.*;
34
35/**
36 * A holder for the X and Y transforms and optionally references to the
37 * X and Y axes for a <code>CartesianGraph</code>.  This class is used with <code>DataModel</code>
38 * and <code>Panel</code>.
39 *
40 * @author Donald Denbo
41 * @version $Revision: 1.2 $, $Date: 2003/08/22 23:02:33 $
42 * @since 3.0
43 **/
44public class DataGroup implements Serializable, ChangeListener {
45  // axis position
46  /**
47   * X axis placed at top of <code>DataGroup</code> area.
48   */
49  public static final int TOP = 0;
50  /**
51   * X axis placed at bottom of <code>DataGroup</code> area.
52   */
53  public static final int BOTTOM = 1;
54  /**
55   * Y axis placed left of <code>DataGroup</code> area.
56   */
57  public static final int LEFT = 2;
58  /**
59   * Y axis placed right of <code>DataGroup</code> area.
60   */
61  public static final int RIGHT = 3;
62  /**
63   * Axes placed in default locations.
64   */
65  public static final int MANUAL = 4;
66  // axis transform / axis type
67  /**
68   * Linear transform type.
69   */
70  public static final int LINEAR = 0;
71  /**
72   * Log transform type.
73   */
74  public static final int LOG = 1;
75  /**
76   * Refer to a transform in another <code>DataGroup</code>.
77   */
78  public static final int REFERENCE = 2;
79  /**
80   * Time axis type.
81   */
82  public static final int TIME = 3;
83  /**
84   * Plain linear axis type.
85   */
86  public static final int PLAIN = 4;
87  //
88  /**
89   * X direction.
90   */
91  public static final int X_DIR = 0;
92  /**
93   * Y direction.
94   */
95  public static final int Y_DIR = 1;
96  //
97  private String id = "";
98  //
99  /**
100   * @label margin
101   */
102  private Margin margin = new Margin(0.25f, 0.5f, 0.5f, 0.25f);
103  private boolean zoomable = true;
104  //
105  /**
106   * @label xAxisHolder
107   * @supplierCardinality 1
108   * @undirected
109   * @link aggregation
110   */
111  private AxisHolder xAxisHolder_ = new AxisHolder(PLAIN, X_DIR, this);
112  /**
113   * @label yAxisHolder
114   * @link aggregation
115   * @undirected
116   * @supplierCardinality 1
117   */
118  private AxisHolder yAxisHolder_ = new AxisHolder(PLAIN, Y_DIR, this);
119  //
120  private boolean zAutoScale = true;
121  private SoTRange zRangeU = new SoTRange.Double(0.0, 1.0, 0.1);
122  private int numberAutoContourLevels = 10;
123  //
124  /**
125   * @label pHolder
126   */
127  private PanelHolder pHolder_ = null;
128  transient private Vector changeListeners;
129  transient private ChangeEvent changeEvent_ = new ChangeEvent(this);
130  transient private boolean instantiated = false;
131
132  static {
133    try {
134      BeanInfo info = Introspector.getBeanInfo(DataGroup.class);
135      PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
136      for(int i=0; i < descriptors.length; i++) {
137        PropertyDescriptor pd = descriptors[i];
138        if(pd.getName().equals("instantiated")) {
139          pd.setValue("transient", Boolean.TRUE);
140        } else if(pd.getName().equals("panelHolder")) {
141          pd.setValue("transient", Boolean.TRUE);
142        }
143      }
144    } catch (IntrospectionException ie) {
145     ie.printStackTrace();
146    }
147  }
148  /**
149   * Default constructor.  <code>PanelHodler</code> is set to <code>null</code>.
150   * X and Y transforms are LINEAR and axes PLAIN.
151   */
152  public DataGroup() {
153    this("Default Id", null);
154  }
155  /**
156   * Simple constructor.  X and Y transforms are LINEAR and axes PLAIN.
157   * @param id data group id
158   * @param ph panelholder parent
159   */
160  public DataGroup(String id, PanelHolder ph) {
161    this(id, ph,
162         LINEAR, PLAIN,
163         LINEAR, PLAIN);
164  }
165  /**
166   * Full constructor.
167   * @param id data group id
168   * @param ph panelholder parent
169   * @param xt x transform type
170   * @param xAxis x axis type
171   * @param yt y transform type
172   * @param yAxis y axis type
173   */
174  public DataGroup(String id, PanelHolder ph,
175                   int xt, int xAxis,
176                   int yt, int yAxis) {
177    this.id = id;
178    pHolder_ = ph;
179    if(xAxisHolder_ == null) {
180      xAxisHolder_ = new AxisHolder(xAxis, X_DIR, this);
181    } else {
182      xAxisHolder_.setAxisType(xAxis);
183      xAxisHolder_.setAxisOrientation(X_DIR);
184      xAxisHolder_.setDataGroup(this);
185    }
186    xAxisHolder_.setTransformType(xt);
187    xAxisHolder_.addChangeListener(this);
188    if(yAxisHolder_ == null) {
189      yAxisHolder_ = new AxisHolder(yAxis, Y_DIR, this);
190    } else {
191      yAxisHolder_.setAxisType(yAxis);
192      yAxisHolder_.setAxisOrientation(Y_DIR);
193      yAxisHolder_.setDataGroup(this);
194    }
195    yAxisHolder_.setTransformType(yt);
196    yAxisHolder_.addChangeListener(this);
197  }
198  /**
199   * Set panelhodler parent.
200   * @param ph panelholder parent
201   */
202  public void setPanelHolder(PanelHolder ph) {
203    if(pHolder_ != null) removeChangeListener(pHolder_);
204    pHolder_ = ph;
205    addChangeListener(pHolder_);
206  }
207  /**
208   * Get parent.
209   * @return panelholder parent
210   */
211  public PanelHolder getPanelHolder() {
212    return pHolder_;
213  }
214  /**
215   * Get X axisholder
216   * @return x axisholder
217   */
218  public AxisHolder getXAxisHolder() {
219    return xAxisHolder_;
220  }
221  /**
222   * Set X axisholder
223   * @param xah x axisholder
224   */
225  public void setXAxisHolder(AxisHolder xah) {
226    xAxisHolder_ = xah;
227    xAxisHolder_.addChangeListener(this);
228  }
229  /**
230   * Get Y axisholder.
231   * @return y axisholder
232   */
233  public AxisHolder getYAxisHolder() {
234    return yAxisHolder_;
235  }
236  /**
237   * Set Y axisholder
238   * @param yah y axisholder
239   */
240  public void setYAxisHolder(AxisHolder yah) {
241    yAxisHolder_ = yah;
242    yAxisHolder_.addChangeListener(this);
243  }
244  /**
245   * Get datagroup id.
246   * @return datagroup id
247   */
248  public String getId() {
249    return id;
250  }
251  /**
252   * Set datagroup id.
253   * @param id datagroup id
254   */
255  public void setId(String id) {
256    String saved = this.id;
257    this.id = id;
258    if(!saved.equals(this.id)) fireStateChanged();
259  }
260  /**
261   * Get the margin.
262   * @return margin
263   */
264  public Margin getMargin() {
265    return (Margin)margin.copy();
266  }
267  /**
268   * Set the margin.  The margin is used to automatically place the axes in a
269   * <code>Panel</code>.  The margin is the distance from each edge of the
270   * <code>Panel</code> to the <code>DataGroup</code>.
271   * Default is (0.25f, 0.5f, 0.5f, 0.25f)
272   * @param margin margin
273   */
274  public void setMargin(Margin margin) {
275   Margin saved = this.margin;
276    this.margin = margin;
277    if(!saved.equals(this.margin)) fireStateChanged();
278  }
279  /**
280   * Set the Margin. Default is (0.25f, 0.5f, 0.5f, 0.25f)
281   * @param top top margin
282   * @param left left margin
283   * @param bottom bottom margin
284   * @param right right margin
285   */
286  public void setMargin(float top, float left, float bottom, float right) {
287    Margin saved = margin;
288    margin = new Margin(top, left, bottom, right);
289    if(!saved.equals(margin)) fireStateChanged();
290  }
291  /**
292   * Remove all <code>ChangeListener</code>s.
293   */
294  public void removeAllChangeListeners() {
295    changeListeners = null;
296  }
297  /**
298   * Set auto Z scale.  Auto Z scale is only effective for grids. Default = true.
299   * @param zAutoScale autoscale if true
300   */
301  public void setZAutoScale(boolean zAutoScale) {
302    boolean saved = this.zAutoScale;
303    this.zAutoScale = zAutoScale;
304    if(saved != zAutoScale) fireStateChanged();
305  }
306  /**
307   * Is auto Z scale?
308   * @return true, if auto z scale
309   */
310  public boolean isZAutoScale() {
311    return zAutoScale;
312  }
313  /**
314   * Set Z range, user units.  Only used if Auto Z Scale is false. Default =
315   * (0, 1, 0.1).
316   * @param zRange Z range
317   */
318  public void setZRangeU(SoTRange zRange) {
319    zRangeU = zRange;
320  }
321  /**
322   * Get Z range.
323   * @return Z range
324   */
325  public SoTRange getZRangeU() {
326    return zRangeU;
327  }
328  /**
329   * Set datagroup zoomable.  If true, datagroup can be zoomed using the mouse.
330   * Default = true.
331   * @param zoomable datagroup zoomable
332   */
333  public void setZoomable(boolean zoomable) {
334    boolean saved = this.zoomable;
335    this.zoomable = zoomable;
336    if(saved != this.zoomable) fireStateChanged();
337  }
338  /**
339   * Is datagroup zoomable?
340   * @return true, if datagroup zoomable
341   */
342  public boolean isZoomable() {
343    return zoomable;
344  }
345  /**
346   * Remove changelistener.
347   * @param l changelistener
348   */
349  public synchronized void removeChangeListener(ChangeListener l) {
350    if (changeListeners != null && changeListeners.contains(l)) {
351      Vector v = (Vector) changeListeners.clone();
352      v.removeElement(l);
353      changeListeners = v;
354    }
355  }
356  /**
357   * Add changelistener
358   * @param l changelistener
359   */
360  public synchronized void addChangeListener(ChangeListener l) {
361    Vector v = changeListeners == null ? new Vector(2) : (Vector) changeListeners.clone();
362    if (!v.contains(l)) {
363      v.addElement(l);
364      changeListeners = v;
365    }
366  }
367  /**
368   * Remove all <code>ChangeListener</code>s that implement the
369   * <code>DesignListener</code> interface.
370   *
371   * @see DesignListener
372   */
373  public synchronized void removeDesignChangeListeners() {
374    if(changeListeners != null) {
375      Vector v = (Vector) changeListeners.clone();
376      Iterator iter = v.iterator();
377      while(iter.hasNext()) {
378        Object obj = iter.next();
379        if(obj instanceof DesignListener) changeListeners.removeElement(obj);
380      }
381    }
382  }
383
384  protected void fireStateChanged() {
385    if (changeListeners != null) {
386      Vector listeners = changeListeners;
387      int count = listeners.size();
388      for (int i = 0; i < count; i++) {
389        ((ChangeListener) listeners.elementAt(i)).stateChanged(changeEvent_);
390      }
391    }
392  }
393  /**
394   * Set instantiated.  Once associated <code>DataGroupLayer</code> object has been created
395   * this property is set true.  Used internally.
396   * @param instantiated true if instantiated
397   */
398  public void setInstantiated(boolean instantiated) {
399    this.instantiated = instantiated;
400  }
401  /**
402   * Is datagrouplayer instantiated?
403   * @return true, if datagrouplayer instantiated
404   */
405  public boolean isInstantiated() {
406    return instantiated;
407  }
408  /**
409   * <code>ChangeListner</code> callback.
410   * @param e ChangeEvent
411   */
412  public void stateChanged(ChangeEvent e) {
413    fireStateChanged();
414  }
415  /**
416   * Get number of auto contour levels.  Valid for grid type data only.
417   * @return number of auto contour levels
418   */
419  public int getNumberAutoContourLevels() {
420    return numberAutoContourLevels;
421  }
422  /**
423   * Set number of auto contour levels. Valid for grid type data only.
424   * @param numberAutoContourLevels number of contour levels
425   */
426  public void setNumberAutoContourLevels(int numberAutoContourLevels) {
427    int saved = this.numberAutoContourLevels;
428    this.numberAutoContourLevels = numberAutoContourLevels;
429    if(saved != this.numberAutoContourLevels) fireStateChanged();
430  }
431}
Note: See TracBrowser for help on using the repository browser.