X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosLanded.java;h=71c1066318bad9c0410e994d7b76429ab41937c5;hp=63a2daf602ff091ec46857e4a76090b39f3b40ae;hb=4e2fd7ae76c23aa8da1390ebcbd8f45276cd7a32;hpb=2c121f1ef495e8af3eb39210baa40e212b691894 diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 63a2daf6..71c10663 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -28,7 +28,7 @@ import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -public class AltosLanded extends JComponent implements AltosFlightDisplay { +public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { GridBagLayout layout; Font label_font; Font value_font; @@ -99,7 +99,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { class Lat extends LandedValue { void show (AltosState state, int crc_errors) { show(); - if (state.gps != null) + if (state.gps != null && state.gps.connected) value.setText(pos(state.gps.lat,"N", "S")); else value.setText("???"); @@ -114,7 +114,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { class Lon extends LandedValue { void show (AltosState state, int crc_errors) { show(); - if (state.gps != null) + if (state.gps != null && state.gps.connected) value.setText(pos(state.gps.lon,"E", "W")); else value.setText("???"); @@ -200,7 +200,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { } public void show(AltosState state, int crc_errors) { - if (state.gps != null) { + if (state.gps != null && state.gps.connected) { bearing.show(state, crc_errors); distance.show(state, crc_errors); lat.show(state, crc_errors); @@ -214,11 +214,51 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { height.show(state, crc_errors); speed.show(state, crc_errors); accel.show(state, crc_errors); + if (reader.backing_file() != null) + graph.setEnabled(true); } - public AltosLanded() { + JButton graph; + AltosFlightReader reader; + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals("graph")) { + File file = reader.backing_file(); + if (file != null) { + String filename = file.getName(); + try { + AltosRecordIterable records = null; + if (filename.endsWith("eeprom")) { + FileInputStream in = new FileInputStream(file); + records = new AltosEepromIterable(in); + } else if (filename.endsWith("telem")) { + FileInputStream in = new FileInputStream(file); + records = new AltosTelemetryIterable(in); + } else { + throw new FileNotFoundException(); + } + try { + new AltosGraphUI(records, filename); + } catch (InterruptedException ie) { + } catch (IOException ie) { + } + } catch (FileNotFoundException fe) { + JOptionPane.showMessageDialog(null, + filename, + "Cannot open file", + JOptionPane.ERROR_MESSAGE); + } + } + } + } + + public AltosLanded(AltosFlightReader in_reader) { layout = new GridBagLayout(); + reader = in_reader; + label_font = new Font("Dialog", Font.PLAIN, 22); value_font = new Font("Monospaced", Font.PLAIN, 22); setLayout(layout); @@ -231,5 +271,20 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { height = new Height(layout, 4); speed = new Speed(layout, 5); accel = new Accel(layout, 6); + + graph = new JButton ("Graph Flight"); + graph.setActionCommand("graph"); + graph.addActionListener(this); + graph.setEnabled(false); + + GridBagConstraints c = new GridBagConstraints(); + + c.gridx = 0; c.gridy = 7; + c.insets = new Insets(10, 10, 10, 10); + c.anchor = GridBagConstraints.WEST; + c.weightx = 0; + c.weighty = 0; + c.fill = GridBagConstraints.VERTICAL; + add(graph, c); } }