forked from j62/ctbrec
1
0
Fork 0

Load stylesheets from parent stage

Also, move the notification to the bottom right
This commit is contained in:
0xboobface 2018-11-29 01:05:03 +01:00
parent cf9a6d3f85
commit 09a65c0a96
3 changed files with 16 additions and 14 deletions

View File

@ -48,7 +48,6 @@ import javafx.scene.control.Alert;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.control.TabPane; import javafx.scene.control.TabPane;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.media.AudioClip;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.stage.Stage; import javafx.stage.Stage;
import okhttp3.Request; import okhttp3.Request;
@ -66,7 +65,7 @@ public class CamrecApplication extends Application {
private TabPane rootPane = new TabPane(); private TabPane rootPane = new TabPane();
private List<Site> sites = new ArrayList<>(); private List<Site> sites = new ArrayList<>();
public static HttpClient httpClient; public static HttpClient httpClient;
private Notification.Notifier notifier; private Notification.Notifier notifier = Notification.Notifier.INSTANCE;
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
@ -93,6 +92,7 @@ public class CamrecApplication extends Application {
} }
createGui(primaryStage); createGui(primaryStage);
checkForUpdates(); checkForUpdates();
new Thread(() -> { new Thread(() -> {
try { try {
Thread.sleep(TimeUnit.SECONDS.toMillis(10)); Thread.sleep(TimeUnit.SECONDS.toMillis(10));
@ -212,7 +212,6 @@ public class CamrecApplication extends Application {
private void registerAlertSystem() { private void registerAlertSystem() {
Notification.Notifier.setNotificationOwner(primaryStage); Notification.Notifier.setNotificationOwner(primaryStage);
notifier = Notification.Notifier.INSTANCE;
EventBusHolder.BUS.register(new Object() { EventBusHolder.BUS.register(new Object() {
@Subscribe @Subscribe
public void modelEvent(Map<String, Object> e) { public void modelEvent(Map<String, Object> e) {
@ -223,10 +222,9 @@ public class CamrecApplication extends Application {
LOG.debug("Alert: {} is {}", model.getName(), status); LOG.debug("Alert: {} is {}", model.getName(), status);
if (Objects.equals("online", status)) { if (Objects.equals("online", status)) {
Platform.runLater(() -> { Platform.runLater(() -> {
AudioClip clip = new AudioClip("file:///tmp/Oxygen-Im-Highlight-Msg.mp3"); notifier.notifyInfo("Model Online", model.getName() + " is now online");
clip.play(); //AudioClip clip = new AudioClip("file:///tmp/Oxygen-Im-Highlight-Msg.mp3");
Notification notification = new Notification("Model Online", model.getName() + " is now online"); //clip.play();
notifier.notify(notification);
}); });
} }
} }

View File

@ -79,7 +79,7 @@ public class Notification {
private static double offsetX = 0; private static double offsetX = 0;
private static double offsetY = 25; private static double offsetY = 25;
private static double spacingY = 5; private static double spacingY = 5;
private static Pos popupLocation = Pos.TOP_RIGHT; private static Pos popupLocation = Pos.BOTTOM_RIGHT;
private static Stage stageRef = null; private static Stage stageRef = null;
private Duration popupLifetime; private Duration popupLifetime;
private Stage stage; private Stage stage;
@ -101,7 +101,10 @@ public class Notification {
} }
private void initGraphics() { private void initGraphics() {
scene = new Scene(new Region()); Region region = new Region();
region.resize(0, 0);
region.setVisible(false);
scene = new Scene(region);
scene.setFill(null); scene.setFill(null);
scene.getStylesheets().add(getClass().getResource("notifier.css").toExternalForm()); scene.getStylesheets().add(getClass().getResource("notifier.css").toExternalForm());
@ -134,6 +137,7 @@ public class Notification {
*/ */
public static void setNotificationOwner(final Stage OWNER) { public static void setNotificationOwner(final Stage OWNER) {
INSTANCE.stage.initOwner(OWNER); INSTANCE.stage.initOwner(OWNER);
INSTANCE.stage.getScene().getStylesheets().addAll(OWNER.getScene().getStylesheets());
} }
/** /**
@ -306,7 +310,6 @@ public class Notification {
final Popup POPUP = new Popup(); final Popup POPUP = new Popup();
POPUP.setX( getX() ); POPUP.setX( getX() );
POPUP.setY( getY() ); POPUP.setY( getY() );
System.out.println(POPUP.getX() + "," + POPUP.getY());
POPUP.getContent().add(popupContent); POPUP.getContent().add(popupContent);
popups.add(POPUP); popups.add(POPUP);
@ -323,6 +326,7 @@ public class Notification {
timeline.setOnFinished(actionEvent -> Platform.runLater(() -> { timeline.setOnFinished(actionEvent -> Platform.runLater(() -> {
POPUP.hide(); POPUP.hide();
popups.remove(POPUP); popups.remove(POPUP);
stage.hide();
})); }));
// Move popup to the right during fade out // Move popup to the right during fade out

View File

@ -19,11 +19,11 @@
-fx-fill : transparent; -fx-fill : transparent;
} }
.notification { .notification {
-fx-background-color : -fx-background; -fx-background-color : -fx-base;
-fx-background-radius: 5; -fx-background-radius: 5;
-fx-effect : innershadow(two-pass-box, rgba(255, 255, 255, 0.6), 5.0, 0.25, 0, 0); -fx-effect : dropshadow(gaussian, rgba(0, 0, 0, 0.8), 20, 0, 0, 0);
-foreground-color : -fx-base; -foreground-color : -fx-text-background-color;
-icon-color : -fx-base; -icon-color : -fx-text-background-color;
} }
.notification .title { .notification .title {