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 import altosui.AltosHexfile;
32 import altosui.AltosFlash;
34 public class AltosFlashUI
36 implements Runnable, ActionListener
50 AltosDevice debug_dongle;
53 public void actionPerformed(ActionEvent e) {
54 if (e.getSource() == cancel) {
58 String cmd = e.getActionCommand();
59 if (cmd.equals("done"))
61 else if (cmd.equals("start")) {
64 pbar.setValue(e.getID());
71 flash = new AltosFlash(file, debug_dongle);
72 flash.addActionListener(this);
75 AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
77 romconfig_ui.set(flash.romconfig());
78 AltosRomconfig romconfig = romconfig_ui.showDialog();
80 if (romconfig != null && romconfig.valid()) {
81 flash.set_romconfig(romconfig);
82 serial_value.setText(String.format("%d",
83 flash.romconfig().serial_number));
84 file_value.setText(file.toString());
89 } catch (FileNotFoundException ee) {
90 JOptionPane.showMessageDialog(frame,
93 JOptionPane.ERROR_MESSAGE);
94 } catch (IOException e) {
95 JOptionPane.showMessageDialog(frame,
98 JOptionPane.ERROR_MESSAGE);
99 } catch (InterruptedException ie) {
106 public void abort() {
111 public void build_dialog() {
112 GridBagConstraints c;
113 Insets il = new Insets(4,4,4,4);
114 Insets ir = new Insets(4,4,4,4);
116 pane = getContentPane();
117 pane.setLayout(new GridBagLayout());
119 c = new GridBagConstraints();
120 c.gridx = 0; c.gridy = 0;
121 c.fill = GridBagConstraints.NONE;
122 c.anchor = GridBagConstraints.LINE_START;
124 serial_label = new JLabel("Serial:");
125 pane.add(serial_label, c);
127 c = new GridBagConstraints();
128 c.gridx = 1; c.gridy = 0;
129 c.fill = GridBagConstraints.HORIZONTAL;
131 c.anchor = GridBagConstraints.LINE_START;
133 serial_value = new JLabel("");
134 pane.add(serial_value, c);
136 c = new GridBagConstraints();
137 c.fill = GridBagConstraints.NONE;
138 c.gridx = 0; c.gridy = 1;
139 c.anchor = GridBagConstraints.LINE_START;
141 file_label = new JLabel("File:");
142 pane.add(file_label, c);
144 c = new GridBagConstraints();
145 c.fill = GridBagConstraints.HORIZONTAL;
147 c.gridx = 1; c.gridy = 1;
148 c.anchor = GridBagConstraints.LINE_START;
150 file_value = new JLabel("");
151 pane.add(file_value, c);
153 pbar = new JProgressBar();
155 pbar.setMaximum(100);
158 pbar.setStringPainted(true);
159 pbar.setPreferredSize(new Dimension(600, 20));
160 c = new GridBagConstraints();
161 c.fill = GridBagConstraints.HORIZONTAL;
162 c.anchor = GridBagConstraints.CENTER;
163 c.gridx = 0; c.gridy = 2;
164 c.gridwidth = GridBagConstraints.REMAINDER;
165 Insets ib = new Insets(4,4,4,4);
169 cancel = new JButton("Cancel");
170 c = new GridBagConstraints();
171 c.fill = GridBagConstraints.NONE;
172 c.anchor = GridBagConstraints.CENTER;
173 c.gridx = 0; c.gridy = 3;
174 c.gridwidth = GridBagConstraints.REMAINDER;
175 Insets ic = new Insets(4,4,4,4);
178 cancel.addActionListener(this);
180 setLocationRelativeTo(frame);
183 public AltosFlashUI(JFrame in_frame) {
184 super(in_frame, "Program Altusmetrum Device", false);
190 debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.product_any);
192 if (debug_dongle == null)
195 JFileChooser hexfile_chooser = new JFileChooser();
197 File firmwaredir = AltosPreferences.firmwaredir();
198 if (firmwaredir != null)
199 hexfile_chooser.setCurrentDirectory(firmwaredir);
201 hexfile_chooser.setDialogTitle("Select Flash Image");
202 hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
203 int returnVal = hexfile_chooser.showOpenDialog(frame);
205 if (returnVal != JFileChooser.APPROVE_OPTION)
208 file = hexfile_chooser.getSelectedFile();
211 AltosPreferences.set_firmwaredir(file.getParentFile());
213 thread = new Thread(this);