altosuilib: Adapt to AltosFlightSeries data processing plan
[fw/altos] / altosuilib / AltosUIFlightSeries.java
1 /*
2  * Copyright © 2017 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 package org.altusmetrum.altosuilib_11;
16
17 import java.util.*;
18 import java.awt.*;
19 import javax.swing.*;
20 import org.altusmetrum.altoslib_11.*;
21
22 import org.jfree.ui.*;
23 import org.jfree.chart.*;
24 import org.jfree.chart.plot.*;
25 import org.jfree.chart.axis.*;
26 import org.jfree.chart.renderer.*;
27 import org.jfree.chart.renderer.xy.*;
28 import org.jfree.chart.labels.*;
29 import org.jfree.data.xy.*;
30 import org.jfree.data.*;
31
32 class AltosUITimeSeriesAxis {
33         Color           color;
34         boolean         enabled;
35         boolean         marker;
36         AltosUIAxis     axis;
37         XYPlot          plot;
38
39         public AltosUITimeSeriesAxis(Color color, boolean enabled, AltosUIAxis axis, XYPlot plot, boolean marker) {
40                 this.color = color;
41                 this.enabled = enabled;
42                 this.axis = axis;
43                 this.plot = plot;
44                 this.marker = marker;
45         }
46 }
47
48 public class AltosUIFlightSeries extends AltosFlightSeries {
49
50         Hashtable<String,AltosUITimeSeriesAxis> axes;
51
52         AltosUIFlightSeries flight_series;
53
54         void fill_axes(String label, AltosUITimeSeriesAxis axis) {
55                 for (AltosTimeSeries ts : series) {
56                         AltosUITimeSeries uts = (AltosUITimeSeries) ts;
57
58                         if (label.equals(ts.label) || (label.equals("default") && uts.color == null)) {
59                                 if (axis.marker)
60                                         uts.set_marker(axis.color, axis.enabled, axis.plot);
61                                 else
62                                         uts.set_axis(axis.color, axis.enabled, axis.axis);
63                         }
64                 }
65         }
66
67         public void register_axis(String label,
68                                   Color color,
69                                   boolean enabled,
70                                   AltosUIAxis axis) {
71                 AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(color,
72                                                                       enabled,
73                                                                       axis,
74                                                                       null,
75                                                                       false);
76                 axes.put(label, tsa);
77                 fill_axes(label, tsa);
78         }
79
80         public void register_marker(String label,
81                                     Color color,
82                                     boolean enabled,
83                                     XYPlot plot) {
84                 AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(color,
85                                                                       enabled,
86                                                                       null,
87                                                                       plot,
88                                                                       true);
89                 axes.put(label, tsa);
90                 fill_axes(label, tsa);
91         }
92
93         public AltosTimeSeries make_series(String label, AltosUnits units) {
94
95
96                 AltosUITimeSeries time_series = new AltosUITimeSeries(label, units);
97
98                 AltosUITimeSeriesAxis tsa = axes.get(label);
99                 if (tsa == null)
100                         tsa = axes.get("default");
101                 if (tsa != null) {
102                         if (tsa.marker)
103                                 time_series.set_marker(tsa.color, tsa.enabled, tsa.plot);
104                         else
105                                 time_series.set_axis(tsa.color, tsa.enabled, tsa.axis);
106                 }
107                 return time_series;
108         }
109
110         public AltosUITimeSeries[] series(AltosCalData cal_data) {
111                 fill_in();
112                 return series.toArray(new AltosUITimeSeries[0]);
113         }
114
115         public AltosUIFlightSeries (AltosCalData cal_data) {
116                 super(cal_data);
117                 axes = new Hashtable<String,AltosUITimeSeriesAxis>();
118         }
119 }