Issue #14: Notification message is now formatted properly and multiple notifications no longer overlap

This commit is contained in:
Brendan Robert 2016-02-25 01:40:27 -06:00
parent ad819c5678
commit eb21dfaec1

View File

@ -41,6 +41,9 @@ import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode; import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
@ -245,24 +248,20 @@ public class JaceUIController {
Label currentNotification = null; Label currentNotification = null;
public void displayNotification(String message) { public void displayNotification(String message) {
if (currentNotification != null) { Label oldNotification = currentNotification;
Label remove = currentNotification;
Application.invokeLater(() -> {
stackPane.getChildren().remove(remove);
});
}
Label notification = new Label(message); Label notification = new Label(message);
notification.setEffect(new DropShadow(1.0, Color.DARKGREY)); currentNotification = notification;
notification.setEffect(new DropShadow(2.0, Color.BLACK));
notification.setTextFill(Color.WHITE); notification.setTextFill(Color.WHITE);
Application.invokeLater(() -> { notification.setBackground(new Background(new BackgroundFill(Color.rgb(0,0,80, 0.7), new CornerRadii(5.0), new Insets(-5.0))));
Application.invokeLater(() -> {
stackPane.getChildren().remove(oldNotification);
stackPane.getChildren().add(notification); stackPane.getChildren().add(notification);
}); });
currentNotification = notification;
notificationExecutor.schedule(()->{ notificationExecutor.schedule(()->{
Application.invokeLater(() -> { Application.invokeLater(() -> {
stackPane.getChildren().remove(notification); stackPane.getChildren().remove(notification);
currentNotification = null;
}); });
}, 4, TimeUnit.SECONDS); }, 4, TimeUnit.SECONDS);
} }