java: Bump java library versions for next release
[fw/altos] / altosuilib / AltosUIGraph.java
index e79e36ba7d3bddb7e1c62c56ca1940500e68edd1..870c4e9356de5fd82d468ba2b0e6b4f200900424 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib_1;
+package org.altusmetrum.altosuilib_3;
 
 import java.io.*;
 import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_5.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
@@ -41,8 +41,10 @@ public class AltosUIGraph implements AltosUnitsListener {
        public ChartPanel               panel;
        NumberAxis                      xAxis;
        AltosUIEnable                   enable;
-       ArrayList<AltosUISeries>        series;
+       ArrayList<AltosUIGrapher>       graphers;
        AltosUIDataSet                  dataSet;
+       int                             axis_index;
+       int                             series_index;
 
        static final private Color gridline_color = new Color(0, 0, 0);
        static final private Color border_color = new Color(255, 255, 255);
@@ -52,33 +54,59 @@ public class AltosUIGraph implements AltosUnitsListener {
                return panel;
        }
 
-       public void addSeries(int index, String label, int fetch, AltosUnits units, Color color) {
-               AltosUISeries           series = new AltosUISeries(label, fetch, units, color);
+       public AltosUIAxis newAxis(String label, AltosUnits units, Color color, int flags) {
+               AltosUIAxis axis = new AltosUIAxis(label, units, color, axis_index++, flags);
+               plot.setRangeAxis(axis.index, axis);
+               return axis;
+       }
+
+       public AltosUIAxis newAxis(String label, AltosUnits units, Color color) {
+               return newAxis(label, units, color, AltosUIAxis.axis_default);
+       }
+
+       public void addSeries(String label, int fetch, AltosUnits units, Color color,
+                             boolean enabled, AltosUIAxis axis) {
+               AltosUISeries           series = new AltosUISeries(label, fetch, units, color, enabled, axis);
                XYSeriesCollection      dataset = new XYSeriesCollection(series);
 
                series.renderer.setPlot(plot);
-               plot.setRangeAxis(index, series.axis);
-               plot.setDataset(index, dataset);
-               plot.setRenderer(index, series.renderer);
-               plot.mapDatasetToRangeAxis(index, index);
+               plot.setDataset(series_index, dataset);
+               plot.setRenderer(series_index, series.renderer);
+               plot.mapDatasetToRangeAxis(series_index, axis.index);
                if (enable != null)
-                       enable.add(label, series, true);
-               this.series.add(series);
+                       enable.add(label, series, enabled);
+               this.graphers.add(series);
+               series_index++;
+       }
+
+       public void addSeries(String label, int fetch, AltosUnits units, Color color) {
+               addSeries(label, fetch, units, color, true, newAxis(label, units, color));
+       }
+
+       public void addMarker(String label, int fetch, Color color) {
+               AltosUIMarker           marker = new AltosUIMarker(fetch, color, plot);
+               this.graphers.add(marker);
        }
-       
+
        public void resetData() {
-               for (AltosUISeries s : series)
-                       s.clear();
+               for (AltosUIGrapher g : graphers) {
+                       g.clear();
+                       g.setNotify(false);
+               }
                if (dataSet != null) {
                        for (AltosUIDataPoint dataPoint : dataSet.dataPoints())
-                               for (AltosUISeries s : series)
-                                       s.add(dataPoint);
+                               for (AltosUIGrapher g : graphers)
+                                       g.add(dataPoint);
+               }
+               for (AltosUIGrapher g : graphers) {
+                       g.setNotify(true);
+                       g.fireSeriesChanged();
                }
        }
 
        public void units_changed(boolean imperial_units) {
-               for (AltosUISeries s : series)
-                       s.set_units();
+               for (AltosUIGrapher g : graphers)
+                       g.set_units();
                resetData();
        }
 
@@ -88,18 +116,20 @@ public class AltosUIGraph implements AltosUnitsListener {
 
        public void setDataSet (AltosUIDataSet dataSet) {
                this.dataSet = dataSet;
+               resetData();
                if (dataSet != null)
                        setName(dataSet.name());
-               resetData();
        }
 
        public AltosUIGraph(AltosUIEnable enable) {
 
                this.enable = enable;
-               this.series = new ArrayList<AltosUISeries>();
+               this.graphers = new ArrayList<AltosUIGrapher>();
+               this.series_index = 0;
+               this.axis_index = 0;
 
                xAxis = new NumberAxis("Time (s)");
-               
+
                xAxis.setAutoRangeIncludesZero(true);
 
                plot = new XYPlot();
@@ -126,4 +156,4 @@ public class AltosUIGraph implements AltosUnitsListener {
 
                AltosPreferences.register_units_listener(this);
        }
-}
\ No newline at end of file
+}