001: package net.sf.jmoney.charts;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Color;
005:
006: import javax.swing.JFrame;
007: import javax.swing.JSplitPane;
008:
009: import net.sf.jmoney.model2.Session;
010:
011: import org.jfree.chart.ChartFactory;
012: import org.jfree.chart.ChartPanel;
013: import org.jfree.chart.JFreeChart;
014: import org.jfree.chart.axis.NumberAxis;
015: import org.jfree.chart.plot.ValueMarker;
016: import org.jfree.chart.plot.XYPlot;
017: import org.jfree.data.time.TimeSeriesCollection;
018:
019: /**
020: * A simple PieChart
021: * @author Faucheux
022: */
023: public abstract class LineChart extends JFrame {
024:
025: public String title;
026: public Session session;
027: public TimeSeriesCollection data;
028: protected JFreeChart chart;
029: public LineChartParameters params;
030:
031: /**
032: * Default constructor.
033: */
034: public LineChart(String title, Session session) {
035: super ();
036: this .title = title;
037: this .session = session;
038:
039: // init the parameters
040: initParameters();
041:
042: }
043:
044: protected abstract void createOrUpdateValues(
045: LineChartParameters params);
046:
047: /**
048: * Starting point for the panel.
049: */
050: public void displayAsWindow() {
051: this .getContentPane().removeAll();
052: this .getContentPane().setLayout(new BorderLayout());
053: this .getContentPane().add(this .getChartPanel());
054: this .setVisible(true);
055: this .pack();
056: }
057:
058: /*
059: * initialize the parameters. This initialization will be called before "setValues"
060: * @author Faucheux
061: */
062: protected void initParameters() {
063: };
064:
065: public ChartPanel getChartPanel() {
066:
067: // create the chart...
068: chart = ChartFactory.createTimeSeriesChart(title, // title
069: "Date", // Name of the X-Axis
070: "Amount", // Name of the Y-Axis
071: data, // data
072: true, // include legend
073: true, // tooltips
074: true // URL
075: );
076:
077: // set the background color for the chart...
078: chart.setBackgroundPaint(Color.yellow);
079:
080: // add a seconde range axis to improve the lisibility
081: NumberAxis axis1 = (NumberAxis) ((XYPlot) chart.getPlot())
082: .getRangeAxis();
083: NumberAxis axis2 = new NumberAxis("Amount");
084: ((XYPlot) chart.getPlot()).setRangeAxis(1, axis2);
085: axis2.setRange(axis1.getRange());
086:
087: // add the chart to a panel...
088: ChartPanel chartPanel = new ChartPanel(chart);
089:
090: // made the 0 line to ressort.
091: chart.getXYPlot().addRangeMarker(new ValueMarker(0.0));
092:
093: JSplitPane splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
094: splitter.setTopComponent(chartPanel);
095: splitter.setBottomComponent(chartPanel);
096: this .getContentPane().add(splitter);
097: splitter.setDividerLocation(0.75);
098:
099: return chartPanel;
100: }
101:
102: }
|