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.*;
24 public class AltosEepromMonitor extends AltosDialog {
36 int min_state, max_state;
38 public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) {
39 super (owner, "Download Flight Data", false);
42 Insets il = new Insets(4,4,4,4);
43 Insets ir = new Insets(4,4,4,4);
45 pane = getContentPane();
46 pane.setLayout(new GridBagLayout());
48 c = new GridBagConstraints();
49 c.gridx = 0; c.gridy = 0;
50 c.fill = GridBagConstraints.NONE;
51 c.anchor = GridBagConstraints.LINE_START;
53 serial_label = new JLabel("Serial:");
54 pane.add(serial_label, c);
56 c = new GridBagConstraints();
57 c.gridx = 1; c.gridy = 0;
58 c.fill = GridBagConstraints.HORIZONTAL;
60 c.anchor = GridBagConstraints.LINE_START;
62 serial_value = new JLabel("");
63 pane.add(serial_value, c);
65 c = new GridBagConstraints();
66 c.fill = GridBagConstraints.NONE;
67 c.gridx = 0; c.gridy = 1;
68 c.anchor = GridBagConstraints.LINE_START;
70 flight_label = new JLabel("Flight:");
71 pane.add(flight_label, c);
73 c = new GridBagConstraints();
74 c.fill = GridBagConstraints.HORIZONTAL;
76 c.gridx = 1; c.gridy = 1;
77 c.anchor = GridBagConstraints.LINE_START;
79 flight_value = new JLabel("");
80 pane.add(flight_value, c);
82 c = new GridBagConstraints();
83 c.fill = GridBagConstraints.NONE;
84 c.gridx = 0; c.gridy = 2;
85 c.anchor = GridBagConstraints.LINE_START;
87 file_label = new JLabel("File:");
88 pane.add(file_label, c);
90 c = new GridBagConstraints();
91 c.fill = GridBagConstraints.HORIZONTAL;
93 c.gridx = 1; c.gridy = 2;
94 c.anchor = GridBagConstraints.LINE_START;
96 file_value = new JLabel("");
97 pane.add(file_value, c);
99 min_state = in_min_state;
100 max_state = in_max_state;
101 pbar = new JProgressBar();
103 pbar.setMaximum((max_state - min_state) * 100);
105 pbar.setString("startup");
106 pbar.setStringPainted(true);
107 pbar.setPreferredSize(new Dimension(600, 20));
108 c = new GridBagConstraints();
109 c.fill = GridBagConstraints.HORIZONTAL;
110 c.anchor = GridBagConstraints.CENTER;
111 c.gridx = 0; c.gridy = 3;
112 c.gridwidth = GridBagConstraints.REMAINDER;
113 Insets ib = new Insets(4,4,4,4);
118 cancel = new JButton("Cancel");
119 c = new GridBagConstraints();
120 c.fill = GridBagConstraints.NONE;
121 c.anchor = GridBagConstraints.CENTER;
122 c.gridx = 0; c.gridy = 4;
123 c.gridwidth = GridBagConstraints.REMAINDER;
124 Insets ic = new Insets(4,4,4,4);
129 setLocationRelativeTo(owner);
133 public void addActionListener (ActionListener l) {
134 cancel.addActionListener(l);
137 private void set_value_internal(String state_name, int in_state, int in_block) {
138 int block = in_block;
139 int state = in_state;
143 if (state < min_state) state = min_state;
144 if (state >= max_state) state = max_state - 1;
147 int pos = state * 100 + block;
149 pbar.setString(state_name);
153 public void set_value(String in_state_name, int in_state, int in_block) {
154 final String state_name = in_state_name;
155 final int state = in_state;
156 final int block = in_block;
157 Runnable r = new Runnable() {
160 set_value_internal(state_name, state, block);
161 } catch (Exception ex) {
165 SwingUtilities.invokeLater(r);
168 private void set_serial_internal(int serial) {
169 serial_value.setText(String.format("%d", serial));
172 public void set_serial(int in_serial) {
173 final int serial = in_serial;
174 Runnable r = new Runnable() {
177 set_serial_internal(serial);
178 } catch (Exception ex) {
182 SwingUtilities.invokeLater(r);
185 private void set_flight_internal(int flight) {
186 flight_value.setText(String.format("%d", flight));
189 public void set_flight(int in_flight) {
190 final int flight = in_flight;
191 Runnable r = new Runnable() {
194 set_flight_internal(flight);
195 } catch (Exception ex) {
199 SwingUtilities.invokeLater(r);
202 private void set_file_internal(String file) {
203 file_value.setText(String.format("%s", file));
206 public void set_file(String in_file) {
207 final String file = in_file;
208 Runnable r = new Runnable() {
211 set_file_internal(file);
212 } catch (Exception ex) {
216 SwingUtilities.invokeLater(r);
219 private void done_internal() {
225 Runnable r = new Runnable() {
229 } catch (Exception ex) {
233 SwingUtilities.invokeLater(r);
236 private void reset_internal() {
237 set_value_internal("startup",min_state,0);
238 set_flight_internal(0);
239 set_file_internal("");
242 public void reset() {
243 Runnable r = new Runnable() {
247 } catch (Exception ex) {
251 SwingUtilities.invokeLater(r);