source: ether_megapoli/trunk/applets/src/gov/noaa/pmel/sgt/demo/JPointDemo.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: 7.4 KB
Line 
1/*
2 * $Id: JPointDemo.java,v 1.7 2001/02/06 00:14:35 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 */
12package gov.noaa.pmel.sgt.demo;
13
14import gov.noaa.pmel.sgt.JPane;
15import gov.noaa.pmel.sgt.Layer;
16import gov.noaa.pmel.sgt.PlainAxis;
17import gov.noaa.pmel.sgt.LineKey;
18import gov.noaa.pmel.sgt.LinearTransform;
19import gov.noaa.pmel.sgt.Graph;
20import gov.noaa.pmel.sgt.CartesianGraph;
21import gov.noaa.pmel.sgt.SGLabel;
22import gov.noaa.pmel.sgt.PointAttribute;
23import gov.noaa.pmel.sgt.LineCartesianRenderer;
24import gov.noaa.pmel.sgt.StackedLayout;
25import gov.noaa.pmel.sgt.Axis;
26import gov.noaa.pmel.sgt.swing.JClassTree;
27import gov.noaa.pmel.sgt.Logo;
28
29import gov.noaa.pmel.sgt.dm.Collection;
30
31import gov.noaa.pmel.util.Point2D;
32import gov.noaa.pmel.util.Range2D;
33import gov.noaa.pmel.util.Dimension2D;
34
35import java.awt.*;
36import javax.swing.*;
37
38/**
39 * Example demonstrating the creation of a simple
40 * graph of many points.
41 *
42 * @author Donald Denbo
43 * @version $Revision: 1.7 $, $Date: 2001/02/06 00:14:35 $
44 * @since 2.0
45 */
46
47public class JPointDemo extends JApplet {
48    JButton tree_;
49    JButton space_;
50    JPane mainPane_;
51 
52  public void init() {
53    setLayout(new BorderLayout(0,0));
54    setSize(553,438);
55
56    add(makeGraph(), BorderLayout.CENTER);
57  }
58
59  public static void main(String[] args) {
60    JPointDemo pd = new JPointDemo();
61    JFrame frame = new JFrame("Point Demo");
62    JPanel button = new JPanel();
63    JPane graph;
64    button.setLayout(new FlowLayout());
65    pd.tree_ = new JButton("Tree View");
66    MyAction myAction = pd. new MyAction();
67    pd.tree_.addActionListener(myAction);
68    button.add(pd.tree_);
69    pd.space_ = new JButton("Add Mark");
70    pd.space_.addActionListener(myAction);
71    button.add(pd.space_);
72    frame.getContentPane().setLayout(new BorderLayout());
73    frame.addWindowListener(new java.awt.event.WindowAdapter() {
74      public void windowClosing(java.awt.event.WindowEvent event) {
75        JFrame fr = (JFrame)event.getSource();
76        fr.setVisible(false);
77        fr.dispose();
78        System.exit(0);
79      }
80    });
81    frame.setSize(553,438);
82    graph = pd.makeGraph();
83    graph.setBatch(true);
84    frame.getContentPane().add(graph, BorderLayout.CENTER);
85    frame.getContentPane().add(button, BorderLayout.SOUTH);
86    frame.pack();
87    frame.setVisible(true);
88    graph.setBatch(false);
89  }
90
91  JPane makeGraph() {
92    /*
93     * This example creates a very simple plot from
94     * scratch (not using one of the sgt.awt classes)
95     * to display a Collection of points.
96     */
97    /*
98     * Create a Pane, place in the center of the Applet
99     * and set the layout to be StackedLayout.
100     */
101    mainPane_ = new JPane("Point Plot Demo", new Dimension(553,438));
102    mainPane_.setLayout(new StackedLayout());
103    mainPane_.setBackground(Color.white);
104    /*
105     * Create a Collection of points using the TestData class.
106     */
107    Range2D xrange, yrange;
108    TestData td;
109    Collection col;
110    xrange = new Range2D(50.0, 150., 10.0);
111    yrange = new Range2D(-20.0, 20.0, 5.0);
112    td = new TestData(xrange, yrange, 50);
113    col = td.getCollection();
114    /*
115     * xsize, ysize are the width and height in physical units
116     * of the Layer graphics region.
117     *
118     * xstart, xend are the start and end points for the X axis
119     * ystart, yend are the start and end points for the Y axis
120     */
121    double xsize = 4.0;
122    double xstart = 0.6;
123    double xend = 3.5;
124    double ysize = 3.0;
125    double ystart = 0.6;
126    double yend = 2.75;
127    /*
128     * Create the layer and add it to the Pane.
129     */
130    Layer layer;
131
132    layer = new Layer("Layer 1", new Dimension2D(xsize, ysize));
133    mainPane_.add(layer);
134    /*
135    * create and add image as a Logo to the layer
136    */
137    Image img = this.getToolkit().getImage(getClass().getResource("ncBrowse48.gif"));
138    //
139    // wait for image to be loaded
140    //
141    if(img != null) {
142      MediaTracker mt = new MediaTracker(this);
143      try {
144        mt.addImage(img, 0);
145        mt.waitForAll();
146        if(mt.isErrorAny())
147          System.err.println("JPointDemo: Error loading image");
148      } catch (InterruptedException e) {}
149    }
150    Logo logo = new Logo(new Point2D.Double(0.0, 0.0), Logo.BOTTOM, Logo.LEFT);
151    logo.setId("ncBrowse logo");
152    logo.setImage(img);
153    layer.addChild(logo);
154    /*
155     * Create a CartesianGraph and transforms.
156     */
157    CartesianGraph graph;
158    LinearTransform xt, yt;
159
160    graph = new CartesianGraph("Point Graph");
161    layer.setGraph(graph);
162    xt = new LinearTransform(xstart, xend, xrange.start, xrange.end);
163    yt = new LinearTransform(ystart, yend, yrange.start, yrange.end);
164    graph.setXTransform(xt);
165    graph.setYTransform(yt);
166    /*
167     * Create the bottom axis, set its range in user units
168     * and its origin. Add the axis to the graph.
169     */
170    PlainAxis xbot;
171    String xLabel = "X Label";
172
173    xbot = new PlainAxis("Botton Axis");
174    xbot.setRangeU(xrange);
175    xbot.setLocationU(new Point2D.Double(xrange.start, yrange.start));
176    Font xbfont = new Font("Helvetica", Font.ITALIC, 14);
177    xbot.setLabelFont(xbfont);
178    SGLabel xtitle = new SGLabel("xaxis title", xLabel, 
179                                 new Point2D.Double(0.0, 0.0));
180    Font xtfont = new Font("Helvetica", Font.PLAIN, 14);
181    xtitle.setFont(xtfont);
182    xtitle.setHeightP(0.2);
183    xbot.setTitle(xtitle);
184    graph.addXAxis(xbot);
185    /*
186     * Create the left axis, set its range in user units
187     * and its origin. Add the axis to the graph.
188     */
189    PlainAxis yleft;
190    String yLabel = "Y Label";
191
192    yleft = new PlainAxis("Left Axis");
193    yleft.setRangeU(yrange);
194    yleft.setLocationU(new Point2D.Double(xrange.start, yrange.start));
195    yleft.setLabelFont(xbfont);
196    SGLabel ytitle = new SGLabel("yaxis title", yLabel, 
197                                 new Point2D.Double(0.0, 0.0));
198    Font ytfont = new Font("Helvetica", Font.PLAIN, 14);
199    ytitle.setFont(ytfont);
200    ytitle.setHeightP(0.2);
201    yleft.setTitle(ytitle);
202    graph.addYAxis(yleft);
203    /*
204     * Create a PointAttribute for the display of the
205     * Collection of points. The points will be red with
206     * the label at the NE corner and in blue.
207     */
208    PointAttribute pattr;
209
210    pattr = new PointAttribute(20, Color.red);
211    pattr.setLabelPosition(PointAttribute.NE);
212    Font pfont = new Font("Helvetica", Font.PLAIN, 12);
213    pattr.setLabelFont(pfont);
214    pattr.setLabelColor(Color.blue);
215    pattr.setLabelHeightP(0.1);
216    pattr.setDrawLabel(true);
217    /*
218     * Associate the attribute and the point Collection
219     * with the graph.
220     */
221    graph.setData(col, pattr);
222   
223    return mainPane_;
224  }
225 
226    void tree_actionPerformed(java.awt.event.ActionEvent e) {
227        JClassTree ct = new JClassTree();
228        ct.setModal(false);
229        ct.setJPane(mainPane_);
230        ct.show();
231    }
232
233  class MyAction implements java.awt.event.ActionListener {
234        public void actionPerformed(java.awt.event.ActionEvent event) {
235           Object obj = event.getSource();
236           if(obj == space_) {
237             System.out.println("  <<Mark>>");
238           }
239           if(obj == tree_)
240               tree_actionPerformed(event);
241        }
242    }
243
244}
Note: See TracBrowser for help on using the repository browser.