2 * Copyright © 2010 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; version 2 of the License.
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.
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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import javax.swing.event.*;
29 import java.util.prefs.*;
31 public class AltosIgniteUI
33 implements ActionListener
41 javax.swing.Timer timer;
43 final static int timeout = 1 * 1000;
49 arm.setText(String.format("%d", time_remaining));
62 arm.setSelected(false);
63 arm.setEnabled(false);
64 fire.setEnabled(false);
70 apogee.setSelected(false);
71 main.setSelected(false);
72 fire.setEnabled(false);
78 if (time_remaining <= 0)
85 if (arm.isEnabled() && arm.isSelected() && time_remaining > 0) {
86 int igniter = AltosIgnite.None;
87 if (apogee.isSelected() && !main.isSelected())
88 igniter = AltosIgnite.Apogee;
89 else if (main.isSelected() && !apogee.isSelected())
90 igniter = AltosIgnite.Main;
91 System.out.printf ("fire %d\n", igniter);
96 public void actionPerformed(ActionEvent e) {
97 String cmd = e.getActionCommand();
98 if (cmd.equals("apogee") || cmd.equals("main")) {
100 arm.setEnabled(true);
103 if (cmd.equals("apogee") && apogee.isSelected())
104 main.setSelected(false);
105 if (cmd.equals("main") && main.isSelected())
106 apogee.setSelected(false);
108 if (cmd.equals("arm")) {
109 if (arm.isSelected()) {
110 fire.setEnabled(true);
115 if (cmd.equals("fire"))
117 if (cmd.equals("tick"))
121 public AltosIgniteUI(JFrame in_owner) {
122 Container pane = getContentPane();
123 GridBagConstraints c = new GridBagConstraints();
124 Insets i = new Insets(4,4,4,4);
126 timer = new javax.swing.Timer(timeout, this);
127 timer.setActionCommand("tick");
131 pane.setLayout(new GridBagLayout());
133 c.fill = GridBagConstraints.NONE;
134 c.anchor = GridBagConstraints.CENTER;
142 label = new JLabel ("Fire Igniter");
148 apogee = new JRadioButton ("Apogee");
150 apogee.addActionListener(this);
151 apogee.setActionCommand("apogee");
156 main = new JRadioButton ("Main");
158 main.addActionListener(this);
159 main.setActionCommand("main");
164 arm = new JToggleButton ("Arm");
166 arm.addActionListener(this);
167 arm.setActionCommand("arm");
168 arm.setEnabled(false);
173 fire = new JButton ("Fire");
174 fire.setEnabled(false);
176 fire.addActionListener(this);
177 fire.setActionCommand("fire");
180 setLocationRelativeTo(owner);