X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUISeries.java;h=aa598bac109b6b89e6f2578244c71cbb1fc51c05;hp=ea76e7418590a05b5195bd8099e2fccef7438133;hb=8ec59ee5a6dda114ff55a4af4669842eed5ef79a;hpb=41ede0267250a1d3b26e19cc9dd78f32609f7f0f diff --git a/altosuilib/AltosUISeries.java b/altosuilib/AltosUISeries.java index ea76e741..aa598bac 100644 --- a/altosuilib/AltosUISeries.java +++ b/altosuilib/AltosUISeries.java @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,14 +16,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib_1; +package org.altusmetrum.altosuilib_11; import java.io.*; import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altoslib_11.*; import org.jfree.ui.*; import org.jfree.chart.*; @@ -34,54 +35,80 @@ import org.jfree.chart.labels.*; import org.jfree.data.xy.*; import org.jfree.data.*; -public class AltosUISeries extends XYSeries { - NumberAxis axis; +class AltosUITime extends AltosUnits { + public double value(double v, boolean imperial_units) { return v; } + + public double inverse(double v, boolean imperial_unis) { return v; } + + public String show_units(boolean imperial_units) { return "s"; } + + public String say_units(boolean imperial_units) { return "seconds"; } + + public int show_fraction(int width, boolean imperial_units) { + if (width < 5) + return 0; + return width - 5; + } + + public int say_fraction(boolean imperial_units) { return 0; } +} + +public class AltosUISeries extends XYSeries implements AltosUIGrapher { + AltosUIAxis axis; String label; AltosUnits units; Color color; XYItemRenderer renderer; int fetch; - - void set_units() { - String units_string = units.show_units(); - axis.setLabel(String.format("%s (%s)", label, units_string)); + boolean enable; + public void set_units() { + axis.set_units(); StandardXYToolTipGenerator ttg; - String example = units.graph_format(4); + String time_example = (new AltosUITime()).graph_format(7); + String example = units.graph_format(7); - ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units_string), - new java.text.DecimalFormat(example), + ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", + units.graph_units()), + new java.text.DecimalFormat(time_example), new java.text.DecimalFormat(example)); renderer.setBaseToolTipGenerator(ttg); } - void set_enable(boolean enable) { - renderer.setSeriesVisible(0, enable); - axis.setVisible(enable); - } + public boolean need_reset() { return true; } - public void add(AltosUIDataPoint dataPoint) { - super.add(dataPoint.x(), dataPoint.y(fetch)); + public void set_enable(boolean enable) { + if (this.enable != enable) { + this.enable = enable; + renderer.setSeriesVisible(0, enable); + axis.set_enable(enable); + } } - public void set_axis(NumberAxis axis) { - this.axis = axis; + public void add(AltosUIDataPoint dataPoint) { + try { + super.add(dataPoint.x(), units.graph_value(dataPoint.y(fetch))); + } catch (AltosUIDataMissing dm) { + } } - public AltosUISeries (String label, int fetch, AltosUnits units, Color color) { + public AltosUISeries (String label, int fetch, AltosUnits units, Color color, + boolean enable, AltosUIAxis axis) { super(label); this.label = label; this.fetch = fetch; this.units = units; this.color = color; + this.enable = enable; + this.axis = axis; - axis = new NumberAxis(); - axis.setLabelPaint(color); - axis.setTickLabelPaint(color); + axis.ref(this.enable); renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesPaint(0, color); + renderer.setSeriesStroke(0, new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + renderer.setSeriesVisible(0, enable); set_units(); } }