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.*;
30 import java.util.concurrent.LinkedBlockingQueue;
33 import altosui.AltosSerial;
34 import altosui.AltosSerialMonitor;
35 import altosui.AltosRecord;
36 import altosui.AltosTelemetry;
37 import altosui.AltosState;
38 import altosui.AltosDeviceDialog;
39 import altosui.AltosPreferences;
40 import altosui.AltosLog;
41 import altosui.AltosVoice;
42 import altosui.AltosFlightStatusTableModel;
43 import altosui.AltosFlightInfoTableModel;
47 public class AltosConfigUI
49 implements ActionListener, ItemListener, DocumentListener
57 JLabel main_deploy_label;
58 JLabel apogee_delay_label;
59 JLabel radio_channel_label;
60 JLabel callsign_label;
68 JComboBox main_deploy_value;
69 JComboBox apogee_delay_value;
70 JComboBox radio_channel_value;
71 JTextField callsign_value;
77 ActionListener listener;
79 static String[] main_deploy_values = {
80 "100", "150", "200", "250", "300", "350",
84 static String[] apogee_delay_values = {
85 "0", "1", "2", "3", "4", "5"
88 static String[] radio_channel_values = new String[10];
90 for (int i = 0; i <= 9; i++)
91 radio_channel_values[i] = String.format("Channel %1d (%7.3fMHz)",
92 i, 434.550 + i * 0.1);
95 /* A window listener to catch closing events and tell the config code */
96 class ConfigListener extends WindowAdapter {
99 public ConfigListener(AltosConfigUI this_ui) {
103 public void windowClosing(WindowEvent e) {
104 ui.actionPerformed(new ActionEvent(e.getSource(),
105 ActionEvent.ACTION_PERFORMED,
110 /* Build the UI using a grid bag */
111 public AltosConfigUI(JFrame in_owner) {
112 super (in_owner, "Configure TeleMetrum", false);
115 GridBagConstraints c;
117 Insets il = new Insets(4,4,4,4);
118 Insets ir = new Insets(4,4,4,4);
120 pane = getContentPane();
121 pane.setLayout(new GridBagLayout());
124 c = new GridBagConstraints();
125 c.gridx = 0; c.gridy = 0;
127 c.fill = GridBagConstraints.NONE;
128 c.anchor = GridBagConstraints.LINE_START;
130 product_label = new JLabel("Product:");
131 pane.add(product_label, c);
133 c = new GridBagConstraints();
134 c.gridx = 3; c.gridy = 0;
136 c.fill = GridBagConstraints.HORIZONTAL;
138 c.anchor = GridBagConstraints.LINE_START;
140 product_value = new JLabel("");
141 pane.add(product_value, c);
144 c = new GridBagConstraints();
145 c.gridx = 0; c.gridy = 1;
147 c.fill = GridBagConstraints.NONE;
148 c.anchor = GridBagConstraints.LINE_START;
150 version_label = new JLabel("Software version:");
151 pane.add(version_label, c);
153 c = new GridBagConstraints();
154 c.gridx = 3; c.gridy = 1;
156 c.fill = GridBagConstraints.HORIZONTAL;
158 c.anchor = GridBagConstraints.LINE_START;
160 version_value = new JLabel("");
161 pane.add(version_value, c);
164 c = new GridBagConstraints();
165 c.gridx = 0; c.gridy = 2;
167 c.fill = GridBagConstraints.NONE;
168 c.anchor = GridBagConstraints.LINE_START;
170 serial_label = new JLabel("Serial:");
171 pane.add(serial_label, c);
173 c = new GridBagConstraints();
174 c.gridx = 3; c.gridy = 2;
176 c.fill = GridBagConstraints.HORIZONTAL;
178 c.anchor = GridBagConstraints.LINE_START;
180 serial_value = new JLabel("");
181 pane.add(serial_value, c);
184 c = new GridBagConstraints();
185 c.gridx = 0; c.gridy = 3;
187 c.fill = GridBagConstraints.NONE;
188 c.anchor = GridBagConstraints.LINE_START;
191 main_deploy_label = new JLabel("Main Deploy Altitude(m):");
192 pane.add(main_deploy_label, c);
194 c = new GridBagConstraints();
195 c.gridx = 3; c.gridy = 3;
197 c.fill = GridBagConstraints.HORIZONTAL;
199 c.anchor = GridBagConstraints.LINE_START;
202 main_deploy_value = new JComboBox(main_deploy_values);
203 main_deploy_value.setEditable(true);
204 main_deploy_value.addItemListener(this);
205 pane.add(main_deploy_value, c);
208 c = new GridBagConstraints();
209 c.gridx = 0; c.gridy = 4;
211 c.fill = GridBagConstraints.NONE;
212 c.anchor = GridBagConstraints.LINE_START;
215 apogee_delay_label = new JLabel("Apogee Delay(s):");
216 pane.add(apogee_delay_label, c);
218 c = new GridBagConstraints();
219 c.gridx = 3; c.gridy = 4;
221 c.fill = GridBagConstraints.HORIZONTAL;
223 c.anchor = GridBagConstraints.LINE_START;
226 apogee_delay_value = new JComboBox(apogee_delay_values);
227 apogee_delay_value.setEditable(true);
228 apogee_delay_value.addItemListener(this);
229 pane.add(apogee_delay_value, c);
232 c = new GridBagConstraints();
233 c.gridx = 0; c.gridy = 5;
235 c.fill = GridBagConstraints.NONE;
236 c.anchor = GridBagConstraints.LINE_START;
239 radio_channel_label = new JLabel("Radio Channel:");
240 pane.add(radio_channel_label, c);
242 c = new GridBagConstraints();
243 c.gridx = 3; c.gridy = 5;
245 c.fill = GridBagConstraints.HORIZONTAL;
247 c.anchor = GridBagConstraints.LINE_START;
250 radio_channel_value = new JComboBox(radio_channel_values);
251 radio_channel_value.setEditable(false);
252 radio_channel_value.addItemListener(this);
253 pane.add(radio_channel_value, c);
256 c = new GridBagConstraints();
257 c.gridx = 0; c.gridy = 6;
259 c.fill = GridBagConstraints.NONE;
260 c.anchor = GridBagConstraints.LINE_START;
263 callsign_label = new JLabel("Callsign:");
264 pane.add(callsign_label, c);
266 c = new GridBagConstraints();
267 c.gridx = 3; c.gridy = 6;
269 c.fill = GridBagConstraints.HORIZONTAL;
271 c.anchor = GridBagConstraints.LINE_START;
274 callsign_value = new JTextField("N0CALL");
275 callsign_value.getDocument().addDocumentListener(this);
276 pane.add(callsign_value, c);
279 c = new GridBagConstraints();
280 c.gridx = 0; c.gridy = 7;
282 c.fill = GridBagConstraints.NONE;
283 c.anchor = GridBagConstraints.LINE_START;
285 save = new JButton("Save");
287 save.addActionListener(this);
288 save.setActionCommand("save");
290 c = new GridBagConstraints();
291 c.gridx = 2; c.gridy = 7;
293 c.fill = GridBagConstraints.NONE;
294 c.anchor = GridBagConstraints.CENTER;
296 reset = new JButton("Reset");
298 reset.addActionListener(this);
299 reset.setActionCommand("reset");
301 c = new GridBagConstraints();
302 c.gridx = 4; c.gridy = 7;
304 c.fill = GridBagConstraints.NONE;
305 c.anchor = GridBagConstraints.LINE_END;
307 close = new JButton("Close");
309 close.addActionListener(this);
310 close.setActionCommand("close");
312 addWindowListener(new ConfigListener(this));
315 /* Once the initial values are set, the config code will show the dialog */
316 public void make_visible() {
318 setLocationRelativeTo(owner);
322 /* If any values have been changed, confirm before closing */
323 public boolean check_dirty() {
325 Object[] options = { "Close anyway", "Keep editing" };
327 i = JOptionPane.showOptionDialog(this,
328 "Configuration modified, close anyway?",
329 "Configuration Modified",
330 JOptionPane.DEFAULT_OPTION,
331 JOptionPane.WARNING_MESSAGE,
332 null, options, options[1]);
339 /* Listen for events from our buttons */
340 public void actionPerformed(ActionEvent e) {
341 String cmd = e.getActionCommand();
343 if (cmd.equals("close"))
346 listener.actionPerformed(e);
347 if (cmd.equals("close")) {
354 /* ItemListener interface method */
355 public void itemStateChanged(ItemEvent e) {
359 /* DocumentListener interface methods */
360 public void changedUpdate(DocumentEvent e) {
364 public void insertUpdate(DocumentEvent e) {
368 public void removeUpdate(DocumentEvent e) {
372 /* Let the config code hook on a listener */
373 public void addActionListener(ActionListener l) {
377 /* set and get all of the dialog values */
378 public void set_product(String product) {
379 product_value.setText(product);
382 public void set_version(String version) {
383 version_value.setText(version);
386 public void set_serial(int serial) {
387 serial_value.setText(String.format("%d", serial));
390 public void set_main_deploy(int new_main_deploy) {
391 main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy));
394 public int main_deploy() {
395 return Integer.parseInt(main_deploy_value.getSelectedItem().toString());
398 public void set_apogee_delay(int new_apogee_delay) {
399 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
402 public int apogee_delay() {
403 return Integer.parseInt(apogee_delay_value.getSelectedItem().toString());
406 public void set_radio_channel(int new_radio_channel) {
407 radio_channel_value.setSelectedIndex(new_radio_channel);
410 public int radio_channel() {
411 return radio_channel_value.getSelectedIndex();
414 public void set_callsign(String new_callsign) {
415 callsign_value.setText(new_callsign);
418 public String callsign() {
419 return callsign_value.getText();
422 public void set_clean() {