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.*;
24 import org.altusmetrum.altoslib_2.*;
26 public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMonitor {
38 int min_state, max_state;
40 public AltosEepromMonitorUI(JFrame owner) {
41 super (owner, "Download Flight Data", false);
44 Insets il = new Insets(4,4,4,4);
45 Insets ir = new Insets(4,4,4,4);
47 pane = getContentPane();
48 pane.setLayout(new GridBagLayout());
50 c = new GridBagConstraints();
51 c.gridx = 0; c.gridy = 0;
52 c.fill = GridBagConstraints.NONE;
53 c.anchor = GridBagConstraints.LINE_START;
55 serial_label = new JLabel("Serial:");
56 pane.add(serial_label, c);
58 c = new GridBagConstraints();
59 c.gridx = 1; c.gridy = 0;
60 c.fill = GridBagConstraints.HORIZONTAL;
62 c.anchor = GridBagConstraints.LINE_START;
64 serial_value = new JLabel("");
65 pane.add(serial_value, c);
67 c = new GridBagConstraints();
68 c.fill = GridBagConstraints.NONE;
69 c.gridx = 0; c.gridy = 1;
70 c.anchor = GridBagConstraints.LINE_START;
72 flight_label = new JLabel("Flight:");
73 pane.add(flight_label, c);
75 c = new GridBagConstraints();
76 c.fill = GridBagConstraints.HORIZONTAL;
78 c.gridx = 1; c.gridy = 1;
79 c.anchor = GridBagConstraints.LINE_START;
81 flight_value = new JLabel("");
82 pane.add(flight_value, c);
84 c = new GridBagConstraints();
85 c.fill = GridBagConstraints.NONE;
86 c.gridx = 0; c.gridy = 2;
87 c.anchor = GridBagConstraints.LINE_START;
89 file_label = new JLabel("File:");
90 pane.add(file_label, c);
92 c = new GridBagConstraints();
93 c.fill = GridBagConstraints.HORIZONTAL;
95 c.gridx = 1; c.gridy = 2;
96 c.anchor = GridBagConstraints.LINE_START;
98 file_value = new JLabel("");
99 pane.add(file_value, c);
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);
132 public void set_states(int min_state, int max_state) {
133 this.min_state = min_state;
134 this.max_state = max_state;
137 public void set_thread(Thread in_eeprom_thread) {
138 final Thread eeprom_thread = in_eeprom_thread;
139 addActionListener(new ActionListener() {
140 public void actionPerformed(ActionEvent e) {
141 if (eeprom_thread != null)
142 eeprom_thread.interrupt();
147 public void start() {
151 public void addActionListener (ActionListener l) {
152 cancel.addActionListener(l);
155 private void set_value_internal(String state_name, int state, int state_block, int block) {
156 if (state_block > 100)
158 if (state < min_state) state = min_state;
159 if (state >= max_state) state = max_state - 1;
162 int pos = state * 100 + state_block;
164 pbar.setString(String.format("block %d state %s", block, state_name));
168 public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) {
169 final String state_name = in_state_name;
170 final int state = in_state;
171 final int state_block = in_state_block;
172 final int block = in_block;
173 Runnable r = new Runnable() {
176 set_value_internal(state_name, state, state_block, block);
177 } catch (Exception ex) {
181 SwingUtilities.invokeLater(r);
184 private void set_serial_internal(int serial) {
185 serial_value.setText(String.format("%d", serial));
188 public void set_serial(int in_serial) {
189 final int serial = in_serial;
190 Runnable r = new Runnable() {
193 set_serial_internal(serial);
194 } catch (Exception ex) {
198 SwingUtilities.invokeLater(r);
201 private void set_flight_internal(int flight) {
202 flight_value.setText(String.format("%d", flight));
205 public void set_flight(int in_flight) {
206 final int flight = in_flight;
207 Runnable r = new Runnable() {
210 set_flight_internal(flight);
211 } catch (Exception ex) {
215 SwingUtilities.invokeLater(r);
218 private void set_filename_internal(String filename) {
219 file_value.setText(String.format("%s", filename));
222 public void set_filename(String in_filename) {
223 final String filename = in_filename;
224 Runnable r = new Runnable() {
227 set_filename_internal(filename);
228 } catch (Exception ex) {
232 SwingUtilities.invokeLater(r);
235 private void done_internal() {
241 Runnable r = new Runnable() {
245 } catch (Exception ex) {
249 SwingUtilities.invokeLater(r);
252 private void reset_internal() {
253 set_value_internal("startup",min_state,0, 0);
254 set_flight_internal(0);
255 set_filename_internal("");
258 public void reset() {
259 Runnable r = new Runnable() {
263 } catch (Exception ex) {
267 SwingUtilities.invokeLater(r);