2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_11;
23 import java.util.ArrayList;
27 import org.altusmetrum.altoslib_11.*;
29 import org.jfree.ui.*;
30 import org.jfree.chart.*;
31 import org.jfree.chart.plot.*;
32 import org.jfree.chart.axis.*;
33 import org.jfree.chart.renderer.*;
34 import org.jfree.chart.renderer.xy.*;
35 import org.jfree.chart.labels.*;
36 import org.jfree.data.xy.*;
37 import org.jfree.data.*;
39 public class AltosUIGraphNew implements AltosUnitsListener {
43 public ChartPanel panel;
46 AltosUITimeSeries[] series;
49 Hashtable<Integer,Boolean> axes_added;
51 static final private Color gridline_color = new Color(0, 0, 0);
52 static final private Color border_color = new Color(255, 255, 255);
53 static final private Color background_color = new Color(255, 255, 255);
55 public JPanel panel() {
59 public AltosUIAxis newAxis(String label, AltosUnits units, Color color, int flags) {
60 AltosUIAxis axis = new AltosUIAxis(label, units, color, axis_index++, flags);
61 plot.setRangeAxis(axis.index, axis);
65 public AltosUIAxis newAxis(String label, AltosUnits units, Color color) {
66 return newAxis(label, units, color, AltosUIAxis.axis_default);
69 void addAxis(AltosUIAxis axis) {
70 if (!axes_added.containsKey(axis.index)) {
71 axes_added.put(axis.index, true);
72 plot.setRangeAxis(axis.index, axis);
76 public void addSeries(AltosUITimeSeries series) {
77 XYSeriesCollection dataset = new XYSeriesCollection(series.xy_series());
81 series.renderer.setPlot(plot);
82 plot.setDataset(series_index, dataset);
83 plot.setRenderer(series_index, series.renderer);
84 plot.mapDatasetToRangeAxis(series_index, series.axis.index);
86 enable.add(series.label, series, series.enable);
90 public void addMarker(AltosUITimeSeries series) {
93 public void units_changed(boolean imperial_units) {
94 for (AltosUITimeSeries s : series)
98 public void setName (String name) {
102 public void set_series(AltosUITimeSeries[] series) {
103 this.series = series;
105 for (AltosUITimeSeries s : series)
108 units_changed(false);
111 public AltosUIGraphNew(AltosUIEnable enable, String title) {
113 this.enable = enable;
117 axes_added = new Hashtable<Integer,Boolean>();
119 xAxis = new NumberAxis("Time (s)");
121 xAxis.setAutoRangeIncludesZero(true);
124 plot.setDomainAxis(xAxis);
125 plot.setOrientation(PlotOrientation.VERTICAL);
126 plot.setDomainPannable(true);
127 plot.setRangePannable(true);
129 chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
132 ChartUtilities.applyCurrentTheme(chart);
134 plot.setDomainGridlinePaint(gridline_color);
135 plot.setRangeGridlinePaint(gridline_color);
136 plot.setBackgroundPaint(background_color);
137 plot.setBackgroundAlpha((float) 1);
139 chart.setBackgroundPaint(background_color);
140 chart.setBorderPaint(border_color);
141 panel = new ChartPanel(chart);
142 panel.setMouseWheelEnabled(true);
143 panel.setPreferredSize(new java.awt.Dimension(800, 500));
145 AltosPreferences.register_units_listener(this);