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.
18 package org.altusmetrum.altosuilib_11;
21 import java.awt.event.*;
24 public class AltosEepromMonitor extends AltosUIDialog {
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(1000);
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 state, int state_block, int block) {
138 if (state_block > 100)
140 if (state < min_state) state = min_state;
141 if (state >= max_state) state = max_state - 1;
144 int pos = state * 100 + state_block;
146 pbar.setString(String.format("block %d state %s", block, state_name));
150 public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) {
151 final String state_name = in_state_name;
152 final int state = in_state;
153 final int state_block = in_state_block;
154 final int block = in_block;
155 Runnable r = new Runnable() {
158 set_value_internal(state_name, state, state_block, block);
159 } catch (Exception ex) {
163 SwingUtilities.invokeLater(r);
166 private void set_serial_internal(int serial) {
167 serial_value.setText(String.format("%d", serial));
170 public void set_serial(int in_serial) {
171 final int serial = in_serial;
172 Runnable r = new Runnable() {
175 set_serial_internal(serial);
176 } catch (Exception ex) {
180 SwingUtilities.invokeLater(r);
183 private void set_flight_internal(int flight) {
184 flight_value.setText(String.format("%d", flight));
187 public void set_flight(int in_flight) {
188 final int flight = in_flight;
189 Runnable r = new Runnable() {
192 set_flight_internal(flight);
193 } catch (Exception ex) {
197 SwingUtilities.invokeLater(r);
200 private void set_file_internal(String file) {
201 file_value.setText(String.format("%s", file));
204 public void set_file(String in_file) {
205 final String file = in_file;
206 Runnable r = new Runnable() {
209 set_file_internal(file);
210 } catch (Exception ex) {
214 SwingUtilities.invokeLater(r);
217 private void done_internal() {
223 Runnable r = new Runnable() {
227 } catch (Exception ex) {
231 SwingUtilities.invokeLater(r);
234 private void reset_internal() {
235 set_value_internal("startup",min_state,0, 0);
236 set_flight_internal(0);
237 set_file_internal("");
240 public void reset() {
241 Runnable r = new Runnable() {
245 } catch (Exception ex) {
249 SwingUtilities.invokeLater(r);