Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show tooltip if text is truncated #1113

3 changes: 2 additions & 1 deletion gui/src/main/java/io/bisq/gui/app/BisqApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.bisq.gui.common.view.View;
import io.bisq.gui.common.view.ViewLoader;
import io.bisq.gui.common.view.guice.InjectorViewFactory;
import io.bisq.gui.components.AutoTooltipLabel;
import io.bisq.gui.main.MainView;
import io.bisq.gui.main.debug.DebugView;
import io.bisq.gui.main.overlays.popups.Popup;
Expand Down Expand Up @@ -398,7 +399,7 @@ private void showDebugWindow() {
}

private void showFPSWindow() {
Label label = new Label();
Label label = new AutoTooltipLabel();
EventStreams.animationTicks()
.latestN(100)
.map(ticks -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public AddressTextField() {
//TODO app wide focus
//focusedProperty().addListener((ov, oldValue, newValue) -> textField.requestFocus());

Label extWalletIcon = new Label();
Label extWalletIcon = new AutoTooltipLabel();
extWalletIcon.setLayoutY(3);
extWalletIcon.getStyleClass().addAll("icon", "highlight");
extWalletIcon.setTooltip(new Tooltip(tooltipText));
AwesomeDude.setIcon(extWalletIcon, AwesomeIcon.SIGNIN);
extWalletIcon.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(this::openWallet));

Label copyIcon = new Label();
Label copyIcon = new AutoTooltipLabel();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().addAll("icon", "highlight");
Tooltip.install(copyIcon, new Tooltip(Res.get("addressTextField.copyToClipboard")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AddressWithIconAndDirection extends AnchorPane {
private final Label openLinkIcon;

public AddressWithIconAndDirection(String text, String address, AwesomeIcon awesomeIcon, boolean received) {
Label directionIcon = new Label();
Label directionIcon = new AutoTooltipLabel();
directionIcon.setLayoutY(3);
directionIcon.getStyleClass().add("icon");
directionIcon.getStyleClass().add(received ? "received-funds-icon" : "sent-funds-icon");
Expand All @@ -29,7 +29,7 @@ public AddressWithIconAndDirection(String text, String address, AwesomeIcon awes

HBox hBox = new HBox();
hBox.setSpacing(-1);
Label label = new Label(text);
Label label = new AutoTooltipLabel(text);
label.setMouseTransparent(true);
HBox.setMargin(label, new Insets(4, 0, 0, 0));
HBox.setHgrow(label, Priority.ALWAYS);
Expand All @@ -44,7 +44,7 @@ public AddressWithIconAndDirection(String text, String address, AwesomeIcon awes

hBox.getChildren().addAll(label, hyperlink);

openLinkIcon = new Label();
openLinkIcon = new AutoTooltipLabel();
openLinkIcon.setLayoutY(3);
openLinkIcon.getStyleClass().addAll("icon", "highlight");
openLinkIcon.setOpacity(0.7);
Expand Down
40 changes: 40 additions & 0 deletions gui/src/main/java/io/bisq/gui/components/AutoTooltipButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.bisq.gui.components;

import com.sun.javafx.scene.control.skin.ButtonSkin;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Skin;

import static io.bisq.gui.components.TooltipUtil.showTooltipIfTruncated;

public class AutoTooltipButton extends Button {

public AutoTooltipButton() {
super();
}

public AutoTooltipButton(String text) {
super(text);
}

public AutoTooltipButton(String text, Node graphic) {
super(text, graphic);
}

@Override
protected Skin<?> createDefaultSkin() {
return new AutoTooltipButtonSkin(this);
}

private class AutoTooltipButtonSkin extends ButtonSkin {
public AutoTooltipButtonSkin(Button button) {
super(button);
}

@Override
protected void layoutChildren(double x, double y, double w, double h) {
super.layoutChildren(x, y, w, h);
showTooltipIfTruncated(this, getSkinnable());
}
}
}
37 changes: 37 additions & 0 deletions gui/src/main/java/io/bisq/gui/components/AutoTooltipLabel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.bisq.gui.components;

import com.sun.javafx.scene.control.skin.LabelSkin;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.text.Text;

import static io.bisq.gui.components.TooltipUtil.showTooltipIfTruncated;

public class AutoTooltipLabel extends Label {

public AutoTooltipLabel(){
super();
}

public AutoTooltipLabel(String text) {
super(text);
}

@Override
protected Skin<?> createDefaultSkin() {
return new AutoTooltipLabelSkin(this);
}

private class AutoTooltipLabelSkin extends LabelSkin {

public AutoTooltipLabelSkin(Label label) {
super(label);
}

@Override
protected void layoutChildren(double x, double y, double w, double h) {
super.layoutChildren(x, y, w, h);
showTooltipIfTruncated(this, getSkinnable());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.bisq.gui.components;

import javafx.scene.control.TableColumn;

public class AutoTooltipTableColumn<S,T> extends TableColumn<S,T> {

public AutoTooltipTableColumn(String text) {
super();

setGraphic(new AutoTooltipLabel(text));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.bisq.gui.components;

import com.sun.javafx.scene.control.skin.ToggleButtonSkin;
import javafx.scene.Node;
import javafx.scene.control.Skin;
import javafx.scene.control.ToggleButton;

import static io.bisq.gui.components.TooltipUtil.showTooltipIfTruncated;

public class AutoTooltipToggleButton extends ToggleButton {

public AutoTooltipToggleButton() {
super();
}

public AutoTooltipToggleButton(String text) {
super(text);
}

public AutoTooltipToggleButton(String text, Node graphic) {
super(text, graphic);
}

@Override
protected Skin<?> createDefaultSkin() {
return new AutoTooltipToggleButtonSkin(this);
}

private class AutoTooltipToggleButtonSkin extends ToggleButtonSkin {
public AutoTooltipToggleButtonSkin(ToggleButton toggleButton) {
super(toggleButton);
}

@Override
protected void layoutChildren(double x, double y, double w, double h) {
super.layoutChildren(x, y, w, h);
showTooltipIfTruncated(this, getSkinnable());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public BsqAddressTextField() {
//focusedProperty().addListener((ov, oldValue, newValue) -> textField.requestFocus());


Label copyIcon = new Label();
Label copyIcon = new AutoTooltipLabel();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().addAll("icon", "highlight");
copyIcon.setTooltip(new Tooltip(Res.get("addressTextField.copyToClipboard")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HyperlinkWithIcon(String text, AwesomeIcon awesomeIcon, boolean isCentere
setSpacing(5);
hyperlink = new Hyperlink(text);

icon = new Label();
icon = new AutoTooltipLabel();
icon.getStyleClass().addAll("icon", "highlight");
AwesomeDude.setIcon(icon, awesomeIcon);
icon.setMinWidth(20);
Expand Down
4 changes: 2 additions & 2 deletions gui/src/main/java/io/bisq/gui/components/InfoDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public InfoDisplay() {
GridPane.setMargin(icon, new Insets(-2, 0, 0, 0));
GridPane.setRowSpan(icon, 2);

label = new Label();
label = new AutoTooltipLabel();
label.textProperty().bind(text);
label.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
// width is set a frame later so we hide it first
Expand All @@ -79,7 +79,7 @@ public InfoDisplay() {

// We need that to know if we have a wrapping or not.
// Did not find a way to get that from the API.
Label testLabel = new Label();
Label testLabel = new AutoTooltipLabel();
testLabel.textProperty().bind(text);

textFlow = new TextFlow();
Expand Down
4 changes: 2 additions & 2 deletions gui/src/main/java/io/bisq/gui/components/InputTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private Point2D getErrorPopupPosition() {


private static void createErrorPopOver(String errorMessage) {
Label errorLabel = new Label(errorMessage);
Label errorLabel = new AutoTooltipLabel(errorMessage);
errorLabel.setId("validation-error");
errorLabel.setPadding(new Insets(0, 10, 0, 10));
errorLabel.setOnMouseClicked(e -> hideErrorMessageDisplay());
Expand All @@ -183,4 +183,4 @@ private static void createErrorPopOver(String errorMessage) {
errorMessageDisplay.setArrowIndent(5);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private Point2D getErrorPopupPosition() {


private static void createErrorPopOver(String errorMessage) {
Label errorLabel = new Label(errorMessage);
Label errorLabel = new AutoTooltipLabel(errorMessage);
errorLabel.setId("validation-error");
errorLabel.setPadding(new Insets(0, 10, 0, 10));
errorLabel.setOnMouseClicked(e -> hideErrorMessageDisplay());
Expand All @@ -170,4 +170,4 @@ private static void createErrorPopOver(String errorMessage) {
errorMessageDisplay.setArrowIndent(5);
}

}
}
4 changes: 2 additions & 2 deletions gui/src/main/java/io/bisq/gui/components/PeerInfoIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public PeerInfoIcon(NodeAddress nodeAddress,
numTradesPane.setMouseTransparent(true);
ImageView numTradesCircle = new ImageView();
numTradesCircle.setId("image-green_circle");
numTradesLabel = new Label();
numTradesLabel = new AutoTooltipLabel();
numTradesLabel.relocate(5, 1);
numTradesLabel.setId("ident-num-label");
numTradesPane.getChildren().addAll(numTradesCircle, numTradesLabel);
Expand All @@ -142,7 +142,7 @@ public PeerInfoIcon(NodeAddress nodeAddress,
tagPane.setMouseTransparent(true);
ImageView tagCircle = new ImageView();
tagCircle.setId("image-blue_circle");
tagLabel = new Label();
tagLabel = new AutoTooltipLabel();
tagLabel.relocate(5, 1);
tagLabel.setId("ident-num-label");
tagPane.getChildren().addAll(tagCircle, tagLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public TableGroupHeadline(String title) {
bg.prefWidthProperty().bind(widthProperty());
bg.prefHeightProperty().bind(heightProperty());

label = new Label();
label = new AutoTooltipLabel();
label.textProperty().bind(text);
label.setLayoutX(8);
label.setPadding(new Insets(-8, 7, 0, 5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class TextFieldWithCopyIcon extends AnchorPane {
///////////////////////////////////////////////////////////////////////////////////////////

public TextFieldWithCopyIcon() {
Label copyIcon = new Label();
Label copyIcon = new AutoTooltipLabel();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().addAll("icon", "highlight");
copyIcon.setTooltip(new Tooltip(Res.get("shared.copyToClipboard")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TitledGroupBg() {
GridPane.setMargin(this, new Insets(-10, -10, -10, -10));
GridPane.setColumnSpan(this, 2);

label = new Label();
label = new AutoTooltipLabel();
label.textProperty().bind(text);
label.setLayoutX(8);
label.setLayoutY(-8);
Expand Down
24 changes: 24 additions & 0 deletions gui/src/main/java/io/bisq/gui/components/TooltipUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.bisq.gui.components;

import javafx.scene.control.Labeled;
import javafx.scene.control.SkinBase;
import javafx.scene.control.Tooltip;
import javafx.scene.text.Text;

public class TooltipUtil {

public static void showTooltipIfTruncated(SkinBase skinBase, Labeled labeled) {
for (Object node : skinBase.getChildren()) {
if (node instanceof Text) {
String displayedText = ((Text) node).getText();
if (displayedText.equals(labeled.getText())) {
if (labeled.getTooltip() != null) {
labeled.setTooltip(null);
}
} else if (labeled.getText() != null){
labeled.setTooltip(new Tooltip(labeled.getText()));
}
}
}
}
}
4 changes: 2 additions & 2 deletions gui/src/main/java/io/bisq/gui/components/TxIdTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public TxIdTextField() {
progressIndicatorTooltip = new Tooltip("-");
txConfidenceIndicator.setTooltip(progressIndicatorTooltip);

copyIcon = new Label();
copyIcon = new AutoTooltipLabel();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().addAll("icon", "highlight");
copyIcon.setTooltip(new Tooltip(Res.get("txIdTextField.copyIcon.tooltip")));
Expand All @@ -82,7 +82,7 @@ public TxIdTextField() {

Tooltip tooltip = new Tooltip(Res.get("txIdTextField.blockExplorerIcon.tooltip"));

blockExplorerIcon = new Label();
blockExplorerIcon = new AutoTooltipLabel();
blockExplorerIcon.getStyleClass().addAll("icon", "highlight");
blockExplorerIcon.setTooltip(tooltip);
AwesomeDude.setIcon(blockExplorerIcon, AwesomeIcon.EXTERNAL_LINK);
Expand Down
Loading