X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=telegps%2FTeleGPS.java;h=7117443632dcfa9553a706be58dba74fefaef2a2;hp=7f34c763428b1cc750de4303620773e1a1398af7;hb=d550c3b3eccbb0283c588b5df69edb2e9b44b4cc;hpb=13f84be8d1568a3fc2ed5eef5dcc2093c149285e diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 7f34c763..71174436 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -26,7 +26,10 @@ import java.util.*; import org.altusmetrum.altoslib_4.*; import org.altusmetrum.altosuilib_2.*; -public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, ActionListener { +public class TeleGPS + extends AltosUIFrame + implements AltosFlightDisplay, AltosFontListener, AltosUnitsListener, ActionListener +{ static String[] telegps_icon_names = { "/telegps-16.png", @@ -50,16 +53,25 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo AltosFlightReader reader; AltosDisplayThread thread; - JTabbedPane pane; + JMenuBar menu_bar; - AltosSiteMap sitemap; - TeleGPSInfo gps_info; - boolean has_map; + JMenu file_menu; + JMenu monitor_menu; + JMenu device_menu; + AltosFreqList frequencies; + + Container bag; + + TeleGPSStatus telegps_status; + TeleGPSStatusUpdate status_update; + + JTabbedPane pane; - JMenuBar menu_bar; - JMenu file_menu; - JMenu monitor_menu; - JMenu device_menu; + AltosSiteMap sitemap; + TeleGPSInfo gps_info; + AltosInfoTable info_table; + + LinkedList displays; /* File menu */ final static String new_command = "new"; @@ -113,41 +125,39 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo } public void reset() { - sitemap.reset(); - gps_info.reset(); - } - - public void set_font() { - sitemap.set_font(); - gps_info.set_font(); + for (AltosFlightDisplay display : displays) + display.reset(); } public void font_size_changed(int font_size) { - set_font(); + for (AltosFlightDisplay display : displays) + display.font_size_changed(font_size); } - -// AltosFlightStatusUpdate status_update; + public void units_changed(boolean imperial_units) { + for (AltosFlightDisplay display : displays) + display.units_changed(imperial_units); + } public void show(AltosState state, AltosListenerState listener_state) { -// status_update.saved_state = state; + try { + status_update.saved_state = state; - if (state == null) - state = new AltosState(); + if (state == null) + state = new AltosState(); - sitemap.show(state, listener_state); - gps_info.show(state, listener_state); - telegps_status.show(state, listener_state); + int i = 0; + for (AltosFlightDisplay display : displays) { + display.show(state, listener_state); + i++; + } + } catch (Exception ex) { + System.out.printf("Exception %s\n", ex.toString()); + for (StackTraceElement e : ex.getStackTrace()) + System.out.printf("%s\n", e.toString()); + } } - Container bag; - AltosFreqList frequencies; - JLabel telemetry; - TeleGPSStatus telegps_status; - TeleGPSStatusUpdate status_update; - - ActionListener show_timer; - void new_window() { new TeleGPS(); } @@ -236,6 +246,16 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo } void graph() { + AltosDataChooser chooser; + chooser = new AltosDataChooser(this); + AltosStateIterable states = chooser.runDialog(); + if (states == null) + return; + try { + new TeleGPSGraphUI(states, chooser.file()); + } catch (InterruptedException ie) { + } catch (IOException ie) { + } } void flash() { @@ -335,13 +355,22 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo static int number_of_windows; + static public void add_window() { + ++number_of_windows; + } + + static public void subtract_window() { + --number_of_windows; + if (number_of_windows == 0) + System.exit(0); + } + private void close() { AltosUIPreferences.unregister_font_listener(this); + AltosPreferences.unregister_units_listener(this); setVisible(false); dispose(); - --number_of_windows; - if (number_of_windows == 0) - System.exit(0); + subtract_window(); } private void add_menu(JMenu menu, String label, String action) { @@ -379,6 +408,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo file_menu = make_menu("File", file_menu_entries); monitor_menu = make_menu("Monitor", monitor_menu_entries); device_menu = make_menu("Device", device_menu_entries); + displays = new LinkedList(); int serial = -1; @@ -391,6 +421,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo c.gridwidth = 2; bag.add(telegps_status, c); c.gridwidth = 1; + displays.add(telegps_status); /* The rest of the window uses a tabbed pane to @@ -409,13 +440,20 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo sitemap = new AltosSiteMap(); pane.add("Site Map", sitemap); + displays.add(sitemap); gps_info = new TeleGPSInfo(); pane.add("Info", gps_info); + displays.add(gps_info); + + info_table = new AltosInfoTable(); + pane.add("Table", info_table); + displays.add(info_table); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); AltosUIPreferences.register_font_listener(this); + AltosPreferences.register_units_listener(this); addWindowListener(new WindowAdapter() { @Override @@ -427,7 +465,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo pack(); setVisible(true); - ++number_of_windows; + add_window(); status_update = new TeleGPSStatusUpdate(telegps_status); @@ -465,6 +503,18 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo return new AltosReplayReader(states.iterator(), file); } + static boolean process_graph(File file) { + AltosStateIterable states = record_iterable(file); + if (states == null) + return false; + try { + new TeleGPSGraphUI(states, file); + } catch (Exception e) { + return false; + } + return true; + } + static boolean process_replay(File file) { AltosReplayReader new_reader = replay_file(file); if (new_reader == null) @@ -548,10 +598,11 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo else { File file = new File(args[i]); switch (process) { + case process_none: case process_graph: - ++errors; + if (!process_graph(file)) + ++errors; break; - case process_none: case process_replay: if (!process_replay(file)) ++errors; @@ -573,14 +624,14 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo } if (errors != 0) System.exit(errors); - if (!any_created) { + if (number_of_windows == 0) { java.util.List devices = AltosUSBDevice.list(AltosLib.product_basestation); if (devices != null) for (AltosDevice device : devices) { new TeleGPS(device); any_created = true; } - if (!any_created) + if (number_of_windows == 0) new TeleGPS(); } }