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 XYLineAndShapeRenderer 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() {
92 public void set_data() {
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);
130 public void set_units() {
132 StandardXYToolTipGenerator ttg;
135 String time_example = (new AltosUITime()).graph_format(7);
136 String example = units.graph_format(7);
138 ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
139 units.graph_units()),
140 new java.text.DecimalFormat(time_example),
141 new java.text.DecimalFormat(example));
142 renderer.setBaseToolTipGenerator(ttg);
147 public AltosXYSeries xy_series() {
151 public void set_enable(boolean enable) {
152 if (this.enable != enable) {
153 this.enable = enable;
155 for (ValueMarker marker : markers) {
157 plot.addDomainMarker(marker);
159 plot.removeDomainMarker(marker);
162 renderer.setSeriesVisible(0, enable);
163 axis.set_enable(enable);
168 public void set_axis(Color color, boolean enable, AltosUIAxis axis) {
170 this.enable = enable;
174 axis.ref(this.enable);
176 renderer = new XYLineAndShapeRenderer(true, false);
177 renderer.setSeriesPaint(0, color);
178 renderer.setSeriesStroke(0, new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
179 renderer.setSeriesVisible(0, enable);
180 xy_series = new AltosXYSeries(label);
183 public void set_marker(Color color, boolean enable, XYPlot plot, boolean marker_top) {
185 this.enable = enable;
188 this.marker_top = marker_top;
191 public void set_shapes_visible(boolean shapes_visible) {
192 renderer.setSeriesShapesVisible(0, shapes_visible);
195 public AltosUITimeSeries(String label, AltosUnits units) {
199 public AltosUITimeSeries(String label, AltosUnits units,
200 Color color, boolean enable,
203 set_axis(color, enable, axis);