1 | /* |
---|
2 | * $Id: JProfileDemo.java,v 1.3 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 | */ |
---|
12 | package gov.noaa.pmel.sgt.demo; |
---|
13 | |
---|
14 | import gov.noaa.pmel.sgt.JPane; |
---|
15 | import gov.noaa.pmel.sgt.swing.JPlotLayout; |
---|
16 | import gov.noaa.pmel.sgt.dm.SGTData; |
---|
17 | |
---|
18 | import gov.noaa.pmel.util.Range2D; |
---|
19 | import gov.noaa.pmel.util.Dimension2D; |
---|
20 | import gov.noaa.pmel.util.Point2D; |
---|
21 | |
---|
22 | import java.awt.*; |
---|
23 | import javax.swing.*; |
---|
24 | /** |
---|
25 | * Example demonstrating how to use <code>JPlotLayout</code> to create |
---|
26 | * a profile plot. |
---|
27 | * |
---|
28 | * @author Donald Denbo |
---|
29 | * @version $Revision: 1.3 $, $Date: 2001/02/06 00:14:35 $ |
---|
30 | * @since 2.0 |
---|
31 | */ |
---|
32 | |
---|
33 | |
---|
34 | public class JProfileDemo extends JApplet { |
---|
35 | public void init() { |
---|
36 | setLayout(null); |
---|
37 | setSize(450,600); |
---|
38 | add("Center", makeGraph()); |
---|
39 | } |
---|
40 | |
---|
41 | public static void main(String[] args) { |
---|
42 | JProfileDemo pd = new JProfileDemo(); |
---|
43 | JFrame frame = new JFrame("Profile Demo"); |
---|
44 | JPane graph; |
---|
45 | frame.getContentPane().setLayout(new BorderLayout()); |
---|
46 | frame.addWindowListener(new java.awt.event.WindowAdapter() { |
---|
47 | public void windowClosing(java.awt.event.WindowEvent event) { |
---|
48 | JFrame fr = (JFrame)event.getSource(); |
---|
49 | fr.setVisible(false); |
---|
50 | fr.dispose(); |
---|
51 | System.exit(0); |
---|
52 | } |
---|
53 | }); |
---|
54 | frame.setSize(450, 600); |
---|
55 | graph = pd.makeGraph(); |
---|
56 | graph.setBatch(true); |
---|
57 | frame.getContentPane().add(graph, BorderLayout.CENTER); |
---|
58 | frame.pack(); |
---|
59 | frame.setVisible(true); |
---|
60 | graph.setBatch(false); |
---|
61 | } |
---|
62 | |
---|
63 | JPlotLayout makeGraph() { |
---|
64 | /* |
---|
65 | * This example uses a pre-created "Layout" for profile |
---|
66 | * data to simplify the construction of a plot. The |
---|
67 | * LineProfileLayout can plot multiple lines, with |
---|
68 | * a legend and provides zooming and line hi-lighting |
---|
69 | * capabilities. |
---|
70 | */ |
---|
71 | SGTData newData; |
---|
72 | TestData td; |
---|
73 | JPlotLayout lpl; |
---|
74 | /* |
---|
75 | * Create a test profile with random data. |
---|
76 | */ |
---|
77 | Range2D zrange = new Range2D(0.0, 495.0, 10.0); |
---|
78 | td = new TestData(TestData.PROFILE, zrange, |
---|
79 | TestData.RANDOM, 1.2f, 0.5f, 30.0f); |
---|
80 | newData = td.getSGTData(); |
---|
81 | /* |
---|
82 | * Create the layout without a Logo image and with the |
---|
83 | * LineKey on the main Pane object. Data object is used |
---|
84 | * to automatically determine the type of plot to create. |
---|
85 | */ |
---|
86 | lpl = new JPlotLayout(newData, "Profile Demo", null, false); |
---|
87 | /* |
---|
88 | * Add first profile. |
---|
89 | */ |
---|
90 | lpl.addData(newData, "First Line"); |
---|
91 | /* |
---|
92 | * Create a second profile. |
---|
93 | */ |
---|
94 | td = new TestData(TestData.PROFILE, zrange, |
---|
95 | TestData.RANDOM, 2.0f, 0.25f, 30.0f); |
---|
96 | lpl.addData(td.getSGTData(), "Second Line"); |
---|
97 | /* |
---|
98 | * Change the layout's three title lines and place the Pane |
---|
99 | * on the Applet. |
---|
100 | */ |
---|
101 | lpl.setTitles("Profile Demo", |
---|
102 | "using a sgt.swing class", |
---|
103 | "JPlotLayout"); |
---|
104 | |
---|
105 | lpl.setSize(new Dimension(450,600)); |
---|
106 | lpl.setLayerSizeP(new Dimension2D(6.0, 8.0)); |
---|
107 | lpl.setKeyLocationP(new Point2D.Double(6.0, 8.0)); |
---|
108 | return lpl; |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|