mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-10 00:27:00 +00:00
psbt decorations
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.ScriptChunk;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Cursor;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Popup;
|
||||
import org.fxmisc.richtext.event.MouseOverTextEvent;
|
||||
import org.fxmisc.richtext.model.TwoDimensional;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.fxmisc.richtext.model.TwoDimensional.Bias.Backward;
|
||||
|
||||
public class TextDecoration extends StackPane {
|
||||
private StringProperty label = new SimpleStringProperty();
|
||||
|
||||
private Rectangle rectangle;
|
||||
private Text text;
|
||||
|
||||
public TextDecoration(String label, String description, String styleClass) {
|
||||
rectangle = new Rectangle();
|
||||
rectangle.setArcHeight(10);
|
||||
rectangle.setArcWidth(10);
|
||||
rectangle.getStyleClass().add("text-decoration-box");
|
||||
|
||||
DropShadow drop = new DropShadow();
|
||||
drop.setWidth(2);
|
||||
drop.setHeight(2);
|
||||
drop.setOffsetX(1);
|
||||
drop.setOffsetY(1);
|
||||
drop.setRadius(2);
|
||||
rectangle.setEffect(drop);
|
||||
|
||||
text = new Text(label);
|
||||
text.setFont(Font.getDefault());
|
||||
text.getStyleClass().add("text-decoration-label");
|
||||
|
||||
if(styleClass != null) {
|
||||
rectangle.getStyleClass().add(styleClass);
|
||||
}
|
||||
|
||||
getChildren().addAll(rectangle, text);
|
||||
|
||||
this.labelProperty().addListener((ob, o, n) -> {
|
||||
// expand the rectangle
|
||||
double width = TextUtils.computeTextWidth(text.getFont(), this.getLabel(), 0.0D) + 2;
|
||||
rectangle.setWidth(width);
|
||||
rectangle.setHeight(text.getFont().getSize());
|
||||
});
|
||||
|
||||
setLabel(label);
|
||||
|
||||
Popup popup = new Popup();
|
||||
Label popupMsg = new Label();
|
||||
popupMsg.getStyleClass().add("tooltip");
|
||||
popup.getContent().add(popupMsg);
|
||||
|
||||
text.setOnMouseEntered(event -> {
|
||||
popupMsg.setText(description);
|
||||
popup.show(this, event.getScreenX(), event.getScreenY() + 10);
|
||||
});
|
||||
text.setOnMouseExited(event -> {
|
||||
popup.hide();
|
||||
});
|
||||
text.setCursor(Cursor.DEFAULT);
|
||||
}
|
||||
|
||||
public final StringProperty labelProperty() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public final String getLabel() {
|
||||
return label.get();
|
||||
}
|
||||
|
||||
public final void setLabel(String value) {
|
||||
this.label.set(value);
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,13 @@ import com.sparrowwallet.sparrow.control.*;
|
||||
import com.sparrowwallet.sparrow.event.TransactionChangedEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Button;
|
||||
import org.controlsfx.control.ToggleSwitch;
|
||||
import org.controlsfx.control.decoration.Decorator;
|
||||
import org.controlsfx.control.decoration.GraphicDecoration;
|
||||
import org.fxmisc.richtext.CodeArea;
|
||||
import tornadofx.control.Field;
|
||||
import tornadofx.control.Fieldset;
|
||||
@@ -169,15 +173,18 @@ public class InputController extends TransactionFormController implements Initia
|
||||
//TODO: Is this safe?
|
||||
Script redeemScript = txInput.getScriptSig().getFirstNestedScript();
|
||||
if(redeemScript == null && psbtInput != null && psbtInput.getRedeemScript() != null) {
|
||||
addPSBTDecoration(redeemScriptArea, "PSBT Redeem Script", "non-final");
|
||||
redeemScript = psbtInput.getRedeemScript();
|
||||
}
|
||||
if(redeemScript == null && psbtInput != null && psbtInput.getFinalScriptSig() != null) {
|
||||
addPSBTDecoration(redeemScriptArea, "PSBT Final ScriptSig", "final");
|
||||
redeemScript = psbtInput.getFinalScriptSig().getFirstNestedScript();
|
||||
}
|
||||
|
||||
scriptSigArea.clear();
|
||||
if(txInput.getScriptSig().isEmpty() && psbtInput != null && psbtInput.getFinalScriptSig() != null) {
|
||||
appendScript(scriptSigArea, psbtInput.getFinalScriptSig(), redeemScript, null);
|
||||
addPSBTDecoration(scriptSigArea, "PSBT Final ScriptSig", "final");
|
||||
} else {
|
||||
appendScript(scriptSigArea, txInput.getScriptSig(), redeemScript, null);
|
||||
}
|
||||
@@ -201,8 +208,11 @@ public class InputController extends TransactionFormController implements Initia
|
||||
if(psbtInput.getFinalScriptWitness() != null) {
|
||||
witnesses = new Script(psbtInput.getFinalScriptWitness().asScriptChunks());
|
||||
witnessScript = psbtInput.getFinalScriptWitness().getWitnessScript();
|
||||
addPSBTDecoration(witnessesArea, "PSBT Final ScriptWitness", "final");
|
||||
addPSBTDecoration(witnessScriptArea, "PSBT Final ScriptWitness", "final");
|
||||
} else if(psbtInput.getWitnessScript() != null) {
|
||||
witnessScript = psbtInput.getWitnessScript();
|
||||
addPSBTDecoration(witnessScriptArea, "PSBT Witness Script", "non-final");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +229,10 @@ public class InputController extends TransactionFormController implements Initia
|
||||
}
|
||||
}
|
||||
|
||||
private void addPSBTDecoration(Node target, String description, String styleClass) {
|
||||
Decorator.addDecoration(target, new GraphicDecoration(new TextDecoration("PSBT", description, styleClass), Pos.TOP_RIGHT));
|
||||
}
|
||||
|
||||
private void initializeStatusFields(TransactionInput txInput) {
|
||||
Transaction transaction = inputForm.getTransaction();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user