altosui: Replace flight status table with labels, fix resize.
authorKeith Packard <keithp@keithp.com>
Sun, 14 Nov 2010 01:09:51 +0000 (17:09 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 14 Nov 2010 01:09:51 +0000 (17:09 -0800)
There's no reason to use a table for the flight status data,
replace that with a selection of widgets instead.

Also, set all of the grid bag constraints for the various flight
status displays so that resize does something sensible.

Adds a scrollbar to the table display so that it can shrink.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosAscent.java
ao-tools/altosui/AltosDescent.java
ao-tools/altosui/AltosFlightStatus.java [new file with mode: 0644]
ao-tools/altosui/AltosFlightUI.java
ao-tools/altosui/AltosLanded.java
ao-tools/altosui/AltosPad.java
ao-tools/altosui/AltosStatusTable.java [deleted file]
ao-tools/altosui/Makefile.am

index 51fa1a89d0f0a3b3ad315f2d62f1274c4671887b..7525b655e43f770acad3aafde74cebb844ad5d61 100644 (file)
@@ -43,6 +43,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                }
                public AscentValue (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
+                       c.weighty = 1;
 
                        label = new JLabel(text);
                        label.setFont(label_font);
@@ -50,6 +51,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        c.gridx = 0; c.gridy = y;
                        c.insets = new Insets(10, 10, 10, 10);
                        c.anchor = GridBagConstraints.WEST;
+                       c.fill = GridBagConstraints.VERTICAL;
+                       c.weightx = 0;
                        layout.setConstraints(label, c);
                        add(label);
 
@@ -58,8 +61,9 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        value.setHorizontalAlignment(SwingConstants.RIGHT);
                        c.gridx = 1; c.gridy = y;
                        c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.HORIZONTAL;
+                       c.fill = GridBagConstraints.BOTH;
                        c.gridwidth = 2;
+                       c.weightx = 1;
                        layout.setConstraints(value, c);
                        add(value);
                }
@@ -88,6 +92,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                }
                public AscentValueHold (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
+                       c.weighty = 1;
 
                        label = new JLabel(text);
                        label.setFont(label_font);
@@ -95,6 +100,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        c.gridx = 0; c.gridy = y;
                        c.insets = new Insets(10, 10, 10, 10);
                        c.anchor = GridBagConstraints.WEST;
+                       c.fill = GridBagConstraints.VERTICAL;
+                       c.weightx = 0;
                        layout.setConstraints(label, c);
                        add(label);
 
@@ -103,6 +110,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        value.setHorizontalAlignment(SwingConstants.RIGHT);
                        c.gridx = 1; c.gridy = y;
                        c.anchor = GridBagConstraints.EAST;
+                       c.fill = GridBagConstraints.BOTH;
+                       c.weightx = 1;
                        layout.setConstraints(value, c);
                        add(value);
 
@@ -111,6 +120,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        max_value.setHorizontalAlignment(SwingConstants.RIGHT);
                        c.gridx = 2; c.gridy = y;
                        c.anchor = GridBagConstraints.EAST;
+                       c.fill = GridBagConstraints.BOTH;
+                       c.weightx = 1;
                        layout.setConstraints(max_value, c);
                        add(max_value);
                }
index 56d3e4feeee45db70cd9dbd10d786f44ca5088a4..b69e36b676440cdfd9afd74ce04436048f384306 100644 (file)
@@ -48,6 +48,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
                public DescentValue (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
+                       c.weighty = 1;
 
                        label = new JLabel(text);
                        label.setFont(label_font);
@@ -55,6 +56,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        c.gridx = 0; c.gridy = y;
                        c.insets = new Insets(10, 10, 10, 10);
                        c.anchor = GridBagConstraints.WEST;
+                       c.fill = GridBagConstraints.VERTICAL;
+                       c.weightx = 0;
                        layout.setConstraints(label, c);
                        add(label);
 
@@ -64,7 +67,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        c.gridx = 1; c.gridy = y;
                        c.gridwidth = 2;
                        c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.HORIZONTAL;
+                       c.fill = GridBagConstraints.BOTH;
+                       c.weightx = 1;
                        layout.setConstraints(value, c);
                        add(value);
                }
@@ -138,50 +142,54 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                JLabel          label;
                JTextField      value;
                JTextField      value_deg;
