psbt decorations

This commit is contained in:
Craig Raw 2020-04-12 13:28:07 +02:00
parent 0366b3637d
commit 3436e5e3ad
6 changed files with 128 additions and 4 deletions

View file

@ -46,7 +46,7 @@ dependencies {
mainClassName = 'com.sparrowwallet.sparrow/com.sparrowwallet.sparrow.MainApp' mainClassName = 'com.sparrowwallet.sparrow/com.sparrowwallet.sparrow.MainApp'
run { run {
applicationDefaultJvmArgs = ["-Xdock:name=Sparrow", "-Xdock:icon=/Users/scy/git/sparrow/src/main/resources/sparrow.png", "--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls"] applicationDefaultJvmArgs = ["-Xdock:name=Sparrow", "-Xdock:icon=/Users/scy/git/sparrow/src/main/resources/sparrow.png", "--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls", "--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls"]
} }
jlink { jlink {
@ -60,7 +60,7 @@ jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages', '--ignore-signing-information', '--exclude-files', '**.png'] options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages', '--ignore-signing-information', '--exclude-files', '**.png']
launcher { launcher {
name = 'sparrow' name = 'sparrow'
jvmArgs = ["--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls"] jvmArgs = ["--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls", "--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls"]
} }
addExtraDependencies("javafx") addExtraDependencies("javafx")
jpackage { jpackage {

View file

@ -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);
}
}

View file

@ -10,9 +10,13 @@ import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.TransactionChangedEvent; import com.sparrowwallet.sparrow.event.TransactionChangedEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import org.controlsfx.control.ToggleSwitch; import org.controlsfx.control.ToggleSwitch;
import org.controlsfx.control.decoration.Decorator;
import org.controlsfx.control.decoration.GraphicDecoration;
import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.CodeArea;
import tornadofx.control.Field; import tornadofx.control.Field;
import tornadofx.control.Fieldset; import tornadofx.control.Fieldset;
@ -169,15 +173,18 @@ public class InputController extends TransactionFormController implements Initia
//TODO: Is this safe? //TODO: Is this safe?
Script redeemScript = txInput.getScriptSig().getFirstNestedScript(); Script redeemScript = txInput.getScriptSig().getFirstNestedScript();
if(redeemScript == null && psbtInput != null && psbtInput.getRedeemScript() != null) { if(redeemScript == null && psbtInput != null && psbtInput.getRedeemScript() != null) {
addPSBTDecoration(redeemScriptArea, "PSBT Redeem Script", "non-final");
redeemScript = psbtInput.getRedeemScript(); redeemScript = psbtInput.getRedeemScript();
} }
if(redeemScript == null && psbtInput != null && psbtInput.getFinalScriptSig() != null) { if(redeemScript == null && psbtInput != null && psbtInput.getFinalScriptSig() != null) {
addPSBTDecoration(redeemScriptArea, "PSBT Final ScriptSig", "final");
redeemScript = psbtInput.getFinalScriptSig().getFirstNestedScript(); redeemScript = psbtInput.getFinalScriptSig().getFirstNestedScript();
} }
scriptSigArea.clear(); scriptSigArea.clear();
if(txInput.getScriptSig().isEmpty() && psbtInput != null && psbtInput.getFinalScriptSig() != null) { if(txInput.getScriptSig().isEmpty() && psbtInput != null && psbtInput.getFinalScriptSig() != null) {
appendScript(scriptSigArea, psbtInput.getFinalScriptSig(), redeemScript, null); appendScript(scriptSigArea, psbtInput.getFinalScriptSig(), redeemScript, null);
addPSBTDecoration(scriptSigArea, "PSBT Final ScriptSig", "final");
} else { } else {
appendScript(scriptSigArea, txInput.getScriptSig(), redeemScript, null); appendScript(scriptSigArea, txInput.getScriptSig(), redeemScript, null);
} }
@ -201,8 +208,11 @@ public class InputController extends TransactionFormController implements Initia
if(psbtInput.getFinalScriptWitness() != null) { if(psbtInput.getFinalScriptWitness() != null) {
witnesses = new Script(psbtInput.getFinalScriptWitness().asScriptChunks()); witnesses = new Script(psbtInput.getFinalScriptWitness().asScriptChunks());
witnessScript = psbtInput.getFinalScriptWitness().getWitnessScript(); witnessScript = psbtInput.getFinalScriptWitness().getWitnessScript();
addPSBTDecoration(witnessesArea, "PSBT Final ScriptWitness", "final");
addPSBTDecoration(witnessScriptArea, "PSBT Final ScriptWitness", "final");
} else if(psbtInput.getWitnessScript() != null) { } else if(psbtInput.getWitnessScript() != null) {
witnessScript = psbtInput.getWitnessScript(); 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) { private void initializeStatusFields(TransactionInput txInput) {
Transaction transaction = inputForm.getTransaction(); Transaction transaction = inputForm.getTransaction();

View file

@ -4,7 +4,7 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import org.controlsfx.control.StatusBar?> <?import org.controlsfx.control.StatusBar?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="750.0" prefWidth="1000.0" fx:controller="com.sparrowwallet.sparrow.AppController" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1"> <VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="200" minWidth="350" prefHeight="750.0" prefWidth="1000.0" fx:controller="com.sparrowwallet.sparrow.AppController" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<MenuBar useSystemMenuBar="true"> <MenuBar useSystemMenuBar="true">
<menus> <menus>

View file

@ -6,6 +6,27 @@
.script-redeem { -fx-fill: #ca1243 } .script-redeem { -fx-fill: #ca1243 }
.script-other { -fx-fill: #a0a1a7 } .script-other { -fx-fill: #a0a1a7 }
.non-final {
-fx-fill: #696c77;
}
.final {
-fx-fill: #383a42;
}
.text-decoration-box {
-fx-translate-x: -10;
-fx-translate-y: 2;
}
.text-decoration-label {
-fx-font-family: "SansSerif";
-fx-font-size: 9px;
-fx-fill: white;
-fx-translate-x: -10;
-fx-translate-y: 2;
}
.uneditable-codearea { .uneditable-codearea {
-fx-font: 14px Courier; -fx-font: 14px Courier;
-fx-padding: 4; -fx-padding: 4;

View file

@ -6,7 +6,7 @@
<?import org.fxmisc.flowless.VirtualizedScrollPane?> <?import org.fxmisc.flowless.VirtualizedScrollPane?>
<?import org.controlsfx.control.MasterDetailPane?> <?import org.controlsfx.control.MasterDetailPane?>
<SplitPane fx:id="tabContent" dividerPositions="0.82" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0" stylesheets="@transaction.css" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.TransactionController"> <SplitPane fx:id="tabContent" dividerPositions="0.82" orientation="VERTICAL" stylesheets="@transaction.css" VBox.vgrow="ALWAYS" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.TransactionController">
<items> <items>
<MasterDetailPane fx:id="transactionMasterDetail" detailSide="BOTTOM"> <MasterDetailPane fx:id="transactionMasterDetail" detailSide="BOTTOM">
<masterNode> <masterNode>