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"))
62 pbar.setValue(e.getID());
69 flash = new AltosFlash(file, debug_dongle);
70 flash.addActionListener(this);
73 if (!flash.check_rom_config()) {
74 AltosRomconfigUI romconfig_ui = new AltosRomconfigUI (frame);
75 romconfig_ui.showDialog();
76 AltosRomconfig romconfig = romconfig_ui.romconfig();
77 if (romconfig == null)
79 flash.set_romconfig(romconfig);
81 serial_value.setText(String.format("%d",
82 flash.romconfig().serial_number));
83 file_value.setText(file.toString());
86 } catch (FileNotFoundException ee) {
87 JOptionPane.showMessageDialog(frame,
90 JOptionPane.ERROR_MESSAGE);
92 } catch (IOException e) {
93 JOptionPane.showMessageDialog(frame,
96 JOptionPane.ERROR_MESSAGE);
98 } catch (InterruptedException ie) {
102 public void abort() {
107 public void build_dialog() {
108 GridBagConstraints c;
109 Insets il = new Insets(4,4,4,4);
110 Insets ir = new Insets(4,4,4,4);
112 pane = getContentPane();
113 pane.setLayout(new GridBagLayout());
115 c = new GridBagConstraints();
116 c.gridx = 0; c.gridy = 0;
117 c.fill = GridBagConstraints.NONE;
118 c.anchor = GridBagConstraints.LINE_START;
120 serial_label = new JLabel("Serial:");
121 pane.add(serial_label, c);
123 c = new GridBagConstraints();
124 c.gridx = 1; c.gridy = 0;
125 c.fill = GridBagConstraints.HORIZONTAL;
127 c.anchor = GridBagConstraints.LINE_START;
129 serial_value = new JLabel("");
130 pane.add(serial_value, c);
132 c = new GridBagConstraints();
133 c.fill = GridBagConstraints.NONE;
134 c.gridx = 0; c.gridy = 1;
135 c.anchor = GridBagConstraints.LINE_START;
137 file_label = new JLabel("File:");
138 pane.add(file_label, c);
140 c = new GridBagConstraints();
141 c.fill = GridBagConstraints.HORIZONTAL;
143 c.gridx = 1; c.gridy = 1;
144 c.anchor = GridBagConstraints.LINE_START;
146 file_value = new JLabel("");
147 pane.add(file_value, c);
149 pbar = new JProgressBar();
151 pbar.setMaximum(100);
154 pbar.setStringPainted(true);
155 pbar.setPreferredSize(new Dimension(600, 20));
156 c = new GridBagConstraints();
157 c.fill = GridBagConstraints.HORIZONTAL;
158 c.anchor = GridBagConstraints.CENTER;
159 c.gridx = 0; c.gridy = 2;
160 c.gridwidth = GridBagConstraints.REMAINDER;
161 Insets ib = new Insets(4,4,4,4);
165 cancel = new JButton("Cancel");
166 c = new GridBagConstraints();
167 c.fill = GridBagConstraints.NONE;
168 c.anchor = GridBagConstraints.CENTER;
169 c.gridx = 0; c.gridy = 3;
170 c.gridwidth = GridBagConstraints.REMAINDER;
171 Insets ic = new Insets(4,4,4,4);
174 cancel.addActionListener(this);
176 setLocationRelativeTo(frame);
179 public AltosFlashUI(JFrame in_frame) {
180 super(in_frame, "Program Altusmetrum Device", false);
186 debug_dongle = AltosDeviceDialog.show(frame, AltosDevice.Any);
188 if (debug_dongle == null)
191 JFileChooser hexfile_chooser = new JFileChooser();
193 hexfile_chooser.setDialogTitle("Select Flash Image");
194 hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
195 int returnVal = hexfile_chooser.showOpenDialog(frame);
197 if (returnVal != JFileChooser.APPROVE_OPTION)
200 file = hexfile_chooser.getSelectedFile();
202 thread = new Thread(this);