Skip to content

Commit 678db27

Browse files
committed
make sure to catch exceptions withing the uI thread
1 parent 4955700 commit 678db27

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/main/java/com/commonwealthrobotics/TimelineManager.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ public void update(boolean clear) {
149149
int my = i;
150150
ContextMenu contextMenu = new ContextMenu();
151151
toAdd.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
152-
if (event.getButton() == MouseButton.PRIMARY) {
153-
int index = ap.get().getCurrentIndex() - 1;
154-
Button button = buttons.get(index < 0 ? 0 : index);
155-
contextMenu.hide();
156-
if (button == toAdd)
157-
return;
158-
new Thread(() -> {
159-
ap.get().moveToOpIndex(my);
160-
}).start();
161-
}
152+
BowlerStudio.runLater(() -> {
153+
if (event.getButton() == MouseButton.PRIMARY) {
154+
int index = ap.get().getCurrentIndex() - 1;
155+
Button button = buttons.get(index < 0 ? 0 : index);
156+
contextMenu.hide();
157+
if (button == toAdd)
158+
return;
159+
new Thread(() -> {
160+
ap.get().moveToOpIndex(my);
161+
}).start();
162+
}
163+
});
164+
162165
});
163166
File f = ap.get().getTimelineImageFile(i - 1);
164167
Image image = new Image(f.toURI().toString());
@@ -196,19 +199,22 @@ public void update(boolean clear) {
196199

197200
// Add event handler for right-click
198201
toAdd.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
199-
if (event.getButton() == MouseButton.SECONDARY) {
200-
// Show context menu where the mouse was clicked
201-
contextMenu.show(toAdd, event.getScreenX(), event.getScreenY());
202-
new Thread(()->{
203-
try {
204-
Thread.sleep(3000);
205-
} catch (InterruptedException e) {
206-
// TODO Auto-generated catch block
207-
e.printStackTrace();
208-
}
209-
BowlerStudio.runLater(()->contextMenu.hide());
210-
}).start();
211-
}
202+
BowlerStudio.runLater(() -> {
203+
if (event.getButton() == MouseButton.SECONDARY) {
204+
// Show context menu where the mouse was clicked
205+
contextMenu.show(toAdd, event.getScreenX(), event.getScreenY());
206+
new Thread(() -> {
207+
try {
208+
Thread.sleep(3000);
209+
} catch (InterruptedException e) {
210+
// TODO Auto-generated catch block
211+
e.printStackTrace();
212+
}
213+
BowlerStudio.runLater(() -> contextMenu.hide());
214+
}).start();
215+
}
216+
});
217+
212218
});
213219
// toAdd.addEventHandler(MouseEvent.MOUSE_ENTERED, ex -> {
214220
// contextMenu.hide();

0 commit comments

Comments
 (0)