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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altosuilib_1;
21 import java.util.ArrayList;
25 import org.altusmetrum.altoslib_1.*;
27 import org.jfree.ui.*;
28 import org.jfree.chart.*;
29 import org.jfree.chart.plot.*;
30 import org.jfree.chart.axis.*;
31 import org.jfree.chart.renderer.*;
32 import org.jfree.chart.renderer.xy.*;
33 import org.jfree.chart.labels.*;
34 import org.jfree.data.xy.*;
35 import org.jfree.data.*;
37 public class AltosUIGraph implements AltosUnitsListener {
41 public ChartPanel panel;
44 ArrayList<AltosUIGrapher> graphers;
45 AltosUIDataSet dataSet;
48 static final private Color gridline_color = new Color(0, 0, 0);
49 static final private Color border_color = new Color(255, 255, 255);
50 static final private Color background_color = new Color(255, 255, 255);
52 public JPanel panel() {
56 public void addSeries(String label, int fetch, AltosUnits units, Color color) {
57 AltosUISeries series = new AltosUISeries(label, fetch, units, color);
58 XYSeriesCollection dataset = new XYSeriesCollection(series);
60 series.renderer.setPlot(plot);
61 plot.setRangeAxis(index, series.axis);
62 plot.setDataset(index, dataset);
63 plot.setRenderer(index, series.renderer);
64 plot.mapDatasetToRangeAxis(index, index);
66 enable.add(label, series, true);
67 this.graphers.add(series);
71 public void addMarker(String label, int fetch, Color color) {
72 AltosUIMarker marker = new AltosUIMarker(fetch, color, plot);
74 enable.add(label, marker, true);
75 this.graphers.add(marker);
78 public void resetData() {
79 for (AltosUIGrapher g : graphers)
81 if (dataSet != null) {
82 for (AltosUIDataPoint dataPoint : dataSet.dataPoints())
83 for (AltosUIGrapher g : graphers)
88 public void units_changed(boolean imperial_units) {
89 for (AltosUIGrapher g : graphers)
94 public void setName (String name) {
98 public void setDataSet (AltosUIDataSet dataSet) {
99 this.dataSet = dataSet;
101 setName(dataSet.name());
105 public AltosUIGraph(AltosUIEnable enable) {
107 this.enable = enable;
108 this.graphers = new ArrayList<AltosUIGrapher>();
111 xAxis = new NumberAxis("Time (s)");
113 xAxis.setAutoRangeIncludesZero(true);
116 plot.setDomainAxis(xAxis);
117 plot.setOrientation(PlotOrientation.VERTICAL);
118 plot.setDomainPannable(true);
119 plot.setRangePannable(true);
121 chart = new JFreeChart("Flight", JFreeChart.DEFAULT_TITLE_FONT,
124 ChartUtilities.applyCurrentTheme(chart);
126 plot.setDomainGridlinePaint(gridline_color);
127 plot.setRangeGridlinePaint(gridline_color);
128 plot.setBackgroundPaint(background_color);
129 plot.setBackgroundAlpha((float) 1);
131 chart.setBackgroundPaint(background_color);
132 chart.setBorderPaint(border_color);
133 panel = new ChartPanel(chart);
134 panel.setMouseWheelEnabled(true);
135 panel.setPreferredSize(new java.awt.Dimension(800, 500));
137 AltosPreferences.register_units_listener(this);