windows: Change install to look for browser in a different place
[fw/altos] / altosui / AltosCompanionInfo.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 javax.swing.*;
22 import org.altusmetrum.altoslib_10.*;
23 import org.altusmetrum.altosuilib_10.*;
24
25 public class AltosCompanionInfo extends JTable implements AltosFlightDisplay {
26         private AltosFlightInfoTableModel model;
27
28         static final int info_columns = 2;
29         static final int info_rows = 17;
30
31         int desired_row_height() {
32                 FontMetrics     infoValueMetrics = getFontMetrics(Altos.table_value_font);
33                 return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
34         }
35
36         public void font_size_changed(int font_size) {
37                 setFont(Altos.table_value_font);
38                 setRowHeight(desired_row_height());
39                 doLayout();
40         }
41
42         public void units_changed(boolean imperial_units) {
43         }
44
45         public AltosCompanionInfo() {
46                 super(new AltosFlightInfoTableModel(info_rows, info_columns));
47                 model = (AltosFlightInfoTableModel) getModel();
48                 setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
49                 setShowGrid(true);
50                 font_size_changed(AltosUIPreferences.font_size());
51         }
52
53         public Dimension getPreferredScrollableViewportSize() {
54                 return getPreferredSize();
55         }
56
57         public void reset() {
58                 model.reset();
59         }
60
61         void info_add_row(int col, String name, String value) {
62                 model.addRow(col, name, value);
63         }
64
65         void info_add_row(int col, String name, String format, Object... parameters) {
66                 info_add_row (col, name, String.format(format, parameters));
67         }
68
69         void info_finish() {
70                 model.finish();
71         }
72
73         public void clear() {
74                 model.clear();
75         }
76
77         AltosCompanion  companion;
78
79         public String board_name() {
80                 if (companion == null)
81                         return "None";
82                 switch (companion.board_id) {
83                 case AltosCompanion.board_id_telescience:
84                         return "TeleScience";
85                 default:
86                         return String.format("%02x\n", companion.board_id);
87                 }
88         }
89
90         public String getName() { return "Companion"; }
91
92         public void show(AltosState state, AltosListenerState listener_state) {
93                 if (state == null)
94                         return;
95                 if (state.companion != null)
96                         companion = state.companion;
97                 reset();
98                 info_add_row(0, "Companion board", "%s", board_name());
99                 if (companion != null) {
100                         info_add_row(0, "Last Data", "%5d", companion.tick);
101                         info_add_row(0, "Update period", "%5.2f s",
102                                      companion.update_period / 100.0);
103                         info_add_row(0, "Channels", "%3d", companion.channels);
104
105                         for (int i = 0; i < companion.channels; i++)
106                                 info_add_row(1, String.format("Channel %2d", i),
107                                              "%6d", companion.companion_data[i]);
108                 }
109                 info_finish();
110         }
111 }