From 3cac6d7c69e464de0cb55a81fed05c57c7fced3e Mon Sep 17 00:00:00 2001 From: nsec1 <167650977+nsec1@users.noreply.github.com> Date: Sun, 23 Jun 2024 19:31:15 -0300 Subject: [PATCH] #967 Text in Pop Ups selectable --- .../src/main/java/haveno/desktop/haveno.css | 13 +++++++ .../haveno/desktop/main/overlays/Overlay.java | 36 +++++++++++++++---- .../windows/DisplayAlertMessageWindow.java | 5 +-- .../main/overlays/windows/TacWindow.java | 2 +- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/haveno.css b/desktop/src/main/java/haveno/desktop/haveno.css index 7c8f358718..e9eb2a986a 100644 --- a/desktop/src/main/java/haveno/desktop/haveno.css +++ b/desktop/src/main/java/haveno/desktop/haveno.css @@ -1200,6 +1200,19 @@ textfield */ -fx-border-color: -bs-background-gray; } +.text-area-no-border { + -fx-border-color: -fx-control-inner-background; +} + +.text-area-no-border .content { + -fx-background-color: -fx-control-inner-background; +} + +.text-area-no-border:focused { + -fx-focus-color: -fx-control-inner-background; + -fx-faint-focus-color: -fx-control-inner-background; +} + /******************************************************************************* * * * Tab pane * diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/Overlay.java b/desktop/src/main/java/haveno/desktop/main/overlays/Overlay.java index 4dd371b5dc..f937fb4add 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/Overlay.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/Overlay.java @@ -33,6 +33,7 @@ import haveno.desktop.components.AutoTooltipCheckBox; import haveno.desktop.components.AutoTooltipLabel; import haveno.desktop.components.BusyAnimation; import haveno.desktop.main.MainView; +import haveno.desktop.util.CssTheme; import haveno.desktop.util.FormBuilder; import haveno.desktop.util.GUIUtil; import haveno.desktop.util.Layout; @@ -41,6 +42,8 @@ import javafx.animation.Interpolator; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; +import javafx.application.Platform; +import javafx.beans.binding.Bindings; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.value.ChangeListener; @@ -56,6 +59,7 @@ import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.Hyperlink; import javafx.scene.control.Label; +import javafx.scene.control.TextArea; import javafx.scene.control.Tooltip; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; @@ -163,7 +167,8 @@ public abstract class Overlay> { protected boolean useAnimation = true; protected boolean showScrollPane = false; - protected Label headlineIcon, copyIcon, headLineLabel, messageLabel; + protected TextArea messageTextArea; + protected Label headlineIcon, copyIcon, headLineLabel; protected String headLine, message, closeButtonText, actionButtonText, secondaryActionButtonText, dontShowAgainId, dontShowAgainText, truncatedMessage; @@ -847,20 +852,37 @@ public abstract class Overlay> { protected void addMessage() { if (message != null) { - messageLabel = new AutoTooltipLabel(truncatedMessage); - messageLabel.setMouseTransparent(true); - messageLabel.setWrapText(true); + messageTextArea = new TextArea(truncatedMessage); + messageTextArea.setEditable(false); + messageTextArea.getStyleClass().add("text-area-no-border"); + messageTextArea.sceneProperty().addListener((o, oldScene, newScene) -> { + if (newScene != null) { + // avoid javafx css warning + CssTheme.loadSceneStyles(newScene, CssTheme.CSS_THEME_LIGHT, false); + messageTextArea.applyCss(); + var text = messageTextArea.lookup(".text"); + + messageTextArea.prefHeightProperty().bind(Bindings.createDoubleBinding(() -> { + return messageTextArea.getFont().getSize() + text.getBoundsInLocal().getHeight(); + }, text.boundsInLocalProperty())); + + text.boundsInLocalProperty().addListener((observableBoundsAfter, boundsBefore, boundsAfter) -> { + Platform.runLater(() -> messageTextArea.requestLayout()); + }); + } + }); + messageTextArea.setWrapText(true); Region messageRegion; if (showScrollPane) { - scrollPane = new ScrollPane(messageLabel); + scrollPane = new ScrollPane(messageTextArea); scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER); scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED); scrollPane.setFitToWidth(true); messageRegion = scrollPane; } else - messageRegion = messageLabel; + messageRegion = messageTextArea; GridPane.setHalignment(messageRegion, HPos.LEFT); GridPane.setHgrow(messageRegion, Priority.ALWAYS); @@ -892,7 +914,7 @@ public abstract class Overlay> { } private void addReportErrorButtons() { - messageLabel.setText(Res.get("popup.reportError", truncatedMessage)); + messageTextArea.setText(Res.get("popup.reportError", truncatedMessage)); Button logButton = new AutoTooltipButton(Res.get("popup.reportError.log")); GridPane.setMargin(logButton, new Insets(20, 0, 0, 0)); diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisplayAlertMessageWindow.java b/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisplayAlertMessageWindow.java index a2af598899..03f4fa3564 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisplayAlertMessageWindow.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisplayAlertMessageWindow.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkNotNull; -import static haveno.desktop.util.FormBuilder.addMultilineLabel; public class DisplayAlertMessageWindow extends Overlay { private static final Logger log = LoggerFactory.getLogger(DisplayAlertMessageWindow.class); @@ -41,6 +40,7 @@ public class DisplayAlertMessageWindow extends Overlay { protected void addMessage() { super.addMessage(); String fontStyleClass = smallScreen ? "small-text" : "normal-text"; - messageLabel.getStyleClass().add(fontStyleClass); + messageTextArea.getStyleClass().add(fontStyleClass); // TODO: link to the wiki // HyperlinkWithIcon hyperlinkWithIcon = addHyperlinkWithIcon(gridPane, ++rowIndex, Res.get("tacWindow.arbitrationSystem"),