From 3871b9ac036e3adfa1da089245fc7973b268c921 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 May 2014 21:56:52 -0700 Subject: telegps: Add 'Info' tab This contains a summary of the tracking info, including position, speed and course. Signed-off-by: Keith Packard --- telegps/TeleGPSInfo.java | 511 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 511 insertions(+) create mode 100644 telegps/TeleGPSInfo.java (limited to 'telegps/TeleGPSInfo.java') diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java new file mode 100644 index 00000000..0fba77d5 --- /dev/null +++ b/telegps/TeleGPSInfo.java @@ -0,0 +1,511 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.telegps; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; + +public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { + GridBagLayout layout; + JLabel cur, max; + + public class Info { + JLabel label; + JTextField value; + AltosLights lights; + + void show() { + value.setVisible(true); + lights.setVisible(true); + label.setVisible(true); + } + + void hide() { + value.setVisible(false); + lights.setVisible(false); + label.setVisible(false); + } + + void show(AltosState state, AltosListenerState listener_state) {} + + void show(String s) { + show(); + value.setText(s); + } + + void show(AltosUnits units, double v) { + show(units.show(8, v)); + } + + void show(String format, double v) { + show(String.format(format, v)); + } + + void reset() { + lights.set(false); + value.setText(""); + } + + void set_font() { + label.setFont(AltosUILib.label_font); + value.setFont(AltosUILib.value_font); + } + + public Info (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + + label = new JLabel(text); + label.setFont(AltosUILib.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(AltosUILib.text_width); + value.setFont(AltosUILib.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.gridwidth = 2; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + } + } + + public class Value { + JLabel label; + JTextField value; + void show(AltosState state, AltosListenerState listener_state) {} + + void reset() { + value.setText(""); + } + + void show() { + label.setVisible(true); + value.setVisible(true); + } + + void show(String s) { + show(); + value.setText(s); + } + + void show(AltosUnits units, double v) { + show(units.show(8, v)); + } + + void show(String format, double v) { + show(String.format(format, v)); + } + + void hide() { + label.setVisible(false); + value.setVisible(false); + } + void set_font() { + label.setFont(AltosUILib.label_font); + value.setFont(AltosUILib.value_font); + } + + public Value (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(AltosUILib.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(AltosUILib.text_width); + value.setFont(AltosUILib.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.gridwidth = 2; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + } + } + + public abstract class DualValue { + JLabel label; + JTextField value1; + JTextField value2; + + void reset() { + value1.setText(""); + value2.setText(""); + } + + void show() { + label.setVisible(true); + value1.setVisible(true); + value2.setVisible(true); + } + + void hide() { + label.setVisible(false); + value1.setVisible(false); + value2.setVisible(false); + } + + void set_font() { + label.setFont(AltosUILib.label_font); + value1.setFont(AltosUILib.value_font); + value2.setFont(AltosUILib.value_font); + } + + abstract void show(AltosState state, AltosListenerState listener_state); + + void show(String v1, String v2) { + show(); + value1.setText(v1); + value2.setText(v2); + } + void show(String f1, double v1, String f2, double v2) { + show(); + value1.setText(String.format(f1, v1)); + value2.setText(String.format(f2, v2)); + } + + public DualValue (GridBagLayout layout, int x, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(AltosUILib.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = x + 1; c.gridy = y; + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value1 = new JTextField(AltosUILib.text_width); + value1.setFont(AltosUILib.value_font); + value1.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 2; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value1, c); + add(value1); + + value2 = new JTextField(AltosUILib.text_width); + value2.setFont(AltosUILib.value_font); + value2.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = x + 3; c.gridy = y; + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + c.gridwidth = 1; + layout.setConstraints(value2, c); + add(value2); + } + } + + public class ValueHold { + JLabel label; + JTextField value; + JTextField max_value; + double max; + + void show(AltosState state, AltosListenerState listener_state) {} + + void reset() { + value.setText(""); + max_value.setText(""); + max = AltosLib.MISSING; + } + + void set_font() { + label.setFont(AltosUILib.label_font); + value.setFont(AltosUILib.value_font); + max_value.setFont(AltosUILib.value_font); + } + + void show(AltosUnits units, double v) { + if (v == AltosLib.MISSING) { + value.setText("Missing"); + max_value.setText("Missing"); + } else { + value.setText(units.show(8, v)); + if (v > max || max == AltosLib.MISSING) { + max_value.setText(units.show(8, v)); + max = v; + } + } + } + + void hide() { + label.setVisible(false); + value.setVisible(false); + max_value.setVisible(false); + } + + public ValueHold (GridBagLayout layout, int y, String text) { + GridBagConstraints c = new GridBagConstraints(); + c.weighty = 1; + + label = new JLabel(text); + label.setFont(AltosUILib.label_font); + label.setHorizontalAlignment(SwingConstants.LEFT); + c.gridx = 1; c.gridy = y; + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + c.anchor = GridBagConstraints.WEST; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(label, c); + add(label); + + value = new JTextField(AltosUILib.text_width); + value.setFont(AltosUILib.value_font); + value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 2; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(value, c); + add(value); + + max_value = new JTextField(AltosUILib.text_width); + max_value.setFont(AltosUILib.value_font); + max_value.setHorizontalAlignment(SwingConstants.RIGHT); + c.gridx = 3; c.gridy = y; + c.anchor = GridBagConstraints.EAST; + c.fill = GridBagConstraints.BOTH; + c.weightx = 1; + layout.setConstraints(max_value, c); + add(max_value); + } + } + + + class Altitude extends ValueHold { + void show (AltosState state, AltosListenerState listener_state) { + show(AltosConvert.height, state.altitude()); + } + public Altitude (GridBagLayout layout, int y) { + super (layout, y, "Altitude"); + } + } + + Altitude altitude; + + class AscentRate extends ValueHold { + void show (AltosState state, AltosListenerState listener_state) { + show(AltosConvert.speed, state.gps_ascent_rate()); + } + public AscentRate (GridBagLayout layout, int y) { + super (layout, y, "Ascent Rate"); + } + } + + AscentRate ascent_rate; + + class GroundSpeed extends ValueHold { + void show (AltosState state, AltosListenerState listener_state) { + show(AltosConvert.speed, state.gps_ground_speed()); + } + public GroundSpeed (GridBagLayout layout, int y) { + super (layout, y, "Ground Speed"); + } + } + + GroundSpeed ground_speed; + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + class Course extends DualValue { + void show (AltosState state, AltosListenerState listener_state) { + double course = state.gps_course(); + if (course != AltosLib.MISSING) + show( String.format("%3.0f°", course), + AltosConvert.bearing_to_words( + AltosConvert.BEARING_LONG, + course)); + } + public Course (GridBagLayout layout, int y) { + super (layout, 0, y, "Course"); + } + } + + Course course; + + class Lat extends Value { + void show (AltosState state, AltosListenerState listener_state) { + if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) + show(pos(state.gps.lat,"N", "S")); + else + show("???"); + } + public Lat (GridBagLayout layout, int y) { + super (layout, y, "Latitude"); + } + } + + Lat lat; + + class Lon extends Value { + void show (AltosState state, AltosListenerState listener_state) { + if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) + show(pos(state.gps.lon,"E", "W")); + else + show("???"); + } + public Lon (GridBagLayout layout, int y) { + super (layout, y, "Longitude"); + } + } + + Lon lon; + + class GPSLocked extends Info { + void show (AltosState state, AltosListenerState listener_state) { + if (state == null || state.gps == null) + hide(); + else { + show("%4d sats", state.gps.nsat); + lights.set(state.gps.locked && state.gps.nsat >= 4); + } + } + public GPSLocked (GridBagLayout layout, int y) { + super (layout, y, "GPS Locked"); + } + } + + GPSLocked gps_locked; + + public void reset() { + lat.reset(); + lon.reset(); + altitude.reset(); + ground_speed.reset(); + ascent_rate.reset(); + course.reset(); + gps_locked.reset(); + } + + public void set_font() { + cur.setFont(AltosUILib.label_font); + max.setFont(AltosUILib.label_font); + lat.set_font(); + lon.set_font(); + altitude.set_font(); + ground_speed.set_font(); + ascent_rate.set_font(); + course.set_font(); + gps_locked.set_font(); + } + + public void show(AltosState state, AltosListenerState listener_state) { + if (state.gps != null && state.gps.connected) { + lat.show(state, listener_state); + lon.show(state, listener_state); + } else { + lat.hide(); + lon.hide(); + } + altitude.show(state, listener_state); + ground_speed.show(state, listener_state); + ascent_rate.show(state, listener_state); + course.show(state, listener_state); + gps_locked.show(state, listener_state); + } + + public void labels(GridBagLayout layout, int y) { + GridBagConstraints c; + + cur = new JLabel("Current"); + cur.setFont(AltosUILib.label_font); + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = y; + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + layout.setConstraints(cur, c); + add(cur); + + max = new JLabel("Maximum"); + max.setFont(AltosUILib.label_font); + c.gridx = 3; c.gridy = y; + layout.setConstraints(max, c); + add(max); + } + + public String getName() { + return "Info"; + } + + public TeleGPSInfo() { + layout = new GridBagLayout(); + + setLayout(layout); + + /* Elements in ascent display: + * + * lat + * lon + * height + */ + int y = 0; + labels(layout, y++); + altitude = new Altitude(layout, y++); + ground_speed = new GroundSpeed(layout, y++); + ascent_rate = new AscentRate(layout, y++); + course = new Course(layout, y++); + lat = new Lat(layout, y++); + lon = new Lon(layout, y++); + gps_locked = new GPSLocked(layout, y++); + } +} -- cgit v1.2.3 From 71715337eb532a1fbe1a753240e7417d5223489f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 May 2014 10:16:15 -0700 Subject: telegps: Add info table Move a couple of files from altosui to altosuilib, hook up the info table after changing it to implement the AltosFlightDisplay interface Signed-off-by: Keith Packard --- altoslib/AltosState.java | 4 + altosui/AltosCompanionInfo.java | 7 +- altosui/AltosFlightInfoTableModel.java | 75 ---------- altosui/AltosIdleMonitorUI.java | 4 +- altosui/AltosInfoTable.java | 236 ------------------------------ altosui/Makefile.am | 2 - altosuilib/AltosFlightInfoTableModel.java | 75 ++++++++++ altosuilib/AltosInfoTable.java | 236 ++++++++++++++++++++++++++++++ altosuilib/Makefile.am | 2 + telegps/TeleGPS.java | 72 +++++---- telegps/TeleGPSInfo.java | 4 + 11 files changed, 371 insertions(+), 346 deletions(-) delete mode 100644 altosui/AltosFlightInfoTableModel.java delete mode 100644 altosui/AltosInfoTable.java create mode 100644 altosuilib/AltosFlightInfoTableModel.java create mode 100644 altosuilib/AltosInfoTable.java (limited to 'telegps/TeleGPSInfo.java') diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 1162e522..ddda82b9 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -713,6 +713,7 @@ public class AltosState implements Cloneable { gps_ground_altitude = new AltosGpsGroundAltitude(); gps_ground_speed = new AltosValue(); gps_ascent_rate = new AltosValue(); + gps_course = new AltosValue(); speak_tick = AltosLib.MISSING; speak_altitude = AltosLib.MISSING; @@ -842,6 +843,9 @@ public class AltosState implements Cloneable { gps_altitude.copy(old.gps_altitude); gps_ground_altitude.copy(old.gps_ground_altitude); + gps_ground_speed.copy(old.gps_ground_speed); + gps_ascent_rate.copy(old.gps_ascent_rate); + gps_course.copy(old.gps_course); pad_lat = old.pad_lat; pad_lon = old.pad_lon; diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index 42413a57..f8d033a8 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -20,8 +20,9 @@ package altosui; import java.awt.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; -public class AltosCompanionInfo extends JTable { +public class AltosCompanionInfo extends JTable implements AltosFlightDisplay { private AltosFlightInfoTableModel model; static final int info_columns = 2; @@ -50,7 +51,7 @@ public class AltosCompanionInfo extends JTable { return getPreferredSize(); } - void info_reset() { + public void reset() { model.reset(); } @@ -88,7 +89,7 @@ public class AltosCompanionInfo extends JTable { return; if (state.companion != null) companion = state.companion; - info_reset(); + reset(); info_add_row(0, "Companion board", "%s", board_name()); if (companion != null) { info_add_row(0, "Last Data", "%5d", companion.tick); diff --git a/altosui/AltosFlightInfoTableModel.java b/altosui/AltosFlightInfoTableModel.java deleted file mode 100644 index 249f6497..00000000 --- a/altosui/AltosFlightInfoTableModel.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import javax.swing.table.*; - -public class AltosFlightInfoTableModel extends AbstractTableModel { - final static private String[] columnNames = {"Field", "Value"}; - - int rows; - int cols; - private String[][] data; - - public int getColumnCount() { return cols; } - public int getRowCount() { return rows; } - public String getColumnName(int col) { return columnNames[col & 1]; } - - public Object getValueAt(int row, int col) { - if (row >= rows || col >= cols) - return ""; - return data[row][col]; - } - - int[] current_row; - - public void reset() { - for (int i = 0; i < cols / 2; i++) - current_row[i] = 0; - } - - public void clear() { - reset(); - for (int c = 0; c < cols; c++) - for (int r = 0; r < rows; r++) - data[r][c] = ""; - fireTableDataChanged(); - } - - public void addRow(int col, String name, String value) { - if (current_row[col] < rows) { - data[current_row[col]][col * 2] = name; - data[current_row[col]][col * 2 + 1] = value; - } - current_row[col]++; - } - - public void finish() { - for (int c = 0; c < cols / 2; c++) - while (current_row[c] < rows) - addRow(c, "", ""); - fireTableDataChanged(); - } - - public AltosFlightInfoTableModel (int in_rows, int in_cols) { - rows = in_rows; - cols = in_cols * 2; - data = new String[rows][cols]; - current_row = new int[in_cols]; - } -} diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index 62b50568..b5652df3 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -234,7 +234,9 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl try { disconnect(); } catch (Exception ex) { - System.out.println(Arrays.toString(ex.getStackTrace())); + System.out.printf("Exception %s\n", ex.toString()); + for (StackTraceElement e : ex.getStackTrace()) + System.out.printf("%s\n", e.toString()); } setVisible(false); dispose(); diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java deleted file mode 100644 index 125fa94c..00000000 --- a/altosui/AltosInfoTable.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright © 2010 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.awt.*; -import javax.swing.*; -import javax.swing.table.*; -import org.altusmetrum.altoslib_4.*; - -public class AltosInfoTable extends JTable { - private AltosFlightInfoTableModel model; - - static final int info_columns = 3; - static final int info_rows = 17; - - int desired_row_height() { - FontMetrics infoValueMetrics = getFontMetrics(Altos.table_value_font); - return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; - } - - int text_width(String t) { - FontMetrics infoValueMetrics = getFontMetrics(Altos.table_value_font); - - return infoValueMetrics.stringWidth(t); - } - - void set_layout() { - setRowHeight(desired_row_height()); - for (int i = 0; i < info_columns * 2; i++) - { - TableColumn column = getColumnModel().getColumn(i); - - if ((i & 1) == 0) - column.setPreferredWidth(text_width(" Satellites Visible")); - else - column.setPreferredWidth(text_width("W 179°59.99999' ")); - } - } - - public AltosInfoTable() { - super(new AltosFlightInfoTableModel(info_rows, info_columns)); - model = (AltosFlightInfoTableModel) getModel(); - setFont(Altos.table_value_font); - setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); - setShowGrid(true); - set_layout(); - doLayout(); - } - - public void set_font() { - setFont(Altos.table_value_font); - set_layout(); - doLayout(); - } - - public Dimension getPreferredScrollableViewportSize() { - return getPreferredSize(); - } - - void info_reset() { - model.reset(); - } - - void info_add_row(int col, String name, String value) { - model.addRow(col, name, value); - } - - void info_add_row(int col, String name, String format, Object... parameters) { - info_add_row (col, name, String.format(format, parameters)); - } - - void info_add_deg(int col, String name, double v, int pos, int neg) { - int c = pos; - if (v < 0) { - c = neg; - v = -v; - } - double deg = Math.floor(v); - double min = (v - deg) * 60; - - info_add_row(col, name, String.format("%c %3.0f°%08.5f'", c, deg, min)); - } - - void info_finish() { - model.finish(); - } - - public void clear() { - model.clear(); - } - - public void show(AltosState state, AltosListenerState listener_state) { - info_reset(); - if (state != null) { - if (state.device_type != AltosLib.MISSING) - info_add_row(0, "Device", "%s", AltosLib.product_name(state.device_type)); - if (state.altitude() != AltosLib.MISSING) - info_add_row(0, "Altitude", "%6.0f m", state.altitude()); - if (state.ground_altitude() != AltosLib.MISSING) - info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude()); - if (state.height() != AltosLib.MISSING) - info_add_row(0, "Height", "%6.0f m", state.height()); - if (state.max_height() != AltosLib.MISSING) - info_add_row(0, "Max height", "%6.0f m", state.max_height()); - if (state.acceleration() != AltosLib.MISSING) - info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration()); - if (state.max_acceleration() != AltosLib.MISSING) - info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration()); - if (state.speed() != AltosLib.MISSING) - info_add_row(0, "Speed", "%8.1f m/s", state.speed()); - if (state.max_speed() != AltosLib.MISSING) - info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed()); - if (state.orient() != AltosLib.MISSING) - info_add_row(0, "Tilt", "%4.0f °", state.orient()); - if (state.max_orient() != AltosLib.MISSING) - info_add_row(0, "Max Tilt", "%4.0f °", state.max_orient()); - if (state.temperature != AltosLib.MISSING) - info_add_row(0, "Temperature", "%9.2f °C", state.temperature); - if (state.battery_voltage != AltosLib.MISSING) - info_add_row(0, "Battery", "%9.2f V", state.battery_voltage); - if (state.apogee_voltage != AltosLib.MISSING) - info_add_row(0, "Drogue", "%9.2f V", state.apogee_voltage); - if (state.main_voltage != AltosLib.MISSING) - info_add_row(0, "Main", "%9.2f V", state.main_voltage); - } - if (listener_state != null) { - info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors); - - if (listener_state.battery != AltosLib.MISSING) - info_add_row(0, "Receiver Battery", "%9.2f", listener_state.battery); - } - - if (state != null) { - if (state.gps == null || !state.gps.connected) { - info_add_row(1, "GPS", "not available"); - } else { - if (state.gps_ready) - info_add_row(1, "GPS state", "%s", "ready"); - else - info_add_row(1, "GPS state", "wait (%d)", - state.gps_waiting); - if (state.gps.locked) - info_add_row(1, "GPS", " locked"); - else if (state.gps.connected) - info_add_row(1, "GPS", " unlocked"); - else - info_add_row(1, "GPS", " missing"); - info_add_row(1, "Satellites", "%6d", state.gps.nsat); - if (state.gps.lat != AltosLib.MISSING) - info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); - if (state.gps.lon != AltosLib.MISSING) - info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); - if (state.gps.alt != AltosLib.MISSING) - info_add_row(1, "GPS altitude", "%8.1f", state.gps.alt); - if (state.gps_height != AltosLib.MISSING) - info_add_row(1, "GPS height", "%8.1f", state.gps_height); - - /* The SkyTraq GPS doesn't report these values */ - /* - if (false) { - info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", - state.gps.ground_speed, - state.gps.course); - info_add_row(1, "GPS climb rate", "%8.1f m/s", - state.gps.climb_rate); - info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", - state.gps.h_error, state.gps.v_error); - } - */ - - info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); - - if (state.npad > 0) { - if (state.from_pad != null) { - info_add_row(1, "Distance from pad", "%6d m", - (int) (state.from_pad.distance + 0.5)); - info_add_row(1, "Direction from pad", "%6d°", - (int) (state.from_pad.bearing + 0.5)); - info_add_row(1, "Elevation from pad", "%6d°", - (int) (state.elevation + 0.5)); - info_add_row(1, "Range from pad", "%6d m", - (int) (state.range + 0.5)); - } else { - info_add_row(1, "Distance from pad", "unknown"); - info_add_row(1, "Direction from pad", "unknown"); - info_add_row(1, "Elevation from pad", "unknown"); - info_add_row(1, "Range from pad", "unknown"); - } - info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); - info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); - info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); - } - if (state.gps.year != AltosLib.MISSING) - info_add_row(1, "GPS date", "%04d-%02d-%02d", - state.gps.year, - state.gps.month, - state.gps.day); - if (state.gps.hour != AltosLib.MISSING) - info_add_row(1, "GPS time", " %02d:%02d:%02d", - state.gps.hour, - state.gps.minute, - state.gps.second); - //int nsat_vis = 0; - int c; - - if (state.gps.cc_gps_sat == null) - info_add_row(2, "Satellites Visible", "%4d", 0); - else { - info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); - for (c = 0; c < state.gps.cc_gps_sat.length; c++) { - info_add_row(2, "Satellite id,C/N0", - "%4d, %4d", - state.gps.cc_gps_sat[c].svid, - state.gps.cc_gps_sat[c].c_n0); - } - } - } - } - info_finish(); - } -} diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 686b5967..add46825 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -21,7 +21,6 @@ altosui_JAVA = \ AltosConfigTD.java \ AltosConfigTDUI.java \ AltosDescent.java \ - AltosFlightInfoTableModel.java \ AltosFlightStatsTable.java \ AltosFlightStatus.java \ AltosFlightStatusUpdate.java \ @@ -32,7 +31,6 @@ altosui_JAVA = \ AltosIgnitor.java \ AltosLaunch.java \ AltosLaunchUI.java \ - AltosInfoTable.java \ AltosLanded.java \ AltosPad.java \ AltosUIPreferencesBackend.java \ diff --git a/altosuilib/AltosFlightInfoTableModel.java b/altosuilib/AltosFlightInfoTableModel.java new file mode 100644 index 00000000..3995efb3 --- /dev/null +++ b/altosuilib/AltosFlightInfoTableModel.java @@ -0,0 +1,75 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altosuilib_2; + +import javax.swing.table.*; + +public class AltosFlightInfoTableModel extends AbstractTableModel { + final static private String[] columnNames = {"Field", "Value"}; + + int rows; + int cols; + private String[][] data; + + public int getColumnCount() { return cols; } + public int getRowCount() { return rows; } + public String getColumnName(int col) { return columnNames[col & 1]; } + + public Object getValueAt(int row, int col) { + if (row >= rows || col >= cols) + return ""; + return data[row][col]; + } + + int[] current_row; + + public void reset() { + for (int i = 0; i < cols / 2; i++) + current_row[i] = 0; + } + + public void clear() { + reset(); + for (int c = 0; c < cols; c++) + for (int r = 0; r < rows; r++) + data[r][c] = ""; + fireTableDataChanged(); + } + + public void addRow(int col, String name, String value) { + if (current_row[col] < rows) { + data[current_row[col]][col * 2] = name; + data[current_row[col]][col * 2 + 1] = value; + } + current_row[col]++; + } + + public void finish() { + for (int c = 0; c < cols / 2; c++) + while (current_row[c] < rows) + addRow(c, "", ""); + fireTableDataChanged(); + } + + public AltosFlightInfoTableModel (int in_rows, int in_cols) { + rows = in_rows; + cols = in_cols * 2; + data = new String[rows][cols]; + current_row = new int[in_cols]; + } +} diff --git a/altosuilib/AltosInfoTable.java b/altosuilib/AltosInfoTable.java new file mode 100644 index 00000000..0d8779d1 --- /dev/null +++ b/altosuilib/AltosInfoTable.java @@ -0,0 +1,236 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altosuilib_2; + +import java.awt.*; +import javax.swing.*; +import javax.swing.table.*; +import org.altusmetrum.altoslib_4.*; + +public class AltosInfoTable extends JTable implements AltosFlightDisplay { + private AltosFlightInfoTableModel model; + + static final int info_columns = 3; + static final int info_rows = 17; + + int desired_row_height() { + FontMetrics infoValueMetrics = getFontMetrics(AltosUILib.table_value_font); + return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; + } + + int text_width(String t) { + FontMetrics infoValueMetrics = getFontMetrics(AltosUILib.table_value_font); + + return infoValueMetrics.stringWidth(t); + } + + void set_layout() { + setRowHeight(desired_row_height()); + for (int i = 0; i < info_columns * 2; i++) + { + TableColumn column = getColumnModel().getColumn(i); + + if ((i & 1) == 0) + column.setPreferredWidth(text_width(" Satellites Visible")); + else + column.setPreferredWidth(text_width("W 179°59.99999' ")); + } + } + + public AltosInfoTable() { + super(new AltosFlightInfoTableModel(info_rows, info_columns)); + model = (AltosFlightInfoTableModel) getModel(); + setFont(AltosUILib.table_value_font); + setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); + setShowGrid(true); + set_layout(); + doLayout(); + } + + public void set_font() { + setFont(AltosUILib.table_value_font); + set_layout(); + doLayout(); + } + + public Dimension getPreferredScrollableViewportSize() { + return getPreferredSize(); + } + + public void reset() { + model.reset(); + } + + void info_add_row(int col, String name, String value) { + model.addRow(col, name, value); + } + + void info_add_row(int col, String name, String format, Object... parameters) { + info_add_row (col, name, String.format(format, parameters)); + } + + void info_add_deg(int col, String name, double v, int pos, int neg) { + int c = pos; + if (v < 0) { + c = neg; + v = -v; + } + double deg = Math.floor(v); + double min = (v - deg) * 60; + + info_add_row(col, name, String.format("%c %3.0f°%08.5f'", c, deg, min)); + } + + void info_finish() { + model.finish(); + } + + public void clear() { + model.clear(); + } + + public void show(AltosState state, AltosListenerState listener_state) { + reset(); + if (state != null) { + if (state.device_type != AltosLib.MISSING) + info_add_row(0, "Device", "%s", AltosLib.product_name(state.device_type)); + if (state.altitude() != AltosLib.MISSING) + info_add_row(0, "Altitude", "%6.0f m", state.altitude()); + if (state.ground_altitude() != AltosLib.MISSING) + info_add_row(0, "Pad altitude", "%6.0f m", state.ground_altitude()); + if (state.height() != AltosLib.MISSING) + info_add_row(0, "Height", "%6.0f m", state.height()); + if (state.max_height() != AltosLib.MISSING) + info_add_row(0, "Max height", "%6.0f m", state.max_height()); + if (state.acceleration() != AltosLib.MISSING) + info_add_row(0, "Acceleration", "%8.1f m/s²", state.acceleration()); + if (state.max_acceleration() != AltosLib.MISSING) + info_add_row(0, "Max acceleration", "%8.1f m/s²", state.max_acceleration()); + if (state.speed() != AltosLib.MISSING) + info_add_row(0, "Speed", "%8.1f m/s", state.speed()); + if (state.max_speed() != AltosLib.MISSING) + info_add_row(0, "Max Speed", "%8.1f m/s", state.max_speed()); + if (state.orient() != AltosLib.MISSING) + info_add_row(0, "Tilt", "%4.0f °", state.orient()); + if (state.max_orient() != AltosLib.MISSING) + info_add_row(0, "Max Tilt", "%4.0f °", state.max_orient()); + if (state.temperature != AltosLib.MISSING) + info_add_row(0, "Temperature", "%9.2f °C", state.temperature); + if (state.battery_voltage != AltosLib.MISSING) + info_add_row(0, "Battery", "%9.2f V", state.battery_voltage); + if (state.apogee_voltage != AltosLib.MISSING) + info_add_row(0, "Drogue", "%9.2f V", state.apogee_voltage); + if (state.main_voltage != AltosLib.MISSING) + info_add_row(0, "Main", "%9.2f V", state.main_voltage); + } + if (listener_state != null) { + info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors); + + if (listener_state.battery != AltosLib.MISSING) + info_add_row(0, "Receiver Battery", "%9.2f", listener_state.battery); + } + + if (state != null) { + if (state.gps == null || !state.gps.connected) { + info_add_row(1, "GPS", "not available"); + } else { + if (state.gps_ready) + info_add_row(1, "GPS state", "%s", "ready"); + else + info_add_row(1, "GPS state", "wait (%d)", + state.gps_waiting); + if (state.gps.locked) + info_add_row(1, "GPS", " locked"); + else if (state.gps.connected) + info_add_row(1, "GPS", " unlocked"); + else + info_add_row(1, "GPS", " missing"); + info_add_row(1, "Satellites", "%6d", state.gps.nsat); + if (state.gps.lat != AltosLib.MISSING) + info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S'); + if (state.gps.lon != AltosLib.MISSING) + info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W'); + if (state.gps.alt != AltosLib.MISSING) + info_add_row(1, "GPS altitude", "%8.1f", state.gps.alt); + if (state.gps_height != AltosLib.MISSING) + info_add_row(1, "GPS height", "%8.1f", state.gps_height); + + /* The SkyTraq GPS doesn't report these values */ + /* + if (false) { + info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°", + state.gps.ground_speed, + state.gps.course); + info_add_row(1, "GPS climb rate", "%8.1f m/s", + state.gps.climb_rate); + info_add_row(1, "GPS error", "%6d m(h)%3d m(v)", + state.gps.h_error, state.gps.v_error); + } + */ + + info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop); + + if (state.npad > 0) { + if (state.from_pad != null) { + info_add_row(1, "Distance from pad", "%6d m", + (int) (state.from_pad.distance + 0.5)); + info_add_row(1, "Direction from pad", "%6d°", + (int) (state.from_pad.bearing + 0.5)); + info_add_row(1, "Elevation from pad", "%6d°", + (int) (state.elevation + 0.5)); + info_add_row(1, "Range from pad", "%6d m", + (int) (state.range + 0.5)); + } else { + info_add_row(1, "Distance from pad", "unknown"); + info_add_row(1, "Direction from pad", "unknown"); + info_add_row(1, "Elevation from pad", "unknown"); + info_add_row(1, "Range from pad", "unknown"); + } + info_add_deg(1, "Pad latitude", state.pad_lat, 'N', 'S'); + info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W'); + info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt); + } + if (state.gps.year != AltosLib.MISSING) + info_add_row(1, "GPS date", "%04d-%02d-%02d", + state.gps.year, + state.gps.month, + state.gps.day); + if (state.gps.hour != AltosLib.MISSING) + info_add_row(1, "GPS time", " %02d:%02d:%02d", + state.gps.hour, + state.gps.minute, + state.gps.second); + //int nsat_vis = 0; + int c; + + if (state.gps.cc_gps_sat == null) + info_add_row(2, "Satellites Visible", "%4d", 0); + else { + info_add_row(2, "Satellites Visible", "%4d", state.gps.cc_gps_sat.length); + for (c = 0; c < state.gps.cc_gps_sat.length; c++) { + info_add_row(2, "Satellite id,C/N0", + "%4d, %4d", + state.gps.cc_gps_sat[c].svid, + state.gps.cc_gps_sat[c].c_n0); + } + } + } + } + info_finish(); + } +} diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index e697b17c..65a8228a 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -56,6 +56,8 @@ altosuilib_JAVA = \ AltosLed.java \ AltosFlashUI.java \ AltosRomconfigUI.java \ + AltosInfoTable.java \ + AltosFlightInfoTableModel.java \ AltosBTDevice.java \ AltosBTDeviceIterator.java \ AltosBTManage.java \ diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 7f34c763..d30d8dc5 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -50,16 +50,25 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo AltosFlightReader reader; AltosDisplayThread thread; - JTabbedPane pane; + JMenuBar menu_bar; - AltosSiteMap sitemap; - TeleGPSInfo gps_info; - boolean has_map; + JMenu file_menu; + JMenu monitor_menu; + JMenu device_menu; + AltosFreqList frequencies; + + Container bag; + + TeleGPSStatus telegps_status; + TeleGPSStatusUpdate status_update; + + JTabbedPane pane; + + AltosSiteMap sitemap; + TeleGPSInfo gps_info; + AltosInfoTable info_table; - JMenuBar menu_bar; - JMenu file_menu; - JMenu monitor_menu; - JMenu device_menu; + LinkedList displays; /* File menu */ final static String new_command = "new"; @@ -113,41 +122,38 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo } public void reset() { - sitemap.reset(); - gps_info.reset(); + for (AltosFlightDisplay display : displays) + display.reset(); } public void set_font() { - sitemap.set_font(); - gps_info.set_font(); + for (AltosFlightDisplay display : displays) + display.set_font(); } public void font_size_changed(int font_size) { set_font(); } - -// AltosFlightStatusUpdate status_update; - public void show(AltosState state, AltosListenerState listener_state) { -// status_update.saved_state = state; + try { + status_update.saved_state = state; - if (state == null) - state = new AltosState(); + if (state == null) + state = new AltosState(); - sitemap.show(state, listener_state); - gps_info.show(state, listener_state); - telegps_status.show(state, listener_state); + int i = 0; + for (AltosFlightDisplay display : displays) { + display.show(state, listener_state); + i++; + } + } catch (Exception ex) { + System.out.printf("Exception %s\n", ex.toString()); + for (StackTraceElement e : ex.getStackTrace()) + System.out.printf("%s\n", e.toString()); + } } - Container bag; - AltosFreqList frequencies; - JLabel telemetry; - TeleGPSStatus telegps_status; - TeleGPSStatusUpdate status_update; - - ActionListener show_timer; - void new_window() { new TeleGPS(); } @@ -379,6 +385,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo file_menu = make_menu("File", file_menu_entries); monitor_menu = make_menu("Monitor", monitor_menu_entries); device_menu = make_menu("Device", device_menu_entries); + displays = new LinkedList(); int serial = -1; @@ -391,6 +398,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo c.gridwidth = 2; bag.add(telegps_status, c); c.gridwidth = 1; + displays.add(telegps_status); /* The rest of the window uses a tabbed pane to @@ -409,9 +417,15 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo sitemap = new AltosSiteMap(); pane.add("Site Map", sitemap); + displays.add(sitemap); gps_info = new TeleGPSInfo(); pane.add("Info", gps_info); + displays.add(gps_info); + + info_table = new AltosInfoTable(); + pane.add("Table", info_table); + displays.add(info_table); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java index 0fba77d5..da3df44e 100644 --- a/telegps/TeleGPSInfo.java +++ b/telegps/TeleGPSInfo.java @@ -58,6 +58,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { show(String.format(format, v)); } + void show(String format, int v) { + show(String.format(format, v)); + } + void reset() { lights.set(false); value.setText(""); -- cgit v1.2.3 From f80075be4ebb9c5fe00c24b8c7638fad23267424 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 May 2014 14:03:58 -0700 Subject: java: Refactor AltosFlightDisplay units and font update handling Make AltosFlightDisplay explicitly implement AltosFontListener and AltosUnitsListener interfaces to make everyone use the same API. Then, actually go implement units listeners so that changing units updates all of the active displays immediately Signed-off-by: Keith Packard --- altosui/AltosAscent.java | 116 ++++++++++++++++++--------- altosui/AltosCompanionInfo.java | 7 +- altosui/AltosDescent.java | 86 +++++++++++++------- altosui/AltosFlightStatus.java | 5 +- altosui/AltosFlightUI.java | 37 +++++---- altosui/AltosIdleMonitorUI.java | 17 ++-- altosui/AltosIgnitor.java | 14 +++- altosui/AltosLanded.java | 67 +++++++++++----- altosui/AltosPad.java | 71 ++++++++++++----- altosuilib/AltosFlightDisplay.java | 4 +- altosuilib/AltosInfoTable.java | 5 +- altosuilib/AltosSiteMap.java | 6 +- telegps/TeleGPS.java | 16 ++-- telegps/TeleGPSInfo.java | 157 +++++++++++++++++++++++++++---------- telegps/TeleGPSStatus.java | 17 ++-- 15 files changed, 431 insertions(+), 194 deletions(-) (limited to 'telegps/TeleGPSInfo.java') diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index f6ccbf0c..fb05fe11 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -26,10 +26,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; JLabel cur, max; - public class AscentStatus { + public class AscentStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosLights lights; + double v; + AltosUnits units; void show() { value.setVisible(true); @@ -50,7 +52,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value.setText(s); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -63,12 +66,18 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lights.set(false); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } - public AscentStatus (GridBagLayout layout, int y, String text) { + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + + public AscentStatus (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -105,10 +114,13 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } } - public class AscentValue { + public abstract class AscentValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; - void show(AltosState state, AltosListenerState listener_state) {} + double v; + AltosUnits units; + + abstract void show(AltosState state, AltosListenerState listener_state); void reset() { value.setText(""); @@ -124,7 +136,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { value.setText(s); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -136,12 +149,18 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { label.setVisible(false); value.setVisible(false); } - void set_font() { + + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } - public AscentValue (GridBagLayout layout, int y, String text) { + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + + public AscentValue (GridBagLayout layout, int y, AltosUnits units, String text) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -167,13 +186,19 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { layout.setConstraints(value, c); add(value); } + + public AscentValue (GridBagLayout layout, int y, String text) { + this(layout, y, null, text); + } } - public class AscentValueHold { + public class AscentValueHold implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; JTextField max_value; double max; + AltosUnits units; + double v; void show(AltosState state, AltosListenerState listener_state) {} @@ -183,23 +208,29 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { max = AltosLib.MISSING; } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); max_value.setFont(Altos.value_font); } - void show(AltosUnits units, double v) { + public void units_changed(boolean imperial_units) { + show(v); + } + + void show(double v) { + this.v = v; if (v == AltosLib.MISSING) { value.setText("Missing"); - max_value.setText("Missing"); } else { value.setText(units.show(8, v)); - if (v > max || max == AltosLib.MISSING) { - max_value.setText(units.show(8, v)); + if (v > max || max == AltosLib.MISSING) max = v; - } } + if (max == AltosLib.MISSING) + max_value.setText("Missing"); + else + max_value.setText(units.show(8, v)); } void hide() { @@ -208,7 +239,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { max_value.setVisible(false); } - public AscentValueHold (GridBagLayout layout, int y, String text) { + public AscentValueHold (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -245,13 +277,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } } - class Height extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.height()); + show(state.height()); } public Height (GridBagLayout layout, int y) { - super (layout, y, "Height"); + super (layout, y, AltosConvert.height, "Height"); } } @@ -259,10 +290,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Speed extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.speed, state.speed()); + show(state.speed()); } public Speed (GridBagLayout layout, int y) { - super (layout, y, "Speed"); + super (layout, y, AltosConvert.speed, "Speed"); } } @@ -270,10 +301,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Accel extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.accel, state.acceleration()); + show(state.acceleration()); } public Accel (GridBagLayout layout, int y) { - super (layout, y, "Acceleration"); + super (layout, y, AltosConvert.accel, "Acceleration"); } } @@ -281,10 +312,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Orient extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.orient, state.orient()); + show(state.orient()); } public Orient (GridBagLayout layout, int y) { - super (layout, y, "Tilt Angle"); + super (layout, y, AltosConvert.orient, "Tilt Angle"); } } @@ -307,7 +338,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good); } public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); + super(layout, y, null, "Apogee Igniter Voltage"); } } @@ -319,7 +350,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lights.set(state.main_voltage >= AltosLib.ao_igniter_good); } public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); + super(layout, y, null, "Main Igniter Voltage"); } } @@ -364,17 +395,28 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { orient.reset(); } - public void set_font() { + public void font_size_changed(int font_size) { cur.setFont(Altos.label_font); max.setFont(Altos.label_font); - lat.set_font(); - lon.set_font(); - main.set_font(); - apogee.set_font(); - height.set_font(); - speed.set_font(); - accel.set_font(); - orient.set_font(); + lat.font_size_changed(font_size); + lon.font_size_changed(font_size); + main.font_size_changed(font_size); + apogee.font_size_changed(font_size); + height.font_size_changed(font_size); + speed.font_size_changed(font_size); + accel.font_size_changed(font_size); + orient.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + lat.units_changed(imperial_units); + lon.units_changed(imperial_units); + main.units_changed(imperial_units); + apogee.units_changed(imperial_units); + height.units_changed(imperial_units); + speed.units_changed(imperial_units); + accel.units_changed(imperial_units); + orient.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index f8d033a8..514ce611 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -33,18 +33,21 @@ public class AltosCompanionInfo extends JTable implements AltosFlightDisplay { return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; } - public void set_font() { + public void font_size_changed(int font_size) { setFont(Altos.table_value_font); setRowHeight(desired_row_height()); doLayout(); } + public void units_changed(boolean imperial_units) { + } + public AltosCompanionInfo() { super(new AltosFlightInfoTableModel(info_rows, info_columns)); model = (AltosFlightInfoTableModel) getModel(); setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); setShowGrid(true); - set_font(); + font_size_changed(AltosUIPreferences.font_size()); } public Dimension getPreferredScrollableViewportSize() { diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 5cb693fe..e6710524 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - public abstract class DescentStatus { + public abstract class DescentStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosLights lights; @@ -58,11 +58,14 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { lights.set(false); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } + public void units_changed(boolean imperial_units) { + } + public DescentStatus (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -101,9 +104,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { } } - public abstract class DescentValue { + public abstract class DescentValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; + AltosUnits units; + double v; void reset() { value.setText(""); @@ -126,7 +131,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value.setText(v); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -134,12 +140,18 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { show(String.format(format, v)); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } - public DescentValue (GridBagLayout layout, int x, int y, String text) { + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + + public DescentValue (GridBagLayout layout, int x, int y, AltosUnits units, String text) { + this.units = units; GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -163,9 +175,13 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { c.weightx = 1; add(value, c); } + + public DescentValue (GridBagLayout layout, int x, int y, String text) { + this(layout, x, y, null, text); + } } - public abstract class DescentDualValue { + public abstract class DescentDualValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value1; JTextField value2; @@ -187,12 +203,15 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { value2.setVisible(false); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value1.setFont(Altos.value_font); value2.setFont(Altos.value_font); } + public void units_changed(boolean imperial_units) { + } + abstract void show(AltosState state, AltosListenerState listener_state); void show(String v1, String v2) { @@ -246,10 +265,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Height extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.height()); + show(state.height()); } public Height (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Height"); + super (layout, x, y, AltosConvert.height, "Height"); } } @@ -257,10 +276,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Speed extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.speed, state.speed()); + show(state.speed()); } public Speed (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Speed"); + super (layout, x, y, AltosConvert.speed, "Speed"); } } @@ -308,13 +327,13 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Distance extends DescentValue { void show(AltosState state, AltosListenerState listener_state) { if (state.from_pad != null) - show(AltosConvert.distance, state.from_pad.distance); + show(state.from_pad.distance); else show("???"); } public Distance (GridBagLayout layout, int x, int y) { - super(layout, x, y, "Ground Distance"); + super(layout, x, y, AltosConvert.distance, "Ground Distance"); } } @@ -364,10 +383,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { class Range extends DescentValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.distance, state.range); + show(state.range); } public Range (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Range"); + super (layout, x, y, AltosConvert.distance, "Range"); } } @@ -397,17 +416,30 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { apogee.reset(); } - public void set_font() { - lat.set_font(); - lon.set_font(); - height.set_font(); - speed.set_font(); - bearing.set_font(); - range.set_font(); - distance.set_font(); - elevation.set_font(); - main.set_font(); - apogee.set_font(); + public void font_size_changed(int font_size) { + lat.font_size_changed(font_size); + lon.font_size_changed(font_size); + height.font_size_changed(font_size); + speed.font_size_changed(font_size); + bearing.font_size_changed(font_size); + range.font_size_changed(font_size); + distance.font_size_changed(font_size); + elevation.font_size_changed(font_size); + main.font_size_changed(font_size); + apogee.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + lat.units_changed(imperial_units); + lon.units_changed(imperial_units); + height.units_changed(imperial_units); + speed.units_changed(imperial_units); + bearing.units_changed(imperial_units); + range.units_changed(imperial_units); + distance.units_changed(imperial_units); + elevation.units_changed(imperial_units); + main.units_changed(imperial_units); + apogee.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index 73b84f8d..459b0495 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -159,7 +159,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_packet.reset(); } - public void set_font () { + public void font_size_changed(int font_size) { call.set_font(); serial.set_font(); flight.set_font(); @@ -168,6 +168,9 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_packet.set_font(); } + public void units_changed(boolean imperial_units) { + } + public void show (AltosState state, AltosListenerState listener_state) { call.show(state, listener_state); serial.show(state, listener_state); diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index 2bd60d6c..baa18686 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -24,7 +24,7 @@ import java.util.concurrent.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener { +public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { AltosVoice voice; AltosFlightReader reader; AltosDisplayThread thread; @@ -83,22 +83,29 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A sitemap.reset(); } - public void set_font() { - pad.set_font(); - ignitor.set_font(); - ascent.set_font(); - descent.set_font(); - landed.set_font(); - flightStatus.set_font(); - flightInfo.set_font(); - sitemap.set_font(); - companion.set_font(); - } - public void font_size_changed(int font_size) { - set_font(); + pad.font_size_changed(font_size); + ignitor.font_size_changed(font_size); + ascent.font_size_changed(font_size); + descent.font_size_changed(font_size); + landed.font_size_changed(font_size); + flightStatus.font_size_changed(font_size); + flightInfo.font_size_changed(font_size); + sitemap.font_size_changed(font_size); + companion.font_size_changed(font_size); } + public void units_changed(boolean imperial_units) { + pad.units_changed(imperial_units); + ignitor.units_changed(imperial_units); + ascent.units_changed(imperial_units); + descent.units_changed(imperial_units); + landed.units_changed(imperial_units); + flightStatus.units_changed(imperial_units); + flightInfo.units_changed(imperial_units); + sitemap.units_changed(imperial_units); + companion.units_changed(imperial_units); + } AltosFlightStatusUpdate status_update; @@ -318,6 +325,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); AltosUIPreferences.register_font_listener(this); + AltosPreferences.register_units_listener(this); addWindowListener(new WindowAdapter() { @Override @@ -326,6 +334,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A setVisible(false); dispose(); AltosUIPreferences.unregister_font_listener(AltosFlightUI.this); + AltosPreferences.unregister_units_listener(AltosFlightUI.this); if (exit_on_close) System.exit(0); } diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index b5652df3..042111ec 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -27,7 +27,7 @@ import java.util.Arrays; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener { +public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosIdleMonitorListener, DocumentListener { AltosDevice device; JTabbedPane pane; AltosPad pad; @@ -56,13 +56,14 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl flightInfo.clear(); } - public void set_font() { - pad.set_font(); - flightInfo.set_font(); + public void font_size_changed(int font_size) { + pad.font_size_changed(font_size); + flightInfo.font_size_changed(font_size); } - public void font_size_changed(int font_size) { - set_font(); + public void units_changed(boolean imperial_units) { + pad.units_changed(imperial_units); + flightInfo.units_changed(imperial_units); } AltosFlightStatusUpdate status_update; @@ -235,8 +236,8 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl disconnect(); } catch (Exception ex) { System.out.printf("Exception %s\n", ex.toString()); - for (StackTraceElement e : ex.getStackTrace()) - System.out.printf("%s\n", e.toString()); + for (StackTraceElement el : ex.getStackTrace()) + System.out.printf("%s\n", el.toString()); } setVisible(false); dispose(); diff --git a/altosui/AltosIgnitor.java b/altosui/AltosIgnitor.java index 7f79f42b..27917b30 100644 --- a/altosui/AltosIgnitor.java +++ b/altosui/AltosIgnitor.java @@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*; public class AltosIgnitor extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - public class LaunchStatus { + public class LaunchStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosLights lights; @@ -66,11 +66,14 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay { hide(); } - public void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } + public void units_changed(boolean imperial_units) { + } + public void set_label(String text) { label.setText(text); } @@ -142,11 +145,14 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay { ignitors[i].reset(); } - public void set_font() { + public void font_size_changed(int font_size) { if (ignitors == null) return; for (int i = 0; i < ignitors.length; i++) - ignitors[i].set_font(); + ignitors[i].font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { } public void show(AltosState state, AltosListenerState listener_state) { diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 707d8fcc..bb52fe2b 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -27,10 +27,13 @@ import org.altusmetrum.altosuilib_2.*; public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { GridBagLayout layout; - public class LandedValue { + public abstract class LandedValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; - void show(AltosState state, AltosListenerState listener_state) {} + AltosUnits units; + double v; + + abstract void show(AltosState state, AltosListenerState listener_state); void reset() { value.setText(""); @@ -46,7 +49,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio value.setText(s); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -54,17 +58,24 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio show(String.format(format, v)); } - public void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + void hide() { label.setVisible(false); value.setVisible(false); } - public LandedValue (GridBagLayout layout, int y, String text) { + public LandedValue (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; + GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -89,6 +100,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio layout.setConstraints(value, c); add(value); } + + public LandedValue (GridBagLayout layout, int y, String text) { + this(layout, y, null, text); + } } String pos(double p, String pos, String neg) { @@ -151,12 +166,12 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio void show (AltosState state, AltosListenerState listener_state) { show(); if (state.from_pad != null) - show(AltosConvert.distance, state.from_pad.distance); + show(state.from_pad.distance); else show("???"); } public Distance (GridBagLayout layout, int y) { - super (layout, y, "Distance"); + super (layout, y, AltosConvert.distance, "Distance"); } } @@ -164,10 +179,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Height extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.max_height()); + show(state.max_height()); } public Height (GridBagLayout layout, int y) { - super (layout, y, "Maximum Height"); + super (layout, y, AltosConvert.height, "Maximum Height"); } } @@ -175,10 +190,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Speed extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.speed, state.max_speed()); + show(state.max_speed()); } public Speed (GridBagLayout layout, int y) { - super (layout, y, "Maximum Speed"); + super (layout, y, AltosConvert.speed, "Maximum Speed"); } } @@ -186,10 +201,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio class Accel extends LandedValue { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.accel, state.max_acceleration()); + show(state.max_acceleration()); } public Accel (GridBagLayout layout, int y) { - super (layout, y, "Maximum Acceleration"); + super (layout, y, AltosConvert.accel, "Maximum Acceleration"); } } @@ -205,14 +220,24 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio accel.reset(); } - public void set_font() { - lat.set_font(); - lon.set_font(); - bearing.set_font(); - distance.set_font(); - height.set_font(); - speed.set_font(); - accel.set_font(); + public void font_size_changed(int font_size) { + lat.font_size_changed(font_size); + lon.font_size_changed(font_size); + bearing.font_size_changed(font_size); + distance.font_size_changed(font_size); + height.font_size_changed(font_size); + speed.font_size_changed(font_size); + accel.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + lat.units_changed(imperial_units); + lon.units_changed(imperial_units); + bearing.units_changed(imperial_units); + distance.units_changed(imperial_units); + height.units_changed(imperial_units); + speed.units_changed(imperial_units); + accel.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index a6ac70db..ce1f2ab7 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*; public class AltosPad extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - public class LaunchStatus { + public class LaunchStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosLights lights; @@ -62,11 +62,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { lights.setVisible(false); } - public void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } + public void units_changed(boolean imperial_units) { + } + public void set_label(String text) { label.setText(text); } @@ -107,10 +110,13 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } } - public class LaunchValue { + public abstract class LaunchValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; - void show(AltosState state, AltosListenerState listener_state) {} + AltosUnits units; + double v; + + abstract void show(AltosState state, AltosListenerState listener_state); void show() { label.setVisible(true); @@ -122,17 +128,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { value.setVisible(false); } - public void set_font() { + public void font_size_changed(int font_size) { label.setFont(Altos.label_font); value.setFont(Altos.value_font); } + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + void show(String s) { show(); value.setText(s); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -148,7 +160,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { value.setText(""); } - public LaunchValue (GridBagLayout layout, int y, String text) { + public LaunchValue (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; + GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); c.weighty = 1; @@ -173,6 +187,10 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { layout.setConstraints(value, c); add(value); } + + public LaunchValue (GridBagLayout layout, int y, String text) { + this(layout, y, null, text); + } } class Battery extends LaunchStatus { @@ -378,13 +396,13 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } } if (alt != AltosLib.MISSING) { - show("%4.0f m", state.gps.alt); + show(alt); set_label(label); } else hide(); } public PadAlt (GridBagLayout layout, int y) { - super (layout, y, "Pad Altitude"); + super (layout, y, AltosConvert.height, "Pad Altitude"); } } @@ -403,17 +421,30 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { pad_alt.reset(); } - public void set_font() { - battery.set_font(); - apogee.set_font(); - main.set_font(); - logging_ready.set_font(); - gps_locked.set_font(); - gps_ready.set_font(); - receiver_battery.set_font(); - pad_lat.set_font(); - pad_lon.set_font(); - pad_alt.set_font(); + public void font_size_changed(int font_size) { + battery.font_size_changed(font_size); + apogee.font_size_changed(font_size); + main.font_size_changed(font_size); + logging_ready.font_size_changed(font_size); + gps_locked.font_size_changed(font_size); + gps_ready.font_size_changed(font_size); + receiver_battery.font_size_changed(font_size); + pad_lat.font_size_changed(font_size); + pad_lon.font_size_changed(font_size); + pad_alt.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + battery.units_changed(imperial_units); + apogee.units_changed(imperial_units); + main.units_changed(imperial_units); + logging_ready.units_changed(imperial_units); + gps_locked.units_changed(imperial_units); + gps_ready.units_changed(imperial_units); + receiver_battery.units_changed(imperial_units); + pad_lat.units_changed(imperial_units); + pad_lon.units_changed(imperial_units); + pad_alt.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { diff --git a/altosuilib/AltosFlightDisplay.java b/altosuilib/AltosFlightDisplay.java index 5695a015..5fb0cab7 100644 --- a/altosuilib/AltosFlightDisplay.java +++ b/altosuilib/AltosFlightDisplay.java @@ -19,10 +19,8 @@ package org.altusmetrum.altosuilib_2; import org.altusmetrum.altoslib_4.*; -public interface AltosFlightDisplay { +public interface AltosFlightDisplay extends AltosUnitsListener, AltosFontListener { void reset(); void show(AltosState state, AltosListenerState listener_state); - - void set_font(); } diff --git a/altosuilib/AltosInfoTable.java b/altosuilib/AltosInfoTable.java index 0d8779d1..24a895eb 100644 --- a/altosuilib/AltosInfoTable.java +++ b/altosuilib/AltosInfoTable.java @@ -62,12 +62,15 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { doLayout(); } - public void set_font() { + public void font_size_changed(int font_size) { setFont(AltosUILib.table_value_font); set_layout(); doLayout(); } + public void units_changed(boolean imperial_units) { + } + public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } diff --git a/altosuilib/AltosSiteMap.java b/altosuilib/AltosSiteMap.java index 7f0e1844..ed77beff 100644 --- a/altosuilib/AltosSiteMap.java +++ b/altosuilib/AltosSiteMap.java @@ -192,11 +192,15 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay, Mous // nothing } - public void set_font() { + public void font_size_changed(int font_size) { for (AltosSiteMapTile tile : mapTiles.values()) tile.set_font(AltosUILib.value_font); } + public void units_changed(boolean imperial_units) { + set_line(); + } + static final int load_mode_cached = 1; static final int load_mode_uncached = 2; diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index d30d8dc5..bef0bbc6 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -26,7 +26,10 @@ import java.util.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, ActionListener { +public class TeleGPS + extends AltosUIFrame + implements AltosFlightDisplay, AltosFontListener, AltosUnitsListener, ActionListener +{ static String[] telegps_icon_names = { "/telegps-16.png", @@ -126,13 +129,14 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo display.reset(); } - public void set_font() { + public void font_size_changed(int font_size) { for (AltosFlightDisplay display : displays) - display.set_font(); + display.font_size_changed(font_size); } - public void font_size_changed(int font_size) { - set_font(); + public void units_changed(boolean imperial_units) { + for (AltosFlightDisplay display : displays) + display.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { @@ -343,6 +347,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo private void close() { AltosUIPreferences.unregister_font_listener(this); + AltosPreferences.unregister_units_listener(this); setVisible(false); dispose(); --number_of_windows; @@ -430,6 +435,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); AltosUIPreferences.register_font_listener(this); + AltosPreferences.register_units_listener(this); addWindowListener(new WindowAdapter() { @Override diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java index da3df44e..2765f5ab 100644 --- a/telegps/TeleGPSInfo.java +++ b/telegps/TeleGPSInfo.java @@ -26,10 +26,12 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { GridBagLayout layout; JLabel cur, max; - public class Info { + public abstract class Info implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosLights lights; + double v; + AltosUnits units; void show() { value.setVisible(true); @@ -43,14 +45,15 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { label.setVisible(false); } - void show(AltosState state, AltosListenerState listener_state) {} + abstract void show(AltosState state, AltosListenerState listener_state); void show(String s) { show(); value.setText(s); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -67,12 +70,19 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value.setText(""); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(AltosUILib.label_font); value.setFont(AltosUILib.value_font); } - public Info (GridBagLayout layout, int y, String text) { + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } + + public Info (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; + GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -106,12 +116,19 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { layout.setConstraints(value, c); add(value); } + + public Info (GridBagLayout layout, int y, String text) { + this(layout, y, null, text); + } } - public class Value { + public abstract class Value implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; - void show(AltosState state, AltosListenerState listener_state) {} + AltosUnits units; + double v = AltosLib.MISSING; + + abstract void show(AltosState state, AltosListenerState listener_state); void reset() { value.setText(""); @@ -127,7 +144,8 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value.setText(s); } - void show(AltosUnits units, double v) { + void show(double v) { + this.v = v; show(units.show(8, v)); } @@ -139,10 +157,14 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { label.setVisible(false); value.setVisible(false); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(AltosUILib.label_font); value.setFont(AltosUILib.value_font); } + public void units_changed(boolean imperial_units) { + if (units != null) + show(v); + } public Value (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); @@ -172,34 +194,44 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { } } - public abstract class DualValue { + public abstract class DualValue implements AltosFontListener, AltosUnitsListener { + AltosLights lights; JLabel label; JTextField value1; JTextField value2; void reset() { + if (lights != null) + lights.set(false); value1.setText(""); value2.setText(""); } void show() { + if (lights != null) + lights.setVisible(true); label.setVisible(true); value1.setVisible(true); value2.setVisible(true); } void hide() { + if (lights != null) + lights.setVisible(false); label.setVisible(false); value1.setVisible(false); value2.setVisible(false); } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(AltosUILib.label_font); value1.setFont(AltosUILib.value_font); value2.setFont(AltosUILib.value_font); } + public void units_changed(boolean imperial_units) { + } + abstract void show(AltosState state, AltosListenerState listener_state); void show(String v1, String v2) { @@ -207,20 +239,37 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value1.setText(v1); value2.setText(v2); } + void show(String f1, double v1, String f2, double v2) { show(); value1.setText(String.format(f1, v1)); value2.setText(String.format(f2, v2)); } - public DualValue (GridBagLayout layout, int x, int y, String text) { + void show(String f1, int v1, String f2, int v2) { + show(); + value1.setText(String.format(f1, v1)); + value2.setText(String.format(f2, v2)); + } + + public DualValue (GridBagLayout layout, int y, String text, boolean want_lights) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; + if (want_lights) { + lights = new AltosLights(); + c.gridx = 0; c.gridy = y; + c.anchor = GridBagConstraints.CENTER; + c.fill = GridBagConstraints.VERTICAL; + c.weightx = 0; + layout.setConstraints(lights, c); + add(lights); + } + label = new JLabel(text); label.setFont(AltosUILib.label_font); label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 1; c.gridy = y; + c.gridx = 1; c.gridy = y; c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.VERTICAL; @@ -231,7 +280,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value1 = new JTextField(AltosUILib.text_width); value1.setFont(AltosUILib.value_font); value1.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 2; c.gridy = y; + c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -241,7 +290,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value2 = new JTextField(AltosUILib.text_width); value2.setFont(AltosUILib.value_font); value2.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 3; c.gridy = y; + c.gridx = 3; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.weightx = 1; @@ -251,13 +300,15 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { } } - public class ValueHold { + abstract public class ValueHold implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; JTextField max_value; + double v; double max; + AltosUnits units; - void show(AltosState state, AltosListenerState listener_state) {} + abstract void show(AltosState state, AltosListenerState listener_state); void reset() { value.setText(""); @@ -265,23 +316,29 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { max = AltosLib.MISSING; } - void set_font() { + public void font_size_changed(int font_size) { label.setFont(AltosUILib.label_font); value.setFont(AltosUILib.value_font); max_value.setFont(AltosUILib.value_font); } - void show(AltosUnits units, double v) { + public void units_changed(boolean imperial_units) { + show(v); + } + + void show(double v) { + this.v = v; if (v == AltosLib.MISSING) { value.setText("Missing"); - max_value.setText("Missing"); } else { value.setText(units.show(8, v)); - if (v > max || max == AltosLib.MISSING) { - max_value.setText(units.show(8, v)); + if (v > max || max == AltosLib.MISSING) max = v; - } } + if (max == AltosLib.MISSING) + max_value.setText("Missing"); + else + max_value.setText(units.show(8, max)); } void hide() { @@ -290,7 +347,8 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { max_value.setVisible(false); } - public ValueHold (GridBagLayout layout, int y, String text) { + public ValueHold (GridBagLayout layout, int y, AltosUnits units, String text) { + this.units = units; GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -330,10 +388,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { class Altitude extends ValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.height, state.altitude()); + show(state.altitude()); } public Altitude (GridBagLayout layout, int y) { - super (layout, y, "Altitude"); + super (layout, y, AltosConvert.height, "Altitude"); } } @@ -341,10 +399,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { class AscentRate extends ValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.speed, state.gps_ascent_rate()); + show(state.gps_ascent_rate()); } public AscentRate (GridBagLayout layout, int y) { - super (layout, y, "Ascent Rate"); + super (layout, y, AltosConvert.speed, "Ascent Rate"); } } @@ -352,10 +410,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { class GroundSpeed extends ValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(AltosConvert.speed, state.gps_ground_speed()); + show(state.gps_ground_speed()); } public GroundSpeed (GridBagLayout layout, int y) { - super (layout, y, "Ground Speed"); + super (layout, y, AltosConvert.speed, "Ground Speed"); } } @@ -382,7 +440,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { course)); } public Course (GridBagLayout layout, int y) { - super (layout, 0, y, "Course"); + super (layout, y, "Course", false); } } @@ -416,17 +474,20 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { Lon lon; - class GPSLocked extends Info { + class GPSLocked extends DualValue { void show (AltosState state, AltosListenerState listener_state) { if (state == null || state.gps == null) hide(); else { - show("%4d sats", state.gps.nsat); - lights.set(state.gps.locked && state.gps.nsat >= 4); + int soln = state.gps.nsat; + int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0; + show("%4d in solution", soln, + "%4d in view", nsat); + lights.set(state.gps.locked && soln >= 4); } } public GPSLocked (GridBagLayout layout, int y) { - super (layout, y, "GPS Locked"); + super (layout, y, "GPS Locked", true); } } @@ -442,16 +503,26 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { gps_locked.reset(); } - public void set_font() { + public void font_size_changed(int font_size) { cur.setFont(AltosUILib.label_font); max.setFont(AltosUILib.label_font); - lat.set_font(); - lon.set_font(); - altitude.set_font(); - ground_speed.set_font(); - ascent_rate.set_font(); - course.set_font(); - gps_locked.set_font(); + lat.font_size_changed(font_size); + lon.font_size_changed(font_size); + altitude.font_size_changed(font_size); + ground_speed.font_size_changed(font_size); + ascent_rate.font_size_changed(font_size); + course.font_size_changed(font_size); + gps_locked.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + lat.units_changed(imperial_units); + lon.units_changed(imperial_units); + altitude.units_changed(imperial_units); + ground_speed.units_changed(imperial_units); + ascent_rate.units_changed(imperial_units); + course.units_changed(imperial_units); + gps_locked.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { diff --git a/telegps/TeleGPSStatus.java b/telegps/TeleGPSStatus.java index fd66b279..37cfae37 100644 --- a/telegps/TeleGPSStatus.java +++ b/telegps/TeleGPSStatus.java @@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*; public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - public class FlightValue { + public class Value { JLabel label; JTextField value; @@ -45,7 +45,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { value.setVisible(visible); } - public FlightValue (GridBagLayout layout, int x, String text) { + public Value (GridBagLayout layout, int x, String text) { GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.CENTER; @@ -69,7 +69,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { } } - class Call extends FlightValue { + class Call extends Value { void show(AltosState state, AltosListenerState listener_state) { value.setText(state.callsign); if (state.callsign == null) @@ -84,7 +84,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { Call call; - class Serial extends FlightValue { + class Serial extends Value { void show(AltosState state, AltosListenerState listener_state) { if (state.serial == AltosLib.MISSING) value.setText("none"); @@ -98,7 +98,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { Serial serial; - class RSSI extends FlightValue { + class RSSI extends Value { void show(AltosState state, AltosListenerState listener_state) { value.setText(String.format("%d", state.rssi())); if (state.rssi == AltosLib.MISSING) @@ -113,7 +113,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { RSSI rssi; - class LastPacket extends FlightValue { + class LastPacket extends Value { void show(AltosState state, AltosListenerState listener_state) { long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; value.setText(String.format("%d", secs)); @@ -132,13 +132,16 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { last_packet.reset(); } - public void set_font () { + public void font_size_changed(int font_size) { call.set_font(); serial.set_font(); rssi.set_font(); last_packet.set_font(); } + public void units_changed(boolean imperial_units) { + } + public void show (AltosState state, AltosListenerState listener_state) { call.show(state, listener_state); serial.show(state, listener_state); -- cgit v1.2.3 From 8044eb8e23366e91c741060939baff5137f841c7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 12 Jun 2014 14:12:08 -0700 Subject: altosui/telegps: Reduce CPU time needed for flight displays Don't update displays which aren't shown; track hierarchy changes to trigger display from most recent state data. Don't update values which haven't changed; remember previous values and compare with new before updating widget contents. Signed-off-by: Keith Packard --- altosui/AltosAscent.java | 45 ++++++++++++---- altosui/AltosDescent.java | 35 ++++++++++++- altosui/AltosFlightStatus.java | 83 ++++++++++++++++++++++------- altosui/AltosIgnitor.java | 1 + altosui/AltosLanded.java | 30 ++++++++++- altosui/AltosPad.java | 116 +++++++++++++++++++++++++---------------- altosuilib/AltosInfoTable.java | 25 ++++++++- altosuilib/AltosUIMapView.java | 3 +- telegps/TeleGPSInfo.java | 46 ++++++++++++---- telegps/TeleGPSStatus.java | 46 ++++++++++++---- 10 files changed, 326 insertions(+), 104 deletions(-) (limited to 'telegps/TeleGPSInfo.java') diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index fb05fe11..c3225709 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -18,14 +18,18 @@ package altosui; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosAscent extends JComponent implements AltosFlightDisplay { +public class AltosAscent extends JComponent implements AltosFlightDisplay, HierarchyListener { GridBagLayout layout; JLabel cur, max; + private AltosState last_state; + private AltosListenerState last_listener_state; + public class AscentStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; @@ -101,6 +105,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -176,6 +181,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -215,22 +221,21 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } public void units_changed(boolean imperial_units) { - show(v); + show(v, max); } - void show(double v) { + void show(double v, double max) { this.v = v; + this.max = max; if (v == AltosLib.MISSING) { value.setText("Missing"); } else { value.setText(units.show(8, v)); - if (v > max || max == AltosLib.MISSING) - max = v; } if (max == AltosLib.MISSING) max_value.setText("Missing"); else - max_value.setText(units.show(8, v)); + max_value.setText(units.show(8, max)); } void hide() { @@ -256,6 +261,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -266,6 +272,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { add(value); max_value = new JTextField(Altos.text_width); + max_value.setEditable(false); max_value.setFont(Altos.value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 3; c.gridy = y; @@ -279,7 +286,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Height extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.height()); + show(state.height(), state.max_height()); } public Height (GridBagLayout layout, int y) { super (layout, y, AltosConvert.height, "Height"); @@ -290,7 +297,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Speed extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.speed()); + show(state.speed(), state.max_speed()); } public Speed (GridBagLayout layout, int y) { super (layout, y, AltosConvert.speed, "Speed"); @@ -301,7 +308,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Accel extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.acceleration()); + show(state.acceleration(), state.max_acceleration()); } public Accel (GridBagLayout layout, int y) { super (layout, y, AltosConvert.accel, "Acceleration"); @@ -312,7 +319,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { class Orient extends AscentValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.orient()); + show(state.orient(), state.max_orient()); } public Orient (GridBagLayout layout, int y) { super (layout, y, AltosConvert.orient, "Tilt Angle"); @@ -420,6 +427,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { } public void show(AltosState state, AltosListenerState listener_state) { + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + if (state.gps != null && state.gps.connected) { lat.show(state, listener_state); lon.show(state, listener_state); @@ -466,6 +479,17 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { return "Ascent"; } + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + public AltosAscent() { layout = new GridBagLayout(); @@ -487,5 +511,6 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay { lon = new Lon(layout, y++); apogee = new Apogee(layout, y++); main = new Main(layout, y++); + addHierarchyListener(this); } } diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index b56a08bc..11bd6dbf 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -18,13 +18,17 @@ package altosui; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosDescent extends JComponent implements AltosFlightDisplay { +public class AltosDescent extends JComponent implements AltosFlightDisplay, HierarchyListener { GridBagLayout layout; + private AltosState last_state; + private AltosListenerState last_listener_state; + public abstract class DescentStatus implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; @@ -91,6 +95,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 4; c.gridy = y; @@ -109,6 +114,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { JTextField value; AltosUnits units; double v; + String last_value = ""; void reset() { value.setText(""); @@ -128,7 +134,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { void show(String v) { show(); - value.setText(v); + + if (!last_value.equals(v)) { + value.setText(v); + last_value = v; + } } void show(double v) { @@ -172,6 +182,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(label, c); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 2; c.gridy = y; @@ -247,6 +258,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(label); value1 = new JTextField(Altos.text_width); + value1.setEditable(false); value1.setFont(Altos.value_font); value1.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 2; c.gridy = y; @@ -257,6 +269,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { add(value1); value2 = new JTextField(Altos.text_width); + value2.setEditable(false); value2.setFont(Altos.value_font); value2.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = x + 4; c.gridy = y; @@ -449,6 +462,12 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { } public void show(AltosState state, AltosListenerState listener_state) { + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + height.show(state, listener_state); speed.show(state, listener_state); if (state.gps != null && state.gps.connected) { @@ -480,6 +499,17 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { return "Descent"; } + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + public AltosDescent() { layout = new GridBagLayout(); @@ -497,5 +527,6 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay { apogee = new Apogee(layout, 5); main = new Main(layout, 6); + addHierarchyListener(this); } } diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index 459b0495..b27deba9 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -61,6 +61,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay add(label); value = new JTextField(""); + value.setEditable(false); value.setFont(Altos.status_font); value.setHorizontalAlignment(SwingConstants.CENTER); c.gridx = x; c.gridy = 1; @@ -70,12 +71,25 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay } class Call extends FlightValue { - void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.callsign); - if (state.callsign == null) - setVisible(false); + + String last_call = ""; + + boolean same_call(String call) { + if (last_call == null) + return call == null; else - setVisible(true); + return last_call.equals(call); + } + + void show(AltosState state, AltosListenerState listener_state) { + if (!same_call(state.callsign)) { + value.setText(state.callsign); + if (state.callsign == null) + setVisible(false); + else + setVisible(true); + last_call = state.callsign; + } } public Call (GridBagLayout layout, int x) { super (layout, x, "Callsign"); @@ -85,11 +99,16 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay Call call; class Serial extends FlightValue { + + int last_serial = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.serial == AltosLib.MISSING) - value.setText("none"); - else - value.setText(String.format("%d", state.serial)); + if (state.serial != last_serial) { + if (state.serial == AltosLib.MISSING) + value.setText("none"); + else + value.setText(String.format("%d", state.serial)); + last_serial = state.serial; + } } public Serial (GridBagLayout layout, int x) { super (layout, x, "Serial"); @@ -99,11 +118,17 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay Serial serial; class Flight extends FlightValue { + + int last_flight = -1; + void show(AltosState state, AltosListenerState listener_state) { - if (state.flight == AltosLib.MISSING) - value.setText("none"); - else - value.setText(String.format("%d", state.flight)); + if (state.flight != last_flight) { + if (state.flight == AltosLib.MISSING) + value.setText("none"); + else + value.setText(String.format("%d", state.flight)); + last_flight = state.flight; + } } public Flight (GridBagLayout layout, int x) { super (layout, x, "Flight"); @@ -113,8 +138,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay Flight flight; class FlightState extends FlightValue { + + int last_state = -1; + void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.state_name()); + if (state.state != last_state) { + value.setText(state.state_name()); + last_state = state.state; + } } public FlightState (GridBagLayout layout, int x) { super (layout, x, "State"); @@ -124,12 +155,18 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay FlightState flight_state; class RSSI extends FlightValue { + + int last_rssi = 10000; + void show(AltosState state, AltosListenerState listener_state) { - value.setText(String.format("%d", state.rssi())); - if (state.rssi == AltosLib.MISSING) - setVisible(false); - else - setVisible(true); + if (state.rssi() != last_rssi) { + value.setText(String.format("%d", state.rssi())); + if (state.rssi == AltosLib.MISSING) + setVisible(false); + else + setVisible(true); + last_rssi = state.rssi(); + } } public RSSI (GridBagLayout layout, int x) { super (layout, x, "RSSI"); @@ -139,9 +176,15 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay RSSI rssi; class LastPacket extends FlightValue { + + long last_secs = -1; + void show(AltosState state, AltosListenerState listener_state) { long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; - value.setText(String.format("%d", secs)); + if (secs != last_secs) { + value.setText(String.format("%d", secs)); + last_secs = secs; + } } public LastPacket(GridBagLayout layout, int x) { super (layout, x, "Age"); diff --git a/altosui/AltosIgnitor.java b/altosui/AltosIgnitor.java index 7f62938d..73318117 100644 --- a/altosui/AltosIgnitor.java +++ b/altosui/AltosIgnitor.java @@ -102,6 +102,7 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index d2628fb0..760b2d64 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -24,14 +24,18 @@ import java.io.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { +public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener, HierarchyListener { GridBagLayout layout; + private AltosState last_state; + private AltosListenerState last_listener_state; + public abstract class LandedValue implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; AltosUnits units; double v; + String last_value = ""; abstract void show(AltosState state, AltosListenerState listener_state); @@ -46,7 +50,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio void show(String s) { show(); - value.setText(s); + if (!last_value.equals(s)) { + value.setText(s); + last_value = s; + } } void show(double v) { @@ -94,6 +101,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 1; c.gridy = y; @@ -244,6 +252,12 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio } public void show(AltosState state, AltosListenerState listener_state) { + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + if (state.gps != null && state.gps.connected) { bearing.show(state, listener_state); distance.show(state, listener_state); @@ -302,6 +316,17 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio return "Landed"; } + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + public AltosLanded(AltosFlightReader in_reader) { layout = new GridBagLayout(); @@ -332,5 +357,6 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio c.weighty = 0; c.fill = GridBagConstraints.VERTICAL; add(graph, c); + addHierarchyListener(this); } } diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index ce1f2ab7..3294949c 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -98,6 +98,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -178,6 +179,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(Altos.text_width); + value.setEditable(false); value.setFont(Altos.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -193,50 +195,56 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } } - class Battery extends LaunchStatus { + class Voltage extends LaunchStatus { + + double voltage(AltosState state) { return AltosLib.MISSING; }; + double good() { return 0; }; + + double last_voltage = -1; + void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.battery_voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", state.battery_voltage); - lights.set(state.battery_voltage >= AltosLib.ao_battery_good); + double voltage = AltosLib.MISSING; + if (state != null) + voltage = voltage(state); + + if (voltage != last_voltage) { + if (voltage == AltosLib.MISSING) + hide(); + else { + show("%4.2f V", voltage); + lights.set(voltage >= good()); + } + last_voltage = voltage; } } + public Voltage (GridBagLayout layout, int y, String name) { super(layout, y, name); } + } + + + class Battery extends Voltage { + double voltage(AltosState state) { return state.battery_voltage; } + double good() { return AltosLib.ao_battery_good; } + public Battery (GridBagLayout layout, int y) { super(layout, y, "Battery Voltage"); } + } Battery battery; - class Apogee extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.apogee_voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", state.apogee_voltage); - lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good); - } - } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); - } + class Apogee extends Voltage { + double voltage(AltosState state) { return state.apogee_voltage; } + double good() { return AltosLib.ao_igniter_good; } + public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); } } Apogee apogee; - class Main extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.main_voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", state.main_voltage); - lights.set(state.main_voltage >= AltosLib.ao_igniter_good); - } - } - public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); - } + class Main extends Voltage { + double voltage(AltosState state) { return state.main_voltage; } + double good() { return AltosLib.ao_igniter_good; } + public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); } } Main main; @@ -328,6 +336,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } class PadLat extends LaunchValue { + + double last_lat = 1000; + void show (AltosState state, AltosListenerState listener_state) { double lat = AltosLib.MISSING; String label = null; @@ -341,11 +352,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Latitude"; } } - if (lat != AltosLib.MISSING) { - show(pos(lat,"N", "S")); - set_label(label); - } else - hide(); + if (lat != last_lat) { + if (lat != AltosLib.MISSING) { + show(pos(lat,"N", "S")); + set_label(label); + } else + hide(); + last_lat = lat; + } } public PadLat (GridBagLayout layout, int y) { super (layout, y, "Pad Latitude"); @@ -355,6 +369,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { PadLat pad_lat; class PadLon extends LaunchValue { + + double last_lon = 1000; + void show (AltosState state, AltosListenerState listener_state) { double lon = AltosLib.MISSING; String label = null; @@ -368,11 +385,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Longitude"; } } - if (lon != AltosLib.MISSING) { - show(pos(lon,"E", "W")); - set_label(label); - } else - hide(); + if (lon != last_lon) { + if (lon != AltosLib.MISSING) { + show(pos(lon,"E", "W")); + set_label(label); + } else + hide(); + last_lon = lon; + } } public PadLon (GridBagLayout layout, int y) { super (layout, y, "Pad Longitude"); @@ -382,6 +402,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { PadLon pad_lon; class PadAlt extends LaunchValue { + + double last_alt = -1000000; + void show (AltosState state, AltosListenerState listener_state) { double alt = AltosLib.MISSING; String label = null; @@ -395,11 +418,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { label = "Pad Altitude"; } } - if (alt != AltosLib.MISSING) { - show(alt); - set_label(label); - } else - hide(); + if (alt != last_alt) { + if (alt != AltosLib.MISSING) { + show(alt); + set_label(label); + } else + hide(); + last_alt = alt; + } } public PadAlt (GridBagLayout layout, int y) { super (layout, y, AltosConvert.height, "Pad Altitude"); diff --git a/altosuilib/AltosInfoTable.java b/altosuilib/AltosInfoTable.java index 24a895eb..8ded1bea 100644 --- a/altosuilib/AltosInfoTable.java +++ b/altosuilib/AltosInfoTable.java @@ -18,16 +18,20 @@ package org.altusmetrum.altosuilib_2; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import org.altusmetrum.altoslib_4.*; -public class AltosInfoTable extends JTable implements AltosFlightDisplay { +public class AltosInfoTable extends JTable implements AltosFlightDisplay, HierarchyListener { private AltosFlightInfoTableModel model; static final int info_columns = 3; static final int info_rows = 17; + private AltosState last_state; + private AltosListenerState last_listener_state; + int desired_row_height() { FontMetrics infoValueMetrics = getFontMetrics(AltosUILib.table_value_font); return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; @@ -56,6 +60,7 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { super(new AltosFlightInfoTableModel(info_rows, info_columns)); model = (AltosFlightInfoTableModel) getModel(); setFont(AltosUILib.table_value_font); + addHierarchyListener(this); setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); setShowGrid(true); set_layout(); @@ -71,6 +76,17 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { public void units_changed(boolean imperial_units) { } + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } @@ -108,6 +124,13 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { } public void show(AltosState state, AltosListenerState listener_state) { + + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + reset(); if (state != null) { if (state.device_type != AltosLib.MISSING) diff --git a/altosuilib/AltosUIMapView.java b/altosuilib/AltosUIMapView.java index 70198682..efae3767 100644 --- a/altosuilib/AltosUIMapView.java +++ b/altosuilib/AltosUIMapView.java @@ -28,7 +28,7 @@ import java.util.*; import java.util.concurrent.*; import org.altusmetrum.altoslib_4.*; -public class AltosUIMapView extends Canvas implements MouseMotionListener, MouseListener, MouseWheelListener, ComponentListener, AltosUIMapTileListener, AltosUIMapStoreListener { +public class AltosUIMapView extends Component implements MouseMotionListener, MouseListener, MouseWheelListener, ComponentListener, AltosUIMapTileListener, AltosUIMapStoreListener { AltosUIMapPath path = new AltosUIMapPath(); @@ -422,7 +422,6 @@ public class AltosUIMapView extends Canvas implements MouseMotionListener, Mouse } public void paint(Graphics g) { - VolatileImage back_buffer = create_back_buffer(); do { GraphicsConfiguration gc = getGraphicsConfiguration(); diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java index 2765f5ab..15eb9b75 100644 --- a/telegps/TeleGPSInfo.java +++ b/telegps/TeleGPSInfo.java @@ -18,14 +18,18 @@ package org.altusmetrum.telegps; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { +public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener { GridBagLayout layout; JLabel cur, max; + private AltosState last_state; + private AltosListenerState last_listener_state; + public abstract class Info implements AltosFontListener, AltosUnitsListener { JLabel label; JTextField value; @@ -280,6 +284,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value1 = new JTextField(AltosUILib.text_width); value1.setFont(AltosUILib.value_font); value1.setHorizontalAlignment(SwingConstants.RIGHT); + value1.setEditable(false); c.gridx = 2; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; @@ -290,6 +295,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { value2 = new JTextField(AltosUILib.text_width); value2.setFont(AltosUILib.value_font); value2.setHorizontalAlignment(SwingConstants.RIGHT); + value1.setEditable(false); c.gridx = 3; c.gridy = y; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; @@ -323,18 +329,16 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { } public void units_changed(boolean imperial_units) { - show(v); + show(v, max); } - void show(double v) { + void show(double v, double max) { this.v = v; - if (v == AltosLib.MISSING) { + this.max = max; + if (v == AltosLib.MISSING) value.setText("Missing"); - } else { + else value.setText(units.show(8, v)); - if (v > max || max == AltosLib.MISSING) - max = v; - } if (max == AltosLib.MISSING) max_value.setText("Missing"); else @@ -364,6 +368,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(AltosUILib.text_width); + value.setEditable(false); value.setFont(AltosUILib.value_font); value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.gridy = y; @@ -374,6 +379,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { add(value); max_value = new JTextField(AltosUILib.text_width); + max_value.setEditable(false); max_value.setFont(AltosUILib.value_font); max_value.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 3; c.gridy = y; @@ -388,7 +394,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { class Altitude extends ValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.altitude()); + show(state.altitude(), state.max_altitude()); } public Altitude (GridBagLayout layout, int y) { super (layout, y, AltosConvert.height, "Altitude"); @@ -399,7 +405,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { class AscentRate extends ValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.gps_ascent_rate()); + show(state.gps_ascent_rate(), state.max_gps_ascent_rate()); } public AscentRate (GridBagLayout layout, int y) { super (layout, y, AltosConvert.speed, "Ascent Rate"); @@ -410,7 +416,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { class GroundSpeed extends ValueHold { void show (AltosState state, AltosListenerState listener_state) { - show(state.gps_ground_speed()); + show(state.gps_ground_speed(), state.max_gps_ground_speed()); } public GroundSpeed (GridBagLayout layout, int y) { super (layout, y, AltosConvert.speed, "Ground Speed"); @@ -526,6 +532,12 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { } public void show(AltosState state, AltosListenerState listener_state) { + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + if (state.gps != null && state.gps.connected) { lat.show(state, listener_state); lon.show(state, listener_state); @@ -562,6 +574,17 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { return "Info"; } + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + public TeleGPSInfo() { layout = new GridBagLayout(); @@ -582,5 +605,6 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay { lat = new Lat(layout, y++); lon = new Lon(layout, y++); gps_locked = new GPSLocked(layout, y++); + addHierarchyListener(this); } } diff --git a/telegps/TeleGPSStatus.java b/telegps/TeleGPSStatus.java index 37cfae37..e6bb1ea5 100644 --- a/telegps/TeleGPSStatus.java +++ b/telegps/TeleGPSStatus.java @@ -61,6 +61,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { add(label); value = new JTextField(""); + value.setEditable(false); value.setFont(AltosUILib.status_font); value.setHorizontalAlignment(SwingConstants.CENTER); c.gridx = x; c.gridy = 1; @@ -70,8 +71,13 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { } class Call extends Value { + String call; + void show(AltosState state, AltosListenerState listener_state) { - value.setText(state.callsign); + if (state.callsign != call) { + value.setText(state.callsign); + call = state.callsign; + } if (state.callsign == null) setVisible(false); else @@ -85,11 +91,15 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { Call call; class Serial extends Value { + int serial = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.serial == AltosLib.MISSING) - value.setText("none"); - else - value.setText(String.format("%d", state.serial)); + if (state.serial != serial) { + if (state.serial == AltosLib.MISSING) + value.setText("none"); + else + value.setText(String.format("%d", state.serial)); + serial = state.serial; + } } public Serial (GridBagLayout layout, int x) { super (layout, x, "Serial"); @@ -99,12 +109,19 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { Serial serial; class RSSI extends Value { + int rssi = 10000; + void show(AltosState state, AltosListenerState listener_state) { - value.setText(String.format("%d", state.rssi())); - if (state.rssi == AltosLib.MISSING) - setVisible(false); - else - setVisible(true); + int new_rssi = state.rssi(); + + if (new_rssi != rssi) { + value.setText(String.format("%d", new_rssi)); + if (state.rssi == AltosLib.MISSING) + setVisible(false); + else + setVisible(true); + rssi = new_rssi; + } } public RSSI (GridBagLayout layout, int x) { super (layout, x, "RSSI"); @@ -114,9 +131,16 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { RSSI rssi; class LastPacket extends Value { + + long last_secs = -1; + void show(AltosState state, AltosListenerState listener_state) { long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; - value.setText(String.format("%d", secs)); + + if (secs != last_secs) { + value.setText(String.format("%d", secs)); + last_secs = secs; + } } public LastPacket(GridBagLayout layout, int x) { super (layout, x, "Age"); -- cgit v1.2.3 From 3f7e885055f8a97f334e0cd3163b760b174114b6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 13 Jun 2014 15:23:30 -0700 Subject: telegps: Add status tab This includes pad-relative information, battery voltage and version information Signed-off-by: Keith Packard --- telegps/Makefile.am | 1 + telegps/TeleGPS.java | 9 +- telegps/TeleGPSInfo.java | 550 ++++++++-------------------------------------- telegps/TeleGPSState.java | 254 +++++++++++++++++++++ 4 files changed, 359 insertions(+), 455 deletions(-) create mode 100644 telegps/TeleGPSState.java (limited to 'telegps/TeleGPSInfo.java') diff --git a/telegps/Makefile.am b/telegps/Makefile.am index e0d596e7..31bcbd79 100644 --- a/telegps/Makefile.am +++ b/telegps/Makefile.am @@ -16,6 +16,7 @@ telegps_JAVA= \ TeleGPSStatus.java \ TeleGPSStatusUpdate.java \ TeleGPSInfo.java \ + TeleGPSState.java \ TeleGPSConfig.java \ TeleGPSConfigUI.java \ TeleGPSPreferences.java \ diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 1898a668..307b5610 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -69,6 +69,7 @@ public class TeleGPS AltosUIMap map; TeleGPSInfo gps_info; + TeleGPSState gps_state; AltosInfoTable info_table; LinkedList displays; @@ -444,13 +445,17 @@ public class TeleGPS bag.add(pane, c); map = new AltosUIMap(); - pane.add("Map", map); + pane.add(map.getName(), map); displays.add(map); gps_info = new TeleGPSInfo(); - pane.add("Info", gps_info); + pane.add(gps_info.getName(), gps_info); displays.add(gps_info); + gps_state = new TeleGPSState(); + pane.add(gps_state.getName(), gps_state); + displays.add(gps_state); + info_table = new AltosInfoTable(); pane.add("Table", info_table); displays.add(info_table); diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java index 15eb9b75..bbf4b472 100644 --- a/telegps/TeleGPSInfo.java +++ b/telegps/TeleGPSInfo.java @@ -17,6 +17,7 @@ package org.altusmetrum.telegps; +import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; @@ -24,420 +25,76 @@ import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener { - GridBagLayout layout; - JLabel cur, max; + + JLabel cur, max; private AltosState last_state; private AltosListenerState last_listener_state; - public abstract class Info implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosLights lights; - double v; - AltosUnits units; - - void show() { - value.setVisible(true); - lights.setVisible(true); - label.setVisible(true); - } - - void hide() { - value.setVisible(false); - lights.setVisible(false); - label.setVisible(false); - } - - abstract void show(AltosState state, AltosListenerState listener_state); - - void show(String s) { - show(); - value.setText(s); - } - - void show(double v) { - this.v = v; - show(units.show(8, v)); - } - - void show(String format, double v) { - show(String.format(format, v)); - } - - void show(String format, int v) { - show(String.format(format, v)); - } - - void reset() { - lights.set(false); - value.setText(""); - } - - public void font_size_changed(int font_size) { - label.setFont(AltosUILib.label_font); - value.setFont(AltosUILib.value_font); - } + abstract class Value extends AltosUIUnitsIndicator { + public abstract void show(AltosState state, AltosListenerState listener_state); - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); - } - - public Info (GridBagLayout layout, int y, AltosUnits units, String text) { - this.units = units; - - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(AltosUILib.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(AltosUILib.text_width); - value.setFont(AltosUILib.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.gridwidth = 2; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - } - - public Info (GridBagLayout layout, int y, String text) { - this(layout, y, null, text); + public Value (Container container, int y, AltosUnits units, String text) { + super(container, y, units, text, 1, false, 2); } } - public abstract class Value implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosUnits units; - double v = AltosLib.MISSING; - - abstract void show(AltosState state, AltosListenerState listener_state); - - void reset() { - value.setText(""); - } - - void show() { - label.setVisible(true); - value.setVisible(true); - } - - void show(String s) { - show(); - value.setText(s); - } - - void show(double v) { - this.v = v; - show(units.show(8, v)); - } - - void show(String format, double v) { - show(String.format(format, v)); - } - - void hide() { - label.setVisible(false); - value.setVisible(false); - } - public void font_size_changed(int font_size) { - label.setFont(AltosUILib.label_font); - value.setFont(AltosUILib.value_font); - } - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); - } - - public Value (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(AltosUILib.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(AltosUILib.text_width); - value.setFont(AltosUILib.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.gridwidth = 2; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); + abstract class DualValue extends AltosUIUnitsIndicator { + public DualValue (Container container, int y, AltosUnits units, String text) { + super(container, y, units, text, 2, false, 1); } } - public abstract class DualValue implements AltosFontListener, AltosUnitsListener { - AltosLights lights; - JLabel label; - JTextField value1; - JTextField value2; - - void reset() { - if (lights != null) - lights.set(false); - value1.setText(""); - value2.setText(""); - } - - void show() { - if (lights != null) - lights.setVisible(true); - label.setVisible(true); - value1.setVisible(true); - value2.setVisible(true); - } - - void hide() { - if (lights != null) - lights.setVisible(false); - label.setVisible(false); - value1.setVisible(false); - value2.setVisible(false); - } - - public void font_size_changed(int font_size) { - label.setFont(AltosUILib.label_font); - value1.setFont(AltosUILib.value_font); - value2.setFont(AltosUILib.value_font); - } - - public void units_changed(boolean imperial_units) { - } - - abstract void show(AltosState state, AltosListenerState listener_state); - - void show(String v1, String v2) { - show(); - value1.setText(v1); - value2.setText(v2); - } - - void show(String f1, double v1, String f2, double v2) { - show(); - value1.setText(String.format(f1, v1)); - value2.setText(String.format(f2, v2)); + abstract class ValueHold extends DualValue { + public void reset() { + super.reset(); + last_values[1] = AltosLib.MISSING; } - - void show(String f1, int v1, String f2, int v2) { - show(); - value1.setText(String.format(f1, v1)); - value2.setText(String.format(f2, v2)); - } - - public DualValue (GridBagLayout layout, int y, String text, boolean want_lights) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - if (want_lights) { - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - } - - label = new JLabel(text); - label.setFont(AltosUILib.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value1 = new JTextField(AltosUILib.text_width); - value1.setFont(AltosUILib.value_font); - value1.setHorizontalAlignment(SwingConstants.RIGHT); - value1.setEditable(false); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value1, c); - add(value1); - - value2 = new JTextField(AltosUILib.text_width); - value2.setFont(AltosUILib.value_font); - value2.setHorizontalAlignment(SwingConstants.RIGHT); - value1.setEditable(false); - c.gridx = 3; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.gridwidth = 1; - layout.setConstraints(value2, c); - add(value2); + public ValueHold (Container container, int y, AltosUnits units, String text) { + super(container, y, units, text); } } - abstract public class ValueHold implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - JTextField max_value; - double v; - double max; - AltosUnits units; - - abstract void show(AltosState state, AltosListenerState listener_state); - - void reset() { - value.setText(""); - max_value.setText(""); - max = AltosLib.MISSING; - } - - public void font_size_changed(int font_size) { - label.setFont(AltosUILib.label_font); - value.setFont(AltosUILib.value_font); - max_value.setFont(AltosUILib.value_font); - } - - public void units_changed(boolean imperial_units) { - show(v, max); - } - - void show(double v, double max) { - this.v = v; - this.max = max; - if (v == AltosLib.MISSING) - value.setText("Missing"); - else - value.setText(units.show(8, v)); - if (max == AltosLib.MISSING) - max_value.setText("Missing"); + class Altitude extends ValueHold { + public double value(AltosState state, int i) { + if (i == 0) + return state.altitude(); else - max_value.setText(units.show(8, max)); - } - - void hide() { - label.setVisible(false); - value.setVisible(false); - max_value.setVisible(false); + return state.max_altitude(); } - public ValueHold (GridBagLayout layout, int y, AltosUnits units, String text) { - this.units = units; - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(AltosUILib.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(AltosUILib.text_width); - value.setEditable(false); - value.setFont(AltosUILib.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - max_value = new JTextField(AltosUILib.text_width); - max_value.setEditable(false); - max_value.setFont(AltosUILib.value_font); - max_value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 3; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(max_value, c); - add(max_value); + public Altitude (Container container, int y) { + super (container, y, AltosConvert.height, "Altitude"); } } - - class Altitude extends ValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.altitude(), state.max_altitude()); - } - public Altitude (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.height, "Altitude"); - } - } - - Altitude altitude; - class AscentRate extends ValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.gps_ascent_rate(), state.max_gps_ascent_rate()); + public double value(AltosState state, int i) { + if (i == 0) + return state.gps_ascent_rate(); + else + return state.max_gps_ascent_rate(); } - public AscentRate (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.speed, "Ascent Rate"); + public AscentRate (Container container, int y) { + super (container, y, AltosConvert.speed, "Ascent Rate"); } } - AscentRate ascent_rate; - class GroundSpeed extends ValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.gps_ground_speed(), state.max_gps_ground_speed()); + public double value(AltosState state, int i) { + if (i == 0) + return state.gps_ground_speed(); + else + return state.max_gps_ground_speed(); } - public GroundSpeed (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.speed, "Ground Speed"); + public GroundSpeed (Container container, int y) { + super (container, y, AltosConvert.speed, "Ground Speed"); } } - GroundSpeed ground_speed; + class Course extends AltosUIIndicator { - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; - } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); - } - - class Course extends DualValue { - void show (AltosState state, AltosListenerState listener_state) { + public void show (AltosState state, AltosListenerState listener_state) { double course = state.gps_course(); if (course != AltosLib.MISSING) show( String.format("%3.0f°", course), @@ -445,43 +102,62 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera AltosConvert.BEARING_LONG, course)); } - public Course (GridBagLayout layout, int y) { - super (layout, y, "Course", false); + public Course (Container container, int y) { + super (container, y, "Course", 2, false, 1); } } - Course course; + class Lat extends AltosUIIndicator { + + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } - class Lat extends Value { - void show (AltosState state, AltosListenerState listener_state) { + public void show (AltosState state, AltosListenerState listener_state) { if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else show("???"); } - public Lat (GridBagLayout layout, int y) { - super (layout, y, "Latitude"); + public Lat (Container container, int y) { + super (container, y, "Latitude", 1, false, 2); } } - Lat lat; + class Lon extends AltosUIIndicator { - class Lon extends Value { - void show (AltosState state, AltosListenerState listener_state) { + String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f", h, deg, min); + } + + public void show (AltosState state, AltosListenerState listener_state) { if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"E", "W")); else show("???"); } - public Lon (GridBagLayout layout, int y) { - super (layout, y, "Longitude"); + public Lon (Container container, int y) { + super (container, y, "Longitude", 1, false, 2); } } - Lon lon; + class GPSLocked extends AltosUIIndicator { - class GPSLocked extends DualValue { - void show (AltosState state, AltosListenerState listener_state) { + public void show (AltosState state, AltosListenerState listener_state) { if (state == null || state.gps == null) hide(); else { @@ -489,46 +165,31 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0; show("%4d in solution", soln, "%4d in view", nsat); - lights.set(state.gps.locked && soln >= 4); + set_lights(state.gps.locked && soln >= 4); } } - public GPSLocked (GridBagLayout layout, int y) { - super (layout, y, "GPS Locked", true); + public GPSLocked (Container container, int y) { + super (container, y, "GPS Locked", 2, true, 1); } } - GPSLocked gps_locked; + LinkedList indicators = new LinkedList(); public void reset() { - lat.reset(); - lon.reset(); - altitude.reset(); - ground_speed.reset(); - ascent_rate.reset(); - course.reset(); - gps_locked.reset(); + for (AltosUIIndicator i : indicators) + i.reset(); } public void font_size_changed(int font_size) { cur.setFont(AltosUILib.label_font); max.setFont(AltosUILib.label_font); - lat.font_size_changed(font_size); - lon.font_size_changed(font_size); - altitude.font_size_changed(font_size); - ground_speed.font_size_changed(font_size); - ascent_rate.font_size_changed(font_size); - course.font_size_changed(font_size); - gps_locked.font_size_changed(font_size); + for (AltosUIIndicator i : indicators) + i.font_size_changed(font_size); } public void units_changed(boolean imperial_units) { - lat.units_changed(imperial_units); - lon.units_changed(imperial_units); - altitude.units_changed(imperial_units); - ground_speed.units_changed(imperial_units); - ascent_rate.units_changed(imperial_units); - course.units_changed(imperial_units); - gps_locked.units_changed(imperial_units); + for (AltosUIIndicator i : indicators) + i.units_changed(imperial_units); } public void show(AltosState state, AltosListenerState listener_state) { @@ -538,21 +199,12 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera return; } - if (state.gps != null && state.gps.connected) { - lat.show(state, listener_state); - lon.show(state, listener_state); - } else { - lat.hide(); - lon.hide(); - } - altitude.show(state, listener_state); - ground_speed.show(state, listener_state); - ascent_rate.show(state, listener_state); - course.show(state, listener_state); - gps_locked.show(state, listener_state); + for (AltosUIIndicator i : indicators) + i.show(state, listener_state); } - public void labels(GridBagLayout layout, int y) { + public void labels(Container container, int y) { + GridBagLayout layout = (GridBagLayout)(container.getLayout()); GridBagConstraints c; cur = new JLabel("Current"); @@ -571,7 +223,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera } public String getName() { - return "Info"; + return "Location"; } public void hierarchyChanged(HierarchyEvent e) { @@ -586,25 +238,17 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera } public TeleGPSInfo() { - layout = new GridBagLayout(); - - setLayout(layout); + setLayout(new GridBagLayout()); - /* Elements in ascent display: - * - * lat - * lon - * height - */ int y = 0; - labels(layout, y++); - altitude = new Altitude(layout, y++); - ground_speed = new GroundSpeed(layout, y++); - ascent_rate = new AscentRate(layout, y++); - course = new Course(layout, y++); - lat = new Lat(layout, y++); - lon = new Lon(layout, y++); - gps_locked = new GPSLocked(layout, y++); + labels(this, y++); + indicators.add(new Altitude(this, y++)); + indicators.add(new GroundSpeed(this, y++)); + indicators.add(new AscentRate(this, y++)); + indicators.add(new Course(this, y++)); + indicators.add(new Lat(this, y++)); + indicators.add(new Lon(this, y++)); + indicators.add(new GPSLocked(this, y++)); addHierarchyListener(this); } } diff --git a/telegps/TeleGPSState.java b/telegps/TeleGPSState.java new file mode 100644 index 00000000..b10e8e70 --- /dev/null +++ b/telegps/TeleGPSState.java @@ -0,0 +1,254 @@ +/* + * Copyright © 2014 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.telegps; + +import java.util.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; + +public class TeleGPSState extends JComponent implements AltosFlightDisplay, HierarchyListener { + GridBagLayout layout; + JLabel cur, max; + + private AltosState last_state; + private AltosListenerState last_listener_state; + + abstract class Value extends AltosUIUnitsIndicator { + public Value (Container container, int y, AltosUnits units, String text) { + super(container, y, units, text, 1, false, 2); + } + } + + abstract class DualValue extends AltosUIUnitsIndicator { + public DualValue (Container container, int y, AltosUnits units, String text) { + super(container, y, units, text, 2, false, 1); + } + } + + abstract class ValueHold extends DualValue { + public void reset() { + super.reset(); + last_values[1] = AltosLib.MISSING; + } + public ValueHold (Container container, int y, AltosUnits units, String text) { + super(container, y, units, text); + } + } + + class Height extends ValueHold { + public double value(AltosState state, int i) { + if (i == 0) + return state.height(); + else + return state.max_height(); + } + + public Height(Container container, int y) { + super(container, y, AltosConvert.height, "Height"); + } + } + + class Speed extends ValueHold { + public double value(AltosState state, int i) { + if (i == 0) + return state.gps_speed(); + else + return state.max_gps_speed(); + } + + public Speed(Container container, int y) { + super(container, y, AltosConvert.speed, "Speed"); + } + } + + class Distance extends Value { + public double value(AltosState state, int i) { + if (state.from_pad != null) + return state.from_pad.distance; + else + return AltosLib.MISSING; + } + + public Distance(Container container, int y) { + super(container, y, AltosConvert.distance, "Distance"); + } + } + + class Range extends Value { + public double value(AltosState state, int i) { + return state.range; + } + public Range (Container container, int y) { + super (container, y, AltosConvert.distance, "Range"); + } + } + + class Bearing extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { + if (state.from_pad != null) { + show( String.format("%3.0f°", state.from_pad.bearing), + state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); + } else { + show("???", "???"); + } + } + public Bearing (Container container, int y) { + super (container, y, "Bearing", 2, false, 1); + } + } + + class Elevation extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { + show("%3.0f°", state.elevation); + } + public Elevation (Container container, int y) { + super (container, y, "Elevation", 1, false, 2); + } + } + + class FirmwareVersion extends AltosUIIndicator { + public void show(AltosState state, AltosListenerState listener_state) { + if (state.firmware_version == null) + show("Missing"); + else + show(state.firmware_version); + } + + public FirmwareVersion(Container container, int y) { + super(container, y, "Firmware Version", 1, false, 2); + } + } + + class FlightLogMax extends AltosUIIndicator { + public void show(AltosState state, AltosListenerState listener_state) { + if (state.flight_log_max == AltosLib.MISSING) + show("Missing"); + else + show(String.format("%dkB", state.flight_log_max)); + } + + public FlightLogMax(Container container, int y) { + super(container, y, "Flight Log Storage", 1, false, 2); + } + } + + class BatteryVoltage extends AltosUIVoltageIndicator { + public double voltage(AltosState state) { + return state.battery_voltage; + } + + public double good() { + return AltosLib.ao_battery_good; + } + + public BatteryVoltage(Container container, int y) { + super(container, y, "Battery Voltage", 2); + } + } + + LinkedList indicators = new LinkedList(); + + public void labels(Container container, int y) { + GridBagLayout layout = (GridBagLayout)(container.getLayout()); + GridBagConstraints c; + + cur = new JLabel("Current"); + cur.setFont(AltosUILib.label_font); + c = new GridBagConstraints(); + c.gridx = 2; c.gridy = y; + c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); + layout.setConstraints(cur, c); + add(cur); + + max = new JLabel("Maximum"); + max.setFont(AltosUILib.label_font); + c.gridx = 3; c.gridy = y; + layout.setConstraints(max, c); + add(max); + } + + public void reset() { + for (AltosUIIndicator i : indicators) + i.reset(); + } + + public void font_size_changed(int font_size) { + for (AltosUIIndicator i : indicators) + i.font_size_changed(font_size); + } + + public void units_changed(boolean imperial_units) { + for (AltosUIIndicator i : indicators) + i.units_changed(imperial_units); + } + + public void show(AltosState state, AltosListenerState listener_state) { + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + + for (AltosUIIndicator i : indicators) + i.show(state, listener_state); + } + + public String getName() { + return "Status"; + } + + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + + public TeleGPSState() { + layout = new GridBagLayout(); + + setLayout(layout); + + /* Elements in state display: + * + * config_version; + * lon + * height + */ + int y = 0; + labels(this, y++); + indicators.add(new Height(this, y++)); + indicators.add(new Speed(this, y++)); + indicators.add(new Distance(this, y++)); + indicators.add(new Range(this, y++)); + indicators.add(new Bearing(this, y++)); + indicators.add(new Elevation(this, y++)); + indicators.add(new FirmwareVersion(this, y++)); + indicators.add(new FlightLogMax(this, y++)); + indicators.add(new BatteryVoltage(this, y++)); + addHierarchyListener(this); + } +} -- cgit v1.2.3 From c11b2f5caa3fbe2bc977e716ec1c3ccee9e75884 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 14 Jun 2014 14:41:13 -0700 Subject: altosui/telegps: Switch to AltosUIIndicator and AltosUIFlightTab Removes replicated code across all flight tabs Signed-off-by: Keith Packard --- altosui/AltosAscent.java | 498 +++++++------------------------------- altosui/AltosCompanionInfo.java | 2 + altosui/AltosDescent.java | 524 ++++++---------------------------------- altosui/AltosFlightStatus.java | 63 ++++- altosui/AltosFlightUI.java | 68 +++--- altosui/AltosIgnitor.java | 175 +++----------- altosui/AltosLanded.java | 302 +++++------------------ altosui/AltosPad.java | 461 ++++++++--------------------------- telegps/TeleGPS.java | 68 ++++-- telegps/TeleGPSInfo.java | 68 ++---- telegps/TeleGPSState.java | 87 ++----- telegps/TeleGPSStatus.java | 38 +++ 12 files changed, 564 insertions(+), 1790 deletions(-) (limited to 'telegps/TeleGPSInfo.java') diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index c3225709..3bc80406 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -17,451 +17,151 @@ package altosui; +import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosAscent extends JComponent implements AltosFlightDisplay, HierarchyListener { - GridBagLayout layout; - JLabel cur, max; +public class AltosAscent extends AltosUIFlightTab { + JLabel cur, max; - private AltosState last_state; - private AltosListenerState last_listener_state; + class Height extends AltosUIUnitsIndicator { - public class AscentStatus implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosLights lights; - double v; - AltosUnits units; - - void show() { - value.setVisible(true); - lights.setVisible(true); - label.setVisible(true); - } - - void hide() { - value.setVisible(false); - lights.setVisible(false); - label.setVisible(false); - } - - void show(AltosState state, AltosListenerState listener_state) {} - - void show(String s) { - show(); - value.setText(s); - } - - void show(double v) { - this.v = v; - show(units.show(8, v)); - } - - void show(String format, double v) { - show(String.format(format, v)); - } - - void reset() { - value.setText(""); - lights.set(false); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); + public double value(AltosState state, int i) { + if (i == 0) + return state.height(); + else + return state.max_height(); } - public AscentStatus (GridBagLayout layout, int y, AltosUnits units, String text) { - this.units = units; - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.gridwidth = 2; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - + public Height(Container container, int y) { + super(container, y, AltosConvert.height, "Height", 2, false, 1); } } - public abstract class AscentValue implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - double v; - AltosUnits units; - - abstract void show(AltosState state, AltosListenerState listener_state); - - void reset() { - value.setText(""); - } - - void show() { - label.setVisible(true); - value.setVisible(true); - } - - void show(String s) { - show(); - value.setText(s); - } - - void show(double v) { - this.v = v; - show(units.show(8, v)); - } - - void show(String format, double v) { - show(String.format(format, v)); - } - - void hide() { - label.setVisible(false); - value.setVisible(false); + class Speed extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { + if (i == 0) + return state.speed(); + else + return state.max_speed(); } - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); + public Speed(Container container, int y) { + super(container, y, AltosConvert.speed, "Speed", 2, false, 1); } + } - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); - } + class Accel extends AltosUIUnitsIndicator { + public boolean hide(double v) { return v == AltosLib.MISSING; } - public AscentValue (GridBagLayout layout, int y, AltosUnits units, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.gridwidth = 2; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); + public double value(AltosState state, int i) { + if (i == 0) + return state.acceleration(); + else + return state.max_acceleration(); } - public AscentValue (GridBagLayout layout, int y, String text) { - this(layout, y, null, text); + public Accel(Container container, int y) { + super(container, y, AltosConvert.accel, "Acceleration", 2, false, 1); } } - public class AscentValueHold implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - JTextField max_value; - double max; - AltosUnits units; - double v; + class Orient extends AltosUIUnitsIndicator { - void show(AltosState state, AltosListenerState listener_state) {} - - void reset() { - value.setText(""); - max_value.setText(""); - max = AltosLib.MISSING; - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - max_value.setFont(Altos.value_font); - } + public boolean hide(double v) { return v == AltosLib.MISSING; } - public void units_changed(boolean imperial_units) { - show(v, max); - } - - void show(double v, double max) { - this.v = v; - this.max = max; - if (v == AltosLib.MISSING) { - value.setText("Missing"); - } else { - value.setText(units.show(8, v)); - } - if (max == AltosLib.MISSING) - max_value.setText("Missing"); + public double value(AltosState state, int i) { + if (i == 0) + return state.orient(); else - max_value.setText(units.show(8, max)); + return state.max_orient(); } - void hide() { - label.setVisible(false); - value.setVisible(false); - max_value.setVisible(false); + public Orient(Container container, int y) { + super(container, y, AltosConvert.orient, "Tilt Angle", 2, false, 1); } - public AscentValueHold (GridBagLayout layout, int y, AltosUnits units, String text) { - this.units = units; - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - max_value = new JTextField(Altos.text_width); - max_value.setEditable(false); - max_value.setFont(Altos.value_font); - max_value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 3; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(max_value, c); - add(max_value); - } } - class Height extends AscentValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.height(), state.max_height()); - } - public Height (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.height, "Height"); + class Apogee extends AltosUIUnitsIndicator { + + public double value(AltosState state, int i) { + return state.apogee_voltage; } - } - Height height; + public boolean good(double v) { return v >= AltosLib.ao_igniter_good; } + public boolean hide(double v) { return v == AltosLib.MISSING; } - class Speed extends AscentValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.speed(), state.max_speed()); - } - public Speed (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.speed, "Speed"); + public Apogee (Container container, int y) { + super(container, y, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 2); } } - Speed speed; - - class Accel extends AscentValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.acceleration(), state.max_acceleration()); + class Main extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { + return state.main_voltage; } - public Accel (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.accel, "Acceleration"); - } - } - Accel accel; + public boolean good(double v) { return v >= AltosLib.ao_igniter_good; } + public boolean hide(double v) { return v == AltosLib.MISSING; } - class Orient extends AscentValueHold { - void show (AltosState state, AltosListenerState listener_state) { - show(state.orient(), state.max_orient()); - } - public Orient (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.orient, "Tilt Angle"); + public Main (Container container, int y) { + super(container, y, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 2); } } - Orient orient; + class Lat extends AltosUIUnitsIndicator { - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; + public boolean hide(AltosState state, int i) { + return state.gps == null || !state.gps.connected; } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); - } - class Apogee extends AscentStatus { - void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.apogee_voltage); - lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good); - } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, null, "Apogee Igniter Voltage"); + public double value(AltosState state, int i) { + if (state.gps == null) + return AltosLib.MISSING; + if (!state.gps.connected) + return AltosLib.MISSING; + return state.gps.lat; } - } - - Apogee apogee; - class Main extends AscentStatus { - void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.main_voltage); - lights.set(state.main_voltage >= AltosLib.ao_igniter_good); - } - public Main (GridBagLayout layout, int y) { - super(layout, y, null, "Main Igniter Voltage"); + Lat (Container container, int y) { + super (container, y, AltosConvert.latitude, "Latitude", 1, false, 2); } } - Main main; + class Lon extends AltosUIUnitsIndicator { - class Lat extends AscentValue { - void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) - show(pos(state.gps.lat,"N", "S")); - else - show("???"); + public boolean hide(AltosState state, int i) { + return state.gps == null || !state.gps.connected; } - public Lat (GridBagLayout layout, int y) { - super (layout, y, "Latitude"); - } - } - Lat lat; - - class Lon extends AscentValue { - void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) - show(pos(state.gps.lon,"E", "W")); - else - show("???"); - } - public Lon (GridBagLayout layout, int y) { - super (layout, y, "Longitude"); + public double value(AltosState state, int i) { + if (state.gps == null) + return AltosLib.MISSING; + if (!state.gps.connected) + return AltosLib.MISSING; + return state.gps.lon; } - } - Lon lon; - - public void reset() { - lat.reset(); - lon.reset(); - main.reset(); - apogee.reset(); - height.reset(); - speed.reset(); - accel.reset(); - orient.reset(); + Lon (Container container, int y) { + super (container, y, AltosConvert.longitude, "Longitude", 1, false, 2); + } } public void font_size_changed(int font_size) { - cur.setFont(Altos.label_font); - max.setFont(Altos.label_font); - lat.font_size_changed(font_size); - lon.font_size_changed(font_size); - main.font_size_changed(font_size); - apogee.font_size_changed(font_size); - height.font_size_changed(font_size); - speed.font_size_changed(font_size); - accel.font_size_changed(font_size); - orient.font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - lat.units_changed(imperial_units); - lon.units_changed(imperial_units); - main.units_changed(imperial_units); - apogee.units_changed(imperial_units); - height.units_changed(imperial_units); - speed.units_changed(imperial_units); - accel.units_changed(imperial_units); - orient.units_changed(imperial_units); - } - - public void show(AltosState state, AltosListenerState listener_state) { - if (!isShowing()) { - last_state = state; - last_listener_state = listener_state; - return; - } - - if (state.gps != null && state.gps.connected) { - lat.show(state, listener_state); - lon.show(state, listener_state); - } else { - lat.hide(); - lon.hide(); - } - height.show(state, listener_state); - if (state.main_voltage != AltosLib.MISSING) - main.show(state, listener_state); - else - main.hide(); - if (state.apogee_voltage != AltosLib.MISSING) - apogee.show(state, listener_state); - else - apogee.hide(); - speed.show(state, listener_state); - accel.show(state, listener_state); - if (state.orient() != AltosLib.MISSING) - orient.show(state, listener_state); - else - orient.hide(); + super.font_size_changed(font_size); + cur.setFont(AltosUILib.label_font); + max.setFont(AltosUILib.label_font); } public void labels(GridBagLayout layout, int y) { GridBagConstraints c; cur = new JLabel("Current"); - cur.setFont(Altos.label_font); + cur.setFont(AltosUILib.label_font); c = new GridBagConstraints(); c.gridx = 2; c.gridy = y; c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); @@ -469,7 +169,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay, Hiera add(cur); max = new JLabel("Maximum"); - max.setFont(Altos.label_font); + max.setFont(AltosUILib.label_font); c.gridx = 3; c.gridy = y; layout.setConstraints(max, c); add(max); @@ -479,38 +179,16 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay, Hiera return "Ascent"; } - public void hierarchyChanged(HierarchyEvent e) { - if (last_state != null && isShowing()) { - AltosState state = last_state; - AltosListenerState listener_state = last_listener_state; - - last_state = null; - last_listener_state = null; - show(state, listener_state); - } - } - public AltosAscent() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in ascent display: - * - * lat - * lon - * height - */ int y = 0; labels(layout, y++); - height = new Height(layout, y++); - speed = new Speed(layout, y++); - accel = new Accel(layout, y++); - orient = new Orient(layout, y++); - lat = new Lat(layout, y++); - lon = new Lon(layout, y++); - apogee = new Apogee(layout, y++); - main = new Main(layout, y++); - addHierarchyListener(this); + add(new Height(this, y++)); + add(new Speed(this, y++)); + add(new Accel(this, y++)); + add(new Orient(this, y++)); + add(new Lat(this, y++)); + add(new Lon(this, y++)); + add(new Apogee(this, y++)); + add(new Main(this, y++)); } } diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index 514ce611..e7b335ac 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -87,6 +87,8 @@ public class AltosCompanionInfo extends JTable implements AltosFlightDisplay { } } + public String getName() { return "Companion"; } + public void show(AltosState state, AltosListenerState listener_state) { if (state == null) return; diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 11bd6dbf..36fc1613 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -17,516 +17,148 @@ package altosui; +import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosDescent extends JComponent implements AltosFlightDisplay, HierarchyListener { - GridBagLayout layout; +public class AltosDescent extends AltosUIFlightTab { - private AltosState last_state; - private AltosListenerState last_listener_state; - - public abstract class DescentStatus implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosLights lights; - - abstract void show(AltosState state, AltosListenerState listener_state); - - void show() { - label.setVisible(true); - value.setVisible(true); - lights.setVisible(true); - } - - void show(String s) { - show(); - value.setText(s); - } - - void show(String format, double value) { - show(String.format(format, value)); - } - - void hide() { - label.setVisible(false); - value.setVisible(false); - lights.setVisible(false); - } - - void reset() { - value.setText(""); - lights.set(false); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - } - - public DescentStatus (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.gridwidth = 3; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 4; c.gridy = y; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); + class Height extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { return state.height(); } + public Height (Container container, int x, int y) { + super (container, x, y, AltosConvert.height, "Height"); } } - public abstract class DescentValue implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosUnits units; - double v; - String last_value = ""; - - void reset() { - value.setText(""); - } - - abstract void show(AltosState state, AltosListenerState listener_state); - - void show() { - label.setVisible(true); - value.setVisible(true); - } + class Speed extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { return state.speed(); } - void hide() { - label.setVisible(false); - value.setVisible(false); - } - - void show(String v) { - show(); - - if (!last_value.equals(v)) { - value.setText(v); - last_value = v; - } - } - - void show(double v) { - this.v = v; - if (v == AltosLib.MISSING) - show("Missing"); - else - show(units.show(8, v)); - } - - void show(String format, double v) { - if (v == AltosLib.MISSING) - show("Missing"); - else - show(String.format(format, v)); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); - } - - public DescentValue (GridBagLayout layout, int x, int y, AltosUnits units, String text) { - this.units = units; - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - add(label, c); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 2; c.gridy = y; - c.gridwidth = 1; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - add(value, c); - } - - public DescentValue (GridBagLayout layout, int x, int y, String text) { - this(layout, x, y, null, text); + public Speed (Container container, int x, int y) { + super (container, x, y, AltosConvert.speed, "Speed"); } } - public abstract class DescentDualValue implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value1; - JTextField value2; + class Lat extends AltosUIUnitsIndicator { - void reset() { - value1.setText(""); - value2.setText(""); - } + public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; } - void show() { - label.setVisible(true); - value1.setVisible(true); - value2.setVisible(true); + public double value(AltosState state, int i) { + if (state.gps == null) + return AltosLib.MISSING; + if (!state.gps.connected) + return AltosLib.MISSING; + return state.gps.lat; } - void hide() { - label.setVisible(false); - value1.setVisible(false); - value2.setVisible(false); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value1.setFont(Altos.value_font); - value2.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - } - - abstract void show(AltosState state, AltosListenerState listener_state); - - void show(String v1, String v2) { - show(); - value1.setText(v1); - value2.setText(v2); - } - void show(String f1, double v1, String f2, double v2) { - show(); - value1.setText(String.format(f1, v1)); - value2.setText(String.format(f2, v2)); - } - - public DescentDualValue (GridBagLayout layout, int x, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = x + 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value1 = new JTextField(Altos.text_width); - value1.setEditable(false); - value1.setFont(Altos.value_font); - value1.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value1, c); - add(value1); - - value2 = new JTextField(Altos.text_width); - value2.setEditable(false); - value2.setFont(Altos.value_font); - value2.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = x + 4; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.gridwidth = 1; - layout.setConstraints(value2, c); - add(value2); - } - } - - class Height extends DescentValue { - void show (AltosState state, AltosListenerState listener_state) { - show(state.height()); - } - public Height (GridBagLayout layout, int x, int y) { - super (layout, x, y, AltosConvert.height, "Height"); + public Lat (Container container, int x, int y) { + super (container, x, y, AltosConvert.latitude, "Latitude"); } } - Height height; + class Lon extends AltosUIUnitsIndicator { + public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; } - class Speed extends DescentValue { - void show (AltosState state, AltosListenerState listener_state) { - show(state.speed()); - } - public Speed (GridBagLayout layout, int x, int y) { - super (layout, x, y, AltosConvert.speed, "Speed"); + public double value(AltosState state, int i) { + if (state.gps == null) + return AltosLib.MISSING; + if (!state.gps.connected) + return AltosLib.MISSING; + return state.gps.lon; } - } - - Speed speed; - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; + public Lon (Container container, int x, int y) { + super (container, x, y, AltosConvert.longitude, "Longitude"); } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %d° %9.6f", h, deg, min); } - class Lat extends DescentValue { - void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) - show(pos(state.gps.lat,"N", "S")); - else - show("???"); - } - public Lat (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Latitude"); + class Apogee extends AltosUIUnitsIndicator { + public boolean hide(double v) { return v == AltosLib.MISSING; } + public double value(AltosState state, int i) { return state.apogee_voltage; } + public double good() { return AltosLib.ao_igniter_good; } + + public Apogee (Container container, int y) { + super(container, 0, y, 3, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 3); } } - Lat lat; + class Main extends AltosUIUnitsIndicator { + public boolean hide(double v) { return v == AltosLib.MISSING; } + public double value(AltosState state, int i) { return state.main_voltage; } + public double good() { return AltosLib.ao_igniter_good; } - class Lon extends DescentValue { - void show (AltosState state, AltosListenerState listener_state) { - if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) - show(pos(state.gps.lon,"W", "E")); - else - show("???"); - } - public Lon (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Longitude"); + public Main (Container container, int y) { + super(container, 0, y, 3, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 3); } } - Lon lon; - - class Distance extends DescentValue { - void show(AltosState state, AltosListenerState listener_state) { + class Distance extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { if (state.from_pad != null) - show(state.from_pad.distance); + return state.from_pad.distance; else - show("???"); + return AltosLib.MISSING; } - public Distance (GridBagLayout layout, int x, int y) { - super(layout, x, y, AltosConvert.distance, "Ground Distance"); + public Distance(Container container, int x, int y) { + super(container, x, y, AltosConvert.distance, "Ground Distance"); } } - Distance distance; - - - class Apogee extends DescentStatus { - void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.apogee_voltage); - lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good); + class Range extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { + return state.range; } - public Apogee (GridBagLayout layout, int y) { - super(layout, y, "Apogee Igniter Voltage"); + public Range (Container container, int x, int y) { + super (container, x, y, AltosConvert.distance, "Range"); } } - Apogee apogee; - - class Main extends DescentStatus { - void show (AltosState state, AltosListenerState listener_state) { - show("%4.2f V", state.main_voltage); - lights.set(state.main_voltage >= AltosLib.ao_igniter_good); - } - public Main (GridBagLayout layout, int y) { - super(layout, y, "Main Igniter Voltage"); - } - } - - Main main; - - class Bearing extends DescentDualValue { - void show (AltosState state, AltosListenerState listener_state) { - if (state.from_pad != null) { + class Bearing extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { + if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) { show( String.format("%3.0f°", state.from_pad.bearing), state.from_pad.bearing_words( AltosGreatCircle.BEARING_LONG)); } else { - show("???", "???"); + show("Missing", "Missing"); } } - public Bearing (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Bearing"); + public Bearing (Container container, int x, int y) { + super (container, x, y, 1, "Bearing", 2, false, 1, 2); } } - Bearing bearing; - - class Range extends DescentValue { - void show (AltosState state, AltosListenerState listener_state) { - show(state.range); - } - public Range (GridBagLayout layout, int x, int y) { - super (layout, x, y, AltosConvert.distance, "Range"); - } - } - - Range range; - - class Elevation extends DescentValue { - void show (AltosState state, AltosListenerState listener_state) { - show("%3.0f°", state.elevation); - } - public Elevation (GridBagLayout layout, int x, int y) { - super (layout, x, y, "Elevation"); - } - } - - Elevation elevation; - - public void reset() { - lat.reset(); - lon.reset(); - height.reset(); - speed.reset(); - bearing.reset(); - range.reset(); - distance.reset(); - elevation.reset(); - main.reset(); - apogee.reset(); - } - - public void font_size_changed(int font_size) { - lat.font_size_changed(font_size); - lon.font_size_changed(font_size); - height.font_size_changed(font_size); - speed.font_size_changed(font_size); - bearing.font_size_changed(font_size); - range.font_size_changed(font_size); - distance.font_size_changed(font_size); - elevation.font_size_changed(font_size); - main.font_size_changed(font_size); - apogee.font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - lat.units_changed(imperial_units); - lon.units_changed(imperial_units); - height.units_changed(imperial_units); - speed.units_changed(imperial_units); - bearing.units_changed(imperial_units); - range.units_changed(imperial_units); - distance.units_changed(imperial_units); - elevation.units_changed(imperial_units); - main.units_changed(imperial_units); - apogee.units_changed(imperial_units); - } - - public void show(AltosState state, AltosListenerState listener_state) { - if (!isShowing()) { - last_state = state; - last_listener_state = listener_state; - return; + class Elevation extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { + if (state.elevation == AltosLib.MISSING) + show("Missing"); + else + show("%3.0f°", state.elevation); } - - height.show(state, listener_state); - speed.show(state, listener_state); - if (state.gps != null && state.gps.connected) { - bearing.show(state, listener_state); - range.show(state, listener_state); - distance.show(state, listener_state); - elevation.show(state, listener_state); - lat.show(state, listener_state); - lon.show(state, listener_state); - } else { - bearing.hide(); - range.hide(); - distance.hide(); - elevation.hide(); - lat.hide(); - lon.hide(); + public Elevation (Container container, int x, int y) { + super (container, x, y, "Elevation", 1, false, 1); } - if (state.main_voltage != AltosLib.MISSING) - main.show(state, listener_state); - else - main.hide(); - if (state.apogee_voltage != AltosLib.MISSING) - apogee.show(state, listener_state); - else - apogee.hide(); } public String getName() { return "Descent"; } - public void hierarchyChanged(HierarchyEvent e) { - if (last_state != null && isShowing()) { - AltosState state = last_state; - AltosListenerState listener_state = last_listener_state; - - last_state = null; - last_listener_state = null; - show(state, listener_state); - } - } - public AltosDescent() { - layout = new GridBagLayout(); - - setLayout(layout); - /* Elements in descent display */ - speed = new Speed(layout, 0, 0); - height = new Height(layout, 2, 0); - elevation = new Elevation(layout, 0, 1); - range = new Range(layout, 2, 1); - bearing = new Bearing(layout, 0, 2); - distance = new Distance(layout, 0, 3); - lat = new Lat(layout, 0, 4); - lon = new Lon(layout, 2, 4); - - apogee = new Apogee(layout, 5); - main = new Main(layout, 6); - addHierarchyListener(this); + add(new Speed(this, 0, 0)); + add(new Height(this, 2, 0)); + add(new Elevation(this, 0, 1)); + add(new Range(this, 2, 1)); + add(new Bearing(this, 0, 2)); + add(new Distance(this, 0, 3)); + add(new Lat(this, 0, 4)); + add(new Lon(this, 2, 4)); + add(new Apogee(this, 5)); + add(new Main(this, 6)); } } diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index b27deba9..46c0b387 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -25,11 +25,21 @@ import org.altusmetrum.altosuilib_2.*; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; - public class FlightValue { + public abstract class FlightValue { JLabel label; JTextField value; - void show(AltosState state, AltosListenerState listener_state) {} + void show() { + label.setVisible(true); + value.setVisible(true); + } + + void hide() { + label.setVisible(false); + value.setVisible(false); + } + + abstract void show(AltosState state, AltosListenerState listener_state); void reset() { value.setText(""); @@ -83,6 +93,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay void show(AltosState state, AltosListenerState listener_state) { if (!same_call(state.callsign)) { + show(); value.setText(state.callsign); if (state.callsign == null) setVisible(false); @@ -91,6 +102,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_call = state.callsign; } } + + public void reset() { + super.reset(); + last_call = ""; + } + public Call (GridBagLayout layout, int x) { super (layout, x, "Callsign"); } @@ -103,6 +120,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay int last_serial = -1; void show(AltosState state, AltosListenerState listener_state) { if (state.serial != last_serial) { + show(); if (state.serial == AltosLib.MISSING) value.setText("none"); else @@ -110,6 +128,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_serial = state.serial; } } + + public void reset() { + super.reset(); + last_serial = -1; + } + public Serial (GridBagLayout layout, int x) { super (layout, x, "Serial"); } @@ -123,6 +147,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay void show(AltosState state, AltosListenerState listener_state) { if (state.flight != last_flight) { + show(); if (state.flight == AltosLib.MISSING) value.setText("none"); else @@ -130,6 +155,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_flight = state.flight; } } + + public void reset() { + super.reset(); + last_flight = -1; + } + public Flight (GridBagLayout layout, int x) { super (layout, x, "Flight"); } @@ -143,10 +174,21 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay void show(AltosState state, AltosListenerState listener_state) { if (state.state != last_state) { - value.setText(state.state_name()); + if (state.state == AltosLib.ao_flight_stateless) + hide(); + else { + show(); + value.setText(state.state_name()); + } last_state = state.state; } } + + public void reset() { + super.reset(); + last_state = -1; + } + public FlightState (GridBagLayout layout, int x) { super (layout, x, "State"); } @@ -160,6 +202,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay void show(AltosState state, AltosListenerState listener_state) { if (state.rssi() != last_rssi) { + show(); value.setText(String.format("%d", state.rssi())); if (state.rssi == AltosLib.MISSING) setVisible(false); @@ -168,6 +211,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_rssi = state.rssi(); } } + + public void reset() { + super.reset(); + last_rssi = 10000; + } + public RSSI (GridBagLayout layout, int x) { super (layout, x, "RSSI"); } @@ -186,6 +235,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay last_secs = secs; } } + + public void reset() { + super.reset(); + last_secs = -1; + } + public LastPacket(GridBagLayout layout, int x) { super (layout, x, "Age"); } @@ -228,6 +283,8 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay return d.height; } + public String getName() { return "Flight Status"; } + public AltosFlightStatus() { layout = new GridBagLayout(); diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index f2bd70a0..43deb631 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -20,6 +20,7 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import java.util.*; import java.util.concurrent.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; @@ -29,6 +30,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { AltosFlightReader reader; AltosDisplayThread thread; + LinkedList displays; + JTabbedPane pane; AltosPad pad; @@ -56,6 +59,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { return ascent; if (state.state <= Altos.ao_flight_main) return descent; + if (state.state == AltosLib.ao_flight_stateless) + return descent; return landed; } @@ -74,37 +79,18 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { } public void reset() { - pad.reset(); - ignitor.reset(); - ascent.reset(); - descent.reset(); - landed.reset(); - flightInfo.clear(); - sitemap.reset(); + for (AltosFlightDisplay d : displays) + d.reset(); } public void font_size_changed(int font_size) { - pad.font_size_changed(font_size); - ignitor.font_size_changed(font_size); - ascent.font_size_changed(font_size); - descent.font_size_changed(font_size); - landed.font_size_changed(font_size); - flightStatus.font_size_changed(font_size); - flightInfo.font_size_changed(font_size); - sitemap.font_size_changed(font_size); - companion.font_size_changed(font_size); + for (AltosFlightDisplay d : displays) + d.font_size_changed(font_size); } public void units_changed(boolean imperial_units) { - pad.units_changed(imperial_units); - ignitor.units_changed(imperial_units); - ascent.units_changed(imperial_units); - descent.units_changed(imperial_units); - landed.units_changed(imperial_units); - flightStatus.units_changed(imperial_units); - flightInfo.units_changed(imperial_units); - sitemap.units_changed(imperial_units); - companion.units_changed(imperial_units); + for (AltosFlightDisplay d : displays) + d.units_changed(imperial_units); } AltosFlightStatusUpdate status_update; @@ -115,8 +101,6 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { if (state == null) state = new AltosState(); - pad.show(state, listener_state); - if (state.state != Altos.ao_flight_startup) { if (!has_state) { pane.setTitleAt(0, "Launch Pad"); @@ -127,10 +111,6 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { } } - ascent.show(state, listener_state); - descent.show(state, listener_state); - landed.show(state, listener_state); - JComponent tab = which_tab(state); if (tab != cur_tab) { if (cur_tab == pane.getSelectedComponent()) { @@ -138,15 +118,12 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { } cur_tab = tab; } - flightStatus.show(state, listener_state); - flightInfo.show(state, listener_state); if (ignitor.should_show(state)) { if (!has_ignitor) { pane.add("Ignitor", ignitor); has_ignitor = true; } - ignitor.show(state, listener_state); } else { if (has_ignitor) { pane.remove(ignitor); @@ -159,25 +136,33 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { pane.add("Companion", companion); has_companion= true; } - companion.show(state, listener_state); } else { if (has_companion) { pane.remove(companion); has_companion = false; } } + if (state.gps != null && state.gps.connected) { if (!has_map) { pane.add("Site Map", sitemap); has_map = true; } - sitemap.show(state, listener_state); } else { if (has_map) { pane.remove(sitemap); has_map = false; } } + + for (AltosFlightDisplay d : displays) { + try { + d.show(state, listener_state); + } catch (Exception e) { + System.out.printf("Exception showing %s\n", d.getName()); + e.printStackTrace(); + } + } } public void set_exit_on_close() { @@ -194,6 +179,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) { AltosUIPreferences.set_component(this); + displays = new LinkedList(); + voice = in_voice; reader = in_reader; @@ -282,6 +269,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { /* Flight status is always visible */ flightStatus = new AltosFlightStatus(); + displays.add(flightStatus); c.gridx = 0; c.gridy = 1; c.fill = GridBagConstraints.HORIZONTAL; @@ -296,21 +284,29 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay { pane = new JTabbedPane(); pad = new AltosPad(); + displays.add(pad); pane.add("Status", pad); ignitor = new AltosIgnitor(); + displays.add(ignitor); ascent = new AltosAscent(); + displays.add(ascent); descent = new AltosDescent(); + displays.add(descent); landed = new AltosLanded(reader); + displays.add(landed); flightInfo = new AltosInfoTable(); + displays.add(flightInfo); pane.add("Table", new JScrollPane(flightInfo)); companion = new AltosCompanionInfo(); + displays.add(companion); has_companion = false; has_state = false; sitemap = new AltosUIMap(); + displays.add(sitemap); has_map = false; /* Make the tabbed pane use the rest of the window space */ diff --git a/altosui/AltosIgnitor.java b/altosui/AltosIgnitor.java index 73318117..990a87e6 100644 --- a/altosui/AltosIgnitor.java +++ b/altosui/AltosIgnitor.java @@ -18,147 +18,37 @@ package altosui; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosIgnitor extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; +public class AltosIgnitor extends AltosUIFlightTab { - public class LaunchStatus implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosLights lights; - - void show(AltosState state, AltosListenerState listener_state) {} - - void reset() { - value.setText(""); - lights.set(false); - } - - public void show() { - label.setVisible(true); - value.setVisible(true); - lights.setVisible(true); - } - - void show(String s) { - show(); - value.setText(s); - } - - void show(String format, double value) { - show(String.format(format, value)); - } - - void show(String format, int value) { - show(String.format(format, value)); - } - - public void hide() { - label.setVisible(false); - value.setVisible(false); - lights.setVisible(false); - } - - public void dispose() { - hide(); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - } - - public void set_label(String text) { - label.setText(text); - } - - public LaunchStatus (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); + public class Ignitor extends AltosUIUnitsIndicator { + int ignitor; + public double value(AltosState state, int i) { + if (state.ignitor_voltage == null || + state.ignitor_voltage.length < ignitor) + return AltosLib.MISSING; + return state.ignitor_voltage[ignitor]; } - } - class Ignitor extends LaunchStatus { - int ignitor; + public double good() { return AltosLib.ao_igniter_good; } - void show (AltosState state, AltosListenerState listener_state) { - if (state == null || state.ignitor_voltage[ignitor] == AltosLib.MISSING) { - hide(); - } else { - show("%4.2f V", state.ignitor_voltage[ignitor]); - lights.set(state.ignitor_voltage[ignitor] >= AltosLib.ao_igniter_good); - } - } - - public Ignitor (GridBagLayout layout, int y) { - super(layout, y, String.format ("%s Voltage", AltosLib.ignitor_name(y))); + public Ignitor (AltosUIFlightTab container, int y) { + super(container, y, AltosConvert.voltage, String.format ("%s Voltage", AltosLib.ignitor_name(y)), 1, true, 1); ignitor = y; } } Ignitor[] ignitors; - public void reset() { - if (ignitors == null) - return; - for (int i = 0; i < ignitors.length; i++) - ignitors[i].reset(); - } - - public void font_size_changed(int font_size) { - if (ignitors == null) - return; - for (int i = 0; i < ignitors.length; i++) - ignitors[i].font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - } - public void show(AltosState state, AltosListenerState listener_state) { - make_ignitors(state); - if (ignitors == null) - return; - for (int i = 0; i < ignitors.length; i++) - ignitors[i].show(state, listener_state); - return; + if (isShowing()) + make_ignitors(state); + super.show(state, listener_state); } public boolean should_show(AltosState state) { @@ -170,33 +60,32 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay { } void make_ignitors(AltosState state) { - int n = state == null ? 0 : state.ignitor_voltage.length; + int n = (state == null || state.ignitor_voltage == null) ? 0 : state.ignitor_voltage.length; + int old_n = ignitors == null ? 0 : ignitors.length; - if (n > 0) { + if (n != old_n) { - if (ignitors == null || ignitors.length != n) { - layout = new GridBagLayout(); + if (ignitors != null) { + for (int i = 0; i < ignitors.length; i++) { + remove(ignitors[i]); + ignitors[i].remove(this); + ignitors = null; + } + } - setLayout(layout); + if (n > 0) { + setVisible(true); ignitors = new Ignitor[n]; - for (int i = 0; i < n; i++) - ignitors[i] = new Ignitor(layout, i); - } - } else { - if (ignitors != null) { - for (int i = 0; i < n; i++) - ignitors[i].dispose(); - ignitors = null; + for (int i = 0; i < n; i++) { + ignitors[i] = new Ignitor(this, i); + add(ignitors[i]); + } + } else setVisible(false); - } } } public String getName() { return "Ignitors"; } - - public AltosIgnitor() { - make_ignitors(null); - } } diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 760b2d64..dd5cf9ab 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -24,256 +24,91 @@ import java.io.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener, HierarchyListener { - GridBagLayout layout; - - private AltosState last_state; - private AltosListenerState last_listener_state; - - public abstract class LandedValue implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosUnits units; - double v; - String last_value = ""; - - abstract void show(AltosState state, AltosListenerState listener_state); - - void reset() { - value.setText(""); - } - - void show() { - label.setVisible(true); - value.setVisible(true); - } - - void show(String s) { - show(); - if (!last_value.equals(s)) { - value.setText(s); - last_value = s; +public class AltosLanded extends AltosUIFlightTab implements ActionListener { + + class Bearing extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { + if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) { + show( String.format("%3.0f°", state.from_pad.bearing), + state.from_pad.bearing_words( + AltosGreatCircle.BEARING_LONG)); + } else { + show("Missing", "Missing"); } } - - void show(double v) { - this.v = v; - if (v == AltosLib.MISSING) - show("Missing"); - else - show(units.show(8, v)); - } - - void show(String format, double v) { - show(String.format(format, v)); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); - } - - void hide() { - label.setVisible(false); - value.setVisible(false); - } - - public LandedValue (GridBagLayout layout, int y, AltosUnits units, String text) { - this.units = units; - - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; - c.insets = new Insets(10, 10, 10, 10); - c.anchor = GridBagConstraints.WEST; - c.weightx = 0; - c.fill = GridBagConstraints.VERTICAL; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 1; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.weightx = 1; - c.fill = GridBagConstraints.BOTH; - layout.setConstraints(value, c); - add(value); - } - - public LandedValue (GridBagLayout layout, int y, String text) { - this(layout, y, null, text); + public Bearing (Container container, int y) { + super (container, y, "Bearing", 2); } } - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; - } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); - } - - class Lat extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(); - if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) - show(pos(state.gps.lat,"N", "S")); + class Distance extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { + if (state.from_pad != null) + return state.from_pad.distance; else - show("???"); - } - public Lat (GridBagLayout layout, int y) { - super (layout, y, "Latitude"); + return AltosLib.MISSING; } - } - - Lat lat; - class Lon extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(); - if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) - show(pos(state.gps.lon,"E", "W")); - else - show("???"); - } - public Lon (GridBagLayout layout, int y) { - super (layout, y, "Longitude"); + public Distance(Container container, int y) { + super(container, y, AltosConvert.distance, "Ground Distance", 2); } } - Lon lon; + class Lat extends AltosUIUnitsIndicator { - class Bearing extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(); - if (state.from_pad != null) - show("%3.0f°", state.from_pad.bearing); - else - show("???"); - } - public Bearing (GridBagLayout layout, int y) { - super (layout, y, "Bearing"); - } - } - - Bearing bearing; + public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; } - class Distance extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(); - if (state.from_pad != null) - show(state.from_pad.distance); - else - show("???"); + public double value(AltosState state, int i) { + if (state.gps == null) + return AltosLib.MISSING; + if (!state.gps.connected) + return AltosLib.MISSING; + return state.gps.lat; } - public Distance (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.distance, "Distance"); - } - } - - Distance distance; - class Height extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(state.max_height()); - } - public Height (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.height, "Maximum Height"); + public Lat (Container container, int y) { + super (container, y, AltosConvert.latitude, "Latitude", 2); } } - Height height; + class Lon extends AltosUIUnitsIndicator { + public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; } - class Speed extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(state.max_speed()); + public double value(AltosState state, int i) { + if (state.gps == null) + return AltosLib.MISSING; + if (!state.gps.connected) + return AltosLib.MISSING; + return state.gps.lon; } - public Speed (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.speed, "Maximum Speed"); + + public Lon (Container container, int y) { + super (container, y, AltosConvert.longitude, "Longitude", 2); } } - Speed speed; + class MaxHeight extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { return state.max_height(); } - class Accel extends LandedValue { - void show (AltosState state, AltosListenerState listener_state) { - show(state.max_acceleration()); - } - public Accel (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.accel, "Maximum Acceleration"); + public MaxHeight (Container container, int y) { + super (container, y, AltosConvert.height, "Maximum Height", 2); } } - Accel accel; - - public void reset() { - lat.reset(); - lon.reset(); - bearing.reset(); - distance.reset(); - height.reset(); - speed.reset(); - accel.reset(); - } + class MaxSpeed extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { return state.max_speed(); } - public void font_size_changed(int font_size) { - lat.font_size_changed(font_size); - lon.font_size_changed(font_size); - bearing.font_size_changed(font_size); - distance.font_size_changed(font_size); - height.font_size_changed(font_size); - speed.font_size_changed(font_size); - accel.font_size_changed(font_size); + public MaxSpeed (Container container, int y) { + super (container, y, AltosConvert.speed, "Maximum Speed", 2); + } } - public void units_changed(boolean imperial_units) { - lat.units_changed(imperial_units); - lon.units_changed(imperial_units); - bearing.units_changed(imperial_units); - distance.units_changed(imperial_units); - height.units_changed(imperial_units); - speed.units_changed(imperial_units); - accel.units_changed(imperial_units); - } + class MaxAccel extends AltosUIUnitsIndicator { + public double value(AltosState state, int i) { return state.max_acceleration(); } - public void show(AltosState state, AltosListenerState listener_state) { - if (!isShowing()) { - last_state = state; - last_listener_state = listener_state; - return; + public MaxAccel (Container container, int y) { + super (container, y, AltosConvert.speed, "Maximum acceleration", 2); } - - if (state.gps != null && state.gps.connected) { - bearing.show(state, listener_state); - distance.show(state, listener_state); - lat.show(state, listener_state); - lon.show(state, listener_state); - } else { - bearing.hide(); - distance.hide(); - lat.hide(); - lon.hide(); - } - height.show(state, listener_state); - speed.show(state, listener_state); - accel.show(state, listener_state); - if (reader.backing_file() != null) - graph.setEnabled(true); } JButton graph; @@ -316,32 +151,17 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio return "Landed"; } - public void hierarchyChanged(HierarchyEvent e) { - if (last_state != null && isShowing()) { - AltosState state = last_state; - AltosListenerState listener_state = last_listener_state; - - last_state = null; - last_listener_state = null; - show(state, listener_state); - } - } - public AltosLanded(AltosFlightReader in_reader) { - layout = new GridBagLayout(); - reader = in_reader; - setLayout(layout); - /* Elements in descent display */ - bearing = new Bearing(layout, 0); - distance = new Distance(layout, 1); - lat = new Lat(layout, 2); - lon = new Lon(layout, 3); - height = new Height(layout, 4); - speed = new Speed(layout, 5); - accel = new Accel(layout, 6); + add(new Bearing(this, 0)); + add(new Distance(this, 1)); + add(new Lat(this, 2)); + add(new Lon(this, 3)); + add(new MaxHeight(this, 4)); + add(new MaxSpeed(this, 5)); + add(new MaxAccel(this, 6)); graph = new JButton ("Graph Flight"); graph.setActionCommand("graph"); @@ -350,7 +170,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio GridBagConstraints c = new GridBagConstraints(); - c.gridx = 0; c.gridy = 7; + c.gridx = 1; c.gridy = 7; c.insets = new Insets(10, 10, 10, 10); c.anchor = GridBagConstraints.WEST; c.weightx = 0; diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index 3294949c..6b5fd150 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -17,280 +17,73 @@ package altosui; -import java.awt.*; -import javax.swing.*; +import java.util.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class AltosPad extends JComponent implements AltosFlightDisplay { - GridBagLayout layout; +public class AltosPad extends AltosUIFlightTab { - public class LaunchStatus implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosLights lights; - - void show(AltosState state, AltosListenerState listener_state) {} - - void reset() { - value.setText(""); - lights.set(false); - } - - public void show() { - label.setVisible(true); - value.setVisible(true); - lights.setVisible(true); - } - - void show(String s) { - show(); - value.setText(s); - } - - void show(String format, double value) { - show(String.format(format, value)); - } - - void show(String format, int value) { - show(String.format(format, value)); - } - - public void hide() { - label.setVisible(false); - value.setVisible(false); - lights.setVisible(false); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - } - - public void set_label(String text) { - label.setText(text); - } - - public LaunchStatus (GridBagLayout layout, int y, String text) { - GridBagConstraints c = new GridBagConstraints(); - c.weighty = 1; - - lights = new AltosLights(); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.CENTER; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(lights, c); - add(lights); - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - - } + class Battery extends AltosUIVoltageIndicator { + public double voltage(AltosState state) { return state.battery_voltage; } + public double good() { return AltosLib.ao_battery_good; } + public Battery (AltosUIFlightTab container, int y) { super(container, y, "Battery Voltage", 2); } } - public abstract class LaunchValue implements AltosFontListener, AltosUnitsListener { - JLabel label; - JTextField value; - AltosUnits units; - double v; - - abstract void show(AltosState state, AltosListenerState listener_state); - - void show() { - label.setVisible(true); - value.setVisible(true); - } - - void hide() { - label.setVisible(false); - value.setVisible(false); - } - - public void font_size_changed(int font_size) { - label.setFont(Altos.label_font); - value.setFont(Altos.value_font); - } - - public void units_changed(boolean imperial_units) { - if (units != null) - show(v); - } - - void show(String s) { - show(); - value.setText(s); - } - - void show(double v) { - this.v = v; - show(units.show(8, v)); - } - - void show(String format, double v) { - show(String.format(format, v)); - } - - public void set_label(String text) { - label.setText(text); - } - - void reset() { - value.setText(""); - } - - public LaunchValue (GridBagLayout layout, int y, AltosUnits units, String text) { - this.units = units; - - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); - c.weighty = 1; - - label = new JLabel(text); - label.setFont(Altos.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 1; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - value = new JTextField(Altos.text_width); - value.setEditable(false); - value.setFont(Altos.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - c.gridx = 2; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - } - - public LaunchValue (GridBagLayout layout, int y, String text) { - this(layout, y, null, text); - } + class Apogee extends AltosUIVoltageIndicator { + public boolean hide(double v) { return v == AltosLib.MISSING; } + public double voltage(AltosState state) { return state.apogee_voltage; } + public double good() { return AltosLib.ao_igniter_good; } + public Apogee (AltosUIFlightTab container, int y) { super(container, y, "Apogee Igniter Voltage", 2); } } - class Voltage extends LaunchStatus { - - double voltage(AltosState state) { return AltosLib.MISSING; }; - double good() { return 0; }; - - double last_voltage = -1; - - void show (AltosState state, AltosListenerState listener_state) { - double voltage = AltosLib.MISSING; - if (state != null) - voltage = voltage(state); - - if (voltage != last_voltage) { - if (voltage == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", voltage); - lights.set(voltage >= good()); - } - last_voltage = voltage; - } - } - public Voltage (GridBagLayout layout, int y, String name) { super(layout, y, name); } - } - - - class Battery extends Voltage { - double voltage(AltosState state) { return state.battery_voltage; } - double good() { return AltosLib.ao_battery_good; } - - public Battery (GridBagLayout layout, int y) { - super(layout, y, "Battery Voltage"); - } - + class Main extends AltosUIVoltageIndicator { + public boolean hide(double v) { return v == AltosLib.MISSING; } + public double voltage(AltosState state) { return state.main_voltage; } + public double good() { return AltosLib.ao_igniter_good; } + public Main (AltosUIFlightTab container, int y) { super(container, y, "Main Igniter Voltage", 2); } } - Battery battery; - - class Apogee extends Voltage { - double voltage(AltosState state) { return state.apogee_voltage; } - double good() { return AltosLib.ao_igniter_good; } - public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); } - } - - Apogee apogee; - - class Main extends Voltage { - double voltage(AltosState state) { return state.main_voltage; } - double good() { return AltosLib.ao_igniter_good; } - public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); } - } - - Main main; - - class LoggingReady extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { + class LoggingReady extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { if (state == null || state.flight == AltosLib.MISSING) { hide(); } else { if (state.flight != 0) { if (state.state <= Altos.ao_flight_pad) show("Ready to record"); - else if (state.state < Altos.ao_flight_landed) + else if (state.state < Altos.ao_flight_landed || + state.state == AltosLib.ao_flight_stateless) show("Recording data"); else show("Recorded data"); } else show("Storage full"); - lights.set(state.flight != 0); + set_lights(state.flight != 0); } } - public LoggingReady (GridBagLayout layout, int y) { - super(layout, y, "On-board Data Logging"); + public LoggingReady (AltosUIFlightTab container, int y) { + super(container, y, "On-board Data Logging", 1, true, 2); } } - LoggingReady logging_ready; - - class GPSLocked extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { + class GPSLocked extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { if (state == null || state.gps == null) hide(); else { - show("%4d sats", state.gps.nsat); - lights.set(state.gps.locked && state.gps.nsat >= 4); + int sol = state.gps.nsat; + int sat = state.gps.cc_gps_sat == null ? 0 : state.gps.cc_gps_sat.length; + show("%d in solution", sol, "%d in view", sat); + set_lights(state.gps.locked && sol >= 4); } } - public GPSLocked (GridBagLayout layout, int y) { - super (layout, y, "GPS Locked"); + public GPSLocked (AltosUIFlightTab container, int y) { + super (container, y, "GPS Locked", 2, true, 1); } } - GPSLocked gps_locked; - - class GPSReady extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { + class GPSReady extends AltosUIIndicator { + public void show (AltosState state, AltosListenerState listener_state) { if (state == null || state.gps == null) hide(); else { @@ -298,48 +91,37 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { show("Ready"); else show("Waiting %d", state.gps_waiting); - lights.set(state.gps_ready); + set_lights(state.gps_ready); } } - public GPSReady (GridBagLayout layout, int y) { - super (layout, y, "GPS Ready"); + public GPSReady (AltosUIFlightTab container, int y) { + super (container, y, "GPS Ready", 1, true, 2); } } - GPSReady gps_ready; + class ReceiverBattery extends AltosUIVoltageIndicator { - class ReceiverBattery extends LaunchStatus { - void show (AltosState state, AltosListenerState listener_state) { - if (listener_state == null || listener_state.battery == AltosLib.MISSING) - hide(); - else { - show("%4.2f V", listener_state.battery); - lights.set(listener_state.battery > AltosLib.ao_battery_good); - } - } - public ReceiverBattery (GridBagLayout layout, int y) { - super(layout, y, "Receiver Battery"); - } - } + public double voltage(AltosState state) { return AltosLib.MISSING; } + + public boolean hide(double v) { return v == AltosLib.MISSING; } + public double good() { return AltosLib.ao_battery_good; } - ReceiverBattery receiver_battery; + public double value(AltosState state, AltosListenerState listener_state, int i) { + if (listener_state == null) + return AltosLib.MISSING; + return listener_state.battery; + } - String pos(double p, String pos, String neg) { - String h = pos; - if (p < 0) { - h = neg; - p = -p; + public ReceiverBattery (AltosUIFlightTab container, int y) { + super(container, y, "Receiver Battery", 2); } - int deg = (int) Math.floor(p); - double min = (p - Math.floor(p)) * 60.0; - return String.format("%s %4d° %9.6f", h, deg, min); } - class PadLat extends LaunchValue { + class PadLat extends AltosUIIndicator { - double last_lat = 1000; + double last_lat = AltosLib.MISSING - 1; - void show (AltosState state, AltosListenerState listener_state) { + public void show (AltosState state, AltosListenerState listener_state) { double lat = AltosLib.MISSING; String label = null; @@ -354,25 +136,29 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } if (lat != last_lat) { if (lat != AltosLib.MISSING) { - show(pos(lat,"N", "S")); + show(AltosConvert.latitude.show(10, lat)); set_label(label); } else hide(); last_lat = lat; } } - public PadLat (GridBagLayout layout, int y) { - super (layout, y, "Pad Latitude"); + + public void reset() { + super.reset(); + last_lat = AltosLib.MISSING - 1; } - } - PadLat pad_lat; + public PadLat (AltosUIFlightTab container, int y) { + super (container, y, "Pad Latitude", 1, false, 2); + } + } - class PadLon extends LaunchValue { + class PadLon extends AltosUIIndicator { - double last_lon = 1000; + double last_lon = AltosLib.MISSING - 1; - void show (AltosState state, AltosListenerState listener_state) { + public void show (AltosState state, AltosListenerState listener_state) { double lon = AltosLib.MISSING; String label = null; @@ -387,25 +173,29 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } if (lon != last_lon) { if (lon != AltosLib.MISSING) { - show(pos(lon,"E", "W")); + show(AltosConvert.longitude.show(10, lon)); set_label(label); } else hide(); last_lon = lon; } } - public PadLon (GridBagLayout layout, int y) { - super (layout, y, "Pad Longitude"); + + public void reset() { + super.reset(); + last_lon = AltosLib.MISSING - 1; } - } - PadLon pad_lon; + public PadLon (AltosUIFlightTab container, int y) { + super (container, y, "Pad Longitude", 1, false, 2); + } + } - class PadAlt extends LaunchValue { + class PadAlt extends AltosUIIndicator { - double last_alt = -1000000; + double last_alt = AltosLib.MISSING - 1; - void show (AltosState state, AltosListenerState listener_state) { + public void show (AltosState state, AltosListenerState listener_state) { double alt = AltosLib.MISSING; String label = null; @@ -420,97 +210,36 @@ public class AltosPad extends JComponent implements AltosFlightDisplay { } if (alt != last_alt) { if (alt != AltosLib.MISSING) { - show(alt); + show(AltosConvert.height.show(5, alt)); set_label(label); } else hide(); last_alt = alt; } } - public PadAlt (GridBagLayout layout, int y) { - super (layout, y, AltosConvert.height, "Pad Altitude"); - } - } - - PadAlt pad_alt; - - public void reset() { - battery.reset(); - apogee.reset(); - main.reset(); - logging_ready.reset(); - gps_locked.reset(); - gps_ready.reset(); - receiver_battery.reset(); - pad_lat.reset(); - pad_lon.reset(); - pad_alt.reset(); - } - public void font_size_changed(int font_size) { - battery.font_size_changed(font_size); - apogee.font_size_changed(font_size); - main.font_size_changed(font_size); - logging_ready.font_size_changed(font_size); - gps_locked.font_size_changed(font_size); - gps_ready.font_size_changed(font_size); - receiver_battery.font_size_changed(font_size); - pad_lat.font_size_changed(font_size); - pad_lon.font_size_changed(font_size); - pad_alt.font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - battery.units_changed(imperial_units); - apogee.units_changed(imperial_units); - main.units_changed(imperial_units); - logging_ready.units_changed(imperial_units); - gps_locked.units_changed(imperial_units); - gps_ready.units_changed(imperial_units); - receiver_battery.units_changed(imperial_units); - pad_lat.units_changed(imperial_units); - pad_lon.units_changed(imperial_units); - pad_alt.units_changed(imperial_units); - } + public void reset() { + super.reset(); + last_alt = AltosLib.MISSING - 1; + } - public void show(AltosState state, AltosListenerState listener_state) { - battery.show(state, listener_state); - apogee.show(state, listener_state); - main.show(state, listener_state); - logging_ready.show(state, listener_state); - pad_alt.show(state, listener_state); - receiver_battery.show(state, listener_state); - gps_locked.show(state, listener_state); - gps_ready.show(state, listener_state); - pad_lat.show(state, listener_state); - pad_lon.show(state, listener_state); + public PadAlt (AltosUIFlightTab container, int y) { + super (container, y, "Pad Altitude", 1, false, 2); + } } + public String getName() { return "Pad"; } public AltosPad() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in pad display: - * - * Battery voltage - * Igniter continuity - * GPS lock status - * GPS ready status - * GPS location - * Pad altitude - * RSSI - */ - battery = new Battery(layout, 0); - apogee = new Apogee(layout, 1); - main = new Main(layout, 2); - logging_ready = new LoggingReady(layout, 3); - gps_locked = new GPSLocked(layout, 4); - gps_ready = new GPSReady(layout, 5); - receiver_battery = new ReceiverBattery(layout, 6); - pad_lat = new PadLat(layout, 7); - pad_lon = new PadLon(layout, 8); - pad_alt = new PadAlt(layout, 9); - show(null, null); + int y = 0; + add(new Battery(this, y++)); + add(new Apogee(this, y++)); + add(new Main(this, y++)); + add(new LoggingReady(this, y++)); + add(new GPSLocked(this, y++)); + add(new GPSReady(this, y++)); + add(new ReceiverBattery(this, y++)); + add(new PadLat(this, y++)); + add(new PadLon(this, y++)); + add(new PadAlt(this, y++)); } } diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index eddb47d8..6e68dd30 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -59,11 +59,13 @@ public class TeleGPS JMenu monitor_menu; JMenu device_menu; AltosFreqList frequencies; + ActionListener frequency_listener; Container bag; TeleGPSStatus telegps_status; TeleGPSStatusUpdate status_update; + javax.swing.Timer status_timer; JTabbedPane pane; @@ -174,7 +176,14 @@ public class TeleGPS void disconnect() { setTitle("TeleGPS"); stop_display(); - remove_frequency_menu(); + if (status_timer != null) { + status_timer.stop(); + status_timer = null; + status_update = null; + } + + telegps_status.disable_receive(); + disable_frequency_menu(); } void connect(AltosDevice device) { @@ -182,8 +191,7 @@ public class TeleGPS disconnect(); try { AltosFlightReader reader = new AltosTelemetryReader(new AltosSerial(device)); - set_reader(reader); - add_frequency_menu(device.getSerial(), reader); + set_reader(reader, device); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(this, ee.getMessage(), @@ -322,15 +330,12 @@ public class TeleGPS } } - void add_frequency_menu(int serial, final AltosFlightReader reader) { - // Channel menu - if (frequencies != null) - return; + void enable_frequency_menu(int serial, final AltosFlightReader reader) { - frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial)); - frequencies.set_product("Monitor"); - frequencies.set_serial(serial); - frequencies.addActionListener(new ActionListener() { + if (frequency_listener != null) + disable_frequency_menu(); + + frequency_listener = new ActionListener() { public void actionPerformed(ActionEvent e) { double frequency = frequencies.frequency(); try { @@ -340,22 +345,37 @@ public class TeleGPS } reader.save_frequency(); } - }); - menu_bar.add(frequencies); + }; + + frequencies.addActionListener(frequency_listener); + frequencies.set_product("Monitor"); + frequencies.set_serial(serial); + frequencies.set_frequency(AltosUIPreferences.frequency(serial)); + frequencies.setEnabled(true); + } - void remove_frequency_menu() { - if (frequencies != null) { - menu_bar.remove(frequencies); - menu_bar.repaint(); - frequencies = null; + void disable_frequency_menu() { + if (frequency_listener != null) { + frequencies.removeActionListener(frequency_listener); + frequencies.setEnabled(false); + frequency_listener = null; } + } - public void set_reader(AltosFlightReader reader) { + public void set_reader(AltosFlightReader reader, AltosDevice device) { + status_update = new TeleGPSStatusUpdate(telegps_status); + + status_timer = new javax.swing.Timer(100, status_update); + status_timer.start(); + setTitle(String.format("TeleGPS %s", reader.name)); thread = new TeleGPSDisplayThread(this, voice(), this, reader); thread.start(); + + if (device != null) + enable_frequency_menu(device.getSerial(), reader); } static int number_of_windows; @@ -414,6 +434,10 @@ public class TeleGPS file_menu = make_menu("File", file_menu_entries); monitor_menu = make_menu("Monitor", monitor_menu_entries); device_menu = make_menu("Device", device_menu_entries); + frequencies = new AltosFreqList(); + frequencies.setEnabled(false); + menu_bar.add(frequencies); + displays = new LinkedList(); int serial = -1; @@ -476,15 +500,11 @@ public class TeleGPS setVisible(true); add_window(); - - status_update = new TeleGPSStatusUpdate(telegps_status); - - new javax.swing.Timer(100, status_update).start(); } public TeleGPS(AltosFlightReader reader) { this(); - set_reader(reader); + set_reader(reader, null); } public TeleGPS(AltosDevice device) { diff --git a/telegps/TeleGPSInfo.java b/telegps/TeleGPSInfo.java index bbf4b472..e87fea90 100644 --- a/telegps/TeleGPSInfo.java +++ b/telegps/TeleGPSInfo.java @@ -24,13 +24,10 @@ import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener { +public class TeleGPSInfo extends AltosUIFlightTab { JLabel cur, max; - private AltosState last_state; - private AltosListenerState last_listener_state; - abstract class Value extends AltosUIUnitsIndicator { public abstract void show(AltosState state, AltosListenerState listener_state); @@ -48,7 +45,6 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera abstract class ValueHold extends DualValue { public void reset() { super.reset(); - last_values[1] = AltosLib.MISSING; } public ValueHold (Container container, int y, AltosUnits units, String text) { super(container, y, units, text); @@ -96,7 +92,9 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera public void show (AltosState state, AltosListenerState listener_state) { double course = state.gps_course(); - if (course != AltosLib.MISSING) + if (course == AltosLib.MISSING) + show("Missing", "Missing"); + else show( String.format("%3.0f°", course), AltosConvert.bearing_to_words( AltosConvert.BEARING_LONG, @@ -124,7 +122,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) show(pos(state.gps.lat,"N", "S")); else - show("???"); + show("Missing"); } public Lat (Container container, int y) { super (container, y, "Latitude", 1, false, 2); @@ -148,7 +146,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) show(pos(state.gps.lon,"E", "W")); else - show("???"); + show("Missing"); } public Lon (Container container, int y) { super (container, y, "Longitude", 1, false, 2); @@ -173,34 +171,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera } } - LinkedList indicators = new LinkedList(); - - public void reset() { - for (AltosUIIndicator i : indicators) - i.reset(); - } - public void font_size_changed(int font_size) { cur.setFont(AltosUILib.label_font); max.setFont(AltosUILib.label_font); - for (AltosUIIndicator i : indicators) - i.font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - for (AltosUIIndicator i : indicators) - i.units_changed(imperial_units); - } - - public void show(AltosState state, AltosListenerState listener_state) { - if (!isShowing()) { - last_state = state; - last_listener_state = listener_state; - return; - } - - for (AltosUIIndicator i : indicators) - i.show(state, listener_state); + super.font_size_changed(font_size); } public void labels(Container container, int y) { @@ -226,29 +200,15 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera return "Location"; } - public void hierarchyChanged(HierarchyEvent e) { - if (last_state != null && isShowing()) { - AltosState state = last_state; - AltosListenerState listener_state = last_listener_state; - - last_state = null; - last_listener_state = null; - show(state, listener_state); - } - } - public TeleGPSInfo() { - setLayout(new GridBagLayout()); - int y = 0; labels(this, y++); - indicators.add(new Altitude(this, y++)); - indicators.add(new GroundSpeed(this, y++)); - indicators.add(new AscentRate(this, y++)); - indicators.add(new Course(this, y++)); - indicators.add(new Lat(this, y++)); - indicators.add(new Lon(this, y++)); - indicators.add(new GPSLocked(this, y++)); - addHierarchyListener(this); + add(new Altitude(this, y++)); + add(new GroundSpeed(this, y++)); + add(new AscentRate(this, y++)); + add(new Course(this, y++)); + add(new Lat(this, y++)); + add(new Lon(this, y++)); + add(new GPSLocked(this, y++)); } } diff --git a/telegps/TeleGPSState.java b/telegps/TeleGPSState.java index b10e8e70..a76182ed 100644 --- a/telegps/TeleGPSState.java +++ b/telegps/TeleGPSState.java @@ -24,12 +24,9 @@ import javax.swing.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class TeleGPSState extends JComponent implements AltosFlightDisplay, HierarchyListener { - GridBagLayout layout; - JLabel cur, max; +public class TeleGPSState extends AltosUIFlightTab { - private AltosState last_state; - private AltosListenerState last_listener_state; + JLabel cur, max; abstract class Value extends AltosUIUnitsIndicator { public Value (Container container, int y, AltosUnits units, String text) { @@ -44,10 +41,6 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier } abstract class ValueHold extends DualValue { - public void reset() { - super.reset(); - last_values[1] = AltosLib.MISSING; - } public ValueHold (Container container, int y, AltosUnits units, String text) { super(container, y, units, text); } @@ -103,12 +96,12 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier class Bearing extends AltosUIIndicator { public void show (AltosState state, AltosListenerState listener_state) { - if (state.from_pad != null) { + if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) { show( String.format("%3.0f°", state.from_pad.bearing), state.from_pad.bearing_words( AltosGreatCircle.BEARING_LONG)); } else { - show("???", "???"); + show("Missing", "Missing"); } } public Bearing (Container container, int y) { @@ -118,7 +111,10 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier class Elevation extends AltosUIIndicator { public void show (AltosState state, AltosListenerState listener_state) { - show("%3.0f°", state.elevation); + if (state.elevation == AltosLib.MISSING) + show("Missing"); + else + show("%3.0f°", state.elevation); } public Elevation (Container container, int y) { super (container, y, "Elevation", 1, false, 2); @@ -165,7 +161,6 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier } } - LinkedList indicators = new LinkedList(); public void labels(Container container, int y) { GridBagLayout layout = (GridBagLayout)(container.getLayout()); @@ -186,69 +181,27 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier add(max); } - public void reset() { - for (AltosUIIndicator i : indicators) - i.reset(); - } - public void font_size_changed(int font_size) { - for (AltosUIIndicator i : indicators) - i.font_size_changed(font_size); - } - - public void units_changed(boolean imperial_units) { - for (AltosUIIndicator i : indicators) - i.units_changed(imperial_units); - } - - public void show(AltosState state, AltosListenerState listener_state) { - if (!isShowing()) { - last_state = state; - last_listener_state = listener_state; - return; - } - - for (AltosUIIndicator i : indicators) - i.show(state, listener_state); + cur.setFont(AltosUILib.label_font); + max.setFont(AltosUILib.label_font); + super.font_size_changed(font_size); } public String getName() { return "Status"; } - public void hierarchyChanged(HierarchyEvent e) { - if (last_state != null && isShowing()) { - AltosState state = last_state; - AltosListenerState listener_state = last_listener_state; - - last_state = null; - last_listener_state = null; - show(state, listener_state); - } - } - public TeleGPSState() { - layout = new GridBagLayout(); - - setLayout(layout); - - /* Elements in state display: - * - * config_version; - * lon - * height - */ int y = 0; labels(this, y++); - indicators.add(new Height(this, y++)); - indicators.add(new Speed(this, y++)); - indicators.add(new Distance(this, y++)); - indicators.add(new Range(this, y++)); - indicators.add(new Bearing(this, y++)); - indicators.add(new Elevation(this, y++)); - indicators.add(new FirmwareVersion(this, y++)); - indicators.add(new FlightLogMax(this, y++)); - indicators.add(new BatteryVoltage(this, y++)); - addHierarchyListener(this); + add(new Height(this, y++)); + add(new Speed(this, y++)); + add(new Distance(this, y++)); + add(new Range(this, y++)); + add(new Bearing(this, y++)); + add(new Elevation(this, y++)); + add(new FirmwareVersion(this, y++)); + add(new FlightLogMax(this, y++)); + add(new BatteryVoltage(this, y++)); } } diff --git a/telegps/TeleGPSStatus.java b/telegps/TeleGPSStatus.java index 14706877..f3951a37 100644 --- a/telegps/TeleGPSStatus.java +++ b/telegps/TeleGPSStatus.java @@ -83,6 +83,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { else setVisible(true); } + + public void reset() { + super.reset(); + call = ""; + } + public Call (GridBagLayout layout, int x) { super (layout, x, "Callsign"); } @@ -101,6 +107,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { serial = state.serial; } } + + public void reset() { + super.reset(); + serial = -1; + } + public Serial (GridBagLayout layout, int x) { super (layout, x, "Serial"); } @@ -121,6 +133,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { last_flight = state.flight; } } + + public void reset() { + super.reset(); + last_flight = -1; + } + public Flight (GridBagLayout layout, int x) { super (layout, x, "Flight"); } @@ -143,6 +161,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { rssi = new_rssi; } } + + public void reset() { + super.reset(); + rssi = 10000; + } + public RSSI (GridBagLayout layout, int x) { super (layout, x, "RSSI"); } @@ -162,6 +186,16 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { last_secs = secs; } } + + void reset() { + super.reset(); + last_secs = -1; + } + + void disable() { + value.setText(""); + } + public LastPacket(GridBagLayout layout, int x) { super (layout, x, "Age"); } @@ -169,6 +203,10 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay { LastPacket last_packet; + public void disable_receive() { + last_packet.disable(); + } + public void reset () { call.reset(); serial.reset(); -- cgit v1.2.3