b88fdd2924cc4f60e9e7e2f407e79b2c9c9acd1d
[fw/altos] / ao-tools / altosui / AltosEepromMonitor.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package altosui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import java.io.*;
26 import java.util.*;
27 import java.text.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
30
31 import altosui.AltosSerial;
32 import altosui.AltosSerialMonitor;
33 import altosui.AltosRecord;
34 import altosui.AltosTelemetry;
35 import altosui.AltosState;
36 import altosui.AltosDeviceDialog;
37 import altosui.AltosPreferences;
38 import altosui.AltosLog;
39 import altosui.AltosVoice;
40
41 public class AltosEepromMonitor extends JDialog {
42
43         Container       pane;
44         Box             box;
45         JLabel          serial_label;
46         JLabel          flight_label;
47         JLabel          file_label;
48         JLabel          serial_value;
49         JLabel          flight_value;
50         JLabel          file_value;
51         JButton         cancel;
52         JProgressBar    pbar;
53         int             min_state, max_state;
54
55         public AltosEepromMonitor(JFrame owner, int in_min_state, int in_max_state) {
56                 super (owner, "Download Flight Data", false);
57
58                 GridBagConstraints c;
59                 Insets il = new Insets(4,4,4,4);
60                 Insets ir = new Insets(4,4,4,4);
61
62                 pane = getContentPane();
63                 pane.setLayout(new GridBagLayout());
64
65                 c = new GridBagConstraints();
66                 c.gridx = 0; c.gridy = 0;
67                 c.fill = GridBagConstraints.NONE;
68                 c.anchor = GridBagConstraints.LINE_START;
69                 c.insets = il;
70                 serial_label = new JLabel("Serial:");
71                 pane.add(serial_label, c);
72
73                 c = new GridBagConstraints();
74                 c.gridx = 1; c.gridy = 0;
75                 c.fill = GridBagConstraints.HORIZONTAL;
76                 c.weightx = 1;
77                 c.anchor = GridBagConstraints.LINE_START;
78                 c.insets = ir;
79                 serial_value = new JLabel("");
80                 pane.add(serial_value, c);
81
82                 c = new GridBagConstraints();
83                 c.fill = GridBagConstraints.NONE;
84                 c.gridx = 0; c.gridy = 1;
85                 c.anchor = GridBagConstraints.LINE_START;
86                 c.insets = il;
87                 flight_label = new JLabel("Flight:");
88                 pane.add(flight_label, c);
89
90                 c = new GridBagConstraints();
91                 c.fill = GridBagConstraints.HORIZONTAL;
92                 c.weightx = 1;
93                 c.gridx = 1; c.gridy = 1;
94                 c.anchor = GridBagConstraints.LINE_START;
95                 c.insets = ir;
96                 flight_value = new JLabel("");
97                 pane.add(flight_value, c);
98
99                 c = new GridBagConstraints();
100                 c.fill = GridBagConstraints.NONE;
101                 c.gridx = 0; c.gridy = 2;
102                 c.anchor = GridBagConstraints.LINE_START;
103                 c.insets = il;
104                 file_label = new JLabel("File:");
105                 pane.add(file_label, c);
106
107                 c = new GridBagConstraints();
108                 c.fill = GridBagConstraints.HORIZONTAL;
109                 c.weightx = 1;
110                 c.gridx = 1; c.gridy = 2;
111                 c.anchor = GridBagConstraints.LINE_START;
112                 c.insets = ir;
113                 file_value = new JLabel("");
114                 pane.add(file_value, c);
115
116                 min_state = in_min_state;
117                 max_state = in_max_state;
118                 pbar = new JProgressBar();
119                 pbar.setMinimum(0);
120                 pbar.setMaximum((max_state - min_state) * 100);
121                 pbar.setValue(0);
122                 pbar.setString("startup");
123                 pbar.setStringPainted(true);
124                 pbar.setPreferredSize(new Dimension(600, 20));
125                 c = new GridBagConstraints();
126                 c.fill = GridBagConstraints.HORIZONTAL;
127                 c.anchor = GridBagConstraints.CENTER;
128                 c.gridx = 0; c.gridy = 3;
129                 c.gridwidth = GridBagConstraints.REMAINDER;
130                 Insets ib = new Insets(4,4,4,4);
131                 c.insets = ib;
132                 pane.add(pbar, c);
133
134
135                 cancel = new JButton("Cancel");
136                 c = new GridBagConstraints();
137                 c.fill = GridBagConstraints.NONE;
138                 c.anchor = GridBagConstraints.CENTER;
139                 c.gridx = 0; c.gridy = 4;
140                 c.gridwidth = GridBagConstraints.REMAINDER;
141                 Insets ic = new Insets(4,4,4,4);
142                 c.insets = ic;
143                 pane.add(cancel, c);
144
145                 pack();
146                 setLocationRelativeTo(owner);
147                 setVisible(true);
148         }
149
150         public void addActionListener (ActionListener l) {
151                 cancel.addActionListener(l);
152         }
153
154         public void set_value(String state_name, int in_state, int in_block) {
155                 int block = in_block;
156                 int state = in_state;
157
158                 if (block > 100)
159                         block = 100;
160                 if (state < min_state) state = min_state;
161                 if (state >= max_state) state = max_state - 1;
162                 state -= min_state;
163
164                 int pos = state * 100 + block;
165
166                 pbar.setString(state_name);
167                 pbar.setValue(pos);
168         }
169
170         public void set_serial(int serial) {
171                 serial_value.setText(String.format("%d", serial));
172         }
173
174         public void set_flight(int flight) {
175                 flight_value.setText(String.format("%d", flight));
176         }
177
178         public void set_file(String file) {
179                 file_value.setText(String.format("%s", file));
180         }
181
182         public void done() {
183                 setVisible(false);
184                 dispose();
185         }
186 }