-        void reset () {
+               void reset () {
                        value.setText("");
                        value_deg.setText("");
-        }
+               }
                void show (AltosState state, int crc_errors) {
                        if (state.from_pad != null) {
-                value.setText(state.from_pad.bearing_words(
-                                AltosGreatCircle.BEARING_LONG));
+                               value.setText(state.from_pad.bearing_words(
+                                                     AltosGreatCircle.BEARING_LONG));
                                value_deg.setText(String.format("%3.0f°", state.from_pad.bearing));
                        } else {
                                value.setText("???");
                                value_deg.setText("???");
-            }
+                       }
                }
                public Bearing (GridBagLayout layout, int y) {
-            GridBagConstraints      c = new GridBagConstraints();
-
-            label = new JLabel("Bearing");
-            label.setFont(label_font);
-            label.setHorizontalAlignment(SwingConstants.LEFT);
-            c.gridx = 0; c.gridy = y;
-            c.insets = new Insets(10, 10, 10, 10);
-            c.anchor = GridBagConstraints.WEST;
-            layout.setConstraints(label, c);
-            add(label);
-
-            value = new JTextField(30);
-            value.setFont(value_font);
-            value.setHorizontalAlignment(SwingConstants.RIGHT);
-            c.gridx = 1; c.gridy = y;
-            c.anchor = GridBagConstraints.EAST;
-            c.fill = GridBagConstraints.HORIZONTAL;
-            layout.setConstraints(value, c);
-            add(value);
-
-            value_deg = new JTextField(5);
-            value_deg.setFont(value_font);
-            value_deg.setHorizontalAlignment(SwingConstants.RIGHT);
-            c.gridx = 2; c.gridy = y;
-            c.anchor = GridBagConstraints.EAST;
-            c.fill = GridBagConstraints.HORIZONTAL;
-
-            layout.setConstraints(value_deg, c);
-            add(value_deg);
+                       GridBagConstraints      c = new GridBagConstraints();
+                       c.weighty = 1;
+
+                       label = new JLabel("Bearing");
+                       label.setFont(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(30);
+                       value.setFont(value_font);
+                       value.setHorizontalAlignment(SwingConstants.RIGHT);
+                       c.gridx = 1; c.gridy = y;
+                       c.anchor = GridBagConstraints.EAST;
+                       c.weightx = 1;
+                       c.fill = GridBagConstraints.BOTH;
+                       layout.setConstraints(value, c);
+                       add(value);
+
+                       value_deg = new JTextField(5);
+                       value_deg.setFont(value_font);
+                       value_deg.setHorizontalAlignment(SwingConstants.RIGHT);
+                       c.gridx = 2; c.gridy = y;
+                       c.anchor = GridBagConstraints.EAST;
+                       c.weightx = 1;
+                       c.fill = GridBagConstraints.BOTH;
+                       layout.setConstraints(value_deg, c);
+                       add(value_deg);
                }
        }
 
