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 org.altusmetrum.altosuilib_1.*;
25 public class AltosEepromMonitor extends AltosUIDialog {
37 int min_state, max_state;
39 public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) {
40 super (owner, "Download Flight Data", false);
43 Insets il = new Insets(4,4,4,4);
44 Insets ir = new Insets(4,4,4,4);
46 pane = getContentPane();
47 pane.setLayout(new GridBagLayout());
49 c = new GridBagConstraints();
50 c.gridx = 0; c.gridy = 0;
51 c.fill = GridBagConstraints.NONE;
52 c.anchor = GridBagConstraints.LINE_START;
54 serial_label = new JLabel("Serial:");
55 pane.add(serial_label, c);
57 c = new GridBagConstraints();
58 c.gridx = 1; c.gridy = 0;
59 c.fill = GridBagConstraints.HORIZONTAL;
61 c.anchor = GridBagConstraints.LINE_START;
63 serial_value = new JLabel("");
64 pane.add(serial_value, c);
66 c = new GridBagConstraints();
67 c.fill = GridBagConstraints.NONE;
68 c.gridx = 0; c.gridy = 1;
69 c.anchor = GridBagConstraints.LINE_START;
71 flight_label = new JLabel("Flight:");
72 pane.add(flight_label, c);
74 c = new GridBagConstraints();
75 c.fill = GridBagConstraints.HORIZONTAL;
77 c.gridx = 1; c.gridy = 1;
78 c.anchor = GridBagConstraints.LINE_START;
80 flight_value = new JLabel("");
81 pane.add(flight_value, c);
83 c = new GridBagConstraints();
84 c.fill = GridBagConstraints.NONE;
85 c.gridx = 0; c.gridy = 2;
86 c.anchor = GridBagConstraints.LINE_START;
88 file_label = new JLabel("File:");
89 pane.add(file_label, c);
91 c = new GridBagConstraints();
92 c.fill = GridBagConstraints.HORIZONTAL;
94 c.gridx = 1; c.gridy = 2;
95 c.anchor = GridBagConstraints.LINE_START;
97 file_value = new JLabel("");
98 pane.add(file_value, c);
100 min_state = in_min_state;
101 max_state = in_max_state;
102 pbar = new JProgressBar();
104 pbar.setMaximum((max_state - min_state) * 100);
106 pbar.setString("startup");
107 pbar.setStringPainted(true);
108 pbar.setPreferredSize(new Dimension(600, 20));
109 c = new GridBagConstraints();
110 c.fill = GridBagConstraints.HORIZONTAL;
111 c.anchor = GridBagConstraints.CENTER;
112 c.gridx = 0; c.gridy = 3;
113 c.gridwidth = GridBagConstraints.REMAINDER;
114 Insets ib = new Insets(4,4,4,4);
119 cancel = new JButton("Cancel");
120 c = new GridBagConstraints();
121 c.fill = GridBagConstraints.NONE;
122 c.anchor = GridBagConstraints.CENTER;
123 c.gridx = 0; c.gridy = 4;
124 c.gridwidth = GridBagConstraints.REMAINDER;
125 Insets ic = new Insets(4,4,4,4);
130 setLocationRelativeTo(owner);
134 public void addActionListener (ActionListener l) {
135 cancel.addActionListener(l);
138 private void set_value_internal(String state_name, int in_state, int in_block) {
139 int block = in_block;
140 int state = in_state;
144 if (state < min_state) state = min_state;
145 if (state >= max_state) state = max_state - 1;
148 int pos = state * 100 + block;
150 pbar.setString(state_name);
154 public void set_value(String in_state_name, int in_state, int in_block) {
155 final String state_name = in_state_name;
156 final int state = in_state;
157 final int block = in_block;
158 Runnable r = new Runnable() {
161 set_value_internal(state_name, state, block);
162 } catch (Exception ex) {
166 SwingUtilities.invokeLater(r);
169 private void set_serial_internal(int serial) {
170 serial_value.setText(String.format("%d", serial));
173 public void set_serial(int in_serial) {
174 final int serial = in_serial;
175 Runnable r = new Runnable() {
178 set_serial_internal(serial);
179 } catch (Exception ex) {
183 SwingUtilities.invokeLater(r);
186 private void set_flight_internal(int flight) {
187 flight_value.setText(String.format("%d", flight));
190 public void set_flight(int in_flight) {
191 final int flight = in_flight;
192 Runnable r = new Runnable() {
195 set_flight_internal(flight);
196 } catch (Exception ex) {
200 SwingUtilities.invokeLater(r);
203 private void set_file_internal(String file) {
204 file_value.setText(String.format("%s", file));
207 public void set_file(String in_file) {
208 final String file = in_file;
209 Runnable r = new Runnable() {
212 set_file_internal(file);
213 } catch (Exception ex) {
217 SwingUtilities.invokeLater(r);
220 private void done_internal() {
226 Runnable r = new Runnable() {
230 } catch (Exception ex) {
234 SwingUtilities.invokeLater(r);
237 private void reset_internal() {
238 set_value_internal("startup",min_state,0);
239 set_flight_internal(0);
240 set_file_internal("");
243 public void reset() {
244 Runnable r = new Runnable() {
248 } catch (Exception ex) {
252 SwingUtilities.invokeLater(r);