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);
+}
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();
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);
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);
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();
}
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)");
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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
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));
+ }
}
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 \
private double ground_altitude;
private ArrayList<Integer> bytes;
String name;
+ MicroStats stats;
class FileEndedException extends Exception {
}
crc_valid = crc == current_crc;
time_step = 0.192;
+ stats = new MicroStats(this);
} catch (FileEndedException fe) {
throw new IOException("File Ended Unexpectedly");
} catch (NonHexcharException ne) {
import org.altusmetrum.altosuilib_1.*;
public class MicroDataPoint implements AltosUIDataPoint {
- public double time;
- public double pressure;
- public double height;
- public double speed;
- public double accel;
+ public double time;
+ public double pressure;
+ public double height;
+ public double speed;
+ public double accel;
+ public MicroStats stats;
public static final int data_height = 0;
public static final int data_speed = 1;
public static final int data_accel = 2;
+ public static final int data_state = 3;
public double x() {
return time;
}
}
- public MicroDataPoint (double pressure, double height, double speed, double accel, double time) {
+ public int id(int index) {
+ if (index == data_state) {
+ return stats.state(time);
+ }
+ return 0;
+ }
+
+ public String id_name(int index) {
+ if (index == data_state)
+ return stats.state_name(time);
+ return "";
+ }
+
+ public MicroDataPoint (double pressure, double height, double speed, double accel, double time, MicroStats stats) {
this.pressure = pressure;
this.height = height;
this.speed = speed;
this.accel = accel;
this.time = time;
+ this.stats = stats;
}
public MicroDataPoint(MicroData data, int i) {
data.height(i),
data.speed(i),
data.acceleration(i),
- data.time(i));
+ data.time(i),
+ data.stats);
}
}
\ No newline at end of file
static final private Color height_color = new Color(194,31,31);
static final private Color speed_color = new Color(31,194,31);
static final private Color accel_color = new Color(31,31,194);
+ static final private Color state_color = new Color(3,3,3);
public MicroGraph(AltosUIEnable enable) {
super(enable);
- addSeries(0, "Height", MicroDataPoint.data_height, AltosConvert.height, height_color);
- addSeries(1, "Speed", MicroDataPoint.data_speed, AltosConvert.speed, speed_color);
- addSeries(2, "Acceleration", MicroDataPoint.data_accel, AltosConvert.accel, accel_color);
+ addSeries("Height", MicroDataPoint.data_height, AltosConvert.height, height_color);
+ addSeries("Speed", MicroDataPoint.data_speed, AltosConvert.speed, speed_color);
+ addSeries("Acceleration", MicroDataPoint.data_accel, AltosConvert.accel, accel_color);
+ addMarker("State", MicroDataPoint.data_state, state_color);
}
}
\ No newline at end of file
File filename;
MicroGraph graph;
AltosUIEnable enable;
- MicroStatsTable stats;
+ MicroStatsTable statsTable;
MicroRaw raw;
MicroData data;
+ MicroStats stats;
Container container;
JTabbedPane pane;
static int number_of_windows;
return mp.SetData(data);
}
this.data = data;
+ stats = new MicroStats(data);
graph.setDataSet(data);
- stats.setData(data);
+ statsTable.setStats(stats);
raw.setData(data);
setTitle(data.name);
return this;
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
- stats.tell_closing();
+ statsTable.tell_closing();
Close();
}
});
enable = new AltosUIEnable();
graph = new MicroGraph(enable);
- stats = new MicroStatsTable();
+ statsTable = new MicroStatsTable();
raw = new MicroRaw();
pane.add(graph.panel, "Graph");
pane.add(enable, "Configure Graph");
- pane.add(stats, "Statistics");
+ pane.add(statsTable, "Statistics");
JScrollPane scroll = new JScrollPane(raw);
pane.add(scroll, "Raw Data");
pane.doLayout();
return descent_height() / descent_duration();
}
+ public static final int state_startup = -1;
+ public static final int state_pad = 0;
+ public static final int state_boost = 1;
+ public static final int state_coast = 2;
+ public static final int state_descent = 3;
+ public static final int state_landed = 4;
+
+ static final String state_names[] = {
+ "pad",
+ "boost",
+ "coast",
+ "descent",
+ "landed"
+ };
+
+ public int state(double t) {
+ if (t >= landed_time)
+ return state_landed;
+ if (t >= apogee_time)
+ return state_descent;
+ if (t >= coast_time)
+ return state_coast;
+ if (t >= 0)
+ return state_boost;
+ return state_pad;
+ }
+
+ public static String state_name(int state) {
+ if (state < 0 || state > state_landed)
+ return "unknown";
+ return state_names[state];
+ }
+
+ public String state_name(double t) {
+ return state_name(state(t));
+ }
+
public MicroStats(MicroData data) {
this.data = data;
set_font();
}
- public void setData(MicroData data) {
- setStats(new MicroStats(data));
- }
-
public MicroStatsTable(MicroStats stats) {
layout = new GridBagLayout();