diff --git a/src/uorocketry/basestation/DataHandler.java b/src/uorocketry/basestation/DataHandler.java index fdab3fd..8c52f89 100644 --- a/src/uorocketry/basestation/DataHandler.java +++ b/src/uorocketry/basestation/DataHandler.java @@ -59,6 +59,39 @@ public void updateTableUIWithData(JTable table, String[] labels) { String dataText = data[i].getFormattedString(); if (hiddenDataTypes.contains(types[i])) dataText = "Hidden Data"; + // Hardcode for now TODO: Move this into config + if (i == data.length - 1 && labels[i].toLowerCase().contains("state")) { + switch (dataText) { + case "0": + dataText = "Init"; + break; + case "1": + dataText = "Wait For Init"; + break; + case "2": + dataText = "Wait For Launch"; + break; + case "3": + dataText = "Powered Flight"; + break; + case "4": + dataText = "Coast"; + break; + case "5": + dataText = "Descent Phase 1"; + break; + case "6": + dataText = "Descent Phase 2"; + break; + case "7": + dataText = "Ground"; + break; + case "8": + dataText = "Max States"; + break; + } + } + // Set data tableModel.setValueAt(dataText, i, 1); } diff --git a/src/uorocketry/basestation/Main.java b/src/uorocketry/basestation/Main.java index 6071903..c29e13e 100644 --- a/src/uorocketry/basestation/Main.java +++ b/src/uorocketry/basestation/Main.java @@ -84,7 +84,7 @@ public class Main implements ComponentListener, ChangeListener, ActionListener, ArrayList currentLogFileName = new ArrayList(2); /** Used to limit displayed data points to speed up rendering */ - public static int maxDataPointsDisplayed = 1000; + public static int maxDataPointsDisplayed = 800; /** How many data sources to record data from. It is set when the config is loaded. */ public static int dataSourceCount = 1; @@ -133,6 +133,9 @@ public class Main implements ComponentListener, ChangeListener, ActionListener, /** Set to true when automatically selecting or deselcting from the data table */ boolean ignoreSelections = false; + /** If true, it will show the latest data instead of showing a subset of all data */ + boolean onlyShowLatestData = false; + /** If true, clicking on data in a chart will hide it */ boolean dataDeletionMode = false; @@ -334,6 +337,8 @@ public void setupUI() { window.addChartButton.addActionListener(this); + window.setMaxDataPointsButton.addActionListener(this); + window.restoreDeletedData.addActionListener(this); window.saveLayout.addActionListener(this); @@ -342,6 +347,7 @@ public void setupUI() { // Checkboxes window.googleEarthCheckBox.addActionListener(this); window.simulationCheckBox.addActionListener(this); + window.onlyShowLatestDataCheckBox.addActionListener(this); window.dataDeletionModeCheckBox.addActionListener(this); // Set simulation checkbox to be default @@ -401,6 +407,10 @@ private void updateUIInternal() { // Move position to end if (latest) { window.maxSliders.get(i).setValue(allData.get(i).size() - 1); + + if (onlyShowLatestData) { + window.minSliders.get(i).setValue(allData.get(i).size() - 1 - maxDataPointsDisplayed); + } } } @@ -486,7 +496,8 @@ public void updateChart(DataChart chart) { if (data != null) { // Ensures that not too many data points are displayed - boolean shouldShowDataPoint = (float) dataPointsAdded / j <= targetRatio; + // Always show data if only showing latest data (that is handled by changing the minSlider) + boolean shouldShowDataPoint = onlyShowLatestData || ((float) dataPointsAdded / j <= targetRatio); if (!data.hiddenDataTypes.contains(data.types[chart.xTypes[i].index]) && shouldShowDataPoint ) { altitudeDataY.get(i).add(data.data[chart.xTypes[i].index].getDecimalValue()); @@ -794,6 +805,13 @@ public void actionPerformed(ActionEvent e) { } else { window.simulationCheckBox.setSelected(simulation); } + } else if (e.getSource() == window.onlyShowLatestDataCheckBox) { + onlyShowLatestData = window.onlyShowLatestDataCheckBox.isSelected(); + } else if (e.getSource() == window.setMaxDataPointsButton) { + try { + int maxDataPoints = Integer.parseInt(window.maxDataPointsTextField.getText()); + maxDataPointsDisplayed = maxDataPoints; + } catch (NumberFormatException err) {} } else if (e.getSource() == window.dataDeletionModeCheckBox) { dataDeletionMode = window.dataDeletionModeCheckBox.isSelected(); } else if (e.getSource() == window.restoreDeletedData) { diff --git a/src/uorocketry/basestation/Window.java b/src/uorocketry/basestation/Window.java index e924572..7fda648 100644 --- a/src/uorocketry/basestation/Window.java +++ b/src/uorocketry/basestation/Window.java @@ -22,6 +22,7 @@ import javax.swing.JScrollPane; import javax.swing.JSlider; import javax.swing.JTable; +import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; import javax.swing.UIManager; @@ -45,6 +46,12 @@ public class Window extends JFrame { JCheckBox googleEarthCheckBox; JCheckBox simulationCheckBox; + private JPanel chartDataPointsOptions; + JCheckBox onlyShowLatestDataCheckBox; + JPanel maxDataPoints; + JButton setMaxDataPointsButton; + JTextField maxDataPointsTextField; + private JPanel dataTools; JButton restoreDeletedData; JCheckBox dataDeletionModeCheckBox; @@ -122,6 +129,28 @@ public Window(Main main) { simulationCheckBox = new JCheckBox("Simulation"); leftPanel.add(simulationCheckBox); + chartDataPointsOptions = new JPanel(); + chartDataPointsOptions.setBorder(new TitledBorder(null, "Chart Data Points", TitledBorder.LEADING, TitledBorder.TOP, null, null)); + leftPanel.add(chartDataPointsOptions); + chartDataPointsOptions.setLayout(new BoxLayout(chartDataPointsOptions, BoxLayout.Y_AXIS)); + + onlyShowLatestDataCheckBox = new JCheckBox("Only Show Latest Data"); + chartDataPointsOptions.add(onlyShowLatestDataCheckBox); + + maxDataPoints = new JPanel(); + maxDataPoints.setAlignmentY(Component.TOP_ALIGNMENT); + maxDataPoints.setAlignmentX(Component.LEFT_ALIGNMENT); + maxDataPoints.setLayout(new BoxLayout(maxDataPoints, BoxLayout.X_AXIS)); + chartDataPointsOptions.add(maxDataPoints); + + maxDataPointsTextField = new JTextField(6); + maxDataPointsTextField.setMaximumSize(maxDataPointsTextField.getPreferredSize()); + maxDataPointsTextField.setText(Main.maxDataPointsDisplayed + ""); + maxDataPoints.add(maxDataPointsTextField); + + setMaxDataPointsButton = new JButton("Set"); + maxDataPoints.add(setMaxDataPointsButton); + dataTools = new JPanel(); dataTools.setBorder(new TitledBorder(null, "Data", TitledBorder.LEADING, TitledBorder.TOP, null, null)); leftPanel.add(dataTools); @@ -227,7 +256,7 @@ public void addJTable(int tableIndex, JSONObject dataSet) { // Adjust width dataTable.getColumnModel().getColumn(0).setPreferredWidth(130); - dataTable.getColumnModel().getColumn(1).setPreferredWidth(100); + dataTable.getColumnModel().getColumn(1).setPreferredWidth(130); dataTable.setFont(new Font("Arial", Font.PLAIN, 15));