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

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

Nouveau projet

File size: 9.1 KB
Line 
1/*
2 * $Id: PointCartesianRenderer.java,v 1.16 2003/08/22 23:02:32 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 gov.noaa.pmel.sgt.dm.SGTPoint;
16import gov.noaa.pmel.sgt.dm.Collection;
17import gov.noaa.pmel.sgt.dm.SGTData;
18
19import gov.noaa.pmel.util.Point2D;
20import gov.noaa.pmel.util.Debug;
21
22import java.util.Vector;
23import java.util.Enumeration;
24import java.awt.Graphics;
25import java.awt.Event;
26import java.awt.Point;
27import java.awt.Color;
28import java.awt.Rectangle;
29import java.beans.PropertyChangeEvent;
30
31/**
32 * Produces a point plot with optional coloring from a second data set. If
33 * a second data set is specified it must have the same shape as the first.
34 *
35 * @author Donald Denbo
36 * @version $Revision: 1.16 $, $Date: 2003/08/22 23:02:32 $
37 * @since 2.0
38 */
39public class PointCartesianRenderer extends CartesianRenderer {
40  /**@shapeType AggregationLink
41   * @label attr
42   * @supplierCardinality 1
43   * @undirected */
44  private PointAttribute attr_ = null;
45  /**@shapeType AggregationLink
46   * @supplierCardinality 0..1
47   * @label point
48   * @undirected */
49  private SGTPoint point_ = null;
50  /**@shapeType AggregationLink
51   * @supplierCardinality 0..1 */
52  private Collection collection_ = null;
53
54  /**
55   * Get the Attribute associated with the data.
56   */
57  public Attribute getAttribute() {
58    return attr_;
59  }
60  private void drawPoint(Graphics g, SGTPoint point, PlotMark pm) {
61    int xp, yp;
62
63    if(pm.getMark() == 0) return;
64
65    if(point.isXTime()) {
66      xp = cg_.getXUtoD(point.getLongTime());
67    } else {
68      xp = cg_.getXUtoD(point.getX());
69    }
70    if(point.isYTime()) {
71      yp = cg_.getYUtoD(point.getLongTime());
72    } else {
73      yp = cg_.getYUtoD(point.getY());
74    }
75    //
76    // check for missing values a Double.NaN is converted to a Integer.MIN_VALUE
77    //
78    if(xp == Integer.MIN_VALUE || yp == Integer.MIN_VALUE) {
79      return;
80    }
81    //
82    // draw regular point
83    //
84    pm.paintMark(g, cg_.getLayer(), xp, yp);
85  }
86  private void drawLabel(Graphics g, SGTPoint point, PointAttribute attr) {
87    int valign,  halign;
88    Point2D.Double loc;
89    double xp, yp;
90    double xl, yl, loff;
91    Layer ly = cg_.getLayer();
92
93    if(point.isXTime()) {
94      xp = cg_.getXUtoP(point.getLongTime());
95    } else {
96      xp = cg_.getXUtoP(point.getX());
97    }
98    if(point.isYTime()) {
99      yp = cg_.getYUtoP(point.getLongTime());
100    } else {
101      yp = cg_.getYUtoP(point.getY());
102    }
103
104    loff = attr.getMarkHeightP()/2.0;
105    xl = 0.0;
106    yl = 0.0;
107    switch(attr.getLabelPosition()) {
108    case PointAttribute.CENTERED:
109      valign = SGLabel.MIDDLE;
110      halign = SGLabel.CENTER;
111      break;
112    case PointAttribute.N:
113      valign = SGLabel.BOTTOM;
114      halign = SGLabel.CENTER;
115      yl = loff;
116      break;
117    default:
118    case PointAttribute.NE:
119      valign = SGLabel.BOTTOM;
120      halign = SGLabel.LEFT;
121      yl = loff;
122      xl = loff;
123      break;
124    case PointAttribute.E:
125      valign = SGLabel.MIDDLE;
126      halign = SGLabel.LEFT;
127      xl = loff;
128      break;
129    case PointAttribute.SE:
130      valign = SGLabel.TOP;
131      halign = SGLabel.LEFT;
132      yl = -loff;
133      xl = loff;
134      break;
135    case PointAttribute.S:
136      valign = SGLabel.TOP;
137      halign = SGLabel.CENTER;
138      yl = -loff;
139      break;
140    case PointAttribute.SW:
141      valign = SGLabel.TOP;
142      halign = SGLabel.RIGHT;
143      yl = -loff;
144      xl = -loff;
145      break;
146    case PointAttribute.W:
147      valign = SGLabel.MIDDLE;
148      halign = SGLabel.RIGHT;
149      xl = -loff;
150      break;
151    case PointAttribute.NW:
152      valign = SGLabel.BOTTOM;
153      halign = SGLabel.RIGHT;
154      yl = loff;
155      xl = -loff;
156      break;
157    }
158    SGLabel pl = new SGLabel("point",
159                             point.getTitle(),
160                             attr.getLabelHeightP(),
161                             new Point2D.Double(xp + xl, yp + yl),
162                             valign,
163                             halign);
164    pl.setColor(attr.getLabelColor());
165    pl.setFont(attr.getLabelFont());
166    pl.setLayer(ly);
167    try {
168      pl.draw(g);
169    } catch (LayerNotFoundException e) {}
170
171  }
172  /**
173   * Default constructor.
174   *
175   * @see CartesianGraph
176   * @see Graph
177   **/
178  public PointCartesianRenderer(CartesianGraph cg) {
179    this(cg, (SGTPoint)null, null);
180  }
181  /**
182   * Construct a PointCartesianRenderer. The default
183   * PointAttribute will be used.
184   *
185   * @param cg the parent CartesianGraph
186   * @param data an SGTPoint object
187   *
188   * @see CartesianGraph
189   * @see Graph
190   **/
191  public PointCartesianRenderer(CartesianGraph cg, SGTPoint point) {
192    this(cg, point, null);
193    cg_ = cg;
194    point_ = point;
195  }
196  /**
197   * Construct a PointCartesianRenderer.
198   *
199   * @param cg the parent CartesianGraph
200   * @param data an SGTPoint object
201   * @param Point the PointAttribute
202   * @see CartesianGraph
203   * @see Graph
204   **/
205  public PointCartesianRenderer(CartesianGraph cg, SGTPoint point, PointAttribute attr) {
206    cg_ = cg;
207    point_ = point;
208    attr_ = attr;
209    if(attr_ != null) attr_.addPropertyChangeListener(this);
210  }
211  /**
212   * Construct a PointCartesianRenderer.
213   *
214   * @param cg the parent CartesianGraph
215   * @param col a Collection of SGTPoint objects
216   * @param point the PointAttribute
217   * @see CartesianGraph
218   * @see Graph
219   **/
220  public PointCartesianRenderer(CartesianGraph cg, Collection col, PointAttribute attr) {
221    cg_ = cg;
222    collection_ = col;
223    attr_ = attr;
224    if(attr_ != null) attr_.addPropertyChangeListener(this);
225  }
226  public void draw(Graphics g) {
227    PointAttribute attr;
228    Object point;
229    PlotMark pm;
230
231    if(cg_.clipping_) {
232      int xmin, xmax, ymin, ymax;
233      int x, y, width, height;
234      if(cg_.xTransform_.isSpace()) {
235        xmin = cg_.getXUtoD(cg_.xClipRange_.start);
236        xmax = cg_.getXUtoD(cg_.xClipRange_.end);
237      } else {
238        xmin = cg_.getXUtoD(cg_.tClipRange_.start);
239        xmax = cg_.getXUtoD(cg_.tClipRange_.end);
240      }
241      if(cg_.yTransform_.isSpace()) {
242        ymin = cg_.getYUtoD(cg_.yClipRange_.start);
243        ymax = cg_.getYUtoD(cg_.yClipRange_.end);
244      } else {
245        ymin = cg_.getYUtoD(cg_.tClipRange_.start);
246        ymax = cg_.getYUtoD(cg_.tClipRange_.end);
247      }
248      if(xmin < xmax) {
249        x = xmin;
250        width = xmax - xmin;
251      } else {
252        x=xmax;
253        width = xmin - xmax;
254      }
255      if(ymin < ymax) {
256        y = ymin;
257        height = ymax - ymin;
258      } else {
259        y = ymax;
260        height = ymin - ymax;
261      }
262      g.setClip(x, y, width, height);
263    }
264    if(attr_ == null) {
265      attr = new PointAttribute(2,
266                                cg_.layer_.getPane().getComponent().getForeground());
267    } else {
268      attr = attr_;
269    }
270    pm = new PlotMark(attr);
271    if(collection_ == null) {
272      g.setColor(attr.getColor());
273      drawPoint(g, point_, pm);
274      if(attr.isDrawLabel()) drawLabel(g, point_, attr);
275    } else {
276      for(Enumeration li = collection_.elements(); li.hasMoreElements();) {
277        point = li.nextElement();
278        if(point instanceof SGTPoint) {
279          g.setColor(attr.getColor());
280          drawPoint(g, (SGTPoint)point, pm);
281          if(attr.isDrawLabel()) drawLabel(g, (SGTPoint)point, attr);
282        }
283      }
284    }
285
286    //
287    // reset clip
288    //
289    Rectangle rect = cg_.getLayer().getPane().getBounds();
290    g.setClip(rect);
291  }
292  /**
293   * Set the Point attribute object. The Point appearance is controlled by
294   * this object.
295   *
296   * @param l Point attribute
297   **/
298  public void setPointAttribute(PointAttribute l) {
299    if(attr_ != null) attr_.removePropertyChangeListener(this);
300    attr_ = l;
301    if(attr_ != null) attr_.addPropertyChangeListener(this);
302  }
303  /**
304   * Get the Point attribute object.
305   *
306   * @return Point attribute
307   **/
308  public PointAttribute getPointAttribute() {
309    return attr_;
310  }
311  /**
312   * Is point data as a collection?
313   */
314  public boolean hasCollection() {
315    return (collection_ != null);
316  }
317  /**
318   * Get the <code>Collection</code> of points.
319   */
320  public Collection getCollection() {
321    return collection_;
322  }
323  public SGTPoint getPoint() {
324    return point_;
325  }
326  /**
327   * Get the associated <code>CartesianGraph</code> object.
328   *
329   * @return <code>CartesianGraph</code>
330   */
331  public CartesianGraph getCartesianGraph() {
332    return cg_;
333  }
334
335  public void propertyChange(PropertyChangeEvent evt) {
336//      if(Debug.EVENT) {
337//        System.out.println("PointCartesianRenderer: " + evt);
338//        System.out.println("                        " + evt.getPropertyName());
339//      }
340    modified("PointCartesianRenderer: propertyChange(" +
341             evt.getSource().toString() + "[" +
342             evt.getPropertyName() + "]" + ")");
343  }
344  /**
345   * @since 3.0
346   */
347  public SGTData getDataAt(Point pt) {
348    return null;
349  }
350}
Note: See TracBrowser for help on using the repository browser.