diff options
Diffstat (limited to 'altosui')
65 files changed, 790 insertions, 1064 deletions
diff --git a/altosui/Altos.java b/altosui/Altos.java index 98af26bc..d25736bf 100644 --- a/altosui/Altos.java +++ b/altosui/Altos.java @@ -20,74 +20,9 @@ package altosui; import java.awt.*; import libaltosJNI.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; -public class Altos extends AltosLib { +public class Altos extends AltosUILib { - static final int tab_elt_pad = 5; - - static Font label_font; - static Font value_font; - static Font status_font; - static Font table_label_font; - static Font table_value_font; - - final static int font_size_small = 1; - final static int font_size_medium = 2; - final static int font_size_large = 3; - - static void set_fonts(int size) { - int brief_size; - int table_size; - int status_size; - - switch (size) { - case font_size_small: - brief_size = 16; - status_size = 18; - table_size = 11; - break; - default: - case font_size_medium: - brief_size = 22; - status_size = 24; - table_size = 14; - break; - case font_size_large: - brief_size = 26; - status_size = 30; - table_size = 17; - break; - } - label_font = new Font("Dialog", Font.PLAIN, brief_size); - value_font = new Font("Monospaced", Font.PLAIN, brief_size); - status_font = new Font("SansSerif", Font.BOLD, status_size); - table_label_font = new Font("SansSerif", Font.PLAIN, table_size); - table_value_font = new Font("Monospaced", Font.PLAIN, table_size); - } - - static final int text_width = 20; - - static public boolean initialized = false; - static public boolean loaded_library = false; - - public static boolean load_library() { - if (!initialized) { - try { - System.loadLibrary("altos"); - libaltos.altos_init(); - loaded_library = true; - } catch (UnsatisfiedLinkError e) { - try { - System.loadLibrary("altos64"); - libaltos.altos_init(); - loaded_library = true; - } catch (UnsatisfiedLinkError e2) { - loaded_library = false; - } - } - initialized = true; - } - return loaded_library; - } } diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index a05c4404..e90e0e23 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosAscent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosBTDevice.java b/altosui/AltosBTDevice.java index 222b3c97..727a9f66 100644 --- a/altosui/AltosBTDevice.java +++ b/altosui/AltosBTDevice.java @@ -17,7 +17,7 @@ package altosui; import libaltosJNI.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosBTDevice extends altos_bt_device implements AltosDevice { diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index 606c0349..1d42365b 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -17,8 +17,8 @@ package altosui; import java.util.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosBTKnown implements Iterable<AltosBTDevice> { LinkedList<AltosBTDevice> devices = new LinkedList<AltosBTDevice>(); diff --git a/altosui/AltosBTManage.java b/altosui/AltosBTManage.java index b7b632a7..4c9b7a6c 100644 --- a/altosui/AltosBTManage.java +++ b/altosui/AltosBTManage.java @@ -23,7 +23,7 @@ import javax.swing.*; import javax.swing.plaf.basic.*; import java.util.*; import java.util.concurrent.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosBTManage extends AltosUIDialog implements ActionListener, Iterable<AltosBTDevice> { LinkedBlockingQueue<AltosBTDevice> found_devices; diff --git a/altosui/AltosCSV.java b/altosui/AltosCSV.java index 1c929a7c..0676f99d 100644 --- a/altosui/AltosCSV.java +++ b/altosui/AltosCSV.java @@ -19,7 +19,7 @@ package altosui; import java.io.*; import java.util.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosCSV implements AltosWriter { File name; diff --git a/altosui/AltosCSVUI.java b/altosui/AltosCSVUI.java index 83bf16a7..42508346 100644 --- a/altosui/AltosCSVUI.java +++ b/altosui/AltosCSVUI.java @@ -21,8 +21,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosCSVUI extends AltosUIDialog diff --git a/altosui/AltosCompanionInfo.java b/altosui/AltosCompanionInfo.java index f2019438..7dd36aec 100644 --- a/altosui/AltosCompanionInfo.java +++ b/altosui/AltosCompanionInfo.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosCompanionInfo extends JTable { private AltosFlightInfoTableModel model; diff --git a/altosui/AltosConfig.java b/altosui/AltosConfig.java index 1cd61a89..4927d3f8 100644 --- a/altosui/AltosConfig.java +++ b/altosui/AltosConfig.java @@ -22,8 +22,8 @@ import javax.swing.*; import java.io.*; import java.util.concurrent.*; import java.text.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosConfig implements ActionListener { diff --git a/altosui/AltosConfigFreqUI.java b/altosui/AltosConfigFreqUI.java index 75101e3d..c90b168f 100644 --- a/altosui/AltosConfigFreqUI.java +++ b/altosui/AltosConfigFreqUI.java @@ -21,8 +21,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; class AltosEditFreqUI extends AltosUIDialog implements ActionListener { Frame frame; diff --git a/altosui/AltosConfigPyroUI.java b/altosui/AltosConfigPyroUI.java index 5cdaf564..3cac56c3 100644 --- a/altosui/AltosConfigPyroUI.java +++ b/altosui/AltosConfigPyroUI.java @@ -21,8 +21,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosConfigPyroUI extends AltosUIDialog diff --git a/altosui/AltosConfigTD.java b/altosui/AltosConfigTD.java index 794f8103..16c9e357 100644 --- a/altosui/AltosConfigTD.java +++ b/altosui/AltosConfigTD.java @@ -21,8 +21,8 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosConfigTD implements ActionListener { diff --git a/altosui/AltosConfigTDUI.java b/altosui/AltosConfigTDUI.java index 54073843..125780a9 100644 --- a/altosui/AltosConfigTDUI.java +++ b/altosui/AltosConfigTDUI.java @@ -21,8 +21,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosConfigTDUI extends AltosUIDialog diff --git a/altosui/AltosConfigUI.java b/altosui/AltosConfigUI.java index 599ed051..4fd0647e 100644 --- a/altosui/AltosConfigUI.java +++ b/altosui/AltosConfigUI.java @@ -21,8 +21,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosConfigUI extends AltosUIDialog diff --git a/altosui/AltosConfigureUI.java b/altosui/AltosConfigureUI.java index 0e411b03..5e42f430 100644 --- a/altosui/AltosConfigureUI.java +++ b/altosui/AltosConfigureUI.java @@ -22,7 +22,7 @@ import java.awt.event.*; import java.beans.*; import javax.swing.*; import javax.swing.event.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosConfigureUI extends AltosUIConfigure @@ -31,6 +31,7 @@ public class AltosConfigureUI AltosVoice voice; public JTextField callsign_value; + public JComboBox position_value; /* DocumentListener interface methods */ public void insertUpdate(DocumentEvent e) { @@ -42,7 +43,7 @@ public class AltosConfigureUI } public void changedUpdate(DocumentEvent e) { - if (callsign_value != null) + if (callsign_value != null) AltosUIPreferences.set_callsign(callsign_value.getText()); } @@ -81,7 +82,7 @@ public class AltosConfigureUI /* Callsign setting */ pane.add(new JLabel("Callsign"), constraints(0, 1)); - JTextField callsign_value = new JTextField(AltosUIPreferences.callsign()); + callsign_value = new JTextField(AltosUIPreferences.callsign()); callsign_value.getDocument().addDocumentListener(this); callsign_value.setToolTipText("Callsign sent in packet mode"); pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH)); @@ -111,6 +112,36 @@ public class AltosConfigureUI row++; } + final static String[] position_names = { + "Top left", + "Top", + "Top right", + "Left", + "Center", + "Right", + "Bottom left", + "Bottom", + "Bottom right", + }; + + public void add_position() { + pane.add(new JLabel ("Menu position"), constraints(0, 1)); + + position_value = new JComboBox (position_names); + position_value.setMaximumRowCount(position_names.length); + int position = AltosUIPreferences.position(); + position_value.setSelectedIndex(position); + position_value.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int position = position_value.getSelectedIndex(); + AltosUIPreferences.set_position(position); + } + }); + pane.add(position_value, constraints(1, 2, GridBagConstraints.BOTH)); + position_value.setToolTipText("Position of main AltosUI window"); + row++; + } + public AltosConfigureUI(JFrame owner, AltosVoice voice) { super(owner); diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java index a8a2ca49..7de18afb 100644 --- a/altosui/AltosDataChooser.java +++ b/altosui/AltosDataChooser.java @@ -20,7 +20,8 @@ package altosui; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosDataChooser extends JFileChooser { JFrame frame; diff --git a/altosui/AltosDataPoint.java b/altosui/AltosDataPoint.java deleted file mode 100644 index 4956e9f3..00000000 --- a/altosui/AltosDataPoint.java +++ /dev/null @@ -1,27 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -interface AltosDataPoint { - int version(); - int serial(); - int flight(); - String callsign(); - double time(); - double rssi(); - - int state(); - String state_name(); - - double acceleration(); - double height(); - double speed(); - double temperature(); - double battery_voltage(); - double drogue_voltage(); - double main_voltage(); - boolean has_accel(); -} - diff --git a/altosui/AltosDataPointReader.java b/altosui/AltosDataPointReader.java deleted file mode 100644 index 88df081f..00000000 --- a/altosui/AltosDataPointReader.java +++ /dev/null @@ -1,79 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.lang.UnsupportedOperationException; -import java.util.NoSuchElementException; -import java.util.Iterator; -import org.altusmetrum.AltosLib.*; - -class AltosDataPointReader implements Iterable<AltosDataPoint> { - Iterator<AltosRecord> iter; - AltosState state; - boolean has_gps; - boolean has_accel; - boolean has_ignite; - - final static int MISSING = AltosRecord.MISSING; - - public AltosDataPointReader(AltosRecordIterable reader) { - this.iter = reader.iterator(); - this.state = null; - has_accel = true; - has_gps = reader.has_gps(); - has_ignite = reader.has_ignite(); - } - - private void read_next_record() - throws NoSuchElementException - { - state = new AltosState(iter.next(), state); - } - - private AltosDataPoint current_dp() { - assert this.state != null; - - return new AltosDataPoint() { - public int version() { return state.data.version; } - public int serial() { return state.data.serial; } - public int flight() { return state.data.flight; } - public String callsign() { return state.data.callsign; } - public double time() { return state.data.time; } - public double rssi() { return state.data.rssi; } - - public int state() { return state.state; } - public String state_name() { return state.data.state(); } - - public double acceleration() { return state.acceleration; } - public double height() { return state.height; } - public double speed() { return state.speed(); } - public double temperature() { return state.temperature; } - public double battery_voltage() { return state.battery; } - public double drogue_voltage() { return state.drogue_sense; } - public double main_voltage() { return state.main_sense; } - public boolean has_accel() { return true; } // return state.acceleration != AltosRecord.MISSING; } - }; - } - - public Iterator<AltosDataPoint> iterator() { - return new Iterator<AltosDataPoint>() { - public void remove() { - throw new UnsupportedOperationException(); - } - public boolean hasNext() { - if (state != null && state.state == Altos.ao_flight_landed) - return false; - return iter.hasNext(); - } - public AltosDataPoint next() { - do { - read_next_record(); - } while (state.data.time < -1.0 && hasNext()); - return current_dp(); - } - }; - } -} - diff --git a/altosui/AltosDebug.java b/altosui/AltosDebug.java index 482f4c36..c69369ef 100644 --- a/altosui/AltosDebug.java +++ b/altosui/AltosDebug.java @@ -18,7 +18,7 @@ package altosui; import java.io.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosDebug extends AltosSerial { diff --git a/altosui/AltosDescent.java b/altosui/AltosDescent.java index 2ea7cbfa..821e3963 100644 --- a/altosui/AltosDescent.java +++ b/altosui/AltosDescent.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosDescent extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosDeviceUIDialog.java b/altosui/AltosDeviceUIDialog.java index 7ed599a3..ceabe843 100644 --- a/altosui/AltosDeviceUIDialog.java +++ b/altosui/AltosDeviceUIDialog.java @@ -20,7 +20,7 @@ package altosui; import javax.swing.*; import java.awt.*; import java.awt.event.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosDeviceUIDialog extends AltosDeviceDialog { diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index 1ba70c7e..6f8aa9ee 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -21,7 +21,7 @@ import java.awt.*; import javax.swing.*; import java.io.*; import java.text.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosDisplayThread extends Thread { diff --git a/altosui/AltosEepromDelete.java b/altosui/AltosEepromDelete.java index b0459bb6..e81a35d1 100644 --- a/altosui/AltosEepromDelete.java +++ b/altosui/AltosEepromDelete.java @@ -21,7 +21,7 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosEepromDelete implements Runnable { AltosEepromList flights; diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 21b46740..801d4ec0 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -23,7 +23,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosEepromDownload implements Runnable { @@ -331,7 +331,7 @@ public class AltosEepromDownload implements Runnable { state = 0; state_block = log.start_block; for (block = log.start_block; !done && block < log.end_block; block++) { - monitor.set_value(AltosLib.state_name(state), state, block - state_block); + monitor.set_value(AltosLib.state_name(state), state, block - state_block, block - log.start_block); AltosEepromChunk eechunk = new AltosEepromChunk(serial_line, block, block == log.start_block); diff --git a/altosui/AltosEepromList.java b/altosui/AltosEepromList.java index f9bd2748..a63d173d 100644 --- a/altosui/AltosEepromList.java +++ b/altosui/AltosEepromList.java @@ -21,7 +21,7 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; /* * Temporary structure to hold the list of stored flights; diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java index cc9adb0c..7a721196 100644 --- a/altosui/AltosEepromManage.java +++ b/altosui/AltosEepromManage.java @@ -21,8 +21,8 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosEepromManage implements ActionListener { @@ -45,6 +45,15 @@ public class AltosEepromManage implements ActionListener { } } + private int countDeletedFlights() { + int count = 0; + for (AltosEepromLog flight : flights) { + if (flight.selected) + count++; + } + return count; + } + private String showDeletedFlights() { String result = ""; @@ -94,7 +103,8 @@ public class AltosEepromManage implements ActionListener { } else if (cmd.equals("delete")) { if (success) { JOptionPane.showMessageDialog(frame, - String.format("Flights erased: %s", + String.format("%d flights erased: %s", + countDeletedFlights(), showDeletedFlights()), serial_line.device.toShortString(), JOptionPane.INFORMATION_MESSAGE); diff --git a/altosui/AltosEepromMonitor.java b/altosui/AltosEepromMonitor.java index 8eae5eb8..50921da1 100644 --- a/altosui/AltosEepromMonitor.java +++ b/altosui/AltosEepromMonitor.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosEepromMonitor extends AltosUIDialog { @@ -101,7 +101,7 @@ public class AltosEepromMonitor extends AltosUIDialog { max_state = in_max_state; pbar = new JProgressBar(); pbar.setMinimum(0); - pbar.setMaximum((max_state - min_state) * 100); + pbar.setMaximum(1000); pbar.setValue(0); pbar.setString("startup"); pbar.setStringPainted(true); @@ -135,30 +135,28 @@ public class AltosEepromMonitor extends AltosUIDialog { cancel.addActionListener(l); } - private void set_value_internal(String state_name, int in_state, int in_block) { - int block = in_block; - int state = in_state; - - if (block > 100) - block = 100; + private void set_value_internal(String state_name, int state, int state_block, int block) { + if (state_block > 100) + state_block = 100; if (state < min_state) state = min_state; if (state >= max_state) state = max_state - 1; state -= min_state; - int pos = state * 100 + block; + int pos = state * 100 + state_block; - pbar.setString(state_name); + pbar.setString(String.format("block %d state %s", block, state_name)); pbar.setValue(pos); } - public void set_value(String in_state_name, int in_state, int in_block) { + public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) { final String state_name = in_state_name; final int state = in_state; + final int state_block = in_state_block; final int block = in_block; Runnable r = new Runnable() { public void run() { try { - set_value_internal(state_name, state, block); + set_value_internal(state_name, state, state_block, block); } catch (Exception ex) { } } @@ -235,7 +233,7 @@ public class AltosEepromMonitor extends AltosUIDialog { } private void reset_internal() { - set_value_internal("startup",min_state,0); + set_value_internal("startup",min_state,0, 0); set_flight_internal(0); set_file_internal(""); } diff --git a/altosui/AltosEepromSelect.java b/altosui/AltosEepromSelect.java index c0886212..a451aa3a 100644 --- a/altosui/AltosEepromSelect.java +++ b/altosui/AltosEepromSelect.java @@ -21,8 +21,8 @@ import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; class AltosEepromItem implements ActionListener { AltosEepromLog log; diff --git a/altosui/AltosFlash.java b/altosui/AltosFlash.java index 7a98ee14..239d4dd7 100644 --- a/altosui/AltosFlash.java +++ b/altosui/AltosFlash.java @@ -20,7 +20,7 @@ package altosui; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosFlash { File file; diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index 921207bc..f26a3916 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosFlashUI extends AltosUIDialog diff --git a/altosui/AltosFlightDisplay.java b/altosui/AltosFlightDisplay.java index 826f9522..d1ed7d2f 100644 --- a/altosui/AltosFlightDisplay.java +++ b/altosui/AltosFlightDisplay.java @@ -17,7 +17,7 @@ package altosui; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public interface AltosFlightDisplay { void reset(); diff --git a/altosui/AltosFlightStats.java b/altosui/AltosFlightStats.java index 1653ca57..da06bb3d 100644 --- a/altosui/AltosFlightStats.java +++ b/altosui/AltosFlightStats.java @@ -18,7 +18,7 @@ package altosui; import java.io.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosFlightStats { double max_height; @@ -34,6 +34,11 @@ public class AltosFlightStats { int flight; int year, month, day; int hour, minute, second; + double lat, lon; + double pad_lat, pad_lon; + boolean has_gps; + boolean has_other_adc; + boolean has_rssi; double landed_time(AltosRecordIterable iterable) { AltosState state = null; @@ -98,11 +103,19 @@ public class AltosFlightStats { year = month = day = -1; hour = minute = second = -1; serial = flight = -1; + lat = lon = -1; + has_gps = false; + has_other_adc = false; + has_rssi = false; for (AltosRecord record : iterable) { if (serial < 0) serial = record.serial; if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0) flight = record.flight; + if ((record.seen & AltosRecord.seen_temp_volt) != 0) + has_other_adc = true; + if (record.rssi != 0) + has_rssi = true; new_state = new AltosState(record, state); end_time = new_state.time; state = new_state; @@ -137,6 +150,15 @@ public class AltosFlightStats { max_speed = state.max_baro_speed; max_acceleration = state.max_acceleration; } + if (state.gps.locked && state.gps.nsat >= 4) { + if (state.state <= Altos.ao_flight_pad) { + pad_lat = state.gps.lat; + pad_lon = state.gps.lon; + } + lat = state.gps.lat; + lon = state.gps.lon; + has_gps = true; + } } for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) { if (state_count[s] > 0) { diff --git a/altosui/AltosFlightStatsTable.java b/altosui/AltosFlightStatsTable.java index 1e0b94fa..a35b5f63 100644 --- a/altosui/AltosFlightStatsTable.java +++ b/altosui/AltosFlightStatsTable.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosFlightStatsTable extends JComponent { GridBagLayout layout; @@ -58,6 +58,17 @@ public class AltosFlightStatsTable extends JComponent { } + static String pos(double p, String pos, String neg) { + String h = pos; + if (p < 0) { + h = neg; + p = -p; + } + int deg = (int) Math.floor(p); + double min = (p - Math.floor(p)) * 60.0; + return String.format("%s %4d° %9.6f'", h, deg, min); + } + public AltosFlightStatsTable(AltosFlightStats stats) { layout = new GridBagLayout(); @@ -65,12 +76,18 @@ public class AltosFlightStatsTable extends JComponent { int y = 0; new FlightStat(layout, y++, "Serial", String.format("%d", stats.serial)); new FlightStat(layout, y++, "Flight", String.format("%d", stats.flight)); - if (stats.year > 0) - new FlightStat(layout, y++, "Date", - String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day)); - if (stats.hour > 0) - new FlightStat(layout, y++, "Time", + if (stats.year > 0 && stats.hour > 0) + new FlightStat(layout, y++, "Date/Time", + String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day), String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second)); + else { + if (stats.year > 0) + new FlightStat(layout, y++, "Date", + String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day)); + if (stats.hour > 0) + new FlightStat(layout, y++, "Time", + String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second)); + } new FlightStat(layout, y++, "Maximum height", String.format("%5.0f m", stats.max_height), String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.max_height))); @@ -94,14 +111,29 @@ public class AltosFlightStatsTable extends JComponent { new FlightStat(layout, y++, "Main descent rate", String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_main]), String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main]))); - for (int s = Altos.ao_flight_boost; s <= Altos.ao_flight_main; s++) { - new FlightStat(layout, y++, String.format("%s time", AltosLib.state_name_capital(s)), - String.format("%6.0f s", stats.state_end[s] - stats.state_start[s])); - } - new FlightStat(layout, y++, "Flight Time", - String.format("%6.0f s", stats.state_end[Altos.ao_flight_main] - + new FlightStat(layout, y++, "Ascent time", + String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_boost] - stats.state_start[AltosLib.ao_flight_boost], + AltosLib.state_name(Altos.ao_flight_boost)), + String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_fast] - stats.state_start[AltosLib.ao_flight_fast], + AltosLib.state_name(Altos.ao_flight_fast)), + String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_coast] - stats.state_start[AltosLib.ao_flight_coast], + AltosLib.state_name(Altos.ao_flight_coast))); + new FlightStat(layout, y++, "Descent time", + String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_drogue] - stats.state_start[AltosLib.ao_flight_drogue], + AltosLib.state_name(Altos.ao_flight_drogue)), + String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_main] - stats.state_start[AltosLib.ao_flight_main], + AltosLib.state_name(Altos.ao_flight_main))); + new FlightStat(layout, y++, "Flight time", + String.format("%6.1f s", stats.state_end[Altos.ao_flight_main] - stats.state_start[Altos.ao_flight_boost])); - + if (stats.has_gps) { + new FlightStat(layout, y++, "Pad location", + pos(stats.pad_lat,"N","S"), + pos(stats.pad_lon,"E","W")); + new FlightStat(layout, y++, "Last reported location", + pos(stats.lat,"N","S"), + pos(stats.lon,"E","W")); + } } }
\ No newline at end of file diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index b97c8dc6..20539a9f 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosFlightStatusTableModel.java b/altosui/AltosFlightStatusTableModel.java index 56ad7e6f..6a327841 100644 --- a/altosui/AltosFlightStatusTableModel.java +++ b/altosui/AltosFlightStatusTableModel.java @@ -27,7 +27,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosFlightStatusTableModel extends AbstractTableModel { private String[] columnNames = { diff --git a/altosui/AltosFlightStatusUpdate.java b/altosui/AltosFlightStatusUpdate.java index bef39e8d..bf679b85 100644 --- a/altosui/AltosFlightStatusUpdate.java +++ b/altosui/AltosFlightStatusUpdate.java @@ -18,7 +18,7 @@ package altosui; import java.awt.event.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosFlightStatusUpdate implements ActionListener { diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index e2dc06bd..c8faab90 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -21,8 +21,8 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener { AltosVoice voice; diff --git a/altosui/AltosFreqList.java b/altosui/AltosFreqList.java index 4edf088c..7464ac3e 100644 --- a/altosui/AltosFreqList.java +++ b/altosui/AltosFreqList.java @@ -18,7 +18,8 @@ package altosui; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosFreqList extends JComboBox { diff --git a/altosui/AltosGraph.java b/altosui/AltosGraph.java index fbcefd61..defe69a0 100644 --- a/altosui/AltosGraph.java +++ b/altosui/AltosGraph.java @@ -1,26 +1,221 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later +/* + * Copyright © 2013 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ package altosui; import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +class AltosVoltage extends AltosUnits { + + public double value(double v) { + return v; + } + + public String show_units() { + return "V"; + } + + public String say_units() { + return "volts"; + } -import org.jfree.chart.JFreeChart; -import org.jfree.chart.ChartUtilities; - -abstract class AltosGraph { - public String filename; - public abstract void addData(AltosDataPoint d); - public abstract JFreeChart createChart(); - public String title; - public void toPNG() throws java.io.IOException { toPNG(300, 500); } - public void toPNG(int width, int height) - throws java.io.IOException - { - File pngout = new File(filename); - JFreeChart chart = createChart(); - ChartUtilities.saveChartAsPNG(pngout, chart, width, height); - System.out.println("Created " + filename); - } + public int show_fraction(int width) { + return width / 2; + } } + +class AltosNsat extends AltosUnits { + + public double value(double v) { + return v; + } + + public String show_units() { + return "Sats"; + } + + public String say_units() { + return "Satellites"; + } + + public int show_fraction(int width) { + return 0; + } +} + +class AltosDbm extends AltosUnits { + + public double value(double v) { + return v; + } + + public String show_units() { + return "dBm"; + } + + public String say_units() { + return "d b m"; + } + + public int show_fraction(int width) { + return 0; + } +} + +public class AltosGraph extends AltosUIGraph { + + static final private Color height_color = new Color(194,31,31); + static final private Color gps_height_color = new Color(150,31,31); + static final private Color range_color = new Color(100, 31, 31); + static final private Color distance_color = new Color(100, 31, 194); + static final private Color speed_color = new Color(31,194,31); + static final private Color accel_color = new Color(31,31,194); + static final private Color voltage_color = new Color(194, 194, 31); + static final private Color battery_voltage_color = new Color(194, 194, 31); + static final private Color drogue_voltage_color = new Color(150, 150, 31); + static final private Color main_voltage_color = new Color(100, 100, 31); + static final private Color gps_nsat_color = new Color (194, 31, 194); + static final private Color gps_nsat_solution_color = new Color (194, 31, 194); + static final private Color gps_nsat_view_color = new Color (150, 31, 150); + static final private Color temperature_color = new Color (31, 194, 194); + static final private Color dbm_color = new Color(31, 100, 100); + static final private Color state_color = new Color(0,0,0); + + static AltosVoltage voltage_units = new AltosVoltage(); + static AltosNsat nsat_units = new AltosNsat(); + static AltosDbm dbm_units = new AltosDbm(); + + AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis; + AltosUIAxis distance_axis; + + public AltosGraph(AltosUIEnable enable, AltosFlightStats stats, AltosGraphDataSet dataSet) { + super(enable); + + height_axis = newAxis("Height", AltosConvert.height, height_color); + speed_axis = newAxis("Speed", AltosConvert.speed, speed_color); + accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color); + voltage_axis = newAxis("Voltage", voltage_units, voltage_color); + temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0); + nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color, + AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer); + dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0); + distance_axis = newAxis("Distance", AltosConvert.distance, range_color); + + addMarker("State", AltosGraphDataPoint.data_state, state_color); + addSeries("Height", + AltosGraphDataPoint.data_height, + AltosConvert.height, + height_color, + true, + height_axis); + addSeries("Speed", + AltosGraphDataPoint.data_speed, + AltosConvert.speed, + speed_color, + true, + speed_axis); + addSeries("Acceleration", + AltosGraphDataPoint.data_accel, + AltosConvert.accel, + accel_color, + true, + accel_axis); + if (stats.has_gps) { + addSeries("Range", + AltosGraphDataPoint.data_range, + AltosConvert.distance, + range_color, + false, + distance_axis); + addSeries("Distance", + AltosGraphDataPoint.data_distance, + AltosConvert.distance, + distance_color, + false, + distance_axis); + addSeries("GPS Height", + AltosGraphDataPoint.data_gps_height, + AltosConvert.height, + gps_height_color, + false, + height_axis); + addSeries("GPS Satellites in Solution", + AltosGraphDataPoint.data_gps_nsat_solution, + nsat_units, + gps_nsat_solution_color, + false, + nsat_axis); + addSeries("GPS Satellites in View", + AltosGraphDataPoint.data_gps_nsat_view, + nsat_units, + gps_nsat_view_color, + false, + nsat_axis); + } + if (stats.has_rssi) + addSeries("Received Signal Strength", + AltosGraphDataPoint.data_rssi, + dbm_units, + dbm_color, + false, + dbm_axis); + if (stats.has_other_adc) { + addSeries("Temperature", + AltosGraphDataPoint.data_temperature, + AltosConvert.temperature, + temperature_color, + false, + temperature_axis); + addSeries("Battery Voltage", + AltosGraphDataPoint.data_battery_voltage, + voltage_units, + battery_voltage_color, + false, + voltage_axis); + addSeries("Drogue Voltage", + AltosGraphDataPoint.data_drogue_voltage, + voltage_units, + drogue_voltage_color, + false, + voltage_axis); + addSeries("Main Voltage", + AltosGraphDataPoint.data_main_voltage, + voltage_units, + main_voltage_color, + false, + voltage_axis); + } + + setDataSet(dataSet); + } +}
\ No newline at end of file diff --git a/altosui/AltosGraphDataPoint.java b/altosui/AltosGraphDataPoint.java new file mode 100644 index 00000000..8e6d6923 --- /dev/null +++ b/altosui/AltosGraphDataPoint.java @@ -0,0 +1,122 @@ +/* + * Copyright © 2013 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import org.altusmetrum.altosuilib_1.*; +import org.altusmetrum.altoslib_1.*; + +public class AltosGraphDataPoint implements AltosUIDataPoint { + + AltosState state; + + public static final int data_height = 0; + public static final int data_speed = 1; + public static final int data_accel = 2; + public static final int data_temp = 3; + public static final int data_battery_voltage = 4; + public static final int data_drogue_voltage = 5; + public static final int data_main_voltage = 6; + public static final int data_rssi = 7; + public static final int data_state = 8; + public static final int data_gps_height = 9; + public static final int data_gps_nsat_solution = 10; + public static final int data_gps_nsat_view = 11; + public static final int data_temperature = 12; + public static final int data_range = 13; + public static final int data_distance = 14; + + public double x() throws AltosUIDataMissing { + if (state.data.time < -2) + throw new AltosUIDataMissing(-1); + return state.data.time; + } + + public double y(int index) throws AltosUIDataMissing { + double y = AltosRecord.MISSING; + switch (index) { + case data_height: + y = state.height; + break; + case data_speed: + y = state.speed(); + break; + case data_accel: + y = state.acceleration; + break; + case data_temp: + y = state.temperature; + break; + case data_battery_voltage: + y = state.battery; + break; + case data_drogue_voltage: + y = state.drogue_sense; + break; + case data_main_voltage: + y = state.main_sense; + break; + case data_rssi: + y = state.data.rssi; + break; + case data_gps_height: + y = state.gps_height; + break; + case data_gps_nsat_solution: + if (state.gps != null) + y = state.gps.nsat; + break; + case data_gps_nsat_view: + if (state.gps != null && state.gps.cc_gps_sat != null) + y = state.gps.cc_gps_sat.length; + break; + case data_temperature: + y = state.temperature; + break; + case data_range: + y = state.range; + break; + case data_distance: + if (state.from_pad != null) + y = state.from_pad.distance; + break; + } + if (y == AltosRecord.MISSING) + throw new AltosUIDataMissing(index); + return y; + } + + public int id(int index) { + if (index == data_state) { + int s = state.data.state; + if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed) + return -1; + return s; + } + return 0; + } + + public String id_name(int index) { + if (index == data_state) + return state.data.state(); + return ""; + } + + public AltosGraphDataPoint (AltosState state) { + this.state = state; + } +}
\ No newline at end of file diff --git a/altosui/AltosGraphDataSet.java b/altosui/AltosGraphDataSet.java new file mode 100644 index 00000000..092b7c74 --- /dev/null +++ b/altosui/AltosGraphDataSet.java @@ -0,0 +1,96 @@ +/* + * Copyright © 2013 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package altosui; + +import java.lang.*; +import java.io.*; +import java.util.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; + +class AltosGraphIterator implements Iterator<AltosUIDataPoint> { + AltosGraphDataSet dataSet; + Iterator<AltosRecord> iterator; + + AltosState state; + + public boolean hasNext() { + return iterator.hasNext(); + } + + public AltosUIDataPoint next() { + state = new AltosState(iterator.next(), state); + + if (dataSet.callsign == null && state.data.callsign != null) + dataSet.callsign = state.data.callsign; + + if (dataSet.serial == 0 && state.data.serial != 0) + dataSet.serial = state.data.serial; + + if (dataSet.flight == 0 && state.data.flight != 0) + dataSet.flight = state.data.flight; + + return new AltosGraphDataPoint(state); + } + + public AltosGraphIterator (Iterator<AltosRecord> iterator, AltosGraphDataSet dataSet) { + this.iterator = iterator; + this.state = null; + this.dataSet = dataSet; + } + + public void remove() { + } +} + +class AltosGraphIterable implements Iterable<AltosUIDataPoint> { + AltosGraphDataSet dataSet; + + public Iterator<AltosUIDataPoint> iterator() { + return new AltosGraphIterator(dataSet.records.iterator(), dataSet); + } + + public AltosGraphIterable(AltosGraphDataSet dataSet) { + this.dataSet = dataSet; + } +} + +public class AltosGraphDataSet implements AltosUIDataSet { + String callsign; + int serial; + int flight; + AltosRecordIterable records; + + public String name() { + if (callsign != null) + return String.format("%s - %d/%d", callsign, serial, flight); + else + return String.format("%d/%d", serial, flight); + } + + public Iterable<AltosUIDataPoint> dataPoints() { + return new AltosGraphIterable(this); + } + + public AltosGraphDataSet (AltosRecordIterable records) { + this.records = records; + this.callsign = null; + this.serial = 0; + this.flight = 0; + } +} diff --git a/altosui/AltosGraphTime.java b/altosui/AltosGraphTime.java deleted file mode 100644 index 62d516b2..00000000 --- a/altosui/AltosGraphTime.java +++ /dev/null @@ -1,235 +0,0 @@ - -// Copyright (c) 2010 Anthony Towns -// GPL v2 or later - -package altosui; - -import java.util.*; -import java.awt.Color; -import java.util.ArrayList; -import java.util.HashMap; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.AxisLocation; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.labels.StandardXYToolTipGenerator; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.plot.ValueMarker; -import org.jfree.chart.renderer.xy.StandardXYItemRenderer; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.jfree.ui.RectangleAnchor; -import org.jfree.ui.TextAnchor; - -class AltosGraphTime extends AltosGraph { - static interface Element { - void attachGraph(AltosGraphTime g); - void gotTimeData(double time, AltosDataPoint d); - void addToPlot(AltosGraphTime g, XYPlot plot); - } - - static class TimeAxis implements Element { - private int axis; - private Color color; - private String label; - private AxisLocation locn; - private double min_y = Double.NaN; - - public TimeAxis(int axis, String label, Color color, AxisLocation locn) - { - this.axis = axis; - this.color = color; - this.label = label; - this.locn = locn; - } - - public void setLowerBound(double min_y) { - this.min_y = min_y; - } - - public void attachGraph(AltosGraphTime g) { return; } - public void gotTimeData(double time, AltosDataPoint d) { return; } - - public void addToPlot(AltosGraphTime g, XYPlot plot) { - NumberAxis numAxis = new NumberAxis(label); - if (!Double.isNaN(min_y)) - numAxis.setLowerBound(min_y); - plot.setRangeAxis(axis, numAxis); - plot.setRangeAxisLocation(axis, locn); - numAxis.setLabelPaint(color); - numAxis.setTickLabelPaint(color); - numAxis.setAutoRangeIncludesZero(false); - } - } - - abstract static class TimeSeries implements Element { - protected XYSeries series; - private String axisName; - private String axisUnits; - private Color color; - - public TimeSeries(String axisName, String axisUnits, String label, Color color) { - this.series = new XYSeries(label); - this.axisName = String.format("%s (%s)", axisName, axisUnits); - this.axisUnits = axisUnits; - this.color = color; - } - - public void attachGraph(AltosGraphTime g) { - g.setAxis(this, axisName, color); - } - abstract public void gotTimeData(double time, AltosDataPoint d); - - public void addToPlot(AltosGraphTime g, XYPlot plot) { - XYSeriesCollection dataset = new XYSeriesCollection(); - dataset.addSeries(this.series); - - XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); - renderer.setSeriesPaint(0, color); - StandardXYToolTipGenerator tool_tip; - - tool_tip = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", axisUnits), - new java.text.DecimalFormat("0.00"), - new java.text.DecimalFormat("0.00")); - renderer.setBaseToolTipGenerator(tool_tip); - - int dataNum = g.getDataNum(this); - int axisNum = g.getAxisNum(this); - - plot.setDataset(dataNum, dataset); - plot.mapDatasetToRangeAxis(dataNum, axisNum); - plot.setRenderer(dataNum, renderer); - } - } - - static class StateMarker implements Element { - private LinkedList<Double> times = new LinkedList<Double>(); - private String name; - private int state; - private int prev_state = Altos.ao_flight_startup; - - StateMarker(int state, String name) { - this.state = state; - this.name = name; - } - - public void attachGraph(AltosGraphTime g) { return; } - public void gotTimeData(double time, AltosDataPoint d) { - if (prev_state != state && d.state() == state) - times.add(time); - prev_state = d.state(); - } - - public void addToPlot(AltosGraphTime g, XYPlot plot) { - for (double time : times) { - ValueMarker m = new ValueMarker(time); - m.setLabel(name); - m.setLabelAnchor(RectangleAnchor.TOP_RIGHT); - m.setLabelTextAnchor(TextAnchor.TOP_LEFT); - plot.addDomainMarker(m); - } - } - } - - private String callsign = null; - private Integer serial = null; - private Integer flight = null; - - private ArrayList<Element> elements; - private HashMap<String,Integer> axes; - private HashMap<Element,Integer> datasets; - private ArrayList<Integer> datasetAxis; - - public AltosGraphTime(String title) { - this.filename = title.toLowerCase().replaceAll("[^a-z0-9]","_")+".png"; - this.title = title; - this.elements = new ArrayList<Element>(); - this.axes = new HashMap<String,Integer>(); - this.datasets = new HashMap<Element,Integer>(); - this.datasetAxis = new ArrayList<Integer>(); - } - - public AltosGraphTime addElement(Element e) { - e.attachGraph(this); - elements.add(e); - return this; - } - - public void setAxis(Element ds, String axisName, Color color) { - Integer axisNum = axes.get(axisName); - int dsNum = datasetAxis.size(); - if (axisNum == null) { - axisNum = newAxis(axisName, color); - } - datasets.put(ds, dsNum); - datasetAxis.add(axisNum); - } - - public int getAxisNum(Element ds) { - return datasetAxis.get( datasets.get(ds) ).intValue(); - } - public int getDataNum(Element ds) { - return datasets.get(ds).intValue(); - } - - private Integer newAxis(String name, Color color) { - int cnt = axes.size(); - AxisLocation locn = AxisLocation.BOTTOM_OR_LEFT; - if (cnt > 0) { - locn = AxisLocation.TOP_OR_RIGHT; - } - Integer res = new Integer(cnt); - axes.put(name, res); - this.addElement(new TimeAxis(cnt, name, color, locn)); - return res; - } - - public void addData(AltosDataPoint d) { - double time = d.time(); - for (Element e : elements) { - e.gotTimeData(time, d); - } - if (callsign == null) callsign = d.callsign(); - if (serial == null) serial = new Integer(d.serial()); - if (flight == null) flight = new Integer(d.flight()); - } - - public JFreeChart createChart() { - NumberAxis xAxis = new NumberAxis("Time (s)"); - xAxis.setAutoRangeIncludesZero(false); - XYPlot plot = new XYPlot(); - plot.setDomainAxis(xAxis); - plot.setOrientation(PlotOrientation.VERTICAL); - - if (serial != null && flight != null) { - title = serial + "/" + flight + ": " + title; - } - if (callsign != null) { - title = callsign + " - " + title; - } - - JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, - plot, true); - ChartUtilities.applyCurrentTheme(chart); - - plot.setDomainPannable(true); - plot.setRangePannable(true); - - for (Element e : elements) { - e.addToPlot(this, plot); - } - - return chart; - } - - public void toPNG() throws java.io.IOException { - if (axes.size() > 1) { - toPNG(800, 500); - } else { - toPNG(300, 500); - } - } -} diff --git a/altosui/AltosGraphUI.java b/altosui/AltosGraphUI.java index d6891ffa..2f3575a4 100644 --- a/altosui/AltosGraphUI.java +++ b/altosui/AltosGraphUI.java @@ -9,8 +9,8 @@ import java.util.ArrayList; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; @@ -18,290 +18,58 @@ import org.jfree.ui.RefineryUtilities; public class AltosGraphUI extends AltosUIFrame { - JTabbedPane pane; - - static final private Color red = new Color(194,31,31); - static final private Color green = new Color(31,194,31); - static final private Color blue = new Color(31,31,194); - //static final private Color black = new Color(31,31,31); - static final private Color yellow = new Color(194,194,31); - //static final private Color cyan = new Color(31,194,194); - static final private Color magenta = new Color(194,31,194); - - static private class OverallGraphs { - AltosGraphTime.Element height = - new AltosGraphTime.TimeSeries("Height", AltosConvert.height.show_units(), "Height (AGL)", red) { - public void gotTimeData(double time, AltosDataPoint d) { - double height = d.height(); - if (height != AltosRecord.MISSING) - series.add(time, AltosConvert.height.value(height)); - } - }; - - AltosGraphTime.Element speed = - new AltosGraphTime.TimeSeries("Speed", AltosConvert.speed.show_units(), "Vertical Speed", green) { - public void gotTimeData(double time, AltosDataPoint d) { - double speed = d.speed(); - if (speed != AltosRecord.MISSING) - series.add(time, AltosConvert.speed.value(speed)); - } - }; - - AltosGraphTime.Element acceleration = - new AltosGraphTime.TimeSeries("Acceleration", - AltosConvert.accel.show_units(), - "Axial Acceleration", blue) - { - public void gotTimeData(double time, AltosDataPoint d) { - double acceleration = d.acceleration(); - if (acceleration != AltosRecord.MISSING) - series.add(time, AltosConvert.accel.value(acceleration)); - } - }; - - AltosGraphTime.Element temperature = - new AltosGraphTime.TimeSeries("Temperature", "\u00B0C", - "Board temperature", red) - { - public void gotTimeData(double time, AltosDataPoint d) { - double temp = d.temperature(); - if (temp != AltosRecord.MISSING) - series.add(time, d.temperature()); - } - }; - - AltosGraphTime.Element drogue_voltage = - new AltosGraphTime.TimeSeries("Voltage", "(V)", "Drogue Continuity", yellow) - { - public void gotTimeData(double time, AltosDataPoint d) { - double v = d.drogue_voltage(); - if (v != AltosRecord.MISSING) - series.add(time, v); - } - }; - - AltosGraphTime.Element main_voltage = - new AltosGraphTime.TimeSeries("Voltage", "(V)", "Main Continuity", magenta) - { - public void gotTimeData(double time, AltosDataPoint d) { - double v = d.main_voltage(); - if (v != AltosRecord.MISSING) - series.add(time, v); - } - }; - - //AltosGraphTime.Element e_pad = new AltosGraphTime.StateMarker(Altos.ao_flight_pad, "Pad"); - AltosGraphTime.Element e_boost = new AltosGraphTime.StateMarker(Altos.ao_flight_boost, "Boost"); - AltosGraphTime.Element e_fast = new AltosGraphTime.StateMarker(Altos.ao_flight_fast, "Fast"); - AltosGraphTime.Element e_coast = new AltosGraphTime.StateMarker(Altos.ao_flight_coast, "Coast"); - AltosGraphTime.Element e_drogue = new AltosGraphTime.StateMarker(Altos.ao_flight_drogue, "Drogue"); - AltosGraphTime.Element e_main = new AltosGraphTime.StateMarker(Altos.ao_flight_main, "Main"); - AltosGraphTime.Element e_landed = new AltosGraphTime.StateMarker(Altos.ao_flight_landed, "Landed"); - - protected AltosGraphTime myAltosGraphTime(String suffix) { - return (new AltosGraphTime("Overall " + suffix)) - .addElement(e_boost) - .addElement(e_fast) - .addElement(e_coast) - .addElement(e_drogue) - .addElement(e_main) - .addElement(e_landed); - } - - public ArrayList<AltosGraph> graphs() { - ArrayList<AltosGraph> graphs = new ArrayList<AltosGraph>(); - - graphs.add( myAltosGraphTime("Summary") - .addElement(height) - .addElement(speed) - .addElement(acceleration) ); - - graphs.add( myAltosGraphTime("Summary") - .addElement(height) - .addElement(speed)); - - graphs.add( myAltosGraphTime("Altitude") - .addElement(height) ); - - graphs.add( myAltosGraphTime("Speed") - .addElement(speed) ); - - graphs.add( myAltosGraphTime("Acceleration") - .addElement(acceleration) ); - - graphs.add( myAltosGraphTime("Temperature") - .addElement(temperature) ); - - graphs.add( myAltosGraphTime("Continuity") - .addElement(drogue_voltage) - .addElement(main_voltage) ); - - return graphs; - } - } - - /* - static private class AscentGraphs extends OverallGraphs { - protected AltosGraphTime myAltosGraphTime(String suffix) { - return (new AltosGraphTime("Ascent " + suffix) { - public void addData(AltosDataPoint d) { - int state = d.state(); - if (Altos.ao_flight_boost <= state && state <= Altos.ao_flight_coast) { - super.addData(d); - } - } - }).addElement(e_boost) - .addElement(e_fast) - .addElement(e_coast); - } - } - */ - - /* - static private class DescentGraphs extends OverallGraphs { - protected AltosGraphTime myAltosGraphTime(String suffix) { - return (new AltosGraphTime("Descent " + suffix) { - public void addData(AltosDataPoint d) { - int state = d.state(); - if (Altos.ao_flight_drogue <= state && state <= Altos.ao_flight_main) { - super.addData(d); - } - } - }).addElement(e_drogue) - .addElement(e_main); - // ((XYGraph)graph[8]).ymin = new Double(-50); - } - } - */ - - public AltosGraphUI(AltosRecordIterable records, String name) throws InterruptedException, IOException { - super(String.format("Altos Graph %s", name)); - - AltosDataPointReader reader = new AltosDataPointReader (records); - - if (reader.has_accel) - init(reader, records, 0); - else - init(reader, records, 1); + JTabbedPane pane; + AltosGraph graph; + AltosUIEnable enable; + AltosSiteMap map; + AltosState state; + AltosGraphDataSet graphDataSet; + AltosFlightStats stats; + AltosFlightStatsTable statsTable; + + boolean fill_map(AltosRecordIterable records) { + boolean any_gps = false; + for (AltosRecord record : records) { + state = new AltosState(record, state); + if (state.gps.locked && state.gps.nsat >= 4) { + map.show(state, 0); + any_gps = true; + } + } + return any_gps; } -// public AltosGraphUI(AltosDataPointReader data, int which) - // { -// super("Altos Graph"); -// init(data, which); -// } - - private void init(AltosDataPointReader data, AltosRecordIterable records, int which) throws InterruptedException, IOException { - pane = new JTabbedPane(); - - AltosGraph graph = createGraph(data, which); + AltosGraphUI(AltosRecordIterable records, File file) throws InterruptedException, IOException { + super(file.getName()); + state = null; - JFreeChart chart = graph.createChart(); - ChartPanel chartPanel = new ChartPanel(chart); - chartPanel.setMouseWheelEnabled(true); - chartPanel.setPreferredSize(new java.awt.Dimension(800, 500)); - pane.add(graph.title, chartPanel); + pane = new JTabbedPane(); - AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records)); - pane.add("Flight Statistics", stats); + enable = new AltosUIEnable(); - setContentPane (pane); + stats = new AltosFlightStats(records); + graphDataSet = new AltosGraphDataSet(records); - pack(); + graph = new AltosGraph(enable, stats, graphDataSet); - RefineryUtilities.centerFrameOnScreen(this); + statsTable = new AltosFlightStatsTable(stats); - setDefaultCloseOperation(DISPOSE_ON_CLOSE); - setVisible(true); - } + map = new AltosSiteMap(); - private static AltosGraph createGraph(Iterable<AltosDataPoint> data, - int which) - { - return createGraphsWhich(data, which).get(0); - } + pane.add("Flight Graph", graph.panel); + pane.add("Configure Graph", enable); + pane.add("Flight Statistics", statsTable); - /* - private static ArrayList<AltosGraph> createGraphs( - Iterable<AltosDataPoint> data) - { - return createGraphsWhich(data, -1); - } - */ + if (fill_map(records)) + pane.add("Map", map); - private static ArrayList<AltosGraph> createGraphsWhich( - Iterable<AltosDataPoint> data, int which) - { - ArrayList<AltosGraph> graph = new ArrayList<AltosGraph>(); - graph.addAll((new OverallGraphs()).graphs()); -// graph.addAll((new AscentGraphs()).graphs()); -// graph.addAll((new DescentGraphs()).graphs()); + setContentPane (pane); - if (which > 0) { - if (which >= graph.size()) { - which = 0; - } - AltosGraph g = graph.get(which); - graph = new ArrayList<AltosGraph>(); - graph.add(g); - } + pack(); - for (AltosDataPoint dp : data) { - for (AltosGraph g : graph) { - g.addData(dp); - } - } - - return graph; - } + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + setVisible(true); + if (state != null) + map.centre(state); + } } - -/* gnuplot bits... - * -300x400 - --------------------------------------------------------- -TOO HARD! :) - -"ascent-gps-accuracy.png" "Vertical error margin to apogee - GPS v Baro (m)" - 5:($7 < 6 ? $24-$11 : 1/0) -"descent-gps-accuracy.png" "Vertical error margin during descent - GPS v Baro (m)" - 5:($7 < 6 ? 1/0 : $24-$11) - -set output "overall-gps-accuracy.png" -set ylabel "distance above sea level (m)" -plot "telemetry.csv" using 5:11 with lines ti "baro altitude" axis x1y1, \ - "telemetry.csv" using 5:24 with lines ti "gps altitude" axis x1y1 - -set term png tiny size 700,700 enhanced -set xlabel "m" -set ylabel "m" -set polar -set grid polar -set rrange[*:*] -set angles degrees - -set output "overall-gps-path.png" -#:30 with yerrorlines -plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0) with lines ti "pad", \ - "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0) with lines ti "boost", \ - "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0) with lines ti "fast", \ - "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0) with lines ti "coast", \ - "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ - "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ - "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" - -set output "ascent-gps-path.png" -plot "telemetry.csv" using (90-$33):($7 == 2 ? $31 : 1/0):30 with lines ti "pad", \ - "telemetry.csv" using (90-$33):($7 == 3 ? $31 : 1/0):20 with lines ti "boost", \ - "telemetry.csv" using (90-$33):($7 == 4 ? $31 : 1/0):10 with lines ti "fast", \ - "telemetry.csv" using (90-$33):($7 == 5 ? $31 : 1/0):5 with lines ti "coast" - -set output "descent-gps-path.png" -plot "telemetry.csv" using (90-$33):($7 == 6 ? $31 : 1/0) with lines ti "drogue", \ - "telemetry.csv" using (90-$33):($7 == 7 ? $31 : 1/0) with lines ti "main", \ - "telemetry.csv" using (90-$33):($7 == 8 ? $31 : 1/0) with lines ti "landed" - - */ - - diff --git a/altosui/AltosIdleMonitorUI.java b/altosui/AltosIdleMonitorUI.java index 1b3dd547..8c883eeb 100644 --- a/altosui/AltosIdleMonitorUI.java +++ b/altosui/AltosIdleMonitorUI.java @@ -20,12 +20,13 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import javax.swing.event.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; -public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener { +public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener { AltosDevice device; JTabbedPane pane; AltosPad pad; @@ -36,11 +37,8 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl boolean remote; void stop_display() { - if (thread != null && thread.isAlive()) { - thread.interrupt(); - try { - thread.join(); - } catch (InterruptedException ie) {} + if (thread != null) { + thread.abort(); } thread = null; } @@ -87,6 +85,48 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl Container bag; AltosFreqList frequencies; + JTextField callsign_value; + + /* DocumentListener interface methods */ + public void changedUpdate(DocumentEvent e) { + if (callsign_value != null) { + String callsign = callsign_value.getText(); + thread.set_callsign(callsign); + AltosUIPreferences.set_callsign(callsign); + } + } + + public void insertUpdate(DocumentEvent e) { + changedUpdate(e); + } + + public void removeUpdate(DocumentEvent e) { + changedUpdate(e); + } + + int row = 0; + + public GridBagConstraints constraints (int x, int width, int fill) { + GridBagConstraints c = new GridBagConstraints(); + Insets insets = new Insets(4, 4, 4, 4); + + c.insets = insets; + c.fill = fill; + if (width == 3) + c.anchor = GridBagConstraints.CENTER; + else if (x == 2) + c.anchor = GridBagConstraints.EAST; + else + c.anchor = GridBagConstraints.WEST; + c.gridx = x; + c.gridwidth = width; + c.gridy = row; + return c; + } + + public GridBagConstraints constraints(int x, int width) { + return constraints(x, width, GridBagConstraints.NONE); + } public AltosIdleMonitorUI(JFrame in_owner) throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException { @@ -100,8 +140,6 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl bag = getContentPane(); bag.setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - setTitle(String.format("AltOS %s", device.toShortString())); /* Stick frequency selector at top of table for telemetry monitoring */ @@ -116,23 +154,21 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl frequency); } }); - c.gridx = 0; - c.gridy = 0; - c.insets = new Insets(3, 3, 3, 3); - c.anchor = GridBagConstraints.WEST; - bag.add (frequencies, c); + bag.add (frequencies, constraints(0, 1)); + bag.add (new JLabel("Callsign:"), constraints(1, 1)); + /* Add callsign configuration */ + callsign_value = new JTextField(AltosUIPreferences.callsign()); + callsign_value.getDocument().addDocumentListener(this); + callsign_value.setToolTipText("Callsign sent in packet mode"); + bag.add(callsign_value, constraints(2, 1, GridBagConstraints.BOTH)); + row++; } /* Flight status is always visible */ flightStatus = new AltosFlightStatus(); - c.gridx = 0; - c.gridy = 1; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1; - c.gridwidth = 2; - bag.add(flightStatus, c); - c.gridwidth = 1; + bag.add(flightStatus, constraints(0, 3, GridBagConstraints.HORIZONTAL)); + row++; /* The rest of the window uses a tabbed pane to * show one of the alternate data views @@ -146,13 +182,7 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl pane.add("Table", new JScrollPane(flightInfo)); /* Make the tabbed pane use the rest of the window space */ - c.gridx = 0; - c.gridy = 2; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - c.weighty = 1; - c.gridwidth = 2; - bag.add(pane, c); + bag.add(pane, constraints(0, 3, GridBagConstraints.BOTH)); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index c1378eb9..14d4eebc 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -23,8 +23,8 @@ import javax.swing.*; import java.io.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosIgniteUI extends AltosUIDialog diff --git a/altosui/AltosInfoTable.java b/altosui/AltosInfoTable.java index 11d1b0c1..c06f57ec 100644 --- a/altosui/AltosInfoTable.java +++ b/altosui/AltosInfoTable.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import javax.swing.*; import javax.swing.table.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosInfoTable extends JTable { private AltosFlightInfoTableModel model; diff --git a/altosui/AltosKML.java b/altosui/AltosKML.java index 281638bf..84f9dc7a 100644 --- a/altosui/AltosKML.java +++ b/altosui/AltosKML.java @@ -18,7 +18,7 @@ package altosui; import java.io.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosKML implements AltosWriter { diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java index 5e073f7d..e13229a8 100644 --- a/altosui/AltosLanded.java +++ b/altosui/AltosLanded.java @@ -21,7 +21,7 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener { GridBagLayout layout; @@ -257,7 +257,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio throw new FileNotFoundException(filename); } try { - new AltosGraphUI(records, filename); + new AltosGraphUI(records, file); } catch (InterruptedException ie) { } catch (IOException ie) { } diff --git a/altosui/AltosLaunch.java b/altosui/AltosLaunch.java index 0bad80aa..04948ee6 100644 --- a/altosui/AltosLaunch.java +++ b/altosui/AltosLaunch.java @@ -20,7 +20,7 @@ package altosui; import java.io.*; import java.util.concurrent.*; import java.awt.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosLaunch { AltosDevice device; diff --git a/altosui/AltosLaunchUI.java b/altosui/AltosLaunchUI.java index 7e7ed010..4d9fbda5 100644 --- a/altosui/AltosLaunchUI.java +++ b/altosui/AltosLaunchUI.java @@ -23,7 +23,7 @@ import javax.swing.*; import java.io.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; class FireButton extends JButton { protected void processMouseEvent(MouseEvent e) { diff --git a/altosui/AltosPad.java b/altosui/AltosPad.java index 2d9c8323..d13f6945 100644 --- a/altosui/AltosPad.java +++ b/altosui/AltosPad.java @@ -19,7 +19,7 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosPad extends JComponent implements AltosFlightDisplay { GridBagLayout layout; diff --git a/altosui/AltosRomconfigUI.java b/altosui/AltosRomconfigUI.java index 5fc786e2..cf4658af 100644 --- a/altosui/AltosRomconfigUI.java +++ b/altosui/AltosRomconfigUI.java @@ -20,7 +20,7 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosRomconfigUI extends AltosUIDialog diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index 14b52310..0c903873 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -25,8 +25,8 @@ import java.io.*; import java.util.*; import java.text.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; class AltosScanResult { String callsign; diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java index 78d862d0..e869f1ab 100644 --- a/altosui/AltosSerial.java +++ b/altosui/AltosSerial.java @@ -25,8 +25,8 @@ import java.io.*; import java.util.*; import java.awt.*; import javax.swing.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; import libaltosJNI.*; @@ -72,7 +72,7 @@ public class AltosSerial extends AltosLink { Object[] options = { "Cancel" }; JOptionPane pane = new JOptionPane(); - pane.setMessage(String.format("Connecting to %s, %7.3f MHz", device.toShortString(), frequency)); + pane.setMessage(String.format("Connecting to %s, %7.3f MHz as %s", device.toShortString(), frequency, callsign)); pane.setOptions(options); pane.setInitialValue(null); diff --git a/altosui/AltosSerialInUseException.java b/altosui/AltosSerialInUseException.java index 932a3684..b45d9157 100644 --- a/altosui/AltosSerialInUseException.java +++ b/altosui/AltosSerialInUseException.java @@ -16,7 +16,7 @@ */ package altosui; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; public class AltosSerialInUseException extends Exception { public AltosDevice device; diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index 4e939b88..f614eae6 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -23,7 +23,8 @@ import java.io.*; import java.lang.Math; import java.awt.geom.Point2D; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // preferred vertical step in a tile in naut. miles @@ -321,6 +322,22 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { last_state = state.state; } + public void centre(Point2D.Double pt) { + Rectangle r = comp.getVisibleRect(); + Point2D.Double copt = translatePoint(pt, tileCoordOffset(topleft)); + int dx = (int)copt.x - r.width/2 - r.x; + int dy = (int)copt.y - r.height/2 - r.y; + r.x += dx; + r.y += dy; + comp.scrollRectToVisible(r); + } + + public void centre(AltosState state) { + if (!state.gps.locked && state.gps.nsat < 4) + return; + centre(pt(state.gps.lat, state.gps.lon)); + } + public void draw_circle(double lat, double lon) { final Point2D.Double pt = pt(lat, lon); diff --git a/altosui/AltosSiteMapPreload.java b/altosui/AltosSiteMapPreload.java index f4dcc903..fd648abc 100644 --- a/altosui/AltosSiteMapPreload.java +++ b/altosui/AltosSiteMapPreload.java @@ -26,7 +26,7 @@ import java.text.*; import java.lang.Math; import java.net.URL; import java.net.URLConnection; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altosuilib_1.*; class AltosMapPos extends Box { AltosUI owner; diff --git a/altosui/AltosSiteMapTile.java b/altosui/AltosSiteMapTile.java index e9d4a20b..10e65bcd 100644 --- a/altosui/AltosSiteMapTile.java +++ b/altosui/AltosSiteMapTile.java @@ -22,7 +22,7 @@ import java.awt.image.*; import javax.swing.*; import java.awt.geom.Point2D; import java.awt.geom.Line2D; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosSiteMapTile extends JLayeredPane { JLabel mapLabel; diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 70142a93..9f8f6dda 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -22,8 +22,8 @@ import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.concurrent.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosUI extends AltosUIFrame { public AltosVoice voice = new AltosVoice(); @@ -48,7 +48,7 @@ public class AltosUI extends AltosUIFrame { } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(AltosUI.this, ee.getMessage(), - "Cannot open target device", + String.format ("Cannot open %s", device.toShortString()), JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { JOptionPane.showMessageDialog(AltosUI.this, @@ -58,17 +58,17 @@ public class AltosUI extends AltosUIFrame { JOptionPane.ERROR_MESSAGE); } catch (IOException ee) { JOptionPane.showMessageDialog(AltosUI.this, - device.toShortString(), - "Unkonwn I/O error", + String.format ("Unknown I/O error on %s", device.toShortString()), + "Unknown I/O error", JOptionPane.ERROR_MESSAGE); } catch (TimeoutException te) { JOptionPane.showMessageDialog(this, - device.toShortString(), + String.format ("Timeout on %s", device.toShortString()), "Timeout error", JOptionPane.ERROR_MESSAGE); } catch (InterruptedException ie) { JOptionPane.showMessageDialog(this, - device.toShortString(), + String.format("Interrupted %s", device.toShortString()), "Interrupted exception", JOptionPane.ERROR_MESSAGE); } @@ -224,14 +224,6 @@ public class AltosUI extends AltosUIFrame { doLayout(); validate(); - setVisible(true); - - Insets i = getInsets(); - Dimension ps = rootPane.getPreferredSize(); - ps.width += i.left + i.right; - ps.height += i.top + i.bottom; - setPreferredSize(ps); - setSize(ps); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override @@ -239,6 +231,11 @@ public class AltosUI extends AltosUIFrame { System.exit(0); } }); + + setLocationByPlatform(false); + + /* Insets aren't set before the window is visible */ + setVisible(true); } private void ConnectToDevice() { @@ -331,7 +328,7 @@ public class AltosUI extends AltosUIFrame { if (record_reader == null) return; try { - new AltosGraphUI(record_reader, chooser.filename()); + new AltosGraphUI(record_reader, chooser.file()); } catch (InterruptedException ie) { } catch (IOException ie) { } @@ -348,15 +345,14 @@ public class AltosUI extends AltosUIFrame { } } - static AltosRecordIterable open_logfile(String filename) { - File file = new File (filename); + static AltosRecordIterable open_logfile(File file) { try { FileInputStream in; in = new FileInputStream(file); - if (filename.endsWith("eeprom")) + if (file.getName().endsWith("eeprom")) return new AltosEepromIterable(in); - else if (filename.endsWith("mega")) + else if (file.getName().endsWith("mega")) return new AltosEepromMegaIterable(in); else return new AltosTelemetryIterable(in); @@ -366,8 +362,7 @@ public class AltosUI extends AltosUIFrame { } } - static AltosWriter open_csv(String filename) { - File file = new File (filename); + static AltosWriter open_csv(File file) { try { return new AltosCSV(file); } catch (FileNotFoundException fe) { @@ -376,8 +371,7 @@ public class AltosUI extends AltosUIFrame { } } - static AltosWriter open_kml(String filename) { - File file = new File (filename); + static AltosWriter open_kml(File file) { try { return new AltosKML(file); } catch (FileNotFoundException fe) { @@ -393,12 +387,12 @@ public class AltosUI extends AltosUIFrame { static final int process_replay = 4; static final int process_summary = 5; - static boolean process_csv(String input) { + static boolean process_csv(File input) { AltosRecordIterable iterable = open_logfile(input); if (iterable == null) return false; - String output = Altos.replace_extension(input,".csv"); + File output = Altos.replace_extension(input,".csv"); System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); if (input.equals(output)) { System.out.printf("Not processing '%s'\n", input); @@ -413,12 +407,12 @@ public class AltosUI extends AltosUIFrame { return true; } - static boolean process_kml(String input) { + static boolean process_kml(File input) { AltosRecordIterable iterable = open_logfile(input); if (iterable == null) return false; - String output = Altos.replace_extension(input,".kml"); + File output = Altos.replace_extension(input,".kml"); System.out.printf("Processing \"%s\" to \"%s\"\n", input, output); if (input.equals(output)) { System.out.printf("Not processing '%s'\n", input); @@ -453,19 +447,15 @@ public class AltosUI extends AltosUIFrame { return recs; } - static AltosRecordIterable record_iterable_file(String filename) { - return record_iterable (new File(filename)); - } - - static AltosReplayReader replay_file(String filename) { - AltosRecordIterable recs = record_iterable_file(filename); + static AltosReplayReader replay_file(File file) { + AltosRecordIterable recs = record_iterable(file); if (recs == null) return null; - return new AltosReplayReader(recs.iterator(), new File(filename)); + return new AltosReplayReader(recs.iterator(), file); } - static boolean process_replay(String filename) { - AltosReplayReader reader = replay_file(filename); + static boolean process_replay(File file) { + AltosReplayReader reader = replay_file(file); if (reader == null) return false; AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader); @@ -473,12 +463,12 @@ public class AltosUI extends AltosUIFrame { return true; } - static boolean process_graph(String filename) { - AltosRecordIterable recs = record_iterable_file(filename); + static boolean process_graph(File file) { + AltosRecordIterable recs = record_iterable(file); if (recs == null) return false; try { - new AltosGraphUI(recs, filename); + new AltosGraphUI(recs, file); return true; } catch (InterruptedException ie) { } catch (IOException ie) { @@ -486,8 +476,8 @@ public class AltosUI extends AltosUIFrame { return false; } - static boolean process_summary(String filename) { - AltosRecordIterable iterable = record_iterable_file(filename); + static boolean process_summary(File file) { + AltosRecordIterable iterable = record_iterable(file); if (iterable == null) return false; try { @@ -552,7 +542,6 @@ public class AltosUI extends AltosUIFrame { /* Handle batch-mode */ if (args.length == 0) { AltosUI altosui = new AltosUI(); - altosui.setVisible(true); java.util.List<AltosDevice> devices = AltosUSBDevice.list(Altos.product_basestation); for (AltosDevice device : devices) @@ -584,26 +573,27 @@ public class AltosUI extends AltosUIFrame { else if (args[i].startsWith("--")) help(1); else { + File file = new File(args[i]); switch (process) { case process_none: case process_graph: - if (!process_graph(args[i])) + if (!process_graph(file)) ++errors; break; case process_replay: - if (!process_replay(args[i])) + if (!process_replay(file)) ++errors; break; case process_kml: - if (!process_kml(args[i])) + if (!process_kml(file)) ++errors; break; case process_csv: - if (!process_csv(args[i])) + if (!process_csv(file)) ++errors; break; case process_summary: - if (!process_summary(args[i])) + if (!process_summary(file)) ++errors; break; } diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java deleted file mode 100644 index 9c56d031..00000000 --- a/altosui/AltosUIPreferences.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright © 2011 Keith Packard <keithp@keithp.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package altosui; - -import java.io.*; -import java.util.*; -import java.awt.Component; -import javax.swing.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; - -public class AltosUIPreferences extends AltosPreferences { - - /* font size preferences name */ - final static String fontSizePreference = "FONT-SIZE"; - - /* Look&Feel preference name */ - final static String lookAndFeelPreference = "LOOK-AND-FEEL"; - - /* UI Component to pop dialogs up */ - static Component component; - - static LinkedList<AltosFontListener> font_listeners; - - static int font_size = Altos.font_size_medium; - - static LinkedList<AltosUIListener> ui_listeners; - - static String look_and_feel = null; - - /* Serial debug */ - static boolean serial_debug; - - public static void init() { - AltosPreferences.init(new AltosUIPreferencesBackend()); - - font_listeners = new LinkedList<AltosFontListener>(); - - font_size = backend.getInt(fontSizePreference, Altos.font_size_medium); - Altos.set_fonts(font_size); - look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); - - ui_listeners = new LinkedList<AltosUIListener>(); - serial_debug = backend.getBoolean(serialDebugPreference, false); - AltosLink.set_debug(serial_debug); - } - - static { init(); } - - static void set_component(Component in_component) { - component = in_component; - } - - private static boolean check_dir(File dir) { - if (!dir.exists()) { - if (!dir.mkdirs()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Cannot create directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - } else if (!dir.isDirectory()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Is not a directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - return true; - } - - /* Configure the log directory. This is where all telemetry and eeprom files - * will be written to, and where replay will look for telemetry files - */ - public static void ConfigureLog() { - JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); - - logdir_chooser.setDialogTitle("Configure Data Logging Directory"); - logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { - File dir = logdir_chooser.getSelectedFile(); - if (check_dir(dir)) - set_logdir(dir); - } - } - public static int font_size() { - synchronized (backend) { - return font_size; - } - } - - static void set_fonts() { - } - - public static void set_font_size(int new_font_size) { - synchronized (backend) { - font_size = new_font_size; - backend.putInt(fontSizePreference, font_size); - flush_preferences(); - Altos.set_fonts(font_size); - for (AltosFontListener l : font_listeners) - l.font_size_changed(font_size); - } - } - - public static void register_font_listener(AltosFontListener l) { - synchronized (backend) { - font_listeners.add(l); - } - } - - public static void unregister_font_listener(AltosFontListener l) { - synchronized (backend) { - font_listeners.remove(l); - } - } - - public static void set_look_and_feel(String new_look_and_feel) { - try { - UIManager.setLookAndFeel(new_look_and_feel); - } catch (Exception e) { - } - synchronized(backend) { - look_and_feel = new_look_and_feel; - backend.putString(lookAndFeelPreference, look_and_feel); - flush_preferences(); - for (AltosUIListener l : ui_listeners) - l.ui_changed(look_and_feel); - } - } - - public static String look_and_feel() { - synchronized (backend) { - return look_and_feel; - } - } - - public static void register_ui_listener(AltosUIListener l) { - synchronized(backend) { - ui_listeners.add(l); - } - } - - public static void unregister_ui_listener(AltosUIListener l) { - synchronized (backend) { - ui_listeners.remove(l); - } - } - public static void set_serial_debug(boolean new_serial_debug) { - AltosLink.set_debug(new_serial_debug); - synchronized (backend) { - serial_debug = new_serial_debug; - backend.putBoolean(serialDebugPreference, serial_debug); - flush_preferences(); - } - } - - public static boolean serial_debug() { - synchronized (backend) { - return serial_debug; - } - } - -} diff --git a/altosui/AltosUIPreferencesBackend.java b/altosui/AltosUIPreferencesBackend.java index 3131fd32..0dac9fc7 100644 --- a/altosui/AltosUIPreferencesBackend.java +++ b/altosui/AltosUIPreferencesBackend.java @@ -19,7 +19,7 @@ package altosui; import java.io.File; import java.util.prefs.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; import javax.swing.filechooser.FileSystemView; public class AltosUIPreferencesBackend implements AltosPreferencesBackend { diff --git a/altosui/AltosVoice.java b/altosui/AltosVoice.java index f84c1122..2ed6a8c2 100644 --- a/altosui/AltosVoice.java +++ b/altosui/AltosVoice.java @@ -20,6 +20,7 @@ package altosui; import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.altosuilib_1.*; public class AltosVoice implements Runnable { VoiceManager voice_manager; diff --git a/altosui/AltosWriter.java b/altosui/AltosWriter.java index 6806c50e..2f70b472 100644 --- a/altosui/AltosWriter.java +++ b/altosui/AltosWriter.java @@ -17,7 +17,7 @@ package altosui; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public interface AltosWriter { diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 7d000f7b..8ae1a72e 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -62,7 +62,6 @@ altosui_JAVA = \ AltosLed.java \ AltosLights.java \ AltosPad.java \ - AltosUIPreferences.java \ AltosUIPreferencesBackend.java \ AltosRomconfig.java \ AltosRomconfigUI.java \ @@ -75,10 +74,9 @@ altosui_JAVA = \ AltosSiteMapTile.java \ AltosUI.java \ AltosWriter.java \ - AltosDataPointReader.java \ - AltosDataPoint.java \ AltosGraph.java \ - AltosGraphTime.java \ + AltosGraphDataPoint.java \ + AltosGraphDataSet.java \ AltosGraphUI.java \ AltosDataChooser.java \ AltosVoice.java \ @@ -100,10 +98,10 @@ FREETTS_CLASS= \ freetts.jar ALTOSLIB_CLASS=\ - AltosLib.jar + altoslib_$(ALTOSLIB_VERSION).jar ALTOSUILIB_CLASS=\ - altosuilib.jar + altosuilib_$(ALTOSUILIB_VERSION).jar LIBALTOS= \ libaltos.so \ diff --git a/altosui/altos-windows.nsi b/altosui/altos-windows.nsi.in index 20dd65f0..cde54b41 100644 --- a/altosui/altos-windows.nsi +++ b/altosui/altos-windows.nsi.in @@ -88,7 +88,8 @@ Section "AltosUI Application" SetOutPath $INSTDIR File "altosui-fat.jar" - File "AltosLib.jar" + File "altoslib_@ALTOSLIB_VERSION@.jar" + File "altosuilib_@ALTOSUILIB_VERSION@.jar" File "cmudict04.jar" File "cmulex.jar" File "cmu_time_awb.jar" |
