Browse Source

add copyable label controls

bwt
Craig Raw 5 years ago
parent
commit
07c5356021
  1. 16
      src/main/java/com/sparrowwallet/sparrow/control/CopyableIdLabel.java
  2. 24
      src/main/java/com/sparrowwallet/sparrow/control/CopyableLabel.java
  3. 37
      src/main/java/com/sparrowwallet/sparrow/control/TextUtils.java
  4. 18
      src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
  5. 14
      src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java
  6. 8
      src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java
  7. 12
      src/main/java/com/sparrowwallet/sparrow/transaction/OutputController.java
  8. 6
      src/main/java/com/sparrowwallet/sparrow/transaction/OutputsController.java
  9. 21
      src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml
  10. 14
      src/main/resources/com/sparrowwallet/sparrow/transaction/input.fxml
  11. 7
      src/main/resources/com/sparrowwallet/sparrow/transaction/inputs.fxml
  12. 8
      src/main/resources/com/sparrowwallet/sparrow/transaction/output.fxml
  13. 7
      src/main/resources/com/sparrowwallet/sparrow/transaction/outputs.fxml

16
src/main/java/com/sparrowwallet/sparrow/control/CopyableIdLabel.java

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

24
src/main/java/com/sparrowwallet/sparrow/control/CopyableLabel.java

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

37
src/main/java/com/sparrowwallet/sparrow/control/TextUtils.java

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

18
src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java

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

14
src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java

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

8
src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java

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

12
src/main/java/com/sparrowwallet/sparrow/transaction/OutputController.java

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

6
src/main/java/com/sparrowwallet/sparrow/transaction/OutputsController.java

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

21
src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml

@ -2,7 +2,6 @@
<?import javafx.geometry.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToggleGroup?>
@ -11,8 +10,10 @@
<?import tornadofx.control.Form?>
<?import tornadofx.control.Fieldset?>
<?import tornadofx.control.Field?>
<?import org.controlsfx.control.SegmentedButton?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.CopyableIdLabel?>
<GridPane hgap="10.0" prefHeight="350.0" prefWidth="600.0" vgap="10.0" alignment="TOP_CENTER" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.HeadersController" stylesheets="@headers.css, @../general.css">
<padding>
<Insets bottom="25.0" left="25.0" right="25.0" top="25.0" />
@ -31,7 +32,7 @@
<Form GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2">
<Fieldset text="Transaction" inputGrow="SOMETIMES">
<Field text="Txid:">
<TextField fx:id="id" editable="false" styleClass="copyable-label, id" prefWidth="520" minWidth="520"/>
<CopyableIdLabel fx:id="id"/>
</Field>
</Fieldset>
</Form>
@ -44,7 +45,7 @@
<Spinner fx:id="version" prefWidth="60" editable="true" />
</Field>
<Field text="Type:">
<TextField fx:id="segwit" editable="false" styleClass="copyable-label"/>
<CopyableLabel fx:id="segwit" />
</Field>
</Fieldset>
</Form>
@ -80,10 +81,10 @@
<Form GridPane.columnIndex="0" GridPane.rowIndex="4">
<Fieldset text="Size" inputGrow="SOMETIMES">
<Field text="Bytes:">
<TextField fx:id="size" editable="false" styleClass="copyable-label" prefWidth="120"/>
<CopyableLabel fx:id="size" />
</Field>
<Field text="vBytes:">
<TextField fx:id="virtualSize" editable="false" styleClass="copyable-label" prefWidth="120"/>
<CopyableLabel fx:id="virtualSize" />
</Field>
</Fieldset>
</Form>
@ -91,10 +92,10 @@
<Form GridPane.columnIndex="1" GridPane.rowIndex="4">
<Fieldset text="Fee" inputGrow="SOMETIMES">
<Field text="Amount:">
<TextField fx:id="fee" editable="false" styleClass="copyable-label" prefWidth="120"/>
<CopyableLabel fx:id="fee" />
</Field>
<Field text="Rate:">
<TextField fx:id="feeRateField" editable="false" styleClass="copyable-label" prefWidth="120"/>
<CopyableLabel fx:id="feeRate" />
</Field>
</Fieldset>
</Form>
@ -104,10 +105,10 @@
<Form GridPane.columnIndex="0" GridPane.rowIndex="6">
<Fieldset text="Blockchain" inputGrow="SOMETIMES">
<Field text="Status:">
<TextField fx:id="blockStatusField" editable="false" styleClass="copyable-label" prefWidth="120"/>
<CopyableLabel fx:id="blockStatusField" />
</Field>
<Field text="Block:">
<TextField fx:id="blockField" editable="false" styleClass="copyable-label" prefWidth="120"/>
<CopyableLabel fx:id="blockField" />
</Field>
</Fieldset>
</Form>

14
src/main/resources/com/sparrowwallet/sparrow/transaction/input.fxml

