1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 02:27:32 +01:00

(gui) Notifications use a PopupWindow instead of a Stage

This commit is contained in:
dpad85 2017-02-24 14:46:12 +01:00
parent 4e2bf2b047
commit 4d99e39184
7 changed files with 20 additions and 47 deletions

View File

@ -97,7 +97,7 @@
.notifications-box {
-fx-background-color: transparent;
-fx-padding: 2em;
-fx-padding: 0;
}
.notification-pane.grid {
-fx-background-color: #252525;

View File

@ -10,7 +10,7 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane fx:id="rootPane" maxHeight="-Infinity" maxWidth="300.0" minHeight="-Infinity" minWidth="150.0" prefWidth="300.0"
<GridPane fx:id="rootPane" minWidth="300.0" prefWidth="300.0" maxWidth="300.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
onMouseEntered="#handleMouseEnter" onMouseExited="#handleMouseExit" onMouseClicked="#handleMouseClick">
<columnConstraints>

View File

@ -1,16 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.URL?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
style="-fx-background-color: transparent" styleClass="notifications-box" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<VBox fx:id="notifsVBox" spacing="10.0"
style="-fx-background-color: transparent" styleClass="notifications-box"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@../commons/globals.css" />
<URL value="@main.css" />
</stylesheets>
<children>
<VBox fx:id="notifsVBox" alignment="TOP_RIGHT" spacing="10.0" />
</children>
</Pane>
</VBox>

View File

@ -10,7 +10,6 @@ import fr.acinq.bitcoin.Crypto.PublicKey
import fr.acinq.bitcoin.{BinaryData, MilliSatoshi, Satoshi}
import fr.acinq.eclair._
import fr.acinq.eclair.gui.controllers._
import fr.acinq.eclair.gui.stages.NotificationsStage
import fr.acinq.eclair.gui.utils.GUIValidators
import fr.acinq.eclair.io.Switchboard.{NewChannel, NewConnection}
import fr.acinq.eclair.payment.CreatePayment
@ -26,11 +25,9 @@ class Handlers(setup: Setup) extends Logging {
import setup._
private var notifsController:Option[NotificationsController] = None
private var notifsStage:Option[NotificationsStage] = None
def initNotifications (controller: NotificationsController, stage: NotificationsStage) = {
def initNotifications (controller: NotificationsController) = {
notifsController = Option(controller)
notifsStage = Option(stage)
}
def open(hostPort: String, fundingSatoshis: Satoshi, pushMsat: MilliSatoshi) = {
@ -97,6 +94,6 @@ class Handlers(setup: Setup) extends Logging {
* @param showAppName true if you want the notification title to be preceded by "Eclair - ". True by default
*/
def notification (title: String, message: String, notificationType: NotificationType = NOTIFICATION_NONE, showAppName: Boolean = true) = {
notifsController.map(_.addNotification(if (showAppName) s"Eclair - $title" else title, message, notificationType, notifsStage))
notifsController.map(_.addNotification(if (showAppName) s"Eclair - $title" else title, message, notificationType))
}
}

View File

@ -14,7 +14,7 @@ import javafx.scene.input.{ContextMenuEvent, MouseEvent}
import javafx.scene.layout.{BorderPane, VBox}
import javafx.scene.paint.Color
import javafx.stage.FileChooser.ExtensionFilter
import javafx.stage.{FileChooser, Stage, WindowEvent}
import javafx.stage._
import javafx.util.Callback
import fr.acinq.eclair.gui.Handlers
@ -281,13 +281,16 @@ class MainController(val handlers: Handlers, val stage: Stage, val setup: Setup,
Platform.runLater(new Runnable() {
override def run = {
// create scene
val scene = new Scene(root)
scene.setFill(Color.TRANSPARENT)
val notifsStage = new NotificationsStage
notifsStage.setScene(scene)
notifsStage.initOwner(stage)
handlers.initNotifications(notifsController, notifsStage)
notifsStage.show
val popup = new Popup
popup.setAutoFix(false)
val margin = 10
val width = 300
popup.setWidth(margin + width)
popup.getContent.add(root)
// positioning the popup @ TOP RIGHT of screen
val screenBounds = Screen.getPrimary.getVisualBounds
popup.show(stage, screenBounds.getMaxX - (margin + width), screenBounds.getMinY + margin)
handlers.initNotifications(notifsController)
}
})
notifsController

View File

@ -9,7 +9,6 @@ import javafx.scene.image.Image
import javafx.scene.layout.{GridPane, VBox}
import javafx.util.Duration
import fr.acinq.eclair.gui.stages.NotificationsStage
import grizzled.slf4j.Logging
sealed trait NotificationType
@ -35,7 +34,7 @@ class NotificationsController extends Logging {
* @param body Body of the notification
* @param notificationType type of the notification (error, warning, success, info...)
*/
def addNotification (title: String, body: String, notificationType: NotificationType, stage: Option[NotificationsStage]) = {
def addNotification (title: String, body: String, notificationType: NotificationType) = {
val loader = new FXMLLoader(getClass.getResource("/gui/main/notificationPane.fxml"))
val notifPaneController = new NotificationPaneController

View File

@ -1,23 +0,0 @@
package fr.acinq.eclair.gui.stages
import javafx.stage.{Modality, Screen, Stage, StageStyle}
/**
* Created by DPA on 17/02/2017.
*/
class NotificationsStage extends Stage {
// set stage props
initModality(Modality.NONE)
initStyle(StageStyle.TRANSPARENT)
setAlwaysOnTop(true)
val WIDTH = 310
setMinWidth(WIDTH)
setWidth(WIDTH)
setMaxWidth(WIDTH)
val screenBounds = Screen.getPrimary.getVisualBounds
setX(screenBounds.getMaxX - WIDTH)
setY(screenBounds.getMinY + 10)
setHeight(screenBounds.getMaxY - 10)
}