altosui: Create abstract interface for flight data display
authorKeith Packard <keithp@keithp.com>
Tue, 9 Nov 2010 18:21:34 +0000 (10:21 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Nov 2010 18:21:34 +0000 (10:21 -0800)
This allows the implementation of the flight data display to occur in
the flight UI instead of the display thread.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosDisplayThread.java
ao-tools/altosui/AltosFlightDisplay.java [new file with mode: 0644]
ao-tools/altosui/AltosFlightUI.java
ao-tools/altosui/Makefile.am

index b15472e..957ac0d 100644 (file)
@@ -36,8 +36,7 @@ public class AltosDisplayThread extends Thread {
        String                  name;
        AltosFlightReader       reader;
        int                     crc_errors;
-       AltosStatusTable        flightStatus;
-       AltosInfoTable          flightInfo;
+       AltosFlightDisplay      display;
 
        class IdleThread extends Thread {
 
@@ -182,10 +181,8 @@ public class AltosDisplayThread extends Thread {
        }
 
        void show(AltosState state, int crc_errors) {
-               if (state != null) {
-                       flightStatus.set(state);
-                       flightInfo.show(state, crc_errors);
-               }
+               if (state != null)
+                       display.show(state, crc_errors);
        }
 
        public void run() {
@@ -197,7 +194,7 @@ public class AltosDisplayThread extends Thread {
 
                idle_thread = new IdleThread();
 
-               flightInfo.clear();
+               display.reset();
                try {
                        for (;;) {
                                try {
@@ -235,11 +232,10 @@ public class AltosDisplayThread extends Thread {
                }
        }
 
-       public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosStatusTable in_status, AltosInfoTable in_info, AltosFlightReader in_reader) {
+       public AltosDisplayThread(Frame in_parent, AltosVoice in_voice, AltosFlightDisplay in_display, AltosFlightReader in_reader) {
                parent = in_parent;
                voice = in_voice;
-               flightStatus = in_status;
-               flightInfo = in_info;
+               display = in_display;
                reader = in_reader;
        }
 }
diff --git a/ao-tools/altosui/AltosFlightDisplay.java b/ao-tools/altosui/AltosFlightDisplay.java
new file mode 100644 (file)
index 0000000..d18d1d1
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public interface AltosFlightDisplay {
+       void reset();
+
+       void show(AltosState state, int crc_errors);
+}
index 84ba9dc..11fc244 100644 (file)
@@ -28,7 +28,7 @@ import java.text.*;
 import java.util.prefs.*;
 import java.util.concurrent.LinkedBlockingQueue;
 
-public class AltosFlightUI extends JFrame {
+public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
        String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" };
        Object[][] statusData = { { "0", "pad", "-50", "0" } };
 
@@ -62,6 +62,15 @@ public class AltosFlightUI extends JFrame {
                stop_display();
        }
 
+       public void reset() {
+               flightInfo.clear();
+       }
+
+       public void show(AltosState state, int crc_errors) {
+               flightStatus.set(state);
+               flightInfo.show(state, crc_errors);
+       }
+
        public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
                voice = in_voice;
                reader = in_reader;
@@ -117,7 +126,7 @@ public class AltosFlightUI extends JFrame {
 
                this.setVisible(true);
 
-               thread = new AltosDisplayThread(this, voice, flightStatus, flightInfo, reader);
+               thread = new AltosDisplayThread(this, voice, this, reader);
 
                thread.start();
        }
index 2322b93..ccb88ed 100644 (file)
@@ -28,6 +28,7 @@ altosui_JAVA = \
        AltosFile.java \
        AltosFlash.java \
        AltosFlashUI.java \
+       AltosFlightDisplay.java \
        AltosFlightInfoTableModel.java \
        AltosFlightReader.java \
        AltosFlightStatusTableModel.java \