@ -12,6 +12,8 @@
<?import java.lang.String?>
<?import org.controlsfx.control.ToggleSwitch?>
<?import com.sparrowwallet.sparrow.control.RelativeTimelockSpinner?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.CopyableIdLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="620.0" stylesheets="@input.css, @script.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.InputController">
<padding>
@ -30,7 +32,7 @@
<Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0">
<Fieldset fx:id="inputFieldset" inputGrow="SOMETIMES" text="Input">
<Field text="Outpoint:">
<TextField fx:id="outpoint" editable="false" minWidth="520" prefWidth="520" styleClass="copyable-label, id" />
<CopyableIdLabel fx:id="outpoint" />
<Button fx:id="outpointSelect" maxWidth="25" minWidth="-Infinity" prefWidth="30" text="Ed">
<graphic>
<Glyph fontFamily="FontAwesome" icon="EDIT" prefWidth="15" />
@ -38,9 +40,9 @@
</Button>
</Field>
<Field text="Spends:">
<TextField fx:id="spends" editable="false" styleClass="copyable-label" maxWidth="80" />
<Label fx:id="from" text="from" maxWidth="30" style="-fx-padding: 0" />
<TextField fx:id="address" editable="false" styleClass="copyable-label, id" />
<CopyableLabel fx:id="spends" />
<CopyableLabel fx:id="from" text="from" />
<CopyableIdLabel fx:id="address" />
</Field>
</Fieldset>
</Form>
@ -93,7 +95,7 @@
<Form GridPane.columnIndex="0" GridPane.rowIndex="4">
<Fieldset text="Status" inputGrow="SOMETIMES">
<Field text="Signatures:">
<TextField fx:id="signatures" editable="false" prefWidth="120" styleClass="copyable-label"/>
<CopyableLabel fx:id="signatures" />
</Field>
<Field text="RBF:">
<ToggleSwitch fx:id="rbf"/>
@ -128,7 +130,7 @@
</SegmentedButton>
</Field>
<Field fx:id="locktimeAbsoluteField" text="Block:">
<TextField fx:id="locktimeAbsolute" editable="false" prefWidth="120" styleClass="copyable-label"/>
<CopyableLabel fx:id="locktimeAbsolute" />
</Field>
<Field fx:id="locktimeRelativeField" text="Value:">
<Spinner fx:id="locktimeRelativeBlocks" editable="true" prefWidth="110"/>

7
src/main/resources/com/sparrowwallet/sparrow/transaction/inputs.fxml

@ -5,6 +5,7 @@
<?import javafx.scene.layout.*?>
<?import tornadofx.control.*?>
<?import javafx.scene.chart.PieChart?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@inputs.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.InputsController">
<padding>
@ -22,10 +23,10 @@
<Form GridPane.columnIndex="0" GridPane.rowIndex="0">
<Fieldset inputGrow="SOMETIMES" text="Inputs">
<Field text="Count:">
<TextField fx:id="count" editable="false" minWidth="520" prefWidth="520" styleClass="copyable-label" />
<CopyableLabel fx:id="count" />
</Field>
<Field text="Total:">
<TextField fx:id="total" editable="false" minWidth="520" prefWidth="520" styleClass="copyable-label" />
<CopyableLabel fx:id="total" />
</Field>
</Fieldset>
</Form>
@ -33,7 +34,7 @@
<Form GridPane.columnIndex="1" GridPane.rowIndex="0">
<Fieldset inputGrow="SOMETIMES" text="Signatures">
<Field text="Status:">
<TextField fx:id="signatures" editable="false" minWidth="520" prefWidth="520" styleClass="copyable-label" />
<CopyableLabel fx:id="signatures" />
</Field>
</Fieldset>
</Form>

8
src/main/resources/com/sparrowwallet/sparrow/transaction/output.fxml

@ -11,6 +11,8 @@
<?import tornadofx.control.Fieldset?>
<?import tornadofx.control.Form?>
<?import javafx.geometry.Insets?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.CopyableIdLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@output.css, @script.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.OutputController">
<padding>
@ -29,9 +31,9 @@
<Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0">
<Fieldset fx:id="outputFieldset" inputGrow="SOMETIMES" text="Output">
<Field text="Sends:">
<TextField fx:id="value" editable="false" styleClass="copyable-label" maxWidth="80"/>
<Label fx:id="to" text="to" />
<TextField fx:id="address" editable="false" styleClass="copyable-label, id" />
<CopyableLabel fx:id="value"/>
<CopyableLabel fx:id="to" text="to" />
<CopyableIdLabel fx:id="address" />
</Field>
</Fieldset>
</Form>

7
src/main/resources/com/sparrowwallet/sparrow/transaction/outputs.fxml

@ -4,8 +4,9 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import tornadofx.control.*?>
<?import javafx.scene.chart.PieChart?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@outputs.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.OutputsController">
<padding>
<Insets bottom="25.0" left="25.0" right="25.0" top="25.0" />
@ -22,10 +23,10 @@
<Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0">
<Fieldset inputGrow="SOMETIMES" text="Outputs">
<Field text="Count:">
<TextField fx:id="count" editable="false" minWidth="520" prefWidth="520" styleClass="copyable-label" />
<CopyableLabel fx:id="count" />
</Field>
<Field text="Total:">
<TextField fx:id="total" editable="false" minWidth="520" prefWidth="520" styleClass="copyable-label" />
<CopyableLabel fx:id="total" />
</Field>
</Fieldset>
</Form>

Loading…
Cancel
Save