altos: Use #define values for ublox packet types
[fw/altos] / altosuilib / AltosUIEnable.java
1 /*
2  * Copyright © 2013 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altosuilib_1;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import java.io.*;
24 import java.util.concurrent.*;
25 import java.util.*;
26 import org.altusmetrum.altoslib_2.*;
27
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
37
38 public class AltosUIEnable extends Container {
39
40         Insets  il, ir;
41         int     y;
42
43         class GraphElement implements ActionListener {
44                 AltosUIGrapher  grapher;
45                 JLabel          label;
46                 JRadioButton    enable;
47                 String          name;
48
49                 public void actionPerformed(ActionEvent ae) {
50                         grapher.set_enable(enable.isSelected());
51                 }
52
53                 GraphElement (String name, AltosUIGrapher grapher, boolean enabled) {
54                         this.name = name;
55                         this.grapher = grapher;
56                         label = new JLabel(name);
57                         enable = new JRadioButton("Enable", enabled);
58                         grapher.set_enable(enabled);                      
59                         enable.addActionListener(this);
60                 }
61         }
62
63         public void add(String name, AltosUIGrapher grapher, boolean enabled) {
64
65                 GraphElement    e = new GraphElement(name, grapher, enabled);
66
67                 /* Add label */
68                 GridBagConstraints c = new GridBagConstraints();
69                 c.gridx = 0; c.gridy = y;
70                 c.fill = GridBagConstraints.NONE;
71                 c.anchor = GridBagConstraints.LINE_START;
72                 c.insets = il;
73                 add(e.label, c);
74
75                 /* Add radio button */
76                 c = new GridBagConstraints();
77                 c.gridx = 1; c.gridy = y;
78                 c.fill = GridBagConstraints.HORIZONTAL;
79                 c.anchor = GridBagConstraints.CENTER;
80                 c.insets = ir;
81                 add(e.enable, c);
82
83                 /* Next row */
84                 y++;
85         }
86
87         public void add_units() {
88                 /* Imperial units setting */
89                 /* Add label */
90                 GridBagConstraints c = new GridBagConstraints();
91                 c.gridx = 0; c.gridy = 1000;
92                 c.fill = GridBagConstraints.NONE;
93                 c.anchor = GridBagConstraints.LINE_START;
94                 c.insets = il;
95                 add(new JLabel("Imperial Units"), c);
96
97                 JRadioButton imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units());
98                 imperial_units.addActionListener(new ActionListener() {
99                                 public void actionPerformed(ActionEvent e) {
100                                         JRadioButton item = (JRadioButton) e.getSource();
101                                         boolean enabled = item.isSelected();
102                                         AltosUIPreferences.set_imperial_units(enabled);
103                                 }
104                         });
105                 imperial_units.setToolTipText("Use Imperial units instead of metric");
106                 c = new GridBagConstraints();
107                 c.gridx = 1; c.gridy = 1000;
108                 c.fill = GridBagConstraints.NONE;
109                 c.anchor = GridBagConstraints.LINE_START;
110                 c.insets = il;
111                 add(imperial_units, c);
112         }
113
114         public AltosUIEnable() {
115                 il = new Insets(4,4,4,4);
116                 ir = new Insets(4,4,4,4);
117                 y = 0;
118                 setLayout(new GridBagLayout());
119                 add_units();
120         }
121 }