mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 08:55:22 -04:00
Customize enzo Notification to meet Bitsquare reqs
This reflects the customizations to Notification originally committed in revision 1a6fb9, but includes *only* the Notification class instead of bringing in all related enzo types and resources. We now rely on the enzo jar for that.
This commit is contained in:
parent
6435e2ab80
commit
a845088a6e
1 changed files with 42 additions and 44 deletions
|
@ -29,25 +29,25 @@ import javafx.collections.ObservableList;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.event.EventType;
|
import javafx.event.EventType;
|
||||||
import javafx.event.WeakEventHandler;
|
import javafx.event.WeakEventHandler;
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.*;
|
import javafx.scene.*;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.image.*;
|
import javafx.scene.image.*;
|
||||||
import javafx.scene.input.*;
|
import javafx.scene.input.*;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.stage.Popup;
|
|
||||||
import javafx.stage.Screen;
|
import javafx.stage.Screen;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
|
||||||
|
import org.controlsfx.control.PopOver;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by
|
* A copy of the original {@link eu.hansolo.enzo.notification.Notification} class at revision eb1d321, containing
|
||||||
* User: hansolo
|
* several changes that were otherwise not possible through subclassing or other customization via the existing
|
||||||
* Date: 01.07.13
|
* Notification API. See git history for this file for exact details as to what has been changed. All other
|
||||||
* Time: 07:10
|
* {@code eu.hansolo.enzo.*} types are loaded from the enzo jar (see build.gradle for details).
|
||||||
*/
|
*/
|
||||||
public class Notification {
|
public class Notification {
|
||||||
public static final Image INFO_ICON = new Image(Notifier.class.getResourceAsStream("info.png"));
|
public static final Image INFO_ICON = new Image(Notifier.class.getResourceAsStream("info.png"));
|
||||||
|
@ -81,10 +81,10 @@ public class Notification {
|
||||||
|
|
||||||
private static final double ICON_WIDTH = 24;
|
private static final double ICON_WIDTH = 24;
|
||||||
private static final double ICON_HEIGHT = 24;
|
private static final double ICON_HEIGHT = 24;
|
||||||
private static double width = 300;
|
private static double width = 321;
|
||||||
private static double height = 80;
|
private static double height = 49;
|
||||||
private static double offsetX = 0;
|
private static double offsetX = 0;
|
||||||
private static double offsetY = 25;
|
private static double offsetY = 2;
|
||||||
private static double spacingY = 5;
|
private static double spacingY = 5;
|
||||||
private static Pos popupLocation = Pos.TOP_RIGHT;
|
private static Pos popupLocation = Pos.TOP_RIGHT;
|
||||||
private static Stage stageRef = null;
|
private static Stage stageRef = null;
|
||||||
|
@ -92,7 +92,7 @@ public class Notification {
|
||||||
private Duration popupAnimationTime;
|
private Duration popupAnimationTime;
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
private Scene scene;
|
private Scene scene;
|
||||||
private ObservableList<Popup> popups;
|
private ObservableList<PopOver> popups;
|
||||||
|
|
||||||
|
|
||||||
// ******************** Constructor ***************************************
|
// ******************** Constructor ***************************************
|
||||||
|
@ -112,11 +112,12 @@ public class Notification {
|
||||||
private void initGraphics() {
|
private void initGraphics() {
|
||||||
scene = new Scene(new Region());
|
scene = new Scene(new Region());
|
||||||
scene.setFill(null);
|
scene.setFill(null);
|
||||||
scene.getStylesheets().add(getClass().getResource("notifier.css").toExternalForm());
|
scene.getStylesheets().setAll(
|
||||||
|
getClass().getResource("/io/bitsquare/gui/bitsquare.css").toExternalForm(),
|
||||||
|
getClass().getResource("/io/bitsquare/gui/images.css").toExternalForm());
|
||||||
|
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
stage.initStyle(StageStyle.TRANSPARENT);
|
stage.initStyle(StageStyle.TRANSPARENT);
|
||||||
stage.setAlwaysOnTop(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -312,7 +313,7 @@ public class Notification {
|
||||||
private void preOrder() {
|
private void preOrder() {
|
||||||
if (popups.isEmpty()) return;
|
if (popups.isEmpty()) return;
|
||||||
IntStream.range(0, popups.size()).parallel().forEachOrdered(
|
IntStream.range(0, popups.size()).parallel().forEachOrdered(
|
||||||
i -> {
|
i -> Platform.runLater(() -> {
|
||||||
switch (popupLocation) {
|
switch (popupLocation) {
|
||||||
case TOP_LEFT:
|
case TOP_LEFT:
|
||||||
case TOP_CENTER:
|
case TOP_CENTER:
|
||||||
|
@ -330,7 +331,7 @@ public class Notification {
|
||||||
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
|
popups.get(i).setY(popups.get(i).getY() - height - spacingY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,39 +341,36 @@ public class Notification {
|
||||||
* @param NOTIFICATION
|
* @param NOTIFICATION
|
||||||
*/
|
*/
|
||||||
private void showPopup(final Notification NOTIFICATION) {
|
private void showPopup(final Notification NOTIFICATION) {
|
||||||
|
ImageView icon = new ImageView(
|
||||||
|
new Image(Notifier.class.getResourceAsStream("/images/notification_logo.png")));
|
||||||
|
icon.relocate(10, 7);
|
||||||
|
|
||||||
Label title = new Label(NOTIFICATION.TITLE);
|
Label title = new Label(NOTIFICATION.TITLE);
|
||||||
title.getStyleClass().add("title");
|
title.setStyle(" -fx-text-fill:#333333; -fx-font-size:12; -fx-font-weight:bold;");
|
||||||
|
title.relocate(60, 6);
|
||||||
|
|
||||||
ImageView icon = new ImageView(NOTIFICATION.IMAGE);
|
Label message = new Label(NOTIFICATION.MESSAGE);
|
||||||
icon.setFitWidth(ICON_WIDTH);
|
message.relocate(60, 25);
|
||||||
icon.setFitHeight(ICON_HEIGHT);
|
message.setStyle(" -fx-text-fill:#333333; -fx-font-size:11; ");
|
||||||
|
|
||||||
Label message = new Label(NOTIFICATION.MESSAGE, icon);
|
Pane popupLayout = new Pane();
|
||||||
message.getStyleClass().add("message");
|
popupLayout.setPrefSize(width, height);
|
||||||
|
popupLayout.getChildren().addAll(icon, title, message);
|
||||||
|
|
||||||
VBox popupLayout = new VBox();
|
PopOver popOver = new PopOver(popupLayout);
|
||||||
popupLayout.setSpacing(10);
|
popOver.setDetachable(false);
|
||||||
popupLayout.setPadding(new Insets(10, 10, 10, 10));
|
popOver.setArrowSize(0);
|
||||||
popupLayout.getChildren().addAll(title, message);
|
popOver.setX(getX());
|
||||||
|
popOver.setY(getY());
|
||||||
StackPane popupContent = new StackPane();
|
popOver.addEventHandler(MouseEvent.MOUSE_PRESSED, new WeakEventHandler<>(event ->
|
||||||
popupContent.setPrefSize(width, height);
|
fireNotificationEvent(new NotificationEvent(NOTIFICATION, Notifier.this, popOver,
|
||||||
popupContent.getStyleClass().add("notification");
|
|
||||||
popupContent.getChildren().addAll(popupLayout);
|
|
||||||
|
|
||||||
final Popup POPUP = new Popup();
|
|
||||||
POPUP.setX(getX());
|
|
||||||
POPUP.setY(getY());
|
|
||||||
POPUP.getContent().add(popupContent);
|
|
||||||
POPUP.addEventHandler(MouseEvent.MOUSE_PRESSED, new WeakEventHandler<>(event ->
|
|
||||||
fireNotificationEvent(new NotificationEvent(NOTIFICATION, Notifier.this, POPUP,
|
|
||||||
NotificationEvent.NOTIFICATION_PRESSED))
|
NotificationEvent.NOTIFICATION_PRESSED))
|
||||||
));
|
));
|
||||||
popups.add(POPUP);
|
popups.add(popOver);
|
||||||
|
|
||||||
// Add a timeline for popup fade out
|
// Add a timeline for popup fade out
|
||||||
KeyValue fadeOutBegin = new KeyValue(POPUP.opacityProperty(), 1.0);
|
KeyValue fadeOutBegin = new KeyValue(popOver.opacityProperty(), 1.0);
|
||||||
KeyValue fadeOutEnd = new KeyValue(POPUP.opacityProperty(), 0.0);
|
KeyValue fadeOutEnd = new KeyValue(popOver.opacityProperty(), 0.0);
|
||||||
|
|
||||||
KeyFrame kfBegin = new KeyFrame(Duration.ZERO, fadeOutBegin);
|
KeyFrame kfBegin = new KeyFrame(Duration.ZERO, fadeOutBegin);
|
||||||
KeyFrame kfEnd = new KeyFrame(popupAnimationTime, fadeOutEnd);
|
KeyFrame kfEnd = new KeyFrame(popupAnimationTime, fadeOutEnd);
|
||||||
|
@ -380,9 +378,9 @@ public class Notification {
|
||||||
Timeline timeline = new Timeline(kfBegin, kfEnd);
|
Timeline timeline = new Timeline(kfBegin, kfEnd);
|
||||||
timeline.setDelay(popupLifetime);
|
timeline.setDelay(popupLifetime);
|
||||||
timeline.setOnFinished(actionEvent -> Platform.runLater(() -> {
|
timeline.setOnFinished(actionEvent -> Platform.runLater(() -> {
|
||||||
POPUP.hide();
|
popOver.hide();
|
||||||
popups.remove(POPUP);
|
popups.remove(popOver);
|
||||||
fireNotificationEvent(new NotificationEvent(NOTIFICATION, Notifier.this, POPUP,
|
fireNotificationEvent(new NotificationEvent(NOTIFICATION, Notifier.this, popOver,
|
||||||
NotificationEvent.HIDE_NOTIFICATION));
|
NotificationEvent.HIDE_NOTIFICATION));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -393,8 +391,8 @@ public class Notification {
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
POPUP.show(stage);
|
popOver.show(stage);
|
||||||
fireNotificationEvent(new NotificationEvent(NOTIFICATION, Notifier.this, POPUP,
|
fireNotificationEvent(new NotificationEvent(NOTIFICATION, Notifier.this, popOver,
|
||||||
NotificationEvent.SHOW_NOTIFICATION));
|
NotificationEvent.SHOW_NOTIFICATION));
|
||||||
timeline.play();
|
timeline.play();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue