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;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosEepromMonitor extends AltosDialog {
44 int min_state, max_state;
46 public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) {
47 super (owner, "Download Flight Data", false);
50 Insets il = new Insets(4,4,4,4);
51 Insets ir = new Insets(4,4,4,4);
53 pane = getContentPane();
54 pane.setLayout(new GridBagLayout());
56 c = new GridBagConstraints();
57 c.gridx = 0; c.gridy = 0;
58 c.fill = GridBagConstraints.NONE;
59 c.anchor = GridBagConstraints.LINE_START;
61 serial_label = new JLabel("Serial:");
62 pane.add(serial_label, c);
64 c = new GridBagConstraints();
65 c.gridx = 1; c.gridy = 0;
66 c.fill = GridBagConstraints.HORIZONTAL;
68 c.anchor = GridBagConstraints.LINE_START;
70 serial_value = new JLabel("");
71 pane.add(serial_value, c);
73 c = new GridBagConstraints();
74 c.fill = GridBagConstraints.NONE;
75 c.gridx = 0; c.gridy = 1;
76 c.anchor = GridBagConstraints.LINE_START;
78 flight_label = new JLabel("Flight:");
79 pane.add(flight_label, c);
81 c = new GridBagConstraints();
82 c.fill = GridBagConstraints.HORIZONTAL;
84 c.gridx = 1; c.gridy = 1;
85 c.anchor = GridBagConstraints.LINE_START;
87 flight_value = new JLabel("");
88 pane.add(flight_value, c);
90 c = new GridBagConstraints();
91 c.fill = GridBagConstraints.NONE;
92 c.gridx = 0; c.gridy = 2;
93 c.anchor = GridBagConstraints.LINE_START;
95 file_label = new JLabel("File:");
96 pane.add(file_label, c);
98 c = new GridBagConstraints();
99 c.fill = GridBagConstraints.HORIZONTAL;
101 c.gridx = 1; c.gridy = 2;
102 c.anchor = GridBagConstraints.LINE_START;
104 file_value = new JLabel("");
105 pane.add(file_value, c);
107 min_state = in_min_state;
108 max_state = in_max_state;
109 pbar = new JProgressBar();
111 pbar.setMaximum((max_state - min_state) * 100);
113 pbar.setString("startup");
114 pbar.setStringPainted(true);
115 pbar.setPreferredSize(new Dimension(600, 20));
116 c = new GridBagConstraints();
117 c.fill = GridBagConstraints.HORIZONTAL;
118 c.anchor = GridBagConstraints.CENTER;
119 c.gridx = 0; c.gridy = 3;
120 c.gridwidth = GridBagConstraints.REMAINDER;
121 Insets ib = new Insets(4,4,4,4);
126 cancel = new JButton("Cancel");
127 c = new GridBagConstraints();
128 c.fill = GridBagConstraints.NONE;
129 c.anchor = GridBagConstraints.CENTER;
130 c.gridx = 0; c.gridy = 4;
131 c.gridwidth = GridBagConstraints.REMAINDER;
132 Insets ic = new Insets(4,4,4,4);
137 setLocationRelativeTo(owner);
141 public void addActionListener (ActionListener l) {
142 cancel.addActionListener(l);
145 private void set_value_internal(String state_name, int in_state, int in_block) {
146 int block = in_block;
147 int state = in_state;
151 if (state < min_state) state = min_state;
152 if (state >= max_state) state = max_state - 1;
155 int pos = state * 100 + block;
157 pbar.setString(state_name);
161 public void set_value(String in_state_name, int in_state, int in_block) {
162 final String state_name = in_state_name;
163 final int state = in_state;
164 final int block = in_block;
165 Runnable r = new Runnable() {
168 set_value_internal(state_name, state, block);
169 } catch (Exception ex) {
173 SwingUtilities.invokeLater(r);
176 private void set_serial_internal(int serial) {
177 serial_value.setText(String.format("%d", serial));
180 public void set_serial(int in_serial) {
181 final int serial = in_serial;
182 Runnable r = new Runnable() {
185 set_serial_internal(serial);
186 } catch (Exception ex) {
190 SwingUtilities.invokeLater(r);
193 private void set_flight_internal(int flight) {
194 flight_value.setText(String.format("%d", flight));
197 public void set_flight(int in_flight) {
198 final int flight = in_flight;
199 Runnable r = new Runnable() {
202 set_flight_internal(flight);
203 } catch (Exception ex) {
207 SwingUtilities.invokeLater(r);
210 private void set_file_internal(String file) {
211 file_value.setText(String.format("%s", file));
214 public void set_file(String in_file) {
215 final String file = in_file;
216 Runnable r = new Runnable() {
219 set_file_internal(file);
220 } catch (Exception ex) {
224 SwingUtilities.invokeLater(r);
227 private void done_internal() {
233 Runnable r = new Runnable() {
237 } catch (Exception ex) {
241 SwingUtilities.invokeLater(r);
244 private void reset_internal() {
245 set_value_internal("startup",min_state,0);
246 set_flight_internal(0);
247 set_file_internal("");
250 public void reset() {
251 Runnable r = new Runnable() {
255 } catch (Exception ex) {
259 SwingUtilities.invokeLater(r);