altosui: Find actual landing time when computing stats (trac #23)
[fw/altos] / altosui / AltosUI.java
index 60adfc7c823a7d480f690ae983da296f73d26af1..89f66c0604521bf89e3de6c10d25586345bd2658 100644 (file)
@@ -30,7 +30,7 @@ import java.util.concurrent.*;
 
 import libaltosJNI.*;
 
-public class AltosUI extends JFrame {
+public class AltosUI extends AltosFrame {
        public AltosVoice voice = new AltosVoice();
 
        public static boolean load_library(Frame frame) {
@@ -52,8 +52,7 @@ public class AltosUI extends JFrame {
                                new AltosFlightUI(voice, reader, device.getSerial());
                } catch (FileNotFoundException ee) {
                        JOptionPane.showMessageDialog(AltosUI.this,
-                                                     String.format("Cannot open device \"%s\"",
-                                                                   device.toShortString()),
+                                                     ee.getMessage(),
                                                      "Cannot open target device",
                                                      JOptionPane.ERROR_MESSAGE);
                } catch (AltosSerialInUseException si) {
@@ -356,7 +355,7 @@ public class AltosUI extends JFrame {
                        else
                                return new AltosTelemetryIterable(in);
                } catch (FileNotFoundException fe) {
-                       System.out.printf("Cannot open '%s'\n", filename);
+                       System.out.printf("%s\n", fe.getMessage());
                        return null;
                }
        }
@@ -366,7 +365,7 @@ public class AltosUI extends JFrame {
                try {
                        return new AltosCSV(file);
                } catch (FileNotFoundException fe) {
-                       System.out.printf("Cannot open '%s'\n", filename);
+                       System.out.printf("%s\n", fe.getMessage());
                        return null;
                }
        }
@@ -376,7 +375,7 @@ public class AltosUI extends JFrame {
                try {
                        return new AltosKML(file);
                } catch (FileNotFoundException fe) {
-                       System.out.printf("Cannot open '%s'\n", filename);
+                       System.out.printf("%s\n", fe.getMessage());
                        return null;
                }
        }
@@ -424,17 +423,17 @@ public class AltosUI extends JFrame {
                }
        }
 
-       static AltosRecordIterable record_iterable_file(String filename) {
+       static AltosRecordIterable record_iterable(File file) {
                FileInputStream in;
                try {
-                       in = new FileInputStream(filename);
+                       in = new FileInputStream(file);
                } catch (Exception e) {
-                       System.out.printf("Failed to open file '%s'\n", filename);
+                       System.out.printf("Failed to open file '%s'\n", file);
                        return null;
                }
                AltosRecordIterable recs;
                AltosReplayReader reader;
-               if (filename.endsWith("eeprom")) {
+               if (file.getName().endsWith("eeprom")) {
                        recs = new AltosEepromIterable(in);
                } else {
                        recs = new AltosTelemetryIterable(in);
@@ -442,6 +441,10 @@ public class AltosUI extends JFrame {
                return recs;
        }
 
+       static AltosRecordIterable record_iterable_file(String filename) {
+               return record_iterable (new File(filename));
+       }
+
        static AltosReplayReader replay_file(String filename) {
                AltosRecordIterable recs = record_iterable_file(filename);
                if (recs == null)
@@ -467,9 +470,9 @@ public class AltosUI extends JFrame {
        }
        
        static void process_summary(String filename) {
-               AltosReplayReader reader = replay_file(filename);
+               AltosRecordIterable iterable = record_iterable_file(filename);
                try {
-                       AltosFlightStats stats = new AltosFlightStats(reader);
+                       AltosFlightStats stats = new AltosFlightStats(iterable);
                        if (stats.serial > 0)
                                System.out.printf("Serial:       %5d\n", stats.serial);
                        if (stats.flight > 0)
@@ -520,7 +523,7 @@ public class AltosUI extends JFrame {
        
        public static void main(final String[] args) {
                try {
-                       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                       UIManager.setLookAndFeel(AltosPreferences.look_and_feel());
                } catch (Exception e) {
                }
                /* Handle batch-mode */