X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosuilib%2FAltosUITimeSeries.java;h=0f5e35ebd8f9aed74e0950c7ba78f66d7076c6e2;hp=dce48baafbcd914b17b25bb58675a830551bc1b2;hb=e6eb659b0e984515a33b3ddabfe8325742a952da;hpb=81eaca2eac0b51a0017379187e042729b87e5f4d diff --git a/altosuilib/AltosUITimeSeries.java b/altosuilib/AltosUITimeSeries.java index dce48baa..0f5e35eb 100644 --- a/altosuilib/AltosUITimeSeries.java +++ b/altosuilib/AltosUITimeSeries.java @@ -35,17 +35,139 @@ import org.jfree.chart.labels.*; import org.jfree.data.xy.*; import org.jfree.data.*; -public class AltosUITimeSeries extends AltosTimeSeries { +class AltosXYSeries extends XYSeries { + + public AltosXYSeries(String label) { + super(label); + } +} + +public class AltosUITimeSeries extends AltosTimeSeries implements AltosUIGrapher { Color color; - boolean enabled; + boolean enable; AltosUIAxis axis; + boolean marker; + XYItemRenderer renderer; + XYPlot plot; + AltosXYSeries xy_series; + ArrayList markers; - public AltosUITimeSeries(String label, AltosUnits units, - Color color, boolean enabled, - AltosUIAxis axis) { - super(label, units); + + /* AltosUIGrapher interface */ + public boolean need_reset() { + return false; + } + + public void clear() { + } + + public void add(AltosUIDataPoint dataPoint) { + } + + public void setNotify(boolean notify) { + } + + public void fireSeriesChanged() { + } + + void set_data() { + if (marker) { + if (markers != null) { + for (ValueMarker marker : markers) + plot.removeDomainMarker(marker); + } + markers = new ArrayList(); + for (AltosTimeValue v : this) { + String s = units.string_value(v.value); + ValueMarker marker = new ValueMarker(v.time); + marker.setLabel(s); + marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); + marker.setLabelTextAnchor(TextAnchor.TOP_LEFT); + marker.setPaint(color); + if (enable) + plot.addDomainMarker(marker); + markers.add(marker); + } + } else { + xy_series.clear(); + + for (AltosTimeValue v : this) { + double value = v.value; + if (units != null) + value = units.graph_value(value); + xy_series.add(v.time, value); + } + } + } + + public void set_units() { + axis.set_units(); + StandardXYToolTipGenerator ttg; + + if (units != null) { + 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.graph_units()), + new java.text.DecimalFormat(time_example), + new java.text.DecimalFormat(example)); + renderer.setBaseToolTipGenerator(ttg); + } + set_data(); + } + + public AltosXYSeries xy_series() { + return xy_series; + } + + public void set_enable(boolean enable) { + if (this.enable != enable) { + this.enable = enable; + if (marker) { + for (ValueMarker marker : markers) { + if (enable) + plot.addDomainMarker(marker); + else + plot.removeDomainMarker(marker); + } + } else { + renderer.setSeriesVisible(0, enable); + axis.set_enable(enable); + } + } + } + + public void set_axis(Color color, boolean enable, AltosUIAxis axis) { this.color = color; - this.enabled = enabled; + this.enable = enable; this.axis = axis; + this.marker = false; + + 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); + xy_series = new AltosXYSeries(label); + } + + public void set_marker(Color color, boolean enable, XYPlot plot) { + this.color = color; + this.enable = enable; + this.marker = true; + this.plot = plot; + } + + public AltosUITimeSeries(String label, AltosUnits units) { + super(label, units); + } + + public AltosUITimeSeries(String label, AltosUnits units, + Color color, boolean enable, + AltosUIAxis axis) { + this(label, units); + set_axis(color, enable, axis); } }