diff --git a/ao-tools/altosui/AltosFlightStatus.java b/ao-tools/altosui/AltosFlightStatus.java
new file mode 100644 (file)
index 0000000..b99a532
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ *
+ * 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 java.awt.event.*;
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.table.*;
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+import java.util.concurrent.LinkedBlockingQueue;
+
+public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
+       GridBagLayout   layout;
+
+       private Font status_font;
+
+       public class FlightValue {
+               JLabel          label;
+               JTextField      value;
+
+               void show(AltosState state, int crc_errors) {}
+
+               void reset() {
+                       value.setText("");
+               }
+               public FlightValue (GridBagLayout layout, int x, String text) {
+                       GridBagConstraints      c = new GridBagConstraints();
+                       c.insets = new Insets(5, 5, 5, 5);
+                       c.anchor = GridBagConstraints.CENTER;
+                       c.fill = GridBagConstraints.BOTH;
+                       c.weightx = 1;
+                       c.weighty = 1;
+
+                       label = new JLabel(text);
+                       label.setFont(status_font);
+                       label.setHorizontalAlignment(SwingConstants.CENTER);
+                       c.gridx = x; c.gridy = 0;
+                       layout.setConstraints(label, c);
+                       add(label);
+
+                       value = new JTextField("");
+                       value.setFont(status_font);
+                       value.setHorizontalAlignment(SwingConstants.CENTER);
+                       c.gridx = x; c.gridy = 1;
+                       layout.setConstraints(value, c);
+                       add(value);
+               }
+       }
+
+       class Call extends FlightValue {
+               void show(AltosState state, int crc_errors) {
+                       value.setText(state.data.callsign);
+               }
+               public Call (GridBagLayout layout, int x) {
+                       super (layout, x, "Callsign");
+               }
+       }
+
+       Call call;
+
+       class Serial extends FlightValue {
+               void show(AltosState state, int crc_errors) {
+                       value.setText(String.format("%d", state.data.serial));
+               }
+               public Serial (GridBagLayout layout, int x) {
+                       super (layout, x, "Serial");
+               }
+       }
+
+       Serial serial;
+
+       class Flight extends FlightValue {
+               void show(AltosState state, int crc_errors) {
+                       value.setText(String.format("%d", state.data.flight));
+               }
+               public Flight (GridBagLayout layout, int x) {
+                       super (layout, x, "Flight");
+               }
+       }
+
+       Flight flight;
+
+       class FlightState extends FlightValue {
+               void show(AltosState state, int crc_errors) {
+                       value.setText(state.data.state());
+               }
+               public FlightState (GridBagLayout layout, int x) {
+                       super (layout, x, "State");
+               }
+       }
+
+       FlightState flight_state;
+
+       class RSSI extends FlightValue {
+               void show(AltosState state, int crc_errors) {
+                       value.setText(String.format("%d", state.data.rssi));
+               }
+               public RSSI (GridBagLayout layout, int x) {
+                       super (layout, x, "RSSI (dBm)");
+               }
+       }
+
+       RSSI rssi;
+
+       public void reset () {
+               call.reset();
+               serial.reset();
+               flight.reset();
+               flight_state.reset();
+               rssi.reset();
+       }
+
+       public void show (AltosState state, int crc_errors) {
+               call.show(state, crc_errors);
+               serial.show(state, crc_errors);
+               flight.show(state, crc_errors);
+               flight_state.show(state, crc_errors);
+               rssi.show(state, crc_errors);
+       }
+
+       public int height() {
+               Dimension d = layout.preferredLayoutSize(this);
+               return d.height;
+       }
+
+       public AltosFlightStatus() {
+               layout = new GridBagLayout();
+
+               status_font = new Font("SansSerif", Font.BOLD, 24);
+               setLayout(layout);
+
+               call = new Call(layout, 0);
+               serial = new Serial(layout, 1);
+               flight = new Flight(layout, 2);
+               flight_state = new FlightState(layout, 3);
+               rssi = new RSSI(layout, 4);
+       }
+}
index 3581c54c1ce8a6b14c5135ecb1839b656bc05ec6..ae31048d2648754573d879cb863a65714f214204 100644 (file)
@@ -45,7 +45,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
        AltosDescent    descent;
        AltosLanded     landed;
 
-       private AltosStatusTable flightStatus;
+       private AltosFlightStatus flightStatus;
+       private JScrollPane flightInfoPane;
        private AltosInfoTable flightInfo;
 
        static final int tab_pad = 1;
@@ -117,7 +118,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                        }
                        cur_tab = tab;
                }
-               flightStatus.set(state);
+               flightStatus.show(state, crc_errors);
                flightInfo.show(state, crc_errors);
        }
 
@@ -133,7 +134,7 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
 
                setTitle(String.format("AltOS %s", reader.name));
 
-               flightStatus = new AltosStatusTable();
+               flightStatus = new AltosFlightStatus();
 
                vbox = new Box (BoxLayout.Y_AXIS);
                vbox.add(flightStatus);
@@ -153,7 +154,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                pane.add("Landed", landed);
 
                flightInfo = new AltosInfoTable();
-               pane.add("Table", flightInfo.box());
+               flightInfoPane = new JScrollPane(flightInfo.box());
+               pane.add("Table", flightInfoPane);
 
                vbox.add(pane);
 
