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 839f0aa0dff23f35e591b68e1d308933c3452b2a..328a0fabf5f1f277c6e7bbecee2e303b409cd7a7 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 aec302e8072d939b17874ec321426bf2b87cb27c..26b9e682d08f771de68bc06c11a432f16a000f5c 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 a84cc3f9a5564a96cedde236d63a3612e3f76e97..4c459cba68cb3080963802c09e71df4ea4fe4d5a 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 679c6809559508a7b7c8719e8255b0d0ac00837a..01d82c242bd3ef7e1915269eee57ad1d40ac0db6 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 82ec47465f90a30477bd434daafe270ca7631b24..56e46436beaafccc2261cd3438852ce48a61bf74 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 24cc379fcec9a1879068d5154de8fcfc60c3c4fb..af6d01b427126c1071a3d4c95beee4d536011401 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)