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 if (!flash.check_rom_config()) {
76 AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
77 romconfig_ui.showDialog();
78 AltosRomconfig romconfig = romconfig_ui.romconfig();
79 if (romconfig == null)
81 flash.set_romconfig(romconfig);
83 serial_value.setText(String.format("%d",
84 flash.romconfig().serial_number));
85 file_value.setText(file.toString());
88 } catch (FileNotFoundException ee) {
89 JOptionPane.showMessageDialog(frame,
92 JOptionPane.ERROR_MESSAGE);
93 } catch (IOException e) {
94 JOptionPane.showMessageDialog(frame,
97 JOptionPane.ERROR_MESSAGE);
98 } catch (InterruptedException ie) {
103 public void abort() {
108 public void build_dialog() {
109 GridBagConstraints c;
110 Insets il = new Insets(4,4,4,4);
111 Insets ir = new Insets(4,4,4,4);
113 pane = getContentPane();
114 pane.setLayout(new GridBagLayout());
116 c = new GridBagConstraints();
117 c.gridx = 0; c.gridy = 0;
118 c.fill = GridBagConstraints.NONE;
119 c.anchor = GridBagConstraints.LINE_START;
121 serial_label = new JLabel("Serial:");
122 pane.add(serial_label, c);
124 c = new GridBagConstraints();
125 c.gridx = 1; c.gridy = 0;
126 c.fill = GridBagConstraints.HORIZONTAL;
128 c.anchor = GridBagConstraints.LINE_START;
130 serial_value = new JLabel("");
131 pane.add(serial_value, c);
133 c = new GridBagConstraints();
134 c.fill = GridBagConstraints.NONE;
135 c.gridx = 0; c.gridy = 1;
136 c.anchor = GridBagConstraints.LINE_START;
138 file_label = new JLabel("File:");
139 pane.add(file_label, c);
141 c = new GridBagConstraints();
142 c.fill = GridBagConstraints.HORIZONTAL;
144 c.gridx = 1; c.gridy = 1;
145 c.anchor = GridBagConstraints.LINE_START;
147 file_value = new JLabel("");
148 pane.add(file_value, c);
150 pbar = new JProgressBar();
152 pbar.setMaximum(100);
155 pbar.setStringPainted(true);
156 pbar.setPreferredSize(new Dimension(600, 20));
157 c = new GridBagConstraints();
158 c.fill = GridBagConstraints.HORIZONTAL;
159 c.anchor = GridBagConstraints.CENTER;
160 c.gridx = 0; c.gridy = 2;
161 c.gridwidth = GridBagConstraints.REMAINDER;
162 Insets ib = new Insets(4,4,4,4);
166 cancel = new JButton("Cancel");
167 c = new GridBagConstraints();
168 c.fill = GridBagConstraints.NONE;
169 c.anchor = GridBagConstraints.CENTER;
170 c.gridx = 0; c.gridy = 3;
171 c.gridwidth = GridBagConstraints.REMAINDER;
172 Insets ic = new Insets(4,4,4,4);
175 cancel.addActionListener(this);
177 setLocationRelativeTo(frame);
180 public AltosFlashUI(JFrame in_frame) {
181 super(in_frame, "Program Altusmetrum Device", false);
187 debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any);
189 if (debug_dongle == null)
192 JFileChooser hexfile_chooser = new JFileChooser();
194 hexfile_chooser.setDialogTitle("Select Flash Image");
195 hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
196 int returnVal = hexfile_chooser.showOpenDialog(frame);
198 if (returnVal != JFileChooser.APPROVE_OPTION)
201 file = hexfile_chooser.getSelectedFile();
203 thread = new Thread(this);