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 romconfig_ui.showDialog();
80 AltosRomconfig romconfig = romconfig_ui.romconfig();
81 if (romconfig == null || !romconfig.valid())
83 flash.set_romconfig(romconfig);
84 serial_value.setText(String.format("%d",
85 flash.romconfig().serial_number));
86 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) {
104 public void abort() {
109 public void build_dialog() {
110 GridBagConstraints c;
111 Insets il = new Insets(4,4,4,4);
112 Insets ir = new Insets(4,4,4,4);
114 pane = getContentPane();
115 pane.setLayout(new GridBagLayout());
117 c = new GridBagConstraints();
118 c.gridx = 0; c.gridy = 0;
119 c.fill = GridBagConstraints.NONE;
120 c.anchor = GridBagConstraints.LINE_START;
122 serial_label = new JLabel("Serial:");
123 pane.add(serial_label, c);
125 c = new GridBagConstraints();
126 c.gridx = 1; c.gridy = 0;
127 c.fill = GridBagConstraints.HORIZONTAL;
129 c.anchor = GridBagConstraints.LINE_START;
131 serial_value = new JLabel("");
132 pane.add(serial_value, c);
134 c = new GridBagConstraints();
135 c.fill = GridBagConstraints.NONE;
136 c.gridx = 0; c.gridy = 1;
137 c.anchor = GridBagConstraints.LINE_START;
139 file_label = new JLabel("File:");
140 pane.add(file_label, c);
142 c = new GridBagConstraints();
143 c.fill = GridBagConstraints.HORIZONTAL;
145 c.gridx = 1; c.gridy = 1;
146 c.anchor = GridBagConstraints.LINE_START;
148 file_value = new JLabel("");
149 pane.add(file_value, c);
151 pbar = new JProgressBar();
153 pbar.setMaximum(100);
156 pbar.setStringPainted(true);
157 pbar.setPreferredSize(new Dimension(600, 20));
158 c = new GridBagConstraints();
159 c.fill = GridBagConstraints.HORIZONTAL;
160 c.anchor = GridBagConstraints.CENTER;
161 c.gridx = 0; c.gridy = 2;
162 c.gridwidth = GridBagConstraints.REMAINDER;
163 Insets ib = new Insets(4,4,4,4);
167 cancel = new JButton("Cancel");
168 c = new GridBagConstraints();
169 c.fill = GridBagConstraints.NONE;
170 c.anchor = GridBagConstraints.CENTER;
171 c.gridx = 0; c.gridy = 3;
172 c.gridwidth = GridBagConstraints.REMAINDER;
173 Insets ic = new Insets(4,4,4,4);
176 cancel.addActionListener(this);
178 setLocationRelativeTo(frame);
181 public AltosFlashUI(JFrame in_frame) {
182 super(in_frame, "Program Altusmetrum Device", false);
188 debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any);
190 if (debug_dongle == null)
193 JFileChooser hexfile_chooser = new JFileChooser();
195 hexfile_chooser.setDialogTitle("Select Flash Image");
196 hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
197 int returnVal = hexfile_chooser.showOpenDialog(frame);
199 if (returnVal != JFileChooser.APPROVE_OPTION)
202 file = hexfile_chooser.getSelectedFile();
204 thread = new Thread(this);