X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosLanded.java;h=47aca29dbeb3e48bb690e325101bd5957a3792d6;hb=578c4b17b8f62f2727654ebda78ee139f9fe13fa;hp=d34efe6dbcfb8f2a7540754809bcfb4df77e790c;hpb=51c7741040d95c5deece939dae5e4136cc04afc4;p=fw%2Faltos diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index d34efe6d..47aca29d 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; @@ -42,10 +42,22 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { value.setText(""); } + void show() { + label.setVisible(true); + value.setVisible(true); + } + + void hide() { + label.setVisible(false); + value.setVisible(false); + } + void show(String format, double v) { + show(); value.setText(String.format(format, v)); } + public LandedValue (GridBagLayout layout, int y, String text) { GridBagConstraints c = new GridBagConstraints(); c.weighty = 1; @@ -86,7 +98,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { class Lat extends LandedValue { void show (AltosState state, int crc_errors) { - if (state.gps != null) + show(); + if (state.gps != null && state.gps.connected) value.setText(pos(state.gps.lat,"N", "S")); else value.setText("???"); @@ -100,7 +113,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { class Lon extends LandedValue { void show (AltosState state, int crc_errors) { - if (state.gps != null) + show(); + if (state.gps != null && state.gps.connected) value.setText(pos(state.gps.lon,"E", "W")); else value.setText("???"); @@ -114,6 +128,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { class Bearing extends LandedValue { void show (AltosState state, int crc_errors) { + show(); if (state.from_pad != null) show("%3.0f°", state.from_pad.bearing); else @@ -128,6 +143,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { class Distance extends LandedValue { void show (AltosState state, int crc_errors) { + show(); if (state.from_pad != null) show("%6.0f m", state.from_pad.distance); else @@ -184,18 +200,65 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay { } public void show(AltosState state, int crc_errors) { - bearing.show(state, crc_errors); - distance.show(state, crc_errors); - lat.show(state, crc_errors); - lon.show(state, crc_errors); + if (state.gps != null && state.gps.connected) { + bearing.show(state, crc_errors); + distance.show(state, crc_errors); + lat.show(state, crc_errors); + lon.show(state, crc_errors); + } else { + bearing.hide(); + distance.hide(); + lat.hide(); + lon.hide(); + } 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); + } 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); @@ -208,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); } }