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