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.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
31 public class AltosFlashUI
33 implements ActionListener
47 AltosDevice debug_dongle;
50 public void actionPerformed(ActionEvent e) {
51 if (e.getSource() == cancel) {
55 String cmd = e.getActionCommand();
56 if (e.getID() == -1) {
57 JOptionPane.showMessageDialog(frame,
60 JOptionPane.ERROR_MESSAGE);
63 } else if (cmd.equals("done")) {
66 } else if (cmd.equals("start")) {
69 pbar.setValue(e.getID());
75 public void build_dialog() {
77 Insets il = new Insets(4,4,4,4);
78 Insets ir = new Insets(4,4,4,4);
80 pane = getContentPane();
81 pane.setLayout(new GridBagLayout());
83 c = new GridBagConstraints();
84 c.gridx = 0; c.gridy = 0;
85 c.fill = GridBagConstraints.NONE;
86 c.anchor = GridBagConstraints.LINE_START;
88 serial_label = new JLabel("Serial:");
89 pane.add(serial_label, c);
91 c = new GridBagConstraints();
92 c.gridx = 1; c.gridy = 0;
93 c.fill = GridBagConstraints.HORIZONTAL;
95 c.anchor = GridBagConstraints.LINE_START;
97 serial_value = new JLabel("");
98 pane.add(serial_value, c);
100 c = new GridBagConstraints();
101 c.fill = GridBagConstraints.NONE;
102 c.gridx = 0; c.gridy = 1;
103 c.anchor = GridBagConstraints.LINE_START;
105 file_label = new JLabel("File:");
106 pane.add(file_label, c);
108 c = new GridBagConstraints();
109 c.fill = GridBagConstraints.HORIZONTAL;
111 c.gridx = 1; c.gridy = 1;
112 c.anchor = GridBagConstraints.LINE_START;
114 file_value = new JLabel("");
115 pane.add(file_value, c);
117 pbar = new JProgressBar();
119 pbar.setMaximum(100);
122 pbar.setStringPainted(true);
123 pbar.setPreferredSize(new Dimension(600, 20));
124 c = new GridBagConstraints();
125 c.fill = GridBagConstraints.HORIZONTAL;
126 c.anchor = GridBagConstraints.CENTER;
127 c.gridx = 0; c.gridy = 2;
128 c.gridwidth = GridBagConstraints.REMAINDER;
129 Insets ib = new Insets(4,4,4,4);
133 cancel = new JButton("Cancel");
134 c = new GridBagConstraints();
135 c.fill = GridBagConstraints.NONE;
136 c.anchor = GridBagConstraints.CENTER;
137 c.gridx = 0; c.gridy = 3;
138 c.gridwidth = GridBagConstraints.REMAINDER;
139 Insets ic = new Insets(4,4,4,4);
142 cancel.addActionListener(this);
144 setLocationRelativeTo(frame);
147 public AltosFlashUI(JFrame in_frame) {
148 super(in_frame, "Program Altusmetrum Device", false);
154 debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any);
156 if (debug_dongle == null)
159 JFileChooser hexfile_chooser = new JFileChooser();
161 File firmwaredir = AltosPreferences.firmwaredir();
162 if (firmwaredir != null)
163 hexfile_chooser.setCurrentDirectory(firmwaredir);
165 hexfile_chooser.setDialogTitle("Select Flash Image");
166 hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
167 int returnVal = hexfile_chooser.showOpenDialog(frame);
169 if (returnVal != JFileChooser.APPROVE_OPTION)
172 file = hexfile_chooser.getSelectedFile();
175 AltosPreferences.set_firmwaredir(file.getParentFile());
178 flash = new AltosFlash(file, debug_dongle);
179 flash.addActionListener(this);
180 AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
182 romconfig_ui.set(flash.romconfig());
183 AltosRomconfig romconfig = romconfig_ui.showDialog();
185 if (romconfig != null && romconfig.valid()) {
186 flash.set_romconfig(romconfig);
187 serial_value.setText(String.format("%d",
188 flash.romconfig().serial_number));
189 file_value.setText(file.toString());
193 } catch (FileNotFoundException ee) {
194 JOptionPane.showMessageDialog(frame,
197 JOptionPane.ERROR_MESSAGE);
198 } catch (AltosSerialInUseException si) {
199 JOptionPane.showMessageDialog(frame,
200 String.format("Device \"%s\" already in use",
201 debug_dongle.toShortString()),
203 JOptionPane.ERROR_MESSAGE);
204 } catch (IOException e) {
205 JOptionPane.showMessageDialog(frame,
208 JOptionPane.ERROR_MESSAGE);
209 } catch (InterruptedException ie) {