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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 import org.altusmetrum.altoslib_13.*;
24 import org.altusmetrum.altosuilib_13.*;
26 public class AltosCompanionInfo extends JTable implements AltosFlightDisplay {
27 private AltosFlightInfoTableModel model;
29 static final int info_columns = 2;
30 static final int info_rows = 17;
32 int desired_row_height() {
33 FontMetrics infoValueMetrics = getFontMetrics(Altos.table_value_font);
34 return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
37 public void font_size_changed(int font_size) {
38 setFont(Altos.table_value_font);
39 setRowHeight(desired_row_height());
43 public void units_changed(boolean imperial_units) {
46 public AltosCompanionInfo() {
47 super(new AltosFlightInfoTableModel(info_rows, info_columns));
48 model = (AltosFlightInfoTableModel) getModel();
49 setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
51 font_size_changed(AltosUIPreferences.font_size());
54 public Dimension getPreferredScrollableViewportSize() {
55 return getPreferredSize();
62 void info_add_row(int col, String name, String value) {
63 model.addRow(col, name, value);
66 void info_add_row(int col, String name, String format, Object... parameters) {
67 info_add_row (col, name, String.format(format, parameters));
78 AltosCompanion companion;
80 public String board_name() {
81 if (companion == null)
83 switch (companion.board_id) {
84 case AltosCompanion.board_id_telescience:
87 return String.format("%02x\n", companion.board_id);
91 public String getName() { return "Companion"; }
93 public void show(AltosState state, AltosListenerState listener_state) {
96 if (state.companion != null)
97 companion = state.companion;
99 info_add_row(0, "Companion board", "%s", board_name());
100 if (companion != null) {
101 info_add_row(0, "Last Data", "%5d", companion.tick);
102 info_add_row(0, "Update period", "%5.2f s",
103 companion.update_period / 100.0);
104 info_add_row(0, "Channels", "%3d", companion.channels);
106 for (int i = 0; i < companion.channels; i++)
107 info_add_row(1, String.format("Channel %2d", i),
108 "%6d", companion.companion_data[i]);