Skip to content

Commit ba9e6cf

Browse files
committed
Fixes OutputSockets preview button toggled wrong
The preview button would initialize off regardless of how the save file had the preview state set. Closes #253
1 parent 1b4e055 commit ba9e6cf

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

ui/src/main/java/edu/wpi/grip/ui/pipeline/OutputSocketController.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package edu.wpi.grip.ui.pipeline;
22

33
import com.google.common.annotations.VisibleForTesting;
4+
import com.google.common.eventbus.Subscribe;
45
import com.google.inject.Inject;
56
import com.google.inject.assistedinject.Assisted;
67
import edu.wpi.grip.core.OutputSocket;
78
import edu.wpi.grip.core.Socket;
89
import edu.wpi.grip.core.SocketHint;
10+
import edu.wpi.grip.core.events.SocketPreviewChangedEvent;
911
import edu.wpi.grip.ui.Controller;
1012
import edu.wpi.grip.ui.annotations.ParametrizedController;
13+
import javafx.beans.InvalidationListener;
1114
import javafx.fxml.FXML;
1215
import javafx.scene.Node;
1316
import javafx.scene.control.Label;
@@ -40,7 +43,8 @@ public class OutputSocketController implements Controller {
4043
@FXML
4144
private StackPane handlePane;
4245

43-
private SocketHandleView.Factory socketHandleFactory;
46+
private final SocketHandleView.Factory socketHandleFactory;
47+
private final InvalidationListener previewListener;
4448

4549
/**
4650
* The "handle" is a simple shape next ot the socket identifier that shows whether or not there is a connection
@@ -59,6 +63,7 @@ public interface Factory {
5963
OutputSocketController(SocketHandleView.Factory socketHandleFactory, @Assisted OutputSocket socket) {
6064
this.socketHandleFactory = checkNotNull(socketHandleFactory, "Socket Handle factory can not be null");
6165
this.socket = checkNotNull(socket, "The output socket can not be null");
66+
this.previewListener = value -> this.socket.setPreviewed(this.preview.isSelected());
6267
}
6368

6469
@FXML
@@ -70,7 +75,7 @@ public void initialize() {
7075

7176
// Show a button to choose if we want to preview the socket or not
7277
this.preview.setSelected(this.socket.isPreviewed());
73-
this.preview.selectedProperty().addListener(value -> this.socket.setPreviewed(this.preview.isSelected()));
78+
this.preview.selectedProperty().addListener(previewListener);
7479

7580
SocketHint<?> socketHint = this.socket.getSocketHint();
7681

@@ -87,6 +92,19 @@ public SocketHandleView getHandle() {
8792
return this.handle;
8893
}
8994

95+
@Subscribe
96+
public void onSocketPreviewChangedEvent(SocketPreviewChangedEvent event) {
97+
if (event.getSocket().equals(socket)) {
98+
// Only try to update the button if the two aren't the same
99+
// This really should only happen we deserialize the pipeline
100+
if (event.getSocket().isPreviewed() != preview.isSelected()) {
101+
preview.selectedProperty().removeListener(previewListener);
102+
preview.setSelected(event.getSocket().isPreviewed());
103+
preview.selectedProperty().addListener(previewListener);
104+
}
105+
}
106+
}
107+
90108
@VisibleForTesting
91109
ToggleButton previewButton() {
92110
return preview;

0 commit comments

Comments
 (0)