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;
34 public class AltosConfigUI
36 implements ActionListener, ItemListener, DocumentListener
44 JLabel main_deploy_label;
45 JLabel apogee_delay_label;
46 JLabel radio_channel_label;
47 JLabel radio_calibration_label;
48 JLabel callsign_label;
56 JComboBox main_deploy_value;
57 JComboBox apogee_delay_value;
58 JComboBox radio_channel_value;
59 JTextField radio_calibration_value;
60 JTextField callsign_value;
66 ActionListener listener;
68 static String[] main_deploy_values = {
69 "100", "150", "200", "250", "300", "350",
73 static String[] apogee_delay_values = {
74 "0", "1", "2", "3", "4", "5"
77 static String[] radio_channel_values = new String[10];
79 for (int i = 0; i <= 9; i++)
80 radio_channel_values[i] = String.format("Channel %1d (%7.3fMHz)",
81 i, 434.550 + i * 0.1);
84 /* A window listener to catch closing events and tell the config code */
85 class ConfigListener extends WindowAdapter {
88 public ConfigListener(AltosConfigUI this_ui) {
92 public void windowClosing(WindowEvent e) {
93 ui.actionPerformed(new ActionEvent(e.getSource(),
94 ActionEvent.ACTION_PERFORMED,
99 /* Build the UI using a grid bag */
100 public AltosConfigUI(JFrame in_owner) {
101 super (in_owner, "Configure TeleMetrum", false);
104 GridBagConstraints c;
106 Insets il = new Insets(4,4,4,4);
107 Insets ir = new Insets(4,4,4,4);
109 pane = getContentPane();
110 pane.setLayout(new GridBagLayout());
113 c = new GridBagConstraints();
114 c.gridx = 0; c.gridy = 0;
116 c.fill = GridBagConstraints.NONE;
117 c.anchor = GridBagConstraints.LINE_START;
119 product_label = new JLabel("Product:");
120 pane.add(product_label, c);
122 c = new GridBagConstraints();
123 c.gridx = 3; c.gridy = 0;
125 c.fill = GridBagConstraints.HORIZONTAL;
127 c.anchor = GridBagConstraints.LINE_START;
129 product_value = new JLabel("");
130 pane.add(product_value, c);
133 c = new GridBagConstraints();
134 c.gridx = 0; c.gridy = 1;
136 c.fill = GridBagConstraints.NONE;
137 c.anchor = GridBagConstraints.LINE_START;
140 version_label = new JLabel("Software version:");
141 pane.add(version_label, c);
143 c = new GridBagConstraints();
144 c.gridx = 3; c.gridy = 1;
146 c.fill = GridBagConstraints.HORIZONTAL;
148 c.anchor = GridBagConstraints.LINE_START;
151 version_value = new JLabel("");
152 pane.add(version_value, c);
155 c = new GridBagConstraints();
156 c.gridx = 0; c.gridy = 2;
158 c.fill = GridBagConstraints.NONE;
159 c.anchor = GridBagConstraints.LINE_START;
162 serial_label = new JLabel("Serial:");
163 pane.add(serial_label, c);
165 c = new GridBagConstraints();
166 c.gridx = 3; c.gridy = 2;
168 c.fill = GridBagConstraints.HORIZONTAL;
170 c.anchor = GridBagConstraints.LINE_START;
173 serial_value = new JLabel("");
174 pane.add(serial_value, c);
177 c = new GridBagConstraints();
178 c.gridx = 0; c.gridy = 3;
180 c.fill = GridBagConstraints.NONE;
181 c.anchor = GridBagConstraints.LINE_START;
184 main_deploy_label = new JLabel("Main Deploy Altitude(m):");
185 pane.add(main_deploy_label, c);
187 c = new GridBagConstraints();
188 c.gridx = 3; c.gridy = 3;
190 c.fill = GridBagConstraints.HORIZONTAL;
192 c.anchor = GridBagConstraints.LINE_START;
195 main_deploy_value = new JComboBox(main_deploy_values);
196 main_deploy_value.setEditable(true);
197 main_deploy_value.addItemListener(this);
198 pane.add(main_deploy_value, c);
201 c = new GridBagConstraints();
202 c.gridx = 0; c.gridy = 4;
204 c.fill = GridBagConstraints.NONE;
205 c.anchor = GridBagConstraints.LINE_START;
208 apogee_delay_label = new JLabel("Apogee Delay(s):");
209 pane.add(apogee_delay_label, c);
211 c = new GridBagConstraints();
212 c.gridx = 3; c.gridy = 4;
214 c.fill = GridBagConstraints.HORIZONTAL;
216 c.anchor = GridBagConstraints.LINE_START;
219 apogee_delay_value = new JComboBox(apogee_delay_values);
220 apogee_delay_value.setEditable(true);
221 apogee_delay_value.addItemListener(this);
222 pane.add(apogee_delay_value, c);
225 c = new GridBagConstraints();
226 c.gridx = 0; c.gridy = 5;
228 c.fill = GridBagConstraints.NONE;
229 c.anchor = GridBagConstraints.LINE_START;
232 radio_channel_label = new JLabel("Radio Channel:");
233 pane.add(radio_channel_label, c);
235 c = new GridBagConstraints();
236 c.gridx = 3; c.gridy = 5;
238 c.fill = GridBagConstraints.HORIZONTAL;
240 c.anchor = GridBagConstraints.LINE_START;
243 radio_channel_value = new JComboBox(radio_channel_values);
244 radio_channel_value.setEditable(false);
245 radio_channel_value.addItemListener(this);
246 pane.add(radio_channel_value, c);
248 /* Radio Calibration */
249 c = new GridBagConstraints();
250 c.gridx = 0; c.gridy = 6;
252 c.fill = GridBagConstraints.NONE;
253 c.anchor = GridBagConstraints.LINE_START;
256 radio_calibration_label = new JLabel("RF Calibration:");
257 pane.add(radio_calibration_label, c);
259 c = new GridBagConstraints();
260 c.gridx = 3; c.gridy = 6;
262 c.fill = GridBagConstraints.HORIZONTAL;
264 c.anchor = GridBagConstraints.LINE_START;
267 radio_calibration_value = new JTextField(String.format("%d", 1186611));
268 radio_calibration_value.getDocument().addDocumentListener(this);
269 pane.add(radio_calibration_value, c);
272 c = new GridBagConstraints();
273 c.gridx = 0; c.gridy = 7;
275 c.fill = GridBagConstraints.NONE;
276 c.anchor = GridBagConstraints.LINE_START;
279 callsign_label = new JLabel("Callsign:");
280 pane.add(callsign_label, c);
282 c = new GridBagConstraints();
283 c.gridx = 3; c.gridy = 7;
285 c.fill = GridBagConstraints.HORIZONTAL;
287 c.anchor = GridBagConstraints.LINE_START;
290 callsign_value = new JTextField("N0CALL");
291 callsign_value.getDocument().addDocumentListener(this);
292 pane.add(callsign_value, c);
295 c = new GridBagConstraints();
296 c.gridx = 0; c.gridy = 8;
298 c.fill = GridBagConstraints.NONE;
299 c.anchor = GridBagConstraints.LINE_START;
301 save = new JButton("Save");
303 save.addActionListener(this);
304 save.setActionCommand("save");
306 c = new GridBagConstraints();
307 c.gridx = 0; c.gridy = 8;
309 c.fill = GridBagConstraints.NONE;
310 c.anchor = GridBagConstraints.CENTER;
312 reset = new JButton("Reset");
314 reset.addActionListener(this);
315 reset.setActionCommand("reset");
317 c = new GridBagConstraints();
318 c.gridx = 0; c.gridy = 8;
320 c.fill = GridBagConstraints.NONE;
321 c.anchor = GridBagConstraints.LINE_END;
323 close = new JButton("Close");
325 close.addActionListener(this);
326 close.setActionCommand("close");
328 addWindowListener(new ConfigListener(this));
331 /* Once the initial values are set, the config code will show the dialog */
332 public void make_visible() {
334 setLocationRelativeTo(owner);
338 /* If any values have been changed, confirm before closing */
339 public boolean check_dirty() {
341 Object[] options = { "Close anyway", "Keep editing" };
343 i = JOptionPane.showOptionDialog(this,
344 "Configuration modified, close anyway?",
345 "Configuration Modified",
346 JOptionPane.DEFAULT_OPTION,
347 JOptionPane.WARNING_MESSAGE,
348 null, options, options[1]);
355 /* Listen for events from our buttons */
356 public void actionPerformed(ActionEvent e) {
357 String cmd = e.getActionCommand();
359 if (cmd.equals("close"))
362 listener.actionPerformed(e);
363 if (cmd.equals("close")) {
370 /* ItemListener interface method */
371 public void itemStateChanged(ItemEvent e) {
375 /* DocumentListener interface methods */
376 public void changedUpdate(DocumentEvent e) {
380 public void insertUpdate(DocumentEvent e) {
384 public void removeUpdate(DocumentEvent e) {
388 /* Let the config code hook on a listener */
389 public void addActionListener(ActionListener l) {
393 /* set and get all of the dialog values */
394 public void set_product(String product) {
395 product_value.setText(product);
398 public void set_version(String version) {
399 version_value.setText(version);
402 public void set_serial(int serial) {
403 serial_value.setText(String.format("%d", serial));
406 public void set_main_deploy(int new_main_deploy) {
407 main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy));
410 public int main_deploy() {
411 return Integer.parseInt(main_deploy_value.getSelectedItem().toString());
414 public void set_apogee_delay(int new_apogee_delay) {
415 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
418 public int apogee_delay() {
419 return Integer.parseInt(apogee_delay_value.getSelectedItem().toString());
422 public void set_radio_channel(int new_radio_channel) {
423 radio_channel_value.setSelectedIndex(new_radio_channel);
426 public int radio_channel() {
427 return radio_channel_value.getSelectedIndex();
430 public void set_radio_calibration(int new_radio_calibration) {
431 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
434 public int radio_calibration() {
435 return Integer.parseInt(radio_calibration_value.getText());
438 public void set_callsign(String new_callsign) {
439 callsign_value.setText(new_callsign);
442 public String callsign() {
443 return callsign_value.getText();
446 public void set_clean() {