summaryrefslogtreecommitdiff
path: root/altosuilib
diff options
context:
space:
mode:
Diffstat (limited to 'altosuilib')
-rw-r--r--altosuilib/AltosUIDataPoint.java4
-rw-r--r--altosuilib/AltosUIEnable.java14
-rw-r--r--altosuilib/AltosUIGraph.java30
-rw-r--r--altosuilib/AltosUIGrapher.java46
-rw-r--r--altosuilib/AltosUIMarker.java103
-rw-r--r--altosuilib/AltosUISeries.java48
-rw-r--r--altosuilib/Makefile.am3
7 files changed, 212 insertions, 36 deletions
diff --git a/altosuilib/AltosUIDataPoint.java b/altosuilib/AltosUIDataPoint.java
index 38857fd1..a98f7cdb 100644
--- a/altosuilib/AltosUIDataPoint.java
+++ b/altosuilib/AltosUIDataPoint.java
@@ -20,4 +20,6 @@ package org.altusmetrum.altosuilib_1;
public interface AltosUIDataPoint {
public abstract double x();
public abstract double y(int index);
-} \ No newline at end of file
+ public abstract int id(int index);
+ public abstract String id_name(int index);
+}
diff --git a/altosuilib/AltosUIEnable.java b/altosuilib/AltosUIEnable.java
index e5695fa0..297cf320 100644
--- a/altosuilib/AltosUIEnable.java
+++ b/altosuilib/AltosUIEnable.java
@@ -41,28 +41,28 @@ public class AltosUIEnable extends Container {
int y;
class GraphElement implements ActionListener {
- AltosUISeries series;
+ AltosUIGrapher grapher;
JLabel label;
JRadioButton enable;
String name;
public void actionPerformed(ActionEvent ae) {
- series.set_enable(enable.isSelected());
+ grapher.set_enable(enable.isSelected());
}
- GraphElement (String name, AltosUISeries series, boolean enabled) {
+ GraphElement (String name, AltosUIGrapher grapher, boolean enabled) {
this.name = name;
- this.series = series;
+ this.grapher = grapher;
label = new JLabel(name);
enable = new JRadioButton("Enable", enabled);
- series.set_enable(enabled);
+ grapher.set_enable(enabled);
enable.addActionListener(this);
}
}
- public void add(String name, AltosUISeries series, boolean enabled) {
+ public void add(String name, AltosUIGrapher grapher, boolean enabled) {
- GraphElement e = new GraphElement(name, series, enabled);
+ GraphElement e = new GraphElement(name, grapher, enabled);
/* Add label */
GridBagConstraints c = new GridBagConstraints();
diff --git a/altosuilib/AltosUIGraph.java b/altosuilib/AltosUIGraph.java
index e79e36ba..e212093a 100644
--- a/altosuilib/AltosUIGraph.java
+++ b/altosuilib/AltosUIGraph.java
@@ -41,8 +41,9 @@ public class AltosUIGraph implements AltosUnitsListener {
public ChartPanel panel;
NumberAxis xAxis;
AltosUIEnable enable;
- ArrayList<AltosUISeries> series;
+ ArrayList<AltosUIGrapher> graphers;
AltosUIDataSet dataSet;
+ int index;
static final private Color gridline_color = new Color(0, 0, 0);
static final private Color border_color = new Color(255, 255, 255);
@@ -52,7 +53,7 @@ public class AltosUIGraph implements AltosUnitsListener {
return panel;
}
- public void addSeries(int index, String label, int fetch, AltosUnits units, Color color) {
+ public void addSeries(String label, int fetch, AltosUnits units, Color color) {
AltosUISeries series = new AltosUISeries(label, fetch, units, color);
XYSeriesCollection dataset = new XYSeriesCollection(series);
@@ -63,22 +64,30 @@ public class AltosUIGraph implements AltosUnitsListener {
plot.mapDatasetToRangeAxis(index, index);
if (enable != null)
enable.add(label, series, true);
- this.series.add(series);
+ this.graphers.add(series);
+ index++;
}
+ public void addMarker(String label, int fetch, Color color) {
+ AltosUIMarker marker = new AltosUIMarker(fetch, color, plot);
+ if (enable != null)
+ enable.add(label, marker, true);
+ this.graphers.add(marker);
+ }
+
public void resetData() {
- for (AltosUISeries s : series)
- s.clear();
+ for (AltosUIGrapher g : graphers)
+ g.clear();
if (dataSet != null) {
for (AltosUIDataPoint dataPoint : dataSet.dataPoints())
- for (AltosUISeries s : series)
- s.add(dataPoint);
+ for (AltosUIGrapher g : graphers)
+ g.add(dataPoint);
}
}
public void units_changed(boolean imperial_units) {
- for (AltosUISeries s : series)
- s.set_units();
+ for (AltosUIGrapher g : graphers)
+ g.set_units();
resetData();
}
@@ -96,7 +105,8 @@ public class AltosUIGraph implements AltosUnitsListener {
public AltosUIGraph(AltosUIEnable enable) {
this.enable = enable;
- this.series = new ArrayList<AltosUISeries>();
+ this.graphers = new ArrayList<AltosUIGrapher>();
+ this.index = 0;
xAxis = new NumberAxis("Time (s)");
diff --git a/altosuilib/AltosUIGrapher.java b/altosuilib/AltosUIGrapher.java
new file mode 100644
index 00000000..c627fec5
--- /dev/null
+++ b/altosuilib/AltosUIGrapher.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altosuilib_1;
+
+import java.io.*;
+import java.util.ArrayList;
+
+import java.awt.*;
+import javax.swing.*;
+import org.altusmetrum.altoslib_1.*;
+
+import org.jfree.ui.*;
+import org.jfree.chart.*;
+import org.jfree.chart.plot.*;
+import org.jfree.chart.axis.*;
+import org.jfree.chart.renderer.*;
+import org.jfree.chart.renderer.xy.*;
+import org.jfree.chart.labels.*;
+import org.jfree.data.xy.*;
+import org.jfree.data.*;
+
+interface AltosUIGrapher {
+
+ public abstract void set_units();
+
+ public abstract void clear();
+
+ public abstract void add(AltosUIDataPoint dataPoint);
+
+ public abstract void set_enable(boolean enable);
+}
diff --git a/altosuilib/AltosUIMarker.java b/altosuilib/AltosUIMarker.java
new file mode 100644
index 00000000..560153f2
--- /dev/null
+++ b/altosuilib/AltosUIMarker.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altosuilib_1;
+
+import java.io.*;
+import java.util.ArrayList;
+
+import java.awt.*;
+import javax.swing.*;
+import org.altusmetrum.altoslib_1.*;
+
+import org.jfree.ui.*;
+import org.jfree.chart.*;
+import org.jfree.chart.plot.*;
+import org.jfree.chart.axis.*;
+import org.jfree.chart.renderer.*;
+import org.jfree.chart.renderer.xy.*;
+import org.jfree.chart.labels.*;
+import org.jfree.data.xy.*;
+import org.jfree.data.*;
+
+public class AltosUIMarker implements AltosUIGrapher {
+ ArrayList<ValueMarker> markers;
+ int last_id;
+ XYPlot plot;
+ boolean enabled;
+ int fetch;
+ Color color;
+
+ private void remove_markers() {
+ for (ValueMarker marker : markers)
+ plot.removeDomainMarker(marker);
+ }
+
+ private void add_markers() {
+ for (ValueMarker marker : markers)
+ plot.addDomainMarker(marker);
+ }
+
+ public void set_units() {
+ }
+
+ public void set_enable(boolean enable) {
+ if (enabled == enable)
+ return;
+ if (enable)
+ add_markers();
+ else
+ remove_markers();
+ enabled = enable;
+ }
+
+ public void clear() {
+ if (enabled)
+ remove_markers();
+ markers = new ArrayList<ValueMarker>();
+ }
+
+ public void add(AltosUIDataPoint dataPoint) {
+ int id = dataPoint.id(fetch);
+ if (id < 0)
+ return;
+ if (id == last_id)
+ return;
+ ValueMarker marker = new ValueMarker(dataPoint.x());
+ marker.setLabel(dataPoint.id_name(fetch));
+ marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
+ marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
+ marker.setPaint(color);
+ if (enabled)
+ plot.addDomainMarker(marker);
+ markers.add(marker);
+ last_id = id;
+ }
+
+ public AltosUIMarker (int fetch, Color color, XYPlot plot, boolean enable) {
+ markers = new ArrayList<ValueMarker>();
+ last_id = -1;
+ this.fetch = fetch;
+ this.color = color;
+ this.plot = plot;
+ this.enabled = enable;
+ }
+
+ public AltosUIMarker (int fetch, Color color, XYPlot plot) {
+ this(fetch, color, plot, true);
+ }
+} \ No newline at end of file
diff --git a/altosuilib/AltosUISeries.java b/altosuilib/AltosUISeries.java
index ea76e741..26679471 100644
--- a/altosuilib/AltosUISeries.java
+++ b/altosuilib/AltosUISeries.java
@@ -34,54 +34,66 @@ import org.jfree.chart.labels.*;
import org.jfree.data.xy.*;
import org.jfree.data.*;
-public class AltosUISeries extends XYSeries {
- NumberAxis axis;
+public class AltosUISeries extends XYSeries implements AltosUIGrapher {
+ AltosUIAxis axis;
String label;
AltosUnits units;
Color color;
XYItemRenderer renderer;
int fetch;
+ boolean enable;
- void set_units() {
- String units_string = units.show_units();
- axis.setLabel(String.format("%s (%s)", label, units_string));
-
+ public void set_units() {
+ axis.set_units();
StandardXYToolTipGenerator ttg;
String example = units.graph_format(4);
- ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units_string),
+ ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
+ units.show_units()),
new java.text.DecimalFormat(example),
new java.text.DecimalFormat(example));
renderer.setBaseToolTipGenerator(ttg);
}
- void set_enable(boolean enable) {
- renderer.setSeriesVisible(0, enable);
- axis.setVisible(enable);
+ public void set_enable(boolean enable) {
+ if (this.enable != enable) {
+ this.enable = enable;
+ renderer.setSeriesVisible(0, enable);
+ axis.set_enable(enable);
+ }
}
public void add(AltosUIDataPoint dataPoint) {
super.add(dataPoint.x(), dataPoint.y(fetch));
}
- public void set_axis(NumberAxis axis) {
- this.axis = axis;
- }
-
- 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);
set_units();
}
+
+ public AltosUISeries (String label, int fetch, AltosUnits units, Color color, boolean enable) {
+ this(label, fetch, units, color,
+ enable,
+ new AltosUIAxis(label, units, color));
+ }
+
+ public AltosUISeries (String label, int fetch, AltosUnits units, Color color) {
+ this(label, fetch, units, color,
+ true,
+ new AltosUIAxis(label, units, color));
+ }
}
diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am
index e338b7cd..faf7921f 100644
--- a/altosuilib/Makefile.am
+++ b/altosuilib/Makefile.am
@@ -14,14 +14,17 @@ altosuilib_JAVA = \
AltosFontListener.java \
AltosPositionListener.java \
AltosUIConfigure.java \
+ AltosUIAxis.java \
AltosUIDataPoint.java \
AltosUIDataSet.java \
AltosUIGraph.java \
+ AltosUIGrapher.java \
AltosUIDialog.java \
AltosUIEnable.java \
AltosUIFrame.java \
AltosUILib.java \
AltosUIListener.java \
+ AltosUIMarker.java \
AltosUIPreferencesBackend.java \
AltosUIPreferences.java \
AltosUISeries.java \