001: package net.sf.jmoney.charts;
002:
003: import javax.swing.JFrame;
004:
005: import net.sf.jmoney.model2.Session;
006:
007: import org.jfree.chart.ChartFactory;
008: import org.jfree.chart.ChartMouseEvent;
009: import org.jfree.chart.ChartMouseListener;
010: import org.jfree.chart.ChartPanel;
011: import org.jfree.chart.JFreeChart;
012: import org.jfree.chart.plot.PiePlot;
013: import org.jfree.chart.title.TextTitle;
014: import org.jfree.data.DefaultPieDataset;
015:
016: /**
017: * A simple PieChart
018: * @author Faucheux
019: */
020: public abstract class PieChart extends JFrame implements
021: ChartMouseListener {
022:
023: protected String title;
024: protected String subTitle;
025: protected Session session;
026: public DefaultPieDataset data;
027: protected JFreeChart chart;
028:
029: /**
030: * Default constructor.
031: */
032: public PieChart(String title, Session session) {
033: super ();
034:
035: this .title = title;
036: this .session = session;
037:
038: }
039:
040: /**
041: * Starting point for the panel.
042: */
043: public void run() {
044: // create a dataset...
045: data = new DefaultPieDataset();
046:
047: // init the parameters
048: initParameters();
049:
050: // set the values
051: createValues();
052:
053: // create the chart...
054: chart = ChartFactory.createPieChart(title, // chart title
055: data, // data
056: true, // include legend
057: false, // tooltips
058: false); // URL
059: chart.addSubtitle(new TextTitle(subTitle));
060:
061: /*
062: // set the background color for the chart...
063: chart.setBackgroundPaint(Color.yellow);
064:
065: */
066:
067: // add the chart to a panel...
068: ChartPanel chartPanel = new ChartPanel(chart);
069: chartPanel.addChartMouseListener(this );
070: this .getContentPane().add(chartPanel);
071: this .pack();
072: this .setVisible(true);
073:
074: }
075:
076: /**
077: * initialize the parameters. This initialization will be called before "setValues"
078: * @author Faucheux
079: */
080: protected void initParameters() {
081: };
082:
083: public ChartPanel getChartPanel() {
084:
085: // create the chart...
086: chart = ChartFactory.createPieChart(title, // chart title
087: data, // data
088: true, // include legend
089: false, // tooltips
090: false); // URL
091: chart.setBorderVisible(true);
092: PiePlot plot = (PiePlot) chart.getPlot();
093: plot.setStartAngle(60);
094:
095: // add the chart to a panel...
096: ChartPanel chartPanel = new ChartPanel(chart);
097:
098: return chartPanel;
099: }
100:
101: protected abstract void createValues();
102:
103: public abstract void chartMouseClicked(ChartMouseEvent e);
104:
105: public void chartMouseMoved(ChartMouseEvent e) {
106: /* Nothing */
107: }
108:
109: }
|