altosui/telegps: Display error message when attempting to graph unknown files
authorKeith Packard <keithp@keithp.com>
Tue, 18 Jun 2019 21:50:18 +0000 (14:50 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 18 Jun 2019 21:50:18 +0000 (14:50 -0700)
Instead of presenting an empty graph window.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosEepromFile.java
altoslib/AltosEepromRecordSet.java
altoslib/AltosRecordSet.java
altoslib/AltosTelemetryFile.java
altosui/AltosUI.java
telegps/TeleGPS.java

index 839f0aa..328a0fa 100644 (file)
@@ -45,6 +45,10 @@ public class AltosEepromFile implements AltosRecordSet {
                return set.cal_data();
        }
 
+       public boolean valid() {
+               return set.valid();
+       }
+
        public void capture_series(AltosDataListener series) {
                set.capture_series(series);
        }
index aec302e..26b9e68 100644 (file)
@@ -21,6 +21,7 @@ public class AltosEepromRecordSet implements AltosRecordSet {
        AltosEeprom                     eeprom;
        TreeSet<AltosEepromRecord>      ordered;
        AltosCalData                    cal_data;
+       boolean                         valid;
 
        public AltosConfigData config_data() {
                return eeprom.config_data();
@@ -52,6 +53,10 @@ public class AltosEepromRecordSet implements AltosRecordSet {
                listener.finish();
        }
 
+       public boolean valid() {
+               return valid;
+       }
+
        public AltosEepromRecordSet(AltosEeprom eeprom) {
                this.eeprom = eeprom;
 
@@ -95,8 +100,11 @@ public class AltosEepromRecordSet implements AltosRecordSet {
 
                if (record == null) {
                        System.out.printf("failed to parse log format %d\n", config_data.log_format);
+                       valid = false;
                        return;
                }
+               valid = true;
+
                int     tick = 0;
                boolean first = true;
 
index a84cc3f..4c459cb 100644 (file)
@@ -19,4 +19,5 @@ import java.util.*;
 public interface AltosRecordSet {
        public AltosCalData cal_data();
        public void capture_series(AltosDataListener listener);
+       public boolean valid();
 }
index 679c680..01d82c2 100644 (file)
@@ -117,6 +117,10 @@ public class AltosTelemetryFile implements AltosRecordSet {
                return cal_data;
        }
 
+       public boolean valid() {
+               return true;
+       }
+
        public void capture_series(AltosDataListener listener) {
                AltosCalData    cal_data = cal_data();
 
index 82ec474..56e4643 100644 (file)
@@ -102,7 +102,7 @@ public class AltosUI extends AltosUIFrame implements AltosEepromGrapher {
 
        /* OSXAdapter interfaces */
        public void macosx_file_handler(String path) {
-               process_graph(new File(path));
+               process_graph(null, new File(path));
        }
 
        public void macosx_quit_handler() {
@@ -324,7 +324,7 @@ public class AltosUI extends AltosUIFrame implements AltosEepromGrapher {
        public void graph_flights(AltosEepromList flights) {
                for (AltosEepromLog flight : flights) {
                        if (flight.graph_selected && flight.file != null) {
-                               process_graph(flight.file);
+                               process_graph(this, flight.file);
                        }
                }
        }
@@ -354,6 +354,25 @@ public class AltosUI extends AltosUIFrame implements AltosEepromGrapher {
                new AltosCSVUI(AltosUI.this, series, chooser.file());
        }
 
+       private static boolean graph_file(AltosUI altosui, AltosRecordSet set, File file) {
+               if (set == null)
+                       return false;
+               if (!set.valid()) {
+                       JOptionPane.showMessageDialog(altosui,
+                                                     String.format("Failed to parse file %s", file),
+                                                     "Graph Failed",
+                                                     JOptionPane.ERROR_MESSAGE);
+                       return false;
+               }
+               try {
+                       new AltosGraphUI(set, file);
+                       return true;
+               } catch (InterruptedException ie) {
+               } catch (IOException ie) {
+               }
+               return false;
+       }
+
        /* Load a flight log CSV file and display a pretty graph.
         */
 
@@ -361,13 +380,7 @@ public class AltosUI extends AltosUIFrame implements AltosEepromGrapher {
                AltosDataChooser chooser;
                chooser = new AltosDataChooser(this);
                AltosRecordSet set = chooser.runDialog();
-               if (set == null)
-                       return;
-               try {
-                       new AltosGraphUI(set, chooser.file());
-               } catch (InterruptedException ie) {
-               } catch (IOException ie) {
-               }
+               graph_file(this, set, chooser.file());
        }
 
        private void ConfigureAltosUI() {
@@ -477,17 +490,9 @@ public class AltosUI extends AltosUIFrame implements AltosEepromGrapher {
                return true;
        }
 
-       static boolean process_graph(File file) {
+       static boolean process_graph(AltosUI altosui, File file) {
                AltosRecordSet set = record_set(file);
-               if (set == null)
-                       return false;
-               try {
-                       new AltosGraphUI(set, file);
-                       return true;
-               } catch (InterruptedException ie) {
-               } catch (IOException ie) {
-               }
-               return false;
+               return graph_file(altosui, set, file);
        }
 
        static boolean process_summary(File file) {
@@ -613,7 +618,7 @@ public class AltosUI extends AltosUIFrame implements AltosEepromGrapher {
                                                if (altosui == null)
                                                        altosui = new AltosUI();
                                        case process_graph:
-                                               if (!process_graph(file))
+                                               if (!process_graph(null, file))
                                                        ++errors;
                                                break;
                                        case process_replay:
index 24cc379..af6d01b 100644 (file)
@@ -307,26 +307,14 @@ public class TeleGPS
        void graph() {
                AltosDataChooser chooser = new AltosDataChooser(this);
                AltosRecordSet set = chooser.runDialog();
-               if (set == null)
-                       return;
-               try {
-                       new TeleGPSGraphUI(set, chooser.file());
-               } catch (InterruptedException ie) {
-               } catch (IOException ie) {
-               }
+               graph_file(this, set, chooser.file());
        }
 
        public void graph_flights(AltosEepromList list) {
                for (AltosEepromLog log : list) {
                        if (log.file != null) {
                                AltosRecordSet set = record_set(log.file);
-                               if (set != null) {
-                                       try {
-                                               new TeleGPSGraphUI(set, log.file);
-                                       } catch (InterruptedException ie) {
-                                       } catch (IOException ie) {
-                                       }
-                               }
+                               graph_file(this, set, log.file);
                        }
                }
        }
@@ -650,10 +638,16 @@ public class TeleGPS
                return new AltosReplayReader(set, file);
        }
 
-       static boolean process_graph(File file) {
-               AltosRecordSet set = record_set(file);
+       private static boolean graph_file(TeleGPS telegps, AltosRecordSet set, File file) {
                if (set == null)
                        return false;
+               if (!set.valid()) {
+                       JOptionPane.showMessageDialog(telegps,
+                                                     String.format("Failed to parse file %s", file),
+                                                     "Graph Failed",
+                                                     JOptionPane.ERROR_MESSAGE);
+                       return false;
+               }
                try {
                        new TeleGPSGraphUI(set, file);
                } catch (Exception e) {
@@ -662,6 +656,11 @@ public class TeleGPS
                return true;
        }
 
+       static boolean process_graph(File file) {
+               AltosRecordSet set = record_set(file);
+               return graph_file(null, set, file);
+       }
+
        static boolean process_replay(File file) {
                AltosReplayReader new_reader = replay_file(file);
                if (new_reader == null)