From 93f9539f7bdeff851efdac0c1eb46e27b063e5ce Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 27 Apr 2021 12:22:39 +0200 Subject: [PATCH] show dialogs on the same screen as the currently focussed window --- .../sparrowwallet/sparrow/AppController.java | 2 ++ .../sparrowwallet/sparrow/AppServices.java | 29 +++++++++++++++++++ .../sparrowwallet/sparrow/WelcomeDialog.java | 1 + .../sparrow/control/DeviceDialog.java | 1 + .../control/KeystorePassphraseDialog.java | 1 + .../control/MasterKeyDisplayDialog.java | 1 + .../sparrow/control/MessageSignDialog.java | 2 ++ .../sparrow/control/QRDisplayDialog.java | 2 ++ .../sparrow/control/QRScanDialog.java | 1 + .../sparrow/control/SeedDisplayDialog.java | 1 + .../sparrow/control/TextAreaDialog.java | 1 + .../sparrow/control/TransactionIdDialog.java | 1 + .../control/WalletBirthDateDialog.java | 1 + .../sparrow/control/WalletExportDialog.java | 1 + .../sparrow/control/WalletImportDialog.java | 1 + .../sparrow/control/WalletNameDialog.java | 1 + .../sparrow/control/WalletPasswordDialog.java | 1 + .../keystoreimport/KeystoreImportDialog.java | 1 + .../preferences/PreferencesDialog.java | 1 + .../sparrow/wallet/AdvancedDialog.java | 1 + .../sparrow/wallet/SendController.java | 2 +- 21 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index d88779c6..a740dbf4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -891,9 +891,11 @@ public class AppController implements Initializable { File walletFile = Storage.getExistingWallet(wallet.getName()); if(walletFile != null) { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + AppServices.setStageIcon(alert.getDialogPane().getScene().getWindow()); alert.setTitle("Existing wallet found"); alert.setHeaderText("Replace existing wallet?"); alert.setContentText("Wallet file " + walletFile.getName() + " already exists.\n"); + AppServices.moveToActiveWindowScreen(alert); Optional result = alert.showAndWait(); if(result.isPresent() && result.get() == ButtonType.CANCEL) { return; diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index c374f7d5..48d0902c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -29,8 +29,11 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.DialogPane; import javafx.scene.image.Image; import javafx.scene.text.Font; +import javafx.stage.Screen; import javafx.stage.Stage; import javafx.stage.Window; import javafx.util.Duration; @@ -508,6 +511,7 @@ public class AppServices { alert.getDialogPane().getScene().getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm()); alert.setTitle(title); alert.setHeaderText(title); + moveToActiveWindowScreen(alert); return alert.showAndWait(); } @@ -520,6 +524,31 @@ public class AppServices { } } + public static void moveToActiveWindowScreen(Dialog dialog) { + Window activeWindow = Stage.getWindows().stream().filter(Window::isFocused).findFirst().orElse(get().walletWindows.keySet().iterator().hasNext() ? get().walletWindows.keySet().iterator().next() : null); + if(activeWindow != null) { + moveToWindowScreen(activeWindow, dialog); + } + } + + public void moveToWalletWindowScreen(Storage storage, Dialog dialog) { + moveToWindowScreen(getWindowForWallet(storage), dialog); + } + + public static void moveToWindowScreen(Window currentWindow, Dialog dialog) { + Window newWindow = dialog.getDialogPane().getScene().getWindow(); + DialogPane dialogPane = dialog.getDialogPane(); + Screen currentScreen = Screen.getScreens().stream().filter(screen -> screen.getVisualBounds().contains(currentWindow.getX(), currentWindow.getY())).findFirst().orElse(null); + if(currentScreen != null && !Screen.getPrimary().getVisualBounds().contains(currentWindow.getX(), currentWindow.getY()) && !currentScreen.getVisualBounds().contains(newWindow.getX(), newWindow.getY())) { + double dialogWidth = dialogPane.getPrefWidth() > 0.0 ? dialogPane.getPrefWidth() : (dialogPane.getWidth() > 0.0 ? dialogPane.getWidth() : 360); + double dialogHeight = dialogPane.getPrefHeight() > 0.0 ? dialogPane.getPrefHeight() : (dialogPane.getHeight() > 0.0 ? dialogPane.getHeight() : 200); + double x = currentWindow.getX() + (currentWindow.getWidth() / 2) - (dialogWidth / 2); + double y = currentWindow.getY() + (currentWindow.getHeight() / 2.2) - (dialogHeight / 2); + newWindow.setX(x); + newWindow.setY(y); + } + } + public static Font getMonospaceFont() { return Font.font("Roboto Mono", 13); } diff --git a/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java b/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java index 3fdf8c48..c0282f25 100644 --- a/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java @@ -21,6 +21,7 @@ public class WelcomeDialog extends Dialog { dialogPane.setPrefWidth(600); dialogPane.setPrefHeight(520); + AppServices.moveToActiveWindowScreen(this); dialogPane.getStylesheets().add(AppServices.class.getResource("welcome.css").toExternalForm()); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java index 198bb630..b02cd5c8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DeviceDialog.java @@ -89,6 +89,7 @@ public abstract class DeviceDialog extends Dialog { dialogPane.setPrefWidth(500); dialogPane.setPrefHeight(360); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton == cancelButtonType ? null : getResult()); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java index 6184a789..1d29916a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/KeystorePassphraseDialog.java @@ -30,6 +30,7 @@ public class KeystorePassphraseDialog extends Dialog { dialogPane.getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK); dialogPane.setPrefWidth(380); dialogPane.setPrefHeight(200); + AppServices.moveToActiveWindowScreen(this); Glyph key = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.KEY); key.setFontSize(50); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MasterKeyDisplayDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/MasterKeyDisplayDialog.java index d13eca87..8119c11e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MasterKeyDisplayDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MasterKeyDisplayDialog.java @@ -41,6 +41,7 @@ public class MasterKeyDisplayDialog extends Dialog { dialogPane.setPrefWidth(500); dialogPane.setPrefHeight(260); + AppServices.moveToActiveWindowScreen(this); Platform.runLater(() -> keystoreAccordion.setExpandedPane(keystorePane)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java index eb6c51d2..7eee7230 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java @@ -185,6 +185,7 @@ public class MessageSignDialog extends Dialog { EventManager.get().unregister(this); }); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton == signButtonType || dialogButton == verifyButtonType ? ButtonBar.ButtonData.APPLY : ButtonBar.ButtonData.OK_DONE); } @@ -275,6 +276,7 @@ public class MessageSignDialog extends Dialog { alert.setTitle("Verification Succeeded"); alert.setHeaderText("Verification Succeeded"); alert.setContentText("The signature verified against the message."); + AppServices.moveToActiveWindowScreen(alert); alert.showAndWait(); } else { AppServices.showErrorDialog("Verification failed", "The provided signature did not match the message for this address."); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java index 371f961a..a06ac1de 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java @@ -96,6 +96,7 @@ public class QRDisplayDialog extends Dialog { dialogPane.setPrefWidth(40 + QR_WIDTH + 40); dialogPane.setPrefHeight(40 + QR_HEIGHT + 85); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton != cancelButtonType ? ur : null); } @@ -118,6 +119,7 @@ public class QRDisplayDialog extends Dialog { dialogPane.getButtonTypes().addAll(cancelButtonType); dialogPane.setPrefWidth(40 + QR_WIDTH + 40); dialogPane.setPrefHeight(40 + QR_HEIGHT + 85); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton != cancelButtonType ? ur : null); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java index 6f6fe80f..79d7a56e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java @@ -137,6 +137,7 @@ public class QRScanDialog extends Dialog { dialogPane.getButtonTypes().addAll(hdButtonType, cancelButtonType); dialogPane.setPrefWidth(646); dialogPane.setPrefHeight(webcamResolutionProperty.get() == WebcamResolution.HD ? 490 : 590); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton != cancelButtonType ? result : null); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/SeedDisplayDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/SeedDisplayDialog.java index bb2ea730..f7ca1711 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/SeedDisplayDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/SeedDisplayDialog.java @@ -44,6 +44,7 @@ public class SeedDisplayDialog extends Dialog { dialogPane.setPrefWidth(500); dialogPane.setPrefHeight(150 + height); + AppServices.moveToActiveWindowScreen(this); Platform.runLater(() -> keystoreAccordion.setExpandedPane(keystorePane)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java index b19998e9..999bb842 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TextAreaDialog.java @@ -59,6 +59,7 @@ public class TextAreaDialog extends Dialog { dialogPane.setPrefWidth(700); dialogPane.setPrefHeight(400); + AppServices.moveToActiveWindowScreen(this); } public final TextArea getEditor() { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java index f00e40f2..dc8e0d10 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionIdDialog.java @@ -63,5 +63,6 @@ public class TransactionIdDialog extends Dialog { txid.setPromptText("f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16"); Platform.runLater(txid::requestFocus); setResultConverter(dialogButton -> dialogButton == okButtonType ? Sha256Hash.wrap(txid.getText()) : null); + AppServices.moveToActiveWindowScreen(this); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletBirthDateDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletBirthDateDialog.java index fb5ec076..103665c1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletBirthDateDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletBirthDateDialog.java @@ -31,6 +31,7 @@ public class WalletBirthDateDialog extends Dialog { dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); dialogPane.setPrefWidth(420); dialogPane.setPrefHeight(200); + AppServices.moveToActiveWindowScreen(this); Glyph wallet = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.HISTORY); wallet.setFontSize(50); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java index d9c849fe..2a4b463e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletExportDialog.java @@ -59,6 +59,7 @@ public class WalletExportDialog extends Dialog { dialogPane.getButtonTypes().addAll(cancelButtonType); dialogPane.setPrefWidth(500); dialogPane.setPrefHeight(480); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton != cancelButtonType ? wallet : null); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java index 1d9b1bf6..51e3177d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletImportDialog.java @@ -73,6 +73,7 @@ public class WalletImportDialog extends Dialog { dialogPane.setPrefWidth(500); dialogPane.setPrefHeight(500); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton != cancelButtonType ? wallet : null); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java index 8b79a5da..e0b33a69 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java @@ -44,6 +44,7 @@ public class WalletNameDialog extends Dialog dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); dialogPane.setPrefWidth(460); dialogPane.setPrefHeight(requestBirthDate ? 250 : 200); + AppServices.moveToActiveWindowScreen(this); Glyph wallet = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.WALLET); wallet.setFontSize(50); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java index 92bebf81..fda849da 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WalletPasswordDialog.java @@ -45,6 +45,7 @@ public class WalletPasswordDialog extends Dialog { dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); dialogPane.setPrefWidth(380); dialogPane.setPrefHeight(260); + AppServices.moveToActiveWindowScreen(this); Glyph lock = new Glyph("FontAwesome", FontAwesome.Glyph.LOCK); lock.setFontSize(50); diff --git a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java index fe1c8c4f..c0d55e44 100644 --- a/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportDialog.java @@ -46,6 +46,7 @@ public class KeystoreImportDialog extends Dialog { dialogPane.getButtonTypes().addAll(watchOnlyButtonType, cancelButtonType); dialogPane.setPrefWidth(650); dialogPane.setPrefHeight(620); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton != cancelButtonType ? getWatchOnlyKeystore() : null); } catch(IOException e) { diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/PreferencesDialog.java b/src/main/java/com/sparrowwallet/sparrow/preferences/PreferencesDialog.java index 27b3def6..82e79490 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/PreferencesDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/PreferencesDialog.java @@ -48,6 +48,7 @@ public class PreferencesDialog extends Dialog { dialogPane.setPrefWidth(750); dialogPane.setPrefHeight(630); + AppServices.moveToActiveWindowScreen(this); preferencesController.reconnectOnClosingProperty().set(AppServices.isConnecting() || AppServices.isConnected()); setOnCloseRequest(event -> { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java b/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java index 6befe0bb..c2cc1a44 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java @@ -34,6 +34,7 @@ public class AdvancedDialog extends Dialog { dialogPane.setPrefWidth(400); dialogPane.setPrefHeight(300); + AppServices.moveToActiveWindowScreen(this); setResultConverter(dialogButton -> dialogButton == passwordButtonType); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 100ebba6..f62919be 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -738,7 +738,7 @@ public class SendController extends WalletFormController implements Initializabl long thisFee = walletTransaction.getFee(); double thisSize = walletTransaction.getTransaction().getVirtualSize(); double effectiveRate = (utxoTxFee + thisFee) / (utxoTxSize + thisSize); - Tooltip tooltip = new Tooltip(String.format("%.2f", effectiveRate) + " sats/vB effective rate"); + Tooltip tooltip = new Tooltip("Child Pays For Parent\n" + String.format("%.2f", effectiveRate) + " sats/vB effective rate"); cpfpFeeRate.setTooltip(tooltip); cpfpFeeRate.setVisible(true); } else {