Change AltosLib to altoslib
[fw/altos] / micropeak / MicroGraph.java
index 8330a67bde7b8a120cfc565496f09a2aa2078315..8cb9504bd12170ec68ad3fa834316c8a22347ff4 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altoslib.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
@@ -39,15 +39,24 @@ class MicroSeries extends XYSeries {
        String          label;
        String          units;
        Color           color;
+       XYItemRenderer  renderer;
        
-       String label() {
-               return String.format("%s (%s)", label, units);
-       }
-
        void set_units(String units) {
                this.units = units;
 
-               axis.setLabel(label());
+               axis.setLabel(String.format("%s (%s)", label, units));
+
+               StandardXYToolTipGenerator      ttg;
+
+               ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units),
+                                                    new java.text.DecimalFormat("0.00"),
+                                                    new java.text.DecimalFormat("0.00"));
+               renderer.setBaseToolTipGenerator(ttg);
+       }
+
+       void set_enable(boolean enable) {
+               renderer.setSeriesVisible(0, enable);
+               axis.setVisible(enable);
        }
 
        public MicroSeries (String label, String units, Color color) {
@@ -56,9 +65,13 @@ class MicroSeries extends XYSeries {
                this.units = units;
                this.color = color;
 
-               axis = new NumberAxis(label());
+               axis = new NumberAxis();
                axis.setLabelPaint(color);
                axis.setTickLabelPaint(color);
+
+               renderer = new XYLineAndShapeRenderer(true, false);
+               renderer.setSeriesPaint(0, color);
+               set_units(units);
        }
 }
 
@@ -88,16 +101,11 @@ public class MicroGraph implements AltosUnitsListener {
        private MicroSeries addSeries(int index, String label, String units, Color color) {
                MicroSeries             series = new MicroSeries(label, units, color);
                XYSeriesCollection      dataset = new XYSeriesCollection(series);
-               XYItemRenderer          renderer = new XYLineAndShapeRenderer(true, false);
 
-               renderer.setSeriesPaint(0, color);
-               renderer.setPlot(plot);
-               renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units),
-                                                                               new java.text.DecimalFormat("0.00"),
-                                                                               new java.text.DecimalFormat("0.00")));
+               series.renderer.setPlot(plot);
                plot.setRangeAxis(index, series.axis);
                plot.setDataset(index, dataset);
-               plot.setRenderer(index, renderer);
+               plot.setRenderer(index, series.renderer);
                plot.mapDatasetToRangeAxis(index, index);
                return series;
        }
@@ -106,11 +114,14 @@ public class MicroGraph implements AltosUnitsListener {
                heightSeries.clear();
                speedSeries.clear();
                accelSeries.clear();
-               for (MicroDataPoint point : data.points()) {
-                       heightSeries.add(point.time, AltosConvert.height.value(point.height));
-                       speedSeries.add(point.time, AltosConvert.speed.value(point.speed));
-                       accelSeries.add(point.time, AltosConvert.accel.value(point.accel));
+               if (data != null) {
+                       for (MicroDataPoint point : data.points()) {
+                               heightSeries.add(point.time, AltosConvert.height.value(point.height));
+                               speedSeries.add(point.time, AltosConvert.speed.value(point.speed));
+                               accelSeries.add(point.time, AltosConvert.accel.value(point.accel));
+                       }
                }
+//             accelSeries.set_enable(false);
        }
 
        public void setName (String name) {
@@ -119,17 +130,16 @@ public class MicroGraph implements AltosUnitsListener {
 
        public void setData (MicroData data) {
                this.data = data;
-               chart.setTitle(data.name);
+               if (data != null)
+                       setName(data.name);
                resetData();
        }
 
        public void units_changed(boolean imperial_units) {
-               if (data != null) {
-                       heightSeries.set_units(AltosConvert.height.show_units());
-                       speedSeries.set_units(AltosConvert.speed.show_units());
-                       accelSeries.set_units(AltosConvert.accel.show_units());
-                       resetData();
-               }
+               heightSeries.set_units(AltosConvert.height.show_units());
+               speedSeries.set_units(AltosConvert.speed.show_units());
+               accelSeries.set_units(AltosConvert.accel.show_units());
+               resetData();
        }
 
        public MicroGraph() {