index d170ccad4574d11962b1e2c77dcee52ea3c9d28d..465c9dcea8ffc8ee7972397f54f2f6e6715502c2 100644 (file)
@@ -48,6 +48,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay {
 
                public LandedValue (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
+                       c.weighty = 1;
 
                        label = new JLabel(text);
                        label.setFont(label_font);
@@ -55,6 +56,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay {
                        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);
 
@@ -63,7 +66,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay {
                        value.setHorizontalAlignment(SwingConstants.RIGHT);
                        c.gridx = 1; c.gridy = y;
                        c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.HORIZONTAL;
+                       c.weightx = 1;
+                       c.fill = GridBagConstraints.BOTH;
                        layout.setConstraints(value, c);
                        add(value);
                }
index da047072dd5d0ca52e29859b234e9ab76978f185..650ed01238fc0a7caac9a8f0893f942a67d1514b 100644 (file)
@@ -46,11 +46,13 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
                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.CENTER;
+                       c.fill = GridBagConstraints.VERTICAL;
+                       c.weightx = 0;
                        layout.setConstraints(lights, c);
                        add(lights);
 
@@ -60,7 +62,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        c.gridx = 1; c.gridy = y;
                        c.insets = new Insets(10, 10, 10, 10);
                        c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.WEST;
+                       c.fill = GridBagConstraints.VERTICAL;
+                       c.weightx = 0;
                        layout.setConstraints(label, c);
                        add(label);
 
@@ -69,6 +72,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        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);
 
@@ -85,13 +90,16 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                }
                public LaunchValue (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
+                       c.insets = new Insets(10, 10, 10, 10);
+                       c.weighty = 1;
 
                        label = new JLabel(text);
                        label.setFont(label_font);
                        label.setHorizontalAlignment(SwingConstants.LEFT);
                        c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(10, 10, 10, 10);
                        c.anchor = GridBagConstraints.WEST;
+                       c.fill = GridBagConstraints.VERTICAL;
+                       c.weightx = 0;
                        layout.setConstraints(label, c);
                        add(label);
 
@@ -100,7 +108,8 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        value.setHorizontalAlignment(SwingConstants.RIGHT);
                        c.gridx = 2; c.gridy = y;
                        c.anchor = GridBagConstraints.EAST;
-                       c.fill = GridBagConstraints.HORIZONTAL;
+                       c.fill = GridBagConstraints.BOTH;
+                       c.weightx = 1;
                        layout.setConstraints(value, c);
                        add(value);
                }
@@ -221,13 +230,10 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
        public AltosPad() {
                layout = new GridBagLayout();
 
-               GridBagConstraints      c;
-
                label_font = new Font("Dialog", Font.PLAIN, 24);
                value_font = new Font("Monospaced", Font.PLAIN, 24);
                setLayout(layout);
 
-               c = new GridBagConstraints();
                /* Elements in pad display:
                 *
                 * Battery voltage
diff --git a/ao-tools/altosui/AltosStatusTable.java b/ao-tools/altosui/AltosStatusTable.java
deleted file mode 100644 (file)
index 02c6232..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright © 2010 Keith Packard <keithp@keithp.com>
- *
- * 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 java.awt.event.*;
-import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import javax.swing.table.*;
-import java.io.*;
-import java.util.*;
-import java.text.*;
-import java.util.prefs.*;
-import java.util.concurrent.LinkedBlockingQueue;
-
-public class AltosStatusTable extends JTable {
-       private AltosFlightStatusTableModel flightStatusModel;
-
-       private Font statusFont = new Font("SansSerif", Font.BOLD, 24);
-
-       public AltosStatusTable() {
-               super((TableModel) new AltosFlightStatusTableModel());
-               flightStatusModel = (AltosFlightStatusTableModel) getModel();
-
-               setFont(statusFont);
-
-               TableColumnModel tcm = getColumnModel();
-
-               for (int i = 0; i < flightStatusModel.getColumnCount(); i++) {
-                       DefaultTableCellRenderer       r = new DefaultTableCellRenderer();
-                       r.setFont(statusFont);
-                       r.setHorizontalAlignment(SwingConstants.CENTER);
-                       tcm.getColumn(i).setCellRenderer(r);
-               }
-
-               setRowHeight(rowHeight());
-               setShowGrid(false);
-       }
-
-       public int rowHeight() {
-               FontMetrics     statusMetrics = getFontMetrics(statusFont);
-               return (statusMetrics.getHeight() + statusMetrics.getLeading()) * 15 / 10;
-       }
-
-       public int height() {
-               return rowHeight * 4;
-       }
-
-       public void set(AltosState state) {
-               flightStatusModel.set(state);
-       }
-}
index f4c743dfa8158aca9e72b6f0bbbd077462cb7a5a..d11ea3e29e770d514ff0af75b28314865f006e1d 100644 (file)
@@ -33,7 +33,7 @@ altosui_JAVA = \
        AltosFlightDisplay.java \
        AltosFlightInfoTableModel.java \
        AltosFlightReader.java \
-       AltosFlightStatusTableModel.java \
+       AltosFlightStatus.java \
        AltosFlightUI.java \
        AltosGPS.java \
        AltosGreatCircle.java \
@@ -61,7 +61,6 @@ altosui_JAVA = \
        AltosSerialInUseException.java \
        AltosSerialMonitor.java \
        AltosState.java \
-       AltosStatusTable.java \
        AltosTelemetry.java \
        AltosTelemetryIterable.java \
        AltosUI.java \