From 6529fd623f0e4b921aea1110c723d7dc03954def Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 18 Jun 2019 14:50:18 -0700 Subject: [PATCH] altosui/telegps: Display error message when attempting to graph unknown files Instead of presenting an empty graph window. Signed-off-by: Keith Packard --- altoslib/AltosEepromFile.java | 4 +++ altoslib/AltosEepromRecordSet.java | 8 ++++++ altoslib/AltosRecordSet.java | 1 + altoslib/AltosTelemetryFile.java | 4 +++ altosui/AltosUI.java | 45 +++++++++++++++++------------- telegps/TeleGPS.java | 31 ++++++++++---------- 6 files changed, 57 insertions(+), 36 deletions(-) diff --git a/altoslib/AltosEepromFile.java b/altoslib/AltosEepromFile.java index 839f0aa0..328a0fab 100644 --- a/altoslib/AltosEepromFile.java +++ b/altoslib/AltosEepromFile.java @@ -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); } diff --git a/altoslib/AltosEepromRecordSet.java b/altoslib/AltosEepromRecordSet.java index aec302e8..26b9e682 100644 --- a/altoslib/AltosEepromRecordSet.java +++ b/altoslib/AltosEepromRecordSet.java @@ -21,6 +21,7 @@ public class AltosEepromRecordSet implements AltosRecordSet { AltosEeprom eeprom; TreeSet 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; diff --git a/altoslib/AltosRecordSet.java b/altoslib/AltosRecordSet.java index a84cc3f9..4c459cba 100644 --- a/altoslib/AltosRecordSet.java +++ b/altoslib/AltosRecordSet.java @@ -19,4 +19,5 @@ import java.util.*; public interface AltosRecordSet { public AltosCalData cal_data(); public void capture_series(AltosDataListener listener); + public boolean valid(); } diff --git a/altoslib/AltosTelemetryFile.java b/altoslib/AltosTelemetryFile.java index 679c6809..01d82c24 100644 --- a/altoslib/AltosTelemetryFile.java +++ b/altoslib/AltosTelemetryFile.java @@ -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(); diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 82ec4746..56e46436 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -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: diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 24cc379f..af6d01b4 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -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) -- 2.30.2