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 (cmd.equals("done"))
58 else if (cmd.equals("start")) {
61 pbar.setValue(e.getID());
72 public void build_dialog() {
74 Insets il = new Insets(4,4,4,4);
75 Insets ir = new Insets(4,4,4,4);
77 pane = getContentPane();
78 pane.setLayout(new GridBagLayout());
80 c = new GridBagConstraints();
81 c.gridx = 0; c.gridy = 0;
82 c.fill = GridBagConstraints.NONE;
83 c.anchor = GridBagConstraints.LINE_START;
85 serial_label = new JLabel("Serial:");
86 pane.add(serial_label, c);
88 c = new GridBagConstraints();
89 c.gridx = 1; c.gridy = 0;
90 c.fill = GridBagConstraints.HORIZONTAL;
92 c.anchor = GridBagConstraints.LINE_START;
94 serial_value = new JLabel("");
95 pane.add(serial_value, c);
97 c = new GridBagConstraints();
98 c.fill = GridBagConstraints.NONE;
99 c.gridx = 0; c.gridy = 1;
100 c.anchor = GridBagConstraints.LINE_START;
102 file_label = new JLabel("File:");
103 pane.add(file_label, c);
105 c = new GridBagConstraints();
106 c.fill = GridBagConstraints.HORIZONTAL;
108 c.gridx = 1; c.gridy = 1;
109 c.anchor = GridBagConstraints.LINE_START;
111 file_value = new JLabel("");
112 pane.add(file_value, c);
114 pbar = new JProgressBar();
116 pbar.setMaximum(100);
119 pbar.setStringPainted(true);
120 pbar.setPreferredSize(new Dimension(600, 20));
121 c = new GridBagConstraints();
122 c.fill = GridBagConstraints.HORIZONTAL;
123 c.anchor = GridBagConstraints.CENTER;
124 c.gridx = 0; c.gridy = 2;
125 c.gridwidth = GridBagConstraints.REMAINDER;
126 Insets ib = new Insets(4,4,4,4);
130 cancel = new JButton("Cancel");
131 c = new GridBagConstraints();
132 c.fill = GridBagConstraints.NONE;
133 c.anchor = GridBagConstraints.CENTER;
134 c.gridx = 0; c.gridy = 3;
135 c.gridwidth = GridBagConstraints.REMAINDER;
136 Insets ic = new Insets(4,4,4,4);
139 cancel.addActionListener(this);
141 setLocationRelativeTo(frame);
144 public AltosFlashUI(JFrame in_frame) {
145 super(in_frame, "Program Altusmetrum Device", false);
151 debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any);
153 if (debug_dongle == null)
156 JFileChooser hexfile_chooser = new JFileChooser();
158 File firmwaredir = AltosPreferences.firmwaredir();
159 if (firmwaredir != null)
160 hexfile_chooser.setCurrentDirectory(firmwaredir);
162 hexfile_chooser.setDialogTitle("Select Flash Image");
163 hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
164 int returnVal = hexfile_chooser.showOpenDialog(frame);
166 if (returnVal != JFileChooser.APPROVE_OPTION)
169 file = hexfile_chooser.getSelectedFile();
172 AltosPreferences.set_firmwaredir(file.getParentFile());
175 flash = new AltosFlash(file, debug_dongle);
176 flash.addActionListener(this);
177 AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
179 romconfig_ui.set(flash.romconfig());
180 AltosRomconfig romconfig = romconfig_ui.showDialog();
182 if (romconfig != null && romconfig.valid()) {
183 flash.set_romconfig(romconfig);
184 serial_value.setText(String.format("%d",
185 flash.romconfig().serial_number));
186 file_value.setText(file.toString());
191 } catch (FileNotFoundException ee) {
192 JOptionPane.showMessageDialog(frame,
195 JOptionPane.ERROR_MESSAGE);
196 } catch (AltosSerialInUseException si) {
197 JOptionPane.showMessageDialog(frame,
198 String.format("Device \"%s\" already in use",
199 debug_dongle.toShortString()),
201 JOptionPane.ERROR_MESSAGE);
202 } catch (IOException e) {
203 JOptionPane.showMessageDialog(frame,
206 JOptionPane.ERROR_MESSAGE);
207 } catch (InterruptedException ie) {