X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=telegps%2FTeleGPS.java;h=7e5ff42aa86c0696445c719da12e2745980dac06;hp=9aaa80c3fc12e4fcf9e16cf462773e864fc9c8b9;hb=98c3c3f7edd58358939f7dacf5b8f4c336712f5b;hpb=7d77d83685cbfce5323767bbfae3bd18be175ffc diff --git a/telegps/TeleGPS.java b/telegps/TeleGPS.java index 9aaa80c3..7e5ff42a 100644 --- a/telegps/TeleGPS.java +++ b/telegps/TeleGPS.java @@ -23,8 +23,8 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.util.*; -import org.altusmetrum.altoslib_4.*; -import org.altusmetrum.altosuilib_2.*; +import org.altusmetrum.altoslib_5.*; +import org.altusmetrum.altosuilib_3.*; public class TeleGPS extends AltosUIFrame @@ -58,59 +58,62 @@ public class TeleGPS JMenu file_menu; JMenu monitor_menu; JMenu device_menu; - AltosFreqList frequencies; + AltosUIFreqList frequencies; + ActionListener frequency_listener; Container bag; TeleGPSStatus telegps_status; TeleGPSStatusUpdate status_update; + javax.swing.Timer status_timer; JTabbedPane pane; AltosUIMap map; TeleGPSInfo gps_info; + TeleGPSState gps_state; AltosInfoTable info_table; LinkedList displays; /* File menu */ final static String new_command = "new"; - final static String preferences_command = "preferences"; + final static String graph_command = "graph"; + final static String export_command = "export"; final static String load_maps_command = "loadmaps"; + final static String preferences_command = "preferences"; final static String close_command = "close"; final static String exit_command = "exit"; static final String[][] file_menu_entries = new String[][] { { "New Window", new_command }, - { "Preferences", preferences_command }, + { "Graph Data", graph_command }, + { "Export Data", export_command }, { "Load Maps", load_maps_command }, + { "Preferences", preferences_command }, { "Close", close_command }, { "Exit", exit_command }, }; /* Monitor menu */ - final static String monitor_command = "monitor"; + final static String connect_command = "connect"; final static String disconnect_command = "disconnect"; final static String scan_command = "scan"; static final String[][] monitor_menu_entries = new String[][] { - { "Monitor Device", monitor_command }, + { "Connect Device", connect_command }, { "Disconnect", disconnect_command }, { "Scan Channels", scan_command }, }; /* Device menu */ final static String download_command = "download"; - final static String export_command = "export"; - final static String graph_command = "graph"; final static String configure_command = "configure"; final static String flash_command = "flash"; static final String[][] device_menu_entries = new String[][] { { "Download Data", download_command }, { "Configure Device", configure_command }, - { "Export Data", export_command }, - { "Graph Data", graph_command }, { "Flash Device", flash_command }, }; @@ -173,7 +176,14 @@ public class TeleGPS void disconnect() { setTitle("TeleGPS"); stop_display(); - remove_frequency_menu(); + if (status_timer != null) { + status_timer.stop(); + status_timer = null; + status_update = null; + } + + telegps_status.disable_receive(); + disable_frequency_menu(); } void connect(AltosDevice device) { @@ -181,8 +191,7 @@ public class TeleGPS disconnect(); try { AltosFlightReader reader = new AltosTelemetryReader(new AltosSerial(device)); - set_reader(reader); - add_frequency_menu(device.getSerial(), reader); + set_reader(reader, device); } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(this, ee.getMessage(), @@ -212,7 +221,7 @@ public class TeleGPS } } - void monitor() { + void connect() { AltosDevice device = AltosDeviceUIDialog.show(this, AltosLib.product_basestation); if (device == null) @@ -285,8 +294,8 @@ public class TeleGPS System.exit(0); /* Monitor menu */ - if (monitor_command.equals(ev.getActionCommand())) { - monitor(); + if (connect_command.equals(ev.getActionCommand())) { + connect(); return; } if (disconnect_command.equals(ev.getActionCommand())) { @@ -321,15 +330,12 @@ public class TeleGPS } } - void add_frequency_menu(int serial, final AltosFlightReader reader) { - // Channel menu - if (frequencies != null) - return; + void enable_frequency_menu(int serial, final AltosFlightReader reader) { - frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial)); - frequencies.set_product("Monitor"); - frequencies.set_serial(serial); - frequencies.addActionListener(new ActionListener() { + if (frequency_listener != null) + disable_frequency_menu(); + + frequency_listener = new ActionListener() { public void actionPerformed(ActionEvent e) { double frequency = frequencies.frequency(); try { @@ -339,22 +345,37 @@ public class TeleGPS } reader.save_frequency(); } - }); - menu_bar.add(frequencies); + }; + + frequencies.addActionListener(frequency_listener); + frequencies.set_product("Monitor"); + frequencies.set_serial(serial); + frequencies.set_frequency(AltosUIPreferences.frequency(serial)); + frequencies.setEnabled(true); + } - void remove_frequency_menu() { - if (frequencies != null) { - menu_bar.remove(frequencies); - menu_bar.repaint(); - frequencies = null; + void disable_frequency_menu() { + if (frequency_listener != null) { + frequencies.removeActionListener(frequency_listener); + frequencies.setEnabled(false); + frequency_listener = null; } + } - public void set_reader(AltosFlightReader reader) { + public void set_reader(AltosFlightReader reader, AltosDevice device) { + status_update = new TeleGPSStatusUpdate(telegps_status); + + status_timer = new javax.swing.Timer(100, status_update); + status_timer.start(); + setTitle(String.format("TeleGPS %s", reader.name)); thread = new TeleGPSDisplayThread(this, voice(), this, reader); thread.start(); + + if (device != null) + enable_frequency_menu(device.getSerial(), reader); } static int number_of_windows; @@ -370,6 +391,7 @@ public class TeleGPS } private void close() { + disconnect(); AltosUIPreferences.unregister_font_listener(this); AltosPreferences.unregister_units_listener(this); setVisible(false); @@ -387,16 +409,38 @@ public class TeleGPS private JMenu make_menu(String label, String[][] items) { JMenu menu = new JMenu(label); - for (int i = 0; i < items.length; i++) + for (int i = 0; i < items.length; i++) { + if (MAC_OS_X) { + if (items[i][1].equals("exit")) + continue; + if (items[i][1].equals("preferences")) + continue; + } add_menu(menu, items[i][0], items[i][1]); + } menu_bar.add(menu); return menu; } + /* OSXAdapter interfaces */ + public void macosx_file_handler(String path) { + process_graph(new File(path)); + } + + public void macosx_quit_handler() { + System.exit(0); + } + + public void macosx_preferences_handler() { + preferences(); + } + public TeleGPS() { AltosUIPreferences.set_component(this); + register_for_macosx_events(); + reader = null; bag = getContentPane(); @@ -412,6 +456,17 @@ public class TeleGPS file_menu = make_menu("File", file_menu_entries); monitor_menu = make_menu("Monitor", monitor_menu_entries); device_menu = make_menu("Device", device_menu_entries); + + frequencies = new AltosUIFreqList(); + frequencies.setEnabled(false); + c.gridx = 0; + c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.WEST; + c.weightx = 0; + c.gridwidth = 1; + bag.add(frequencies, c); + displays = new LinkedList(); int serial = -1; @@ -443,13 +498,17 @@ public class TeleGPS bag.add(pane, c); map = new AltosUIMap(); - pane.add("Map", map); + pane.add(map.getName(), map); displays.add(map); gps_info = new TeleGPSInfo(); - pane.add("Info", gps_info); + pane.add(gps_info.getName(), gps_info); displays.add(gps_info); + gps_state = new TeleGPSState(); + pane.add(gps_state.getName(), gps_state); + displays.add(gps_state); + info_table = new AltosInfoTable(); pane.add("Table", info_table); displays.add(info_table); @@ -470,15 +529,11 @@ public class TeleGPS setVisible(true); add_window(); - - status_update = new TeleGPSStatusUpdate(telegps_status); - - new javax.swing.Timer(100, status_update).start(); } public TeleGPS(AltosFlightReader reader) { this(); - set_reader(reader); + set_reader(reader, null); } public TeleGPS(AltosDevice device) {