dynamically truncate input and output labels in the tree on a transaction tab, and add tooltips if necessary

This commit is contained in:
Craig Raw 2025-04-10 15:42:04 +02:00
parent b3a6340c45
commit c9d7b8ef9a
3 changed files with 22 additions and 7 deletions

View file

@ -49,7 +49,7 @@ class LabelCell extends TextFieldTreeTableCell<Entry, String> implements Confirm
double width = label == null || label.length() < 20 ? 0.0 : TextUtils.computeTextWidth(getFont(), label, 0.0D);
if(width > getTableColumn().getWidth()) {
Tooltip tooltip = new Tooltip(label);
tooltip.setPrefWidth(getTreeTableView().getWidth());
tooltip.setMaxWidth(getTreeTableView().getWidth());
tooltip.setWrapText(true);
setTooltip(tooltip);
} else {

View file

@ -9,19 +9,19 @@ import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.TransactionTabData;
import com.sparrowwallet.sparrow.control.TextUtils;
import com.sparrowwallet.sparrow.control.TransactionHexArea;
import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.net.ElectrumServer;
import javafx.application.Platform;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.control.*;
import javafx.scene.input.*;
import javafx.scene.layout.Pane;
import org.controlsfx.control.MasterDetailPane;
@ -44,6 +44,9 @@ public class TransactionController implements Initializable {
@FXML
private MasterDetailPane transactionMasterDetail;
@FXML
private SplitPane txSplitPane;
@FXML
private TreeView<TransactionForm> txtree;
@ -67,6 +70,8 @@ public class TransactionController implements Initializable {
private TreeItem<TransactionForm> draggedItem;
private TreeCell<TransactionForm> dropZone;
private final DoubleProperty txTreeWidthProperty = new SimpleDoubleProperty();
@Override
public void initialize(URL location, ResourceBundle resources) {
EventManager.get().register(this);
@ -99,6 +104,8 @@ public class TransactionController implements Initializable {
}
private void initializeTxTree() {
txTreeWidthProperty.bind(txSplitPane.widthProperty().multiply(txSplitPane.getDividers().getFirst().positionProperty()));
HeadersForm headersForm = new HeadersForm(txdata);
TreeItem<TransactionForm> rootItem = new TreeItem<>(headersForm);
rootItem.setExpanded(true);
@ -159,9 +166,17 @@ public class TransactionController implements Initializable {
if(form != null) {
Label label = form.getLabel();
label.setMaxWidth(115);
label.maxWidthProperty().bind(txTreeWidthProperty.subtract(70));
setGraphic(label);
double width = TextUtils.computeTextWidth(label.getFont(), label.getText(), 0.0D);
if(width > label.getMaxWidth()) {
Tooltip tooltip = new Tooltip(label.getText());
tooltip.setMaxWidth(transactionMasterDetail.getWidth());
tooltip.setWrapText(true);
label.setTooltip(tooltip);
}
if(form.getSigningWallet() != null) {
setOnDragDetected(null);
setOnDragOver(null);

View file

@ -10,7 +10,7 @@
<items>
<MasterDetailPane fx:id="transactionMasterDetail" detailSide="BOTTOM">
<masterNode>
<SplitPane dividerPositions="0.15">
<SplitPane fx:id="txSplitPane" dividerPositions="0.15">
<items>
<TreeView fx:id="txtree" minWidth="170">
<SplitPane.resizableWithParent>false</SplitPane.resizableWithParent>