KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > demo > graph > SwingDemoPanel


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25 package org.jrobin.demo.graph;
26
27 import javax.swing.*;
28 import java.awt.*;
29
30 import org.jrobin.graph.RrdGraph;
31
32 /**
33  * <p>Extended JPanel for use in the GUI demo application.</p>
34  *
35  * @author Arne Vandamme (cobralord@jrobin.org)
36  */

37 public class SwingDemoPanel extends JPanel
38 {
39     private RrdGraph graph;
40     private int width, height;
41
42     SwingDemoPanel( RrdGraph graph )
43     {
44         this.graph = graph;
45     }
46
47     public void paintComponent( Graphics g )
48     {
49         try
50         {
51             // Render the image directly on the Graphics object of the JPanel
52
// Width and height of 0 means autoscale the graph
53
graph.specifyImageSize(true);
54             graph.renderImage( (Graphics2D) g, width, height );
55
56         }
57         catch ( Exception JavaDoc e ) {
58             e.printStackTrace();
59         }
60     }
61
62     void setGraphDimension(Dimension d) {
63         width = d.width;
64         height = d.height;
65         repaint();
66     }
67 }
68
Popular Tags