KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > designer > ChartPanel


1 /***************************************************************************************
2  * File Info: $Id: ChartPanel.java,v 1.1 2003/08/09 16:57:29 nathaniel_auvil Exp $
3  *
4  * Description:
5  *
6  * Last Reviewed: NEVER
7  * Maintainer: Nathaniel Auvil
8  * Copyright: <copyright.icore>
9  ***************************************************************************************/

10
11
12 package org.krysalis.jcharts.designer;
13
14
15
16 import org.krysalis.jcharts.Chart;
17 import org.krysalis.jcharts.properties.PropertyException;
18 import org.krysalis.jcharts.chartData.ChartDataException;
19
20 import javax.swing.*;
21 import java.awt.*;
22
23
24 public class ChartPanel extends JPanel {
25
26     private Designer designer;
27     private Chart chart;
28
29
30     /***********************************************************************************
31      *
32      * @param designer
33      **********************************************************************************/

34     public ChartPanel( Designer designer ) {
35         super();
36
37         super.setMinimumSize( new Dimension( 400, 400 ) );
38         super.setVisible( true );
39
40         this.designer = designer;
41     }
42
43
44     /**********************************************************************************
45      *
46      * @param chart
47      * @param width
48      * @param height
49      **********************************************************************************/

50     public void setChart( Chart chart, int width, int height ) {
51         this.chart = chart;
52         super.setSize( width, height );
53 //todo this does not set the size correctly
54
}
55
56
57     /***********************************************************************************
58      *
59      * @param graphics
60      **********************************************************************************/

61     public void paint( Graphics graphics ) {
62         super.paint( graphics );
63
64         if( this.chart != null ) {
65             try {
66                 this.chart.setGraphics2D( (Graphics2D) graphics );
67                 this.chart.render();
68             }
69             catch( ChartDataException chartDataException ) {
70                 chartDataException.printStackTrace();
71             }
72             catch( PropertyException propertyException ) {
73                 propertyException.printStackTrace();
74             }
75         }
76     }
77
78
79 }
80
Popular Tags