Skip to content

Commit 798e7e3

Browse files
committed
Fix Platform.runLater() usage
Our code is not really written to handle asyncronous GUI updates in many situations, such as updating the pipeline view when steps are added/deleted/moved. So, in these situations we should block the calling thread until the GUI thread has finished performing the specified action. In addition, it is not necessary to call Platorm.runLater() from the GUI thread.
1 parent a9f405e commit 798e7e3

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void loadCamera(Dialog<ButtonType> dialog, SupplierWithIO<CameraSource>
164164
} catch (IOException e) {
165165
// This will run it again with the new values retrieved by the supplier
166166
failureCallback.accept(e);
167-
Platform.runLater(() -> loadCamera(dialog, cameraSourceSupplier, failureCallback));
167+
loadCamera(dialog, cameraSourceSupplier, failureCallback);
168168
}
169169
});
170170
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.google.common.eventbus.EventBus;
44
import com.google.common.eventbus.Subscribe;
5+
import com.sun.javafx.application.PlatformImpl;
56
import edu.wpi.grip.core.*;
67
import edu.wpi.grip.core.events.*;
78
import edu.wpi.grip.ui.pipeline.input.InputSocketView;
89
import edu.wpi.grip.ui.pipeline.source.SourceView;
910
import edu.wpi.grip.ui.pipeline.source.SourceViewFactory;
10-
import javafx.application.Platform;
1111
import javafx.beans.InvalidationListener;
1212
import javafx.beans.property.ReadOnlyObjectProperty;
1313
import javafx.collections.ObservableList;
@@ -197,7 +197,7 @@ private ConnectionView findConnectionView(Connection connection) {
197197
* details of adding the connection.
198198
*/
199199
private void addConnectionView(Connection connection) {
200-
Platform.runLater(() -> {
200+
PlatformImpl.runAndWait(() -> {
201201
// Before adding a connection control, we have to look up the controls for both sockets in the connection so
202202
// we know where to position it.
203203
final OutputSocketView outputSocketView = findOutputSocketView(connection.getOutputSocket());
@@ -218,7 +218,7 @@ private void addConnectionView(Connection connection) {
218218
final double x2 = inputSocketBounds.getMinX() + inputSocketBounds.getWidth() / 2.0;
219219
final double y2 = inputSocketBounds.getMinY() + inputSocketBounds.getHeight() / 2.0;
220220

221-
Platform.runLater(() -> {
221+
PlatformImpl.runAndWait(() -> {
222222
connectionView.inputHandleProperty().setValue(new Point2D(x1, y1));
223223
connectionView.outputHandleProperty().setValue(new Point2D(x2, y2));
224224
((ReadOnlyObjectProperty) observable).get();
@@ -236,20 +236,20 @@ private void addConnectionView(Connection connection) {
236236

237237
@Subscribe
238238
public void onSourceAdded(SourceAddedEvent event) {
239-
Platform.runLater(() ->
239+
PlatformImpl.runAndWait(() ->
240240
this.sources.getChildren().add(
241241
SourceViewFactory.createSourceControlsView(eventBus, event.getSource())));
242242
}
243243

244244
@Subscribe
245245
public void onSourceRemoved(SourceRemovedEvent event) {
246-
Platform.runLater(() -> this.sources.getChildren().remove(findSourceView(event.getSource())));
246+
PlatformImpl.runAndWait(() -> this.sources.getChildren().remove(findSourceView(event.getSource())));
247247
}
248248

249249
@Subscribe
250250
public void onStepAdded(StepAddedEvent event) {
251251
// Add a new control to the pipelineview for the step that was added
252-
Platform.runLater(() -> {
252+
PlatformImpl.runAndWait(() -> {
253253
int index = event.getIndex().or(this.steps.getChildren().size());
254254
this.steps.getChildren().add(index, new StepView(this.eventBus, event.getStep()));
255255
});
@@ -258,7 +258,7 @@ public void onStepAdded(StepAddedEvent event) {
258258
@Subscribe
259259
public void onStepRemoved(StepRemovedEvent event) {
260260
// Remove the control that corresponds with the step that was removed
261-
Platform.runLater(() -> {
261+
PlatformImpl.runAndWait(() -> {
262262
final StepView stepView = findStepView(event.getStep());
263263
this.steps.getChildren().remove(stepView);
264264
this.eventBus.unregister(stepView);
@@ -267,7 +267,7 @@ public void onStepRemoved(StepRemovedEvent event) {
267267

268268
@Subscribe
269269
public void onStepMoved(StepMovedEvent event) {
270-
Platform.runLater(() -> {
270+
PlatformImpl.runAndWait(() -> {
271271
final StepView stepView = findStepView(event.getStep());
272272

273273
final int oldIndex = this.getSteps().indexOf(stepView);
@@ -283,13 +283,13 @@ public void onStepMoved(StepMovedEvent event) {
283283
@Subscribe
284284
public void onConnectionAdded(ConnectionAddedEvent event) {
285285
// Add the new connection view
286-
Platform.runLater(() -> this.addConnectionView(event.getConnection()));
286+
PlatformImpl.runAndWait(() -> this.addConnectionView(event.getConnection()));
287287
}
288288

289289
@Subscribe
290290
public void onConnectionRemoved(ConnectionRemovedEvent event) {
291291
// Remove the control that corresponds with the connection that was removed
292-
Platform.runLater(() -> {
292+
PlatformImpl.runAndWait(() -> {
293293
final ConnectionView connectionView = findConnectionView(event.getConnection());
294294
this.connections.getChildren().remove(connectionView);
295295
this.eventBus.unregister(connectionView);

0 commit comments

Comments
 (0)