Skip to content

Commit 61e43c5

Browse files
committed
Allowing application to properly close
1 parent 11417e3 commit 61e43c5

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
package com.JayPi4c.RobbiSimulator.controller;
22

3-
import javafx.concurrent.Service;
4-
import javafx.concurrent.Task;
3+
import javafx.animation.KeyFrame;
4+
import javafx.animation.Timeline;
55
import javafx.scene.Node;
66
import javafx.scene.Parent;
7+
import javafx.util.Duration;
78
import lombok.extern.slf4j.Slf4j;
89
import org.controlsfx.control.NotificationPane;
910

10-
import java.util.concurrent.*;
11-
1211
import static com.JayPi4c.RobbiSimulator.utils.I18nUtils.i18n;
1312

1413
@Slf4j
1514
public class NotificationController {
1615

1716
private final NotificationPane notificationPane;
18-
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
19-
Thread thread = Executors.defaultThreadFactory().newThread(r);
20-
thread.setDaemon(true);
21-
return thread;
22-
});
23-
private Future<?> schedulerFuture;
17+
private final Timeline hideTimeline = new Timeline();
2418

2519
public NotificationController(Node node) {
2620
notificationPane = new NotificationPane(node);
2721
notificationPane.setShowFromTop(false);
2822
notificationPane.getStyleClass().add(NotificationPane.STYLE_CLASS_DARK);
23+
hideTimeline.setCycleCount(1);
2924
}
3025

3126
public Parent getScene() {
@@ -41,12 +36,14 @@ public Parent getScene() {
4136
* @param args the arguments for the message
4237
*/
4338
public void showMessage(int timeout, String key, Object... args) {
44-
if (schedulerFuture != null && !schedulerFuture.isDone()) {
45-
schedulerFuture.cancel(true);
46-
}
47-
logger.info("Showing snackbar-message: {}; {}", key, i18n(key, args));
39+
hideTimeline.stop();
4840
notificationPane.show(i18n(key, args));
49-
schedulerFuture = scheduler.schedule(notificationPane::hide, timeout, TimeUnit.MILLISECONDS);
41+
KeyFrame kf = new KeyFrame(Duration.millis(timeout), e -> {
42+
if (notificationPane.isShowing())
43+
notificationPane.hide();
44+
});
45+
hideTimeline.getKeyFrames().setAll(kf);
46+
hideTimeline.play();
5047
}
5148

5249
}

src/main/java/com/JayPi4c/RobbiSimulator/view/Toolbar.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Toolbar extends ToolBar {
2121
/**
2222
* Constant for the maximum value for the speed slider.
2323
*/
24-
public static final int MAX_SPEED_VALUE = 100;
24+
public static final int MAX_SPEED_VALUE = 10;
2525
private MenuBar menubar;
2626
// Tool bar
2727
private Button newButtonToolbar;
@@ -148,6 +148,8 @@ private void createToolbar() {
148148
stopToggleButtonToolbar.setToggleGroup(simulationGroupToolbar);
149149

150150
speedSliderToolbar = new Slider(MIN_SPEED_VALUE, MAX_SPEED_VALUE, (MIN_SPEED_VALUE + MAX_SPEED_VALUE) / 2d);
151+
speedSliderToolbar.setShowTickLabels(true);
152+
speedSliderToolbar.setShowTickMarks(true);
151153

152154
getItems().addAll(newButtonToolbar, loadButtonToolbar, new Separator(), saveButtonToolbar, compileButtonToolbar,
153155
new Separator(), changeSizeButtonToolbar, placeRobbiToggleButtonToolbar, placeHollowToggleButtonToolbar,

0 commit comments

Comments
 (0)