Skip to content

Commit

Permalink
Switched latest button to use toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Nov 4, 2020
1 parent d3cb1f5 commit 782caf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/uorocketry/basestation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ private void updateUIInternal() {
// Set max value of the sliders
window.maxSliders.get(i).setMaximum(allData.get(i).size() - 1);
window.minSliders.get(i).setMaximum(allData.get(i).size() - 1);

// Move position to end
if (latest) {
window.maxSliders.get(i).setValue(allData.get(i).size() - 1);
}
}

DataHandler currentDataHandler = allData.get(i).get(currentDataIndexes.get(i));
Expand Down Expand Up @@ -663,7 +668,7 @@ public void stateChanged(ChangeEvent e) {
if (e.getSource() instanceof JSlider && window.maxSliders.contains(e.getSource())) {
JSlider maxSlider = (JSlider) e.getSource();
int tableIndex = window.maxSliders.indexOf(maxSlider);

currentDataIndexes.set(tableIndex, maxSlider.getValue());

// Check if min is too high
Expand All @@ -672,8 +677,6 @@ public void stateChanged(ChangeEvent e) {
window.minSliders.get(tableIndex).setValue(minDataIndexes.get(tableIndex));
}

// Update the latest value
latest = maxSlider.getValue() == maxSlider.getMaximum() - 1;

updateUI();
} else if (e.getSource() instanceof JSlider && window.minSliders.contains(e.getSource())) {
Expand Down Expand Up @@ -717,11 +720,6 @@ public void serialEvent(SerialPortEvent e) {

updateUI();

// Move position to end
if (latest) {
window.maxSliders.get(tableIndex).setValue(allData.get(0).size() - 1);
}

// Add this message to the log file
logFileStringBuilder.append(delimitedMessage);

Expand Down Expand Up @@ -763,10 +761,16 @@ public void actionPerformed(ActionEvent e) {
}

} else if (e.getSource() == window.latestButton) {
latest = true;
latest = !latest;

for (int i = 0; i < window.maxSliders.size(); i++) { latest = true;
window.maxSliders.get(i).setValue(allData.get(0).size() - 1);
if (latest) {
window.latestButton.setText("Detach From Latest");

for (int i = 0; i < window.maxSliders.size(); i++) {
window.maxSliders.get(i).setValue(allData.get(0).size() - 1);
}
} else {
window.latestButton.setText("Latest");
}
} else if (e.getSource() == window.addChartButton) {
addChart();
Expand Down
2 changes: 1 addition & 1 deletion src/uorocketry/basestation/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Window(Main main) {
pauseButton = new JButton("Pause");
eastSliderButtons.add(pauseButton);

latestButton = new JButton("Latest");
latestButton = new JButton("Detach From Latest");
eastSliderButtons.add(latestButton);

sidePanel = new JPanel();
Expand Down

0 comments on commit 782caf8

Please sign in to comment.