]> git.gag.com Git - fw/altos/blob - altosuilib/AltosUIFlightSeries.java
altoslib: use motor pressure calibration data for EasyMotor
[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_14;
16
17 import java.util.*;
18 import java.awt.*;
19 import javax.swing.*;
20 import org.altusmetrum.altoslib_14.*;
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         AltosUILineStyle        line_style;
34         boolean                 enabled;
35         boolean                 marker;
36         boolean                 marker_top;
37         AltosUIAxis             axis;
38         XYPlot                  plot;
39
40         public AltosUITimeSeriesAxis(AltosUILineStyle line_style, boolean enabled,
41                                      AltosUIAxis axis, XYPlot plot, boolean marker, boolean marker_top) {
42                 this.line_style = line_style;
43                 this.enabled = enabled;
44                 this.axis = axis;
45                 this.plot = plot;
46                 this.marker = marker;
47                 this.marker_top = marker_top;
48         }
49 }
50
51 public class AltosUIFlightSeries extends AltosFlightSeries {
52
53         Hashtable<String,AltosUITimeSeriesAxis> axes;
54
55         void fill_axes(String label, AltosUITimeSeriesAxis axis) {
56                 for (AltosTimeSeries ts : series) {
57                         AltosUITimeSeries uts = (AltosUITimeSeries) ts;
58
59                         if (label.equals(ts.label) || (label.equals("default") && uts.line_style == null)) {
60                                 uts.custom_axis_set = true;
61                                 if (axis.marker)
62                                         uts.set_marker(axis.line_style, axis.enabled, axis.plot, axis.marker_top);
63                                 else
64                                         uts.set_axis(axis.line_style, axis.enabled, axis.axis);
65                         }
66                 }
67         }
68
69         void check_axes() {
70                 for (AltosTimeSeries ts : series) {
71                         AltosUITimeSeries uts = (AltosUITimeSeries) ts;
72
73                         if (!uts.custom_axis_set)
74                                 System.out.printf("%s using default axis\n", ts.label);
75                 }
76         }
77
78         public void register_axis(String label,
79                                   AltosUILineStyle line_style,
80                                   boolean enabled,
81                                   AltosUIAxis axis) {
82                 AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(line_style,
83                                                                       enabled,
84                                                                       axis,
85                                                                       null,
86                                                                       false,
87                                                                       false);
88                 axes.put(label, tsa);
89                 fill_axes(label, tsa);
90         }
91
92         public void register_marker(String label,
93                                     AltosUILineStyle line_style,
94                                     boolean enabled,
95                                     XYPlot plot,
96                                     boolean marker_top) {
97                 AltosUITimeSeriesAxis tsa = new AltosUITimeSeriesAxis(line_style,
98                                                                       enabled,
99                                                                       null,
100                                                                       plot,
101                                                                       true,
102                                                                       marker_top);
103                 axes.put(label, tsa);
104                 fill_axes(label, tsa);
105         }
106
107         public AltosTimeSeries make_series(String label, AltosUnits units) {
108
109                 AltosUITimeSeries time_series = new AltosUITimeSeries(label, units);
110
111                 AltosUITimeSeriesAxis tsa = axes.get(label);
112                 if (tsa == null)
113                         tsa = axes.get("default");
114                 else
115                         time_series.custom_axis_set = true;
116                 if (tsa != null) {
117                         if (tsa.marker)
118                                 time_series.set_marker(tsa.line_style, tsa.enabled, tsa.plot, tsa.marker_top);
119                         else
120                                 time_series.set_axis(tsa.line_style, tsa.enabled, tsa.axis);
121                 }
122                 return time_series;
123         }
124
125         public AltosUITimeSeries[] series(AltosCalData cal_data) {
126                 finish();
127                 return series.toArray(new AltosUITimeSeries[0]);
128         }
129
130         public AltosUIFlightSeries (AltosCalData cal_data) {
131                 super(cal_data);
132                 axes = new Hashtable<String,AltosUITimeSeriesAxis>();
133         }
134 }