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.
22 import org.altusmetrum.altoslib_4.*;
23 import org.altusmetrum.altosuilib_2.*;
25 public class AltosCompanionInfo extends JTable implements AltosFlightDisplay {
26 private AltosFlightInfoTableModel model;
28 static final int info_columns = 2;
29 static final int info_rows = 17;
31 int desired_row_height() {
32 FontMetrics infoValueMetrics = getFontMetrics(Altos.table_value_font);
33 return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
36 public void set_font() {
37 setFont(Altos.table_value_font);
38 setRowHeight(desired_row_height());
42 public AltosCompanionInfo() {
43 super(new AltosFlightInfoTableModel(info_rows, info_columns));
44 model = (AltosFlightInfoTableModel) getModel();
45 setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
50 public Dimension getPreferredScrollableViewportSize() {
51 return getPreferredSize();
58 void info_add_row(int col, String name, String value) {
59 model.addRow(col, name, value);
62 void info_add_row(int col, String name, String format, Object... parameters) {
63 info_add_row (col, name, String.format(format, parameters));
74 AltosCompanion companion;
76 public String board_name() {
77 if (companion == null)
79 switch (companion.board_id) {
80 case AltosCompanion.board_id_telescience:
83 return String.format("%02x\n", companion.board_id);
87 public void show(AltosState state, AltosListenerState listener_state) {
90 if (state.companion != null)
91 companion = state.companion;
93 info_add_row(0, "Companion board", "%s", board_name());
94 if (companion != null) {
95 info_add_row(0, "Last Data", "%5d", companion.tick);
96 info_add_row(0, "Update period", "%5.2f s",
97 companion.update_period / 100.0);
98 info_add_row(0, "Channels", "%3d", companion.channels);
100 for (int i = 0; i < companion.channels; i++)
101 info_add_row(1, String.format("Channel %2d", i),
102 "%6d", companion.companion_data[i]);