KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > graph > Test


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.graph;
8
9 import java.awt.BorderLayout JavaDoc;
10 import java.awt.Color JavaDoc;
11
12 import javax.swing.JFrame JavaDoc;
13
14 import org.ejtools.graph.renderer.TriAxisLayoutRenderer;
15
16 /**
17  * Description of the Class
18  *
19  * @author Laurent Etiemble
20  * @version $Revision: 1.7 $
21  * @todo Javadoc to complete
22  */

23 public class Test
24 {
25    /** Constructor for Test. */
26    public Test()
27    {
28       super();
29    }
30
31
32    /**
33     * The main program for the Test class
34     *
35     * @param args The command line arguments
36     * @exception Exception Description of the Exception
37     */

38    public static void main(String JavaDoc[] args)
39       throws Exception JavaDoc
40    {
41       Track t1 = new Track("Toto");
42       t1.setColor(Color.blue);
43       Track t2 = new Track("Tata");
44       t2.setColor(Color.red);
45
46       CompositeTrack ct = new CompositeTrack();
47       ct.addTrack(t1);
48       ct.addTrack(t2);
49
50       TriAxisLayoutRenderer cg = new TriAxisLayoutRenderer();
51       cg.setGraphElement(ct);
52
53 // BorderGraph cg = new BorderGraph();
54
// cg.setGraphElement(t1);
55

56 // Renderer rd = new DefaultRenderer();
57
// Renderer rd = new GridRenderer(new SimpleDateFormat("HH:mm:ss.SSS"), new DecimalFormat("0"));
58
// cg.addRenderer(rd, BorderLayout.CENTER);
59
// Axis axis = new HorizontalAxis(new SimpleDateFormat("HH:mm:ss.SSS"), Axis.BOTTOM);
60
// cg.addRenderer(axis, BorderLayout.SOUTH);
61
// axis = new VerticalAxis(new DecimalFormat("0"), Axis.LEFT);
62
// cg.addRenderer(axis, BorderLayout.WEST);
63
// axis = new VerticalAxis(new DecimalFormat("0"), Axis.RIGHT);
64
// cg.addRenderer(axis, BorderLayout.EAST);
65

66       /*
67        * GridBagGraph cg = new GridBagGraph();
68        * cg.setGraphElement(ct);
69        * GridBagConstraints constraints = new GridBagConstraints();
70        * / Renderer rd = new DefaultRenderer();
71        * Renderer rd = new GridRenderer(new SimpleDateFormat("HH:mm:ss.SSS"), new DecimalFormat("0"));
72        * constraints.gridx = 1;
73        * constraints.gridy = 0;
74        * constraints.fill = GridBagConstraints.BOTH;
75        * constraints.weightx = 1.0;
76        * constraints.weighty = 1.0;
77        * cg.addRenderer(rd, constraints);
78        * Axis axis = new HorizontalAxis(new SimpleDateFormat("HH:mm:ss.SSS"), Axis.BOTTOM);
79        * constraints.gridx = 1;
80        * constraints.gridy = 1;
81        * constraints.fill = GridBagConstraints.HORIZONTAL;
82        * constraints.weightx = 0.0;
83        * constraints.weighty = 0.0;
84        * cg.addRenderer(axis, constraints);
85        * axis = new VerticalAxis(new DecimalFormat("0"), Axis.LEFT);
86        * constraints.gridx = 0;
87        * constraints.gridy = 0;
88        * constraints.fill = GridBagConstraints.VERTICAL;
89        * constraints.weightx = 0.0;
90        * constraints.weighty = 0.0;
91        * cg.addRenderer(axis, constraints);
92        * axis = new VerticalAxis(new DecimalFormat("0"), Axis.RIGHT);
93        * constraints.gridx = 2;
94        * constraints.gridy = 0;
95        * constraints.fill = GridBagConstraints.VERTICAL;
96        * constraints.weightx = 0.0;
97        * constraints.weighty = 0.0;
98        * cg.addRenderer(axis, constraints);
99        */

100       cg.setVisible(true);
101
102       JFrame JavaDoc frame = new JFrame JavaDoc("Test");
103       frame.getContentPane().setLayout(new BorderLayout JavaDoc());
104       frame.getContentPane().add(cg, BorderLayout.CENTER);
105       frame.setSize(600, 400);
106
107       frame.show();
108
109       double i = 0;
110       double scale = 1.0d;
111       while (i < 50)
112       {
113          System.out.println(i);
114          t1.addValue(Math.cos(i * 10 * Math.PI / 180) * 20);
115          t2.addValue(Math.sin(i * 10 * Math.PI / 180) * 20);
116          Thread.sleep(200);
117          cg.repaint();
118          i++;
119          if ((i % 20) == 0)
120          {
121             scale = scale / 1.5;
122             cg.setHorizontalScale(scale);
123          }
124       }
125
126       System.exit(0);
127    }
128 }
129
Popular Tags