Merge branch 'buttonbox' into sitemap
authorAnthony Towns <aj@erisian.com.au>
Sun, 21 Nov 2010 00:45:15 +0000 (10:45 +1000)
committerAnthony Towns <aj@erisian.com.au>
Sun, 21 Nov 2010 00:45:15 +0000 (10:45 +1000)
Conflicts:
ao-tools/altosui/AltosFlightUI.java

1  2 
ao-tools/altosui/AltosFlightUI.java
ao-tools/altosui/AltosInfoTable.java

index c85fc9776259a150d5eabd8f1ed4ea46de08bb7e,d5bcdb104d8f63a00224259155fe6fc67cf8a046..1107d52725a62125d46c1c1940d73f908747d69a
@@@ -42,10 -42,8 +42,9 @@@ public class AltosFlightUI extends JFra
        AltosAscent     ascent;
        AltosDescent    descent;
        AltosLanded     landed;
-     AltosSiteMap    sitemap;
++      AltosSiteMap    sitemap;
  
        private AltosFlightStatus flightStatus;
-       private JScrollPane flightInfoPane;
        private AltosInfoTable flightInfo;
  
        static final int tab_pad = 1;
                return tab_landed;
        }
  
-       public int width() {
-               return flightInfo.width();
-       }
-       public int height() {
-               return flightStatus.height() + flightInfo.height();
-       }
        void stop_display() {
                if (thread != null && thread.isAlive()) {
                        thread.interrupt();
@@@ -95,7 -85,6 +86,7 @@@
                descent.reset();
                landed.reset();
                flightInfo.clear();
 +              sitemap.reset();
        }
  
        public void show(AltosState state, int crc_errors) {
                }
                flightStatus.show(state, crc_errors);
                flightInfo.show(state, crc_errors);
 +              sitemap.show(state, crc_errors);
        }
  
        public void set_exit_on_close() {
  
                setTitle(String.format("AltOS %s", reader.name));
  
+               /* Stick channel selector at top of table for telemetry monitoring */
                if (serial >= 0) {
                        // Channel menu
                        channels = new AltosChannelMenu(AltosPreferences.channel(serial));
                        channels.addActionListener(new ActionListener() {
--                                      public void actionPerformed(ActionEvent e) {
--                                              int channel = channels.getSelectedIndex();
--                                              reader.set_channel(channel);
--                                              AltosPreferences.set_channel(serial, channel);
--                                      }
--                              });
++                              public void actionPerformed(ActionEvent e) {
++                                      int channel = channels.getSelectedIndex();
++                                      reader.set_channel(channel);
++                                      AltosPreferences.set_channel(serial, channel);
++                              }
++                      });
                        c.gridx = 0;
                        c.gridy = 0;
                        c.anchor = GridBagConstraints.WEST;
                        bag.add (channels, c);
                }
  
+               /* Flight status is always visible */
                flightStatus = new AltosFlightStatus();
                c.gridx = 0;
                c.gridy = 1;
                c.weightx = 1;
                bag.add(flightStatus, c);
  
+               /* The rest of the window uses a tabbed pane to
+                * show one of the alternate data views
+                */
                pane = new JTabbedPane();
  
                pad = new AltosPad();
                pane.add("Landed", landed);
  
                flightInfo = new AltosInfoTable();
-               flightInfoPane = new JScrollPane(flightInfo.box());
-               pane.add("Table", flightInfoPane);
+               pane.add("Table", new JScrollPane(flightInfo));
  
-         sitemap = new AltosSiteMap();
-         pane.add("Site Map", sitemap);
++              sitemap = new AltosSiteMap();
++              pane.add("Site Map", sitemap);
 +
+               /* Make the tabbed pane use the rest of the window space */
                c.gridx = 0;
                c.gridy = 2;
                c.fill = GridBagConstraints.BOTH;
                c.weighty = 1;
                bag.add(pane, c);
  
-               this.setSize(this.getPreferredSize());
-               this.validate();
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                addWindowListener(new WindowAdapter() {
                        @Override
                        }
                });
  
-               this.setVisible(true);
+               pack();
+               setVisible(true);
  
                thread = new AltosDisplayThread(this, voice, this, reader);
  
index 9f2bef5be6e3712230291fc43e6b4f15313e210d,c571d5c901be7a2d32ad99d01847f25aa3d99ce2..723f830169f6722298a593cf6ce8f8972bae850b
@@@ -28,70 -28,44 +28,44 @@@ import java.text.*
  import java.util.prefs.*;
  import java.util.concurrent.LinkedBlockingQueue;
  
- public class AltosInfoTable {
-       private Box                       box;
-       private JTable                    table[];
-       private AltosFlightInfoTableModel model[];
-       private Box                       ibox[];
+ public class AltosInfoTable extends JTable {
+       private AltosFlightInfoTableModel model;
  
 -      private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 12);
 -      private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 12);
 +      private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14);
 +      private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14);
  
        static final int info_columns = 3;
        static final int info_rows = 17;
  
-       public AltosInfoTable() {
-               box = Box.createHorizontalBox();
-               model = new AltosFlightInfoTableModel[info_columns];
-               table = new JTable[info_columns];
-               ibox = new Box[info_columns];
-               for (int i = 0; i < info_columns; i++) {
-                       model[i] = new AltosFlightInfoTableModel();
-                       table[i] = new JTable(model[i]);
-                       ibox[i] = box.createVerticalBox();
-                       table[i].setFont(infoValueFont);
-                       table[i].setRowHeight(rowHeight());
-                       table[i].setShowGrid(true);
-                       ibox[i].add(table[i].getTableHeader());
-                       ibox[i].add(table[i]);
-                       box.add(ibox[i]);
-               }
-       }
-       public int rowHeight() {
-               FontMetrics     infoValueMetrics = table[0].getFontMetrics(infoValueFont);
-               return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 20 / 10;
-       }
-       public int columnWidth() {
-               FontMetrics     infoValueMetrics = table[0].getFontMetrics(infoValueFont);
-               return infoValueMetrics.charWidth('0') * 20 * 2;
-       }
-       public int height() {
-               return rowHeight() * info_rows;
+       int desired_row_height() {
+               FontMetrics     infoValueMetrics = getFontMetrics(infoValueFont);
+               return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
        }
  
-       public int width() {
-               return columnWidth() * info_columns;
+       public AltosInfoTable() {
+               super(new AltosFlightInfoTableModel(info_rows, info_columns));
+               model = (AltosFlightInfoTableModel) getModel();
+               setFont(infoValueFont);
+               setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
+               setShowGrid(true);
+               setRowHeight(desired_row_height());
+               doLayout();
        }
  
-       public Box box() {
-               return box;
+       public Dimension getPreferredScrollableViewportSize() {
+               return getPreferredSize();
        }
  
        void info_reset() {
-               for (int i = 0; i < info_columns; i++)
-                       model[i].resetRow();
+               model.reset();
        }
  
        void info_add_row(int col, String name, String value) {
-               model[col].addRow(name, value);
+               model.addRow(col, name, value);
        }
  
        void info_add_row(int col, String name, String format, Object... parameters) {
-               model[col].addRow(name, String.format(format, parameters));
+               info_add_row (col, name, String.format(format, parameters));
        }
  
        void info_add_deg(int col, String name, double v, int pos, int neg) {
                double  deg = Math.floor(v);
                double  min = (v - deg) * 60;
  
-               model[col].addRow(name, String.format("%3.0f°%08.5f'", deg, min));
+               info_add_row(col, name, String.format("%3.0f°%08.5f'", deg, min));
        }
  
        void info_finish() {
-               for (int i = 0; i < info_columns; i++)
-                       model[i].finish();
+               model.finish();
        }
  
        public void clear() {
-               info_reset();
-               info_finish();
+               model.clear();
        }
  
        public void show(AltosState state, int crc_errors) {