2 * Copyright © 2017 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_12;
22 import java.util.ArrayList;
26 import org.altusmetrum.altoslib_12.*;
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
38 class AltosUITime extends AltosUnits {
39 public double value(double v, boolean imperial_units) { return v; }
41 public double inverse(double v, boolean imperial_unis) { return v; }
43 public String show_units(boolean imperial_units) { return "s"; }
45 public String say_units(boolean imperial_units) { return "seconds"; }
47 public int show_fraction(int width, boolean imperial_units) {
53 public int say_fraction(boolean imperial_units) { return 0; }
56 class AltosXYSeries extends XYSeries {
58 public AltosXYSeries(String label) {
63 public class AltosUITimeSeries extends AltosTimeSeries implements AltosUIGrapher {
69 XYItemRenderer renderer;
71 AltosXYSeries xy_series;
72 ArrayList<ValueMarker> markers;
75 /* AltosUIGrapher interface */
76 public boolean need_reset() {
83 public void add(AltosUIDataPoint dataPoint) {
86 public void setNotify(boolean notify) {
89 public void fireSeriesChanged() {
94 if (markers != null) {
95 for (ValueMarker marker : markers)
96 plot.removeDomainMarker(marker);
98 markers = new ArrayList<ValueMarker>();
99 for (AltosTimeValue v : this) {
100 String s = units.string_value(v.value);
101 ValueMarker marker = new ValueMarker(v.time);
104 marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
105 marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
107 marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
108 marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
110 marker.setPaint(color);
112 plot.addDomainMarker(marker);
118 xy_series.setNotify(false);
119 for (AltosTimeValue v : this) {
120 double value = v.value;
122 value = units.graph_value(value);
123 xy_series.add(v.time, value);
125 xy_series.setNotify(true);
129 public void set_units() {
131 StandardXYToolTipGenerator ttg;
134 String time_example = (new AltosUITime()).graph_format(7);
135 String example = units.graph_format(7);
137 ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
138 units.graph_units()),
139 new java.text.DecimalFormat(time_example),
140 new java.text.DecimalFormat(example));
141 renderer.setBaseToolTipGenerator(ttg);
146 public AltosXYSeries xy_series() {
150 public void set_enable(boolean enable) {
151 if (this.enable != enable) {
152 this.enable = enable;
154 for (ValueMarker marker : markers) {
156 plot.addDomainMarker(marker);
158 plot.removeDomainMarker(marker);
161 renderer.setSeriesVisible(0, enable);
162 axis.set_enable(enable);
167 public void set_axis(Color color, boolean enable, AltosUIAxis axis) {
169 this.enable = enable;
173 axis.ref(this.enable);
175 renderer = new XYLineAndShapeRenderer(true, false);
176 renderer.setSeriesPaint(0, color);
177 renderer.setSeriesStroke(0, new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
178 renderer.setSeriesVisible(0, enable);
179 xy_series = new AltosXYSeries(label);
182 public void set_marker(Color color, boolean enable, XYPlot plot, boolean marker_top) {
184 this.enable = enable;
187 this.marker_top = marker_top;
190 public AltosUITimeSeries(String label, AltosUnits units) {
194 public AltosUITimeSeries(String label, AltosUnits units,
195 Color color, boolean enable,
198 set_axis(color, enable, axis);