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 AltosRomconfigUI
33 implements ActionListener
38 JLabel radio_calibration_label;
41 JTextField serial_value;
42 JTextField radio_calibration_value;
47 /* Build the UI using a grid bag */
48 public AltosRomconfigUI(JFrame in_owner) {
49 super (in_owner, "Configure TeleMetrum Rom Values", true);
54 Insets il = new Insets(4,4,4,4);
55 Insets ir = new Insets(4,4,4,4);
57 pane = getContentPane();
58 pane.setLayout(new GridBagLayout());
61 c = new GridBagConstraints();
62 c.gridx = 0; c.gridy = 0;
64 c.fill = GridBagConstraints.NONE;
65 c.anchor = GridBagConstraints.LINE_START;
67 serial_label = new JLabel("Serial:");
68 pane.add(serial_label, c);
70 c = new GridBagConstraints();
71 c.gridx = 3; c.gridy = 0;
73 c.fill = GridBagConstraints.HORIZONTAL;
75 c.anchor = GridBagConstraints.LINE_START;
77 serial_value = new JTextField("0");
78 pane.add(serial_value, c);
80 /* Radio calibration value */
81 c = new GridBagConstraints();
82 c.gridx = 0; c.gridy = 1;
84 c.fill = GridBagConstraints.NONE;
85 c.anchor = GridBagConstraints.LINE_START;
88 radio_calibration_label = new JLabel("Radio Calibration:");
89 pane.add(radio_calibration_label, c);
91 c = new GridBagConstraints();
92 c.gridx = 3; c.gridy = 1;
94 c.fill = GridBagConstraints.HORIZONTAL;
96 c.anchor = GridBagConstraints.LINE_START;
99 radio_calibration_value = new JTextField("1186611");
100 pane.add(radio_calibration_value, c);
103 c = new GridBagConstraints();
104 c.gridx = 0; c.gridy = 2;
106 c.fill = GridBagConstraints.NONE;
107 c.anchor = GridBagConstraints.CENTER;
109 ok = new JButton("OK");
111 ok.addActionListener(this);
112 ok.setActionCommand("ok");
114 c = new GridBagConstraints();
115 c.gridx = 3; c.gridy = 2;
117 c.fill = GridBagConstraints.NONE;
118 c.anchor = GridBagConstraints.CENTER;
120 cancel = new JButton("Cancel");
122 cancel.addActionListener(this);
123 cancel.setActionCommand("cancel");
126 setLocationRelativeTo(owner);
131 /* Listen for events from our buttons */
132 public void actionPerformed(ActionEvent e) {
133 String cmd = e.getActionCommand();
135 if (cmd.equals("ok")) {
136 AltosRomconfig romconfig = romconfig();
137 if (romconfig == null || !romconfig.valid()) {
138 JOptionPane.showMessageDialog(this,
139 "Invalid serial number or radio calibration value",
140 "Invalid rom configuration",
141 JOptionPane.ERROR_MESSAGE);
150 return Integer.parseInt(serial_value.getText());
153 void set_serial(int serial) {
154 serial_value.setText(String.format("%d", serial));
157 int radio_calibration() {
158 return Integer.parseInt(radio_calibration_value.getText());
161 void set_radio_calibration(int calibration) {
162 radio_calibration_value.setText(String.format("%d", calibration));
165 public void set(AltosRomconfig config) {
166 if (config != null && config.valid()) {
167 set_serial(config.serial_number);
168 set_radio_calibration(config.radio_calibration);
172 AltosRomconfig romconfig() {
174 return new AltosRomconfig(serial(), radio_calibration());
175 } catch (NumberFormatException ne) {
180 public AltosRomconfig showDialog() {