2 * Copyright © 2017 Keith Packard <keithp@keithp.com>
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 3 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 package org.altusmetrum.altosuilib_12;
22 import java.awt.event.*;
25 import javax.swing.event.*;
26 import org.altusmetrum.altoslib_12.*;
28 public class AltosUIAccelCal
30 implements AltosAccelCalListener, ActionListener
43 int accel_plus, accel_minus;
45 private void make_visible() {
46 System.out.printf("Make calibration dialog visible\n");
52 public boolean doit() {
58 public int accel_cal_plus() {
61 return AltosLib.MISSING;
64 public int accel_cal_minus() {
67 return AltosLib.MISSING;
70 /* AltosAccelCalListener interface */
71 public void set_thread(AltosAccelCal cal, Thread thread) {
75 public void set_phase(AltosAccelCal cal, final int phase) {
76 SwingUtilities.invokeLater(new Runnable() {
79 case AltosAccelCal.phase_antenna_up:
80 message.setText("Orient antenna upwards and click on Antenna Up");
81 antenna_up.setEnabled(true);
82 antenna_down.setEnabled(false);
85 case AltosAccelCal.phase_antenna_down:
86 message.setText("Orient antenna upwards and click on Antenna Down");
87 antenna_up.setEnabled(false);
88 antenna_down.setEnabled(true);
96 public void cal_done(AltosAccelCal cal, int plus, int minus) {
99 SwingUtilities.invokeLater(new Runnable() {
101 message.setText("Calibration succeeded, press OK to continue");
102 antenna_up.setEnabled(false);
103 antenna_down.setEnabled(false);
109 public void message(AltosAccelCal cal, final String msg) {
110 SwingUtilities.invokeLater(new Runnable() {
112 message.setText(msg);
117 public void error(AltosAccelCal cal, String msg) {
121 /* ActionListener interface */
122 public void actionPerformed(ActionEvent e) {
123 String cmd = e.getActionCommand();
125 if ("up".equals(cmd)) {
127 antenna_up.setEnabled(false);
128 } else if ("down".equals(cmd)) {
130 antenna_down.setEnabled(false);
131 } else if ("ok".equals(cmd)) {
133 this.setVisible(false);
136 } catch (InterruptedException ie) {
138 } else if ("cancel".equals(cmd)) {
140 this.setVisible(false);
143 } catch (InterruptedException ie) {
147 public AltosUIAccelCal(Frame owner, AltosLink link) {
148 super(owner, "Calibrate Accelerometer", true);
153 pane = getContentPane();
154 pane.setLayout(new GridBagLayout());
156 GridBagConstraints c = new GridBagConstraints();
157 c.insets = new Insets(4,4,4,4);
161 c.fill = GridBagConstraints.HORIZONTAL;
162 c.anchor = GridBagConstraints.WEST;
169 message = new JTextField(64);
170 pane.add(message, c);
174 c.fill = GridBagConstraints.NONE;
175 c.anchor = GridBagConstraints.WEST;
182 antenna_up = new JButton("Antenna Up");
183 antenna_up.setActionCommand("up");
184 antenna_up.setEnabled(false);
185 antenna_up.addActionListener(this);
186 pane.add(antenna_up, c);
189 c.fill = GridBagConstraints.NONE;
190 c.anchor = GridBagConstraints.WEST;
197 antenna_down = new JButton("Antenna Down");
198 antenna_down.setActionCommand("down");
199 antenna_down.setEnabled(false);
200 antenna_down.addActionListener(this);
201 pane.add(antenna_down, c);
204 c.fill = GridBagConstraints.NONE;
205 c.anchor = GridBagConstraints.WEST;
212 ok = new JButton("OK");
213 ok.setActionCommand("ok");
214 ok.setEnabled(false);
215 ok.addActionListener(this);
219 c.fill = GridBagConstraints.NONE;
220 c.anchor = GridBagConstraints.WEST;
227 cancel = new JButton("Cancel");
228 cancel.setActionCommand("cancel");
229 cancel.setEnabled(true);
230 cancel.addActionListener(this);
233 cal = new AltosAccelCal(this.link, this);