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(1000);
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 state, int state_block, int block) {
139 if (state_block > 100)
141 if (state < min_state) state = min_state;
142 if (state >= max_state) state = max_state - 1;
145 int pos = state * 100 + state_block;
147 pbar.setString(String.format("block %d state %s", block, state_name));
151 public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) {
152 final String state_name = in_state_name;
153 final int state = in_state;
154 final int state_block = in_state_block;
155 final int block = in_block;
156 Runnable r = new Runnable() {
159 set_value_internal(state_name, state, state_block, block);
160 } catch (Exception ex) {
164 SwingUtilities.invokeLater(r);
167 private void set_serial_internal(int serial) {
168 serial_value.setText(String.format("%d", serial));
171 public void set_serial(int in_serial) {
172 final int serial = in_serial;
173 Runnable r = new Runnable() {
176 set_serial_internal(serial);
177 } catch (Exception ex) {
181 SwingUtilities.invokeLater(r);
184 private void set_flight_internal(int flight) {
185 flight_value.setText(String.format("%d", flight));
188 public void set_flight(int in_flight) {
189 final int flight = in_flight;
190 Runnable r = new Runnable() {
193 set_flight_internal(flight);
194 } catch (Exception ex) {
198 SwingUtilities.invokeLater(r);
201 private void set_file_internal(String file) {
202 file_value.setText(String.format("%s", file));
205 public void set_file(String in_file) {
206 final String file = in_file;
207 Runnable r = new Runnable() {
210 set_file_internal(file);
211 } catch (Exception ex) {
215 SwingUtilities.invokeLater(r);
218 private void done_internal() {
224 Runnable r = new Runnable() {
228 } catch (Exception ex) {
232 SwingUtilities.invokeLater(r);
235 private void reset_internal() {
236 set_value_internal("startup",min_state,0, 0);
237 set_flight_internal(0);
238 set_file_internal("");
241 public void reset() {
242 Runnable r = new Runnable() {
246 } catch (Exception ex) {
250 SwingUtilities.invokeLater(r);