mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-09 16:24:53 +00:00
add copyable label controls
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import javafx.scene.text.Font;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class CopyableIdLabel extends CopyableLabel {
|
||||
public CopyableIdLabel() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public CopyableIdLabel(String text) {
|
||||
super(text);
|
||||
setFont(Font.font("Courier"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
public class CopyableLabel extends TextField {
|
||||
public CopyableLabel() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public CopyableLabel(String text) {
|
||||
super(text);
|
||||
|
||||
this.setEditable(false);
|
||||
this.getStyleClass().add("copyable-label");
|
||||
this.setPrefWidth(10);
|
||||
this.textProperty().addListener((ob, o, n) -> {
|
||||
// expand the textfield
|
||||
double width = TextUtils.computeTextWidth(this.getFont(), this.getText(), 0.0D) + 2;
|
||||
this.setPrefWidth(width);
|
||||
this.setMaxWidth(width);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextBoundsType;
|
||||
|
||||
public class TextUtils {
|
||||
static final Text helper;
|
||||
static final double DEFAULT_WRAPPING_WIDTH;
|
||||
static final double DEFAULT_LINE_SPACING;
|
||||
static final String DEFAULT_TEXT;
|
||||
static final TextBoundsType DEFAULT_BOUNDS_TYPE;
|
||||
|
||||
static {
|
||||
helper = new Text();
|
||||
DEFAULT_WRAPPING_WIDTH = helper.getWrappingWidth();
|
||||
DEFAULT_LINE_SPACING = helper.getLineSpacing();
|
||||
DEFAULT_TEXT = helper.getText();
|
||||
DEFAULT_BOUNDS_TYPE = helper.getBoundsType();
|
||||
}
|
||||
|
||||
public static double computeTextWidth(Font font, String text, double help0) {
|
||||
helper.setText(text);
|
||||
helper.setFont(font);
|
||||
|
||||
helper.setWrappingWidth(0.0D);
|
||||
helper.setLineSpacing(0.0D);
|
||||
double d = Math.min(helper.prefWidth(-1.0D), help0);
|
||||
helper.setWrappingWidth((int) Math.ceil(d));
|
||||
d = Math.ceil(helper.getLayoutBounds().getWidth());
|
||||
|
||||
helper.setWrappingWidth(DEFAULT_WRAPPING_WIDTH);
|
||||
helper.setLineSpacing(DEFAULT_LINE_SPACING);
|
||||
helper.setText(DEFAULT_TEXT);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.sparrowwallet.sparrow.transaction;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.CopyableIdLabel;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
@@ -19,13 +21,13 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
private HeadersForm headersForm;
|
||||
|
||||
@FXML
|
||||
private TextField id;
|
||||
private CopyableIdLabel id;
|
||||
|
||||
@FXML
|
||||
private Spinner<Integer> version;
|
||||
|
||||
@FXML
|
||||
private TextField segwit;
|
||||
private CopyableLabel segwit;
|
||||
|
||||
@FXML
|
||||
private ToggleGroup locktimeToggleGroup;
|
||||
@@ -61,16 +63,16 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
private DateTimePicker locktimeDate;
|
||||
|
||||
@FXML
|
||||
private TextField fee;
|
||||
private CopyableLabel size;
|
||||
|
||||
@FXML
|
||||
private TextField size;
|
||||
private CopyableLabel virtualSize;
|
||||
|
||||
@FXML
|
||||
private TextField virtualSize;
|
||||
private CopyableLabel fee;
|
||||
|
||||
@FXML
|
||||
private TextField feeRateField;
|
||||
private CopyableLabel feeRate;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
@@ -175,8 +177,8 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
|
||||
if(feeAmt != null) {
|
||||
fee.setText(feeAmt + " sats");
|
||||
double feeRate = feeAmt.doubleValue() / tx.getVirtualSize();
|
||||
feeRateField.setText(String.format("%.2f", feeRate) + " sats/vByte");
|
||||
double feeRateAmt = feeAmt.doubleValue() / tx.getVirtualSize();
|
||||
feeRate.setText(String.format("%.2f", feeRateAmt) + " sats/vByte");
|
||||
} else {
|
||||
fee.setText("Unknown");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.sparrowwallet.drongo.crypto.ECKey;
|
||||
import com.sparrowwallet.drongo.protocol.*;
|
||||
import com.sparrowwallet.drongo.psbt.PSBTInput;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.CopyableIdLabel;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import com.sparrowwallet.sparrow.control.RelativeTimelockSpinner;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
@@ -32,19 +34,19 @@ public class InputController extends TransactionFormController implements Initia
|
||||
private Fieldset inputFieldset;
|
||||
|
||||
@FXML
|
||||
private TextField outpoint;
|
||||
private CopyableIdLabel outpoint;
|
||||
|
||||
@FXML
|
||||
private Button outpointSelect;
|
||||
|
||||
@FXML
|
||||
private TextField spends;
|
||||
private CopyableLabel spends;
|
||||
|
||||
@FXML
|
||||
private Label from;
|
||||
private CopyableLabel from;
|
||||
|
||||
@FXML
|
||||
private TextField address;
|
||||
private CopyableIdLabel address;
|
||||
|
||||
@FXML
|
||||
private CodeArea scriptSigArea;
|
||||
@@ -68,7 +70,7 @@ public class InputController extends TransactionFormController implements Initia
|
||||
private CodeArea witnessesArea;
|
||||
|
||||
@FXML
|
||||
private TextField signatures;
|
||||
private CopyableLabel signatures;
|
||||
|
||||
@FXML
|
||||
private ToggleSwitch rbf;
|
||||
@@ -95,7 +97,7 @@ public class InputController extends TransactionFormController implements Initia
|
||||
private Field locktimeRelativeField;
|
||||
|
||||
@FXML
|
||||
private TextField locktimeAbsolute;
|
||||
private CopyableLabel locktimeAbsolute;
|
||||
|
||||
@FXML
|
||||
private Spinner<Integer> locktimeRelativeBlocks;
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.sparrowwallet.sparrow.transaction;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.*;
|
||||
import com.sparrowwallet.drongo.psbt.PSBTInput;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -16,13 +16,13 @@ public class InputsController extends TransactionFormController implements Initi
|
||||
private InputsForm inputsForm;
|
||||
|
||||
@FXML
|
||||
private TextField count;
|
||||
private CopyableLabel count;
|
||||
|
||||
@FXML
|
||||
private TextField total;
|
||||
private CopyableLabel total;
|
||||
|
||||
@FXML
|
||||
private TextField signatures;
|
||||
private CopyableLabel signatures;
|
||||
|
||||
@FXML
|
||||
private PieChart inputsPie;
|
||||
|
||||
@@ -3,10 +3,10 @@ package com.sparrowwallet.sparrow.transaction;
|
||||
import com.sparrowwallet.drongo.address.Address;
|
||||
import com.sparrowwallet.drongo.protocol.NonStandardScriptException;
|
||||
import com.sparrowwallet.drongo.protocol.TransactionOutput;
|
||||
import com.sparrowwallet.sparrow.control.CopyableIdLabel;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import org.fxmisc.richtext.CodeArea;
|
||||
import tornadofx.control.Fieldset;
|
||||
|
||||
@@ -20,13 +20,13 @@ public class OutputController extends TransactionFormController implements Initi
|
||||
private Fieldset outputFieldset;
|
||||
|
||||
@FXML
|
||||
private TextField value;
|
||||
private CopyableLabel value;
|
||||
|
||||
@FXML
|
||||
private Label to;
|
||||
private CopyableLabel to;
|
||||
|
||||
@FXML
|
||||
private TextField address;
|
||||
private CopyableIdLabel address;
|
||||
|
||||
@FXML
|
||||
private CodeArea scriptPubKeyArea;
|
||||
@@ -42,7 +42,7 @@ public class OutputController extends TransactionFormController implements Initi
|
||||
outputFieldset.setText("Output #" + txOutput.getIndex());
|
||||
|
||||
value.setText(txOutput.getValue() + " sats");
|
||||
|
||||
to.setVisible(false);
|
||||
try {
|
||||
Address[] addresses = txOutput.getScript().getToAddresses();
|
||||
to.setVisible(true);
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.sparrowwallet.sparrow.transaction;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.drongo.protocol.TransactionOutput;
|
||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -14,10 +14,10 @@ public class OutputsController extends TransactionFormController implements Init
|
||||
private OutputsForm outputsForm;
|
||||
|
||||
@FXML
|
||||
private TextField count;
|
||||
private CopyableLabel count;
|
||||
|
||||
@FXML
|
||||
private TextField total;
|
||||
private CopyableLabel total;
|
||||
|
||||
@FXML
|
||||
private PieChart outputsPie;
|
||||
|
||||
Reference in New Issue
Block a user