source: ether_megapoli/trunk/service/implementation/gov2/noaa/pmel/sgt/CartesianRenderer.java @ 192

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

Servlet _ Contour en cours _ package gov2

File size: 6.2 KB
Line 
1/*
2 * $Id: CartesianRenderer.java,v 1.13 2003/08/22 23:02:31 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.SGTData;
16import gov.noaa.pmel.sgt.dm.SGTPoint;
17import gov.noaa.pmel.sgt.dm.SGTLine;
18import gov.noaa.pmel.sgt.dm.SGTGrid;
19import gov.noaa.pmel.sgt.dm.SGTImage;
20import gov.noaa.pmel.sgt.dm.Collection;
21import gov.noaa.pmel.sgt.dm.SGTVector;
22import gov.noaa.pmel.sgt.dm.Annotation;
23
24import gov.noaa.pmel.util.Debug;
25
26import java.awt.Graphics;
27import java.awt.Rectangle;
28import java.awt.Point;
29import java.beans.PropertyChangeListener;
30
31/**
32 * <code>CartesianRenderer</code> defines an interface to enable data to
33 * be rendered on a <code>CartesianGraph</code>.
34 *
35 * @see CartesianGraph
36 *
37 * @author Donald Denbo
38 * @version $Revision: 1.13 $, $Date: 2003/08/22 23:02:31 $
39 * @since 1.0
40 */
41public abstract class CartesianRenderer implements PropertyChangeListener {
42  /**
43   * Factory method to create a new Renderer instance given
44   * the <code>SGTData</code> object and <code>Attribute</code>.
45   * For example, a <code>LineCartesianRenderer</code>
46   * is created if <code>SGTData</code> object is a <code>SGTLine</code>.
47   * <p>
48   * A renderer is constucted based on the two arguements.
49   * <p>
50   * <TABLE BORDER="1" CELLPADDING="2" BGCOLOR="white">
51   *    <TR>
52   *            <TH WIDTH="25%" BGCOLOR="#FFFFCC">
53   *                    <P>SGTData
54   *            </TH>
55   *            <TH WIDTH="25%" BGCOLOR="#FFFFCC">
56   *                    <P>Attribute
57   *            </TH>
58   *            <TH WIDTH="50%" BGCOLOR="#FFFFCC">
59   *                    <P>CartesianRenderer
60   *            </TH>
61   *    </TR>
62   *    <TR>
63   *            <TD WIDTH="25%">SGTPoint</TD>
64   *            <TD WIDTH="25%">PointAttribute</TD>
65   *            <TD WIDTH="50%">PointCartesianRenderer</TD>
66   *    </TR>
67   *    <TR>
68   *            <TD WIDTH="25%">SGTLine</TD>
69   *            <TD WIDTH="25%">LineAttribute</TD>
70   *            <TD WIDTH="50%">LineCartesianRenderer</TD>
71   *    </TR>
72   *    <TR>
73   *            <TD WIDTH="25%">SGTGrid</TD>
74   *            <TD WIDTH="25%">GridAttribute</TD>
75   *            <TD WIDTH="50%">GridCartesianRenderer</TD>
76   *    </TR>
77   *    <TR>
78   *            <TD WIDTH="25%">SGTVector</TD>
79   *            <TD WIDTH="25%">VectorAttribute</TD>
80   *            <TD WIDTH="50%">VectorCartesianRenderer</TD>
81   *    </TR>
82   *    <TR>
83   *            <TD WIDTH="25%">Collection</TD>
84   *            <TD WIDTH="25%">PointAttribute</TD>
85   *            <TD WIDTH="50%">PointCartesianRenderer</TD>
86   *    </TR>
87   *    <TR>
88   *            <TD WIDTH="25%">Collection</TD>
89   *            <TD WIDTH="25%">LineAttribute</TD>
90   *            <TD WIDTH="50%">LineCartesianRenderer</TD>
91   *    </TR>
92   *    <TR>
93   *            <TD WIDTH="25%">Collection</TD>
94   *            <TD WIDTH="25%">VectorAttribute</TD>
95   *            <TD WIDTH="50%">VectorCartesianRenderer</TD>
96   *    </TR>
97   *    <TR>
98   *            <TD WIDTH="25%">Annotation</TD>
99   *            <TD WIDTH="25%">n/a</TD>
100   *            <TD WIDTH="50%">AnnotationCartesianRenderer</TD>
101   *    </TR>
102   *</TABLE>
103   *<p>
104   *
105   * @param dmo DataModel object
106   */
107  public static CartesianRenderer getRenderer(CartesianGraph cg,
108                                              SGTData dmo,
109                                              Attribute attr) {
110    if(dmo instanceof SGTPoint) {
111      return new PointCartesianRenderer(cg,
112                                        (SGTPoint)dmo,
113                                        (PointAttribute)attr);
114    } else if(dmo instanceof SGTLine) {
115      return new LineCartesianRenderer(cg,
116                                       (SGTLine)dmo,
117                                       (LineAttribute)attr);
118    } else if(dmo instanceof SGTGrid) {
119      return new GridCartesianRenderer(cg,
120                                       (SGTGrid)dmo,
121                                       (GridAttribute)attr);
122    } else if(dmo instanceof SGTVector) {
123      return new VectorCartesianRenderer(cg,
124                                         (SGTVector)dmo,
125                                         (VectorAttribute)attr);
126    } else if(dmo instanceof Collection) {
127      Object fe = ((Collection)dmo).firstElement();
128      if(fe instanceof SGTPoint) {
129        return new PointCartesianRenderer(cg,
130                                          (Collection)dmo,
131                                          (PointAttribute)attr);
132      } else if(fe instanceof SGTLine) {
133        return new LineCartesianRenderer(cg,
134                                         (Collection)dmo,
135                                         (LineAttribute)attr);
136      } else if(fe instanceof SGTVector) {
137        return new VectorCartesianRenderer(cg,
138                                           (Collection)dmo,
139                                           (VectorAttribute)attr);
140      }
141    } else if(dmo instanceof Annotation) {
142      return new AnnotationCartesianRenderer(cg,
143                                             (Annotation)dmo,
144                                             null);
145    }
146    return null;
147  }
148  /**
149   * Render the <code>SGTData</code> object. This method should
150   * never be called directly.
151   *
152   * @see Pane#draw
153   */
154  public abstract void draw(Graphics g);
155  /**
156   * Get the <code>Attribute</code> associated with the
157   * renderer.
158   *
159   * @return the <code>Attribute</code>
160   */
161  public abstract Attribute getAttribute();
162  /**
163   * Get the <code>CartesianGraph</code> associated with the
164   * renderer.
165   * @since 2.0
166   *
167   * @return the <code>CartesianGraph</code>
168   */
169  public abstract CartesianGraph getCartesianGraph();
170/** @directed
171 * @label cg*/
172  protected CartesianGraph cg_;
173  /**
174   * Get parent pane.
175   * @since 2.0
176   */
177  public AbstractPane getPane() {
178    return cg_.getPane();
179  }
180  /**
181   * For internal sgt use.
182   * @since 2.0
183   */
184  public void modified(String mess) {
185    if(cg_ != null)
186      cg_.modified(mess);
187  }
188  /**
189   * Find data object.
190   * @since 3.0
191   */
192  public SGTData getDataAt(int x, int y) {
193    return getDataAt(new Point(x, y));
194  }
195  /**
196   * Find data object.
197   * @since 3.0
198   */
199  public abstract SGTData getDataAt(Point pt);
200}
201
202
Note: See TracBrowser for help on using the repository browser.