revise transaction pane

This commit is contained in:
Craig Raw 2020-03-28 13:39:21 +02:00
parent b6b18a2a7c
commit 7a2e503624
4 changed files with 157 additions and 108 deletions

View file

@ -8,6 +8,8 @@ import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import tornadofx.control.DateTimePicker;
import tornadofx.control.Field;
import tornadofx.control.Fieldset;
import java.net.URL;
import java.time.*;
@ -22,43 +24,46 @@ public class HeadersController implements Initializable, TransactionListener {
private GridPane layout;
@FXML
private TextField idField;
private TextField id;
@FXML
private Spinner<Integer> versionField;
private Spinner<Integer> version;
@FXML
private Label segwitField;
private TextField segwit;
@FXML
private Label segwitVersionLabel;
private ToggleGroup locktimeType;
@FXML
private Spinner<Integer> segwitVersionField;
private ToggleButton locktimeBlockType;
@FXML
private ToggleGroup locktimeTypeField;
private ToggleButton locktimeDateType;
@FXML
private ToggleButton locktimeBlockTypeField;
private Fieldset locktimeFieldset;
@FXML
private ToggleButton locktimeDateTypeField;
private Field locktimeBlockField;
@FXML
private Spinner<Integer> locktimeBlockField;
private Field locktimeDateField;
@FXML
private DateTimePicker locktimeDateField;
private Spinner<Integer> locktimeBlock;
@FXML
private Label feeField;
private DateTimePicker locktimeDate;
@FXML
private Label sizeField;
private TextField fee;
@FXML
private Label virtualSizeField;
private TextField size;
@FXML
private TextField virtualSize;
@Override
public void initialize(URL location, ResourceBundle resources) {
@ -71,38 +76,38 @@ public class HeadersController implements Initializable, TransactionListener {
updateTxId();
versionField.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 2, (int)tx.getVersion()));
versionField.valueProperty().addListener((obs, oldValue, newValue) -> {
version.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 2, (int)tx.getVersion()));
version.valueProperty().addListener((obs, oldValue, newValue) -> {
tx.setVersion(newValue);
EventManager.get().notify(tx);
});
segwitField.setText(tx.isSegwit() ? "Segwit" : "Legacy" );
String type = "Legacy";
if(tx.isSegwit()) {
segwitVersionField.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 2, tx.getSegwitVersion()));
segwitVersionField.valueProperty().addListener((obs, oldValue, newValue) -> {
tx.setSegwitVersion(newValue);
EventManager.get().notify(tx);
});
} else {
layout.getChildren().removeAll(segwitVersionLabel, segwitVersionField);
type = "Segwit";
if(tx.getSegwitVersion() == 2) {
type = "Taproot";
}
}
segwit.setText(type);
locktimeTypeField.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
if(locktimeTypeField.getSelectedToggle() != null) {
String selection = locktimeTypeField.getSelectedToggle().getUserData().toString();
locktimeType.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
if(locktimeType.getSelectedToggle() != null) {
String selection = locktimeType.getSelectedToggle().getUserData().toString();
if(selection.equals("block")) {
locktimeBlockField.setVisible(true);
locktimeDateField.setVisible(false);
Integer block = locktimeBlockField.getValue();
locktimeFieldset.getChildren().remove(locktimeDateField);
locktimeFieldset.getChildren().remove(locktimeBlockField);
locktimeFieldset.getChildren().add(locktimeBlockField);
Integer block = locktimeBlock.getValue();
if(block != null) {
tx.setLockTime(block);
EventManager.get().notify(tx);
}
} else {
locktimeBlockField.setVisible(false);
locktimeDateField.setVisible(true);
LocalDateTime date = locktimeDateField.getDateTimeValue();
locktimeFieldset.getChildren().remove(locktimeBlockField);
locktimeFieldset.getChildren().remove(locktimeDateField);
locktimeFieldset.getChildren().add(locktimeDateField);
LocalDateTime date = locktimeDate.getDateTimeValue();
if(date != null) {
tx.setLockTime(date.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()));
EventManager.get().notify(tx);
@ -112,42 +117,39 @@ public class HeadersController implements Initializable, TransactionListener {
});
if(tx.getLockTime() < MAX_BLOCK_LOCKTIME) {
locktimeBlockField.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, (int)MAX_BLOCK_LOCKTIME-1, (int)tx.getLockTime()));
locktimeBlockField.setVisible(true);
locktimeDateField.setVisible(false);
locktimeTypeField.selectToggle(locktimeBlockTypeField);
locktimeBlock.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, (int)MAX_BLOCK_LOCKTIME-1, (int)tx.getLockTime()));
locktimeType.selectToggle(locktimeBlockType);
} else {
locktimeBlock.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, (int)MAX_BLOCK_LOCKTIME-1));
LocalDateTime date = Instant.ofEpochSecond(tx.getLockTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
locktimeDateField.setDateTimeValue(date);
locktimeBlockField.setVisible(false);
locktimeDateField.setVisible(true);
locktimeTypeField.selectToggle(locktimeDateTypeField);
locktimeDate.setDateTimeValue(date);
locktimeType.selectToggle(locktimeDateType);
}
locktimeBlockField.valueProperty().addListener((obs, oldValue, newValue) -> {
locktimeBlock.valueProperty().addListener((obs, oldValue, newValue) -> {
tx.setLockTime(newValue);
EventManager.get().notify(tx);
});
locktimeDateField.setFormat("yyyy-MM-dd HH:mm:ss");
locktimeDateField.dateTimeValueProperty().addListener((obs, oldValue, newValue) -> {
locktimeDate.setFormat("yyyy-MM-dd HH:mm:ss");
locktimeDate.dateTimeValueProperty().addListener((obs, oldValue, newValue) -> {
tx.setLockTime(newValue.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()));
EventManager.get().notify(tx);
});
if(form.getPsbt() != null) {
feeField.setText(form.getPsbt().getFee().toString() + " sats");
fee.setText(form.getPsbt().getFee().toString() + " sats");
} else {
feeField.setText("Unknown");
fee.setText("Unknown");
}
sizeField.setText(tx.getSize() + " B");
size.setText(tx.getSize() + " B");
virtualSizeField.setText(tx.getVirtualSize() + " vB");
virtualSize.setText(tx.getVirtualSize() + " vB");
}
private void updateTxId() {
idField.setText(headersForm.getTransaction().calculateTxId(false).toString());
id.setText(headersForm.getTransaction().calculateTxId(false).toString());
}
@Override

View file

@ -2,81 +2,110 @@
<?import javafx.geometry.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.control.Separator?>
<?import tornadofx.control.DateTimePicker?>
<?import tornadofx.control.Form?>
<?import tornadofx.control.Fieldset?>
<?import tornadofx.control.Field?>
<GridPane fx:id="layout" hgap="10.0" prefHeight="350.0" prefWidth="600.0" vgap="10.0" alignment="CENTER" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.craigraw.sparrow.form.HeadersController" stylesheets="@../general.css">
<padding>
<Insets bottom="25.0" left="25.0" right="25.0" top="25.0" />
</padding>
<columnConstraints>
<ColumnConstraints minWidth="100" prefWidth="100"
maxWidth="Infinity" halignment="RIGHT">
<ColumnConstraints minWidth="290" prefWidth="290"
maxWidth="Infinity">
</ColumnConstraints>
<ColumnConstraints minWidth="200" prefWidth="200"
maxWidth="Infinity" hgrow="ALWAYS">
<ColumnConstraints minWidth="290" prefWidth="290"
maxWidth="Infinity">
</ColumnConstraints>
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<!-- Add Header Label -->
<Label text="Headers" GridPane.columnIndex="0"
GridPane.rowIndex="0" GridPane.columnSpan="2"
GridPane.rowSpan="1" GridPane.halignment="LEFT" >
<font>
<Font name="Arial" size="24" ></Font>
</font>
<GridPane.margin>
<Insets top="0" right="0" bottom="10" left="0"></Insets>
</GridPane.margin>
</Label>
<Form GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2">
<Fieldset text="Transaction" inputGrow="SOMETIMES">
<Field text="ID:">
<TextField fx:id="id" editable="false" styleClass="copyable-label, id" prefWidth="520" minWidth="520"/>
</Field>
</Fieldset>
</Form>
<Label text="Transaction ID: " GridPane.columnIndex="0" GridPane.rowIndex="1" />
<TextField fx:id="idField" editable="false" styleClass="copyable-label" prefHeight="40" prefWidth="520" minWidth="520" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Separator GridPane.columnIndex="0" GridPane.rowIndex="1" GridPane.columnSpan="2" styleClass="form-separator"/>
<Label text="Version: " GridPane.columnIndex="0" GridPane.rowIndex="2" />
<Spinner fx:id="versionField" prefHeight="40" prefWidth="60" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Form GridPane.columnIndex="0" GridPane.rowIndex="2">
<Fieldset text="Headers" inputGrow="SOMETIMES">
<Field text="Version:">
<Spinner fx:id="version" prefWidth="60" editable="true" />
</Field>
<Field text="Type:">
<TextField fx:id="segwit" editable="false" styleClass="copyable-label"/>
</Field>
</Fieldset>
</Form>
<Label text="Type: " GridPane.columnIndex="0" GridPane.rowIndex="3" />
<Label fx:id="segwitField" prefHeight="40" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Form GridPane.columnIndex="1" GridPane.rowIndex="2">
<Fieldset fx:id="locktimeFieldset" text="Locktime" inputGrow="SOMETIMES">
<Field text="Type:">
<HBox fillHeight="true">
<children>
<ToggleButton fx:id="locktimeBlockType" text="Block" userData="block">
<toggleGroup>
<ToggleGroup fx:id="locktimeType" />
</toggleGroup>
</ToggleButton>
<ToggleButton fx:id="locktimeDateType" text="Date" toggleGroup="$locktimeType" userData="date" />
</children>
</HBox>
</Field>
<Field fx:id="locktimeBlockField" text="Block:">
<Spinner fx:id="locktimeBlock" prefWidth="120"/>
</Field>
<Field fx:id="locktimeDateField" text="Date:">
<DateTimePicker fx:id="locktimeDate" prefWidth="180"/>
</Field>
</Fieldset>
</Form>
<Label fx:id="segwitVersionLabel" text="Segwit Version: " GridPane.columnIndex="0" GridPane.rowIndex="4" />
<Spinner fx:id="segwitVersionField" prefWidth="60" prefHeight="40" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Separator GridPane.columnIndex="0" GridPane.rowIndex="3" GridPane.columnSpan="2" styleClass="form-separator"/>
<Separator GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="2" GridPane.rowSpan="1" GridPane.halignment="LEFT" />
<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"/>
</Field>
<Field text="vBytes:">
<TextField fx:id="virtualSize" editable="false" styleClass="copyable-label" prefWidth="120"/>
</Field>
</Fieldset>
</Form>
<Label text="Locktime Type: " GridPane.columnIndex="0" GridPane.rowIndex="6" />
<HBox fillHeight="true" GridPane.columnIndex="1" GridPane.rowIndex="6">
<children>
<ToggleButton fx:id="locktimeBlockTypeField" text="Block" userData="block">
<toggleGroup>
<ToggleGroup fx:id="locktimeTypeField" />
</toggleGroup>
</ToggleButton>
<ToggleButton fx:id="locktimeDateTypeField" text="Date" toggleGroup="$locktimeTypeField" userData="date" />
</children>
</HBox>
<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"/>
</Field>
<Field text="Rate:">
<TextField fx:id="feeRateField" editable="false" styleClass="copyable-label" prefWidth="120"/>
</Field>
</Fieldset>
</Form>
<Label text="Locktime: " GridPane.columnIndex="0" GridPane.rowIndex="7" />
<Spinner fx:id="locktimeBlockField" prefHeight="40" prefWidth="120" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
<DateTimePicker fx:id="locktimeDateField" visible="false" prefHeight="40" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
<Separator GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="2" styleClass="form-separator"/>
<Separator GridPane.columnIndex="0" GridPane.rowIndex="8" GridPane.columnSpan="2" GridPane.rowSpan="1" GridPane.halignment="LEFT" />
<Label text="Size: " GridPane.columnIndex="0" GridPane.rowIndex="9" />
<Label fx:id="sizeField" prefHeight="40" prefWidth="120" GridPane.columnIndex="1" GridPane.rowIndex="9"/>
<Label text="Virtual Size: " GridPane.columnIndex="0" GridPane.rowIndex="10" />
<Label fx:id="virtualSizeField" prefHeight="40" prefWidth="120" GridPane.columnIndex="1" GridPane.rowIndex="10"/>
<Label text="Fee: " GridPane.columnIndex="0" GridPane.rowIndex="11" />
<Label fx:id="feeField" prefHeight="40" prefWidth="120" GridPane.columnIndex="1" GridPane.rowIndex="11"/>
<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"/>
</Field>
<Field text="Block:">
<TextField fx:id="blockField" editable="false" styleClass="copyable-label" prefWidth="120"/>
</Field>
</Fieldset>
</Form>
</GridPane>

View file

@ -2,5 +2,22 @@
-fx-background-color: transparent ;
-fx-background-insets: 0px ;
-fx-border :none;
-fx-padding: 0;
-fx-padding: 5 0 5 0;
}
.form .fieldset:horizontal .label-container {
-fx-pref-width: 80px;
-fx-pref-height: 25px;
}
.form .field {
-fx-padding: 5 5;
}
.id {
-fx-font-family: Courier;
}
.form-separator {
-fx-padding: -15 0 0 0;
}

View file

@ -1,21 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.fxmisc.richtext.*?>
<?import javafx.scene.text.TextFlow?>
<?import org.fxmisc.richtext.CodeArea?>
<SplitPane dividerPositions="0.7" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0" VBox.vgrow="ALWAYS" fx:controller="com.craigraw.sparrow.TransactionController" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" stylesheets="@transaction.css">
<?import org.fxmisc.flowless.VirtualizedScrollPane?>
<SplitPane 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.craigraw.sparrow.TransactionController">
<items>
<SplitPane dividerPositions="0.2" prefHeight="160.0" prefWidth="200.0">
<items>
<TreeView prefHeight="154.0" prefWidth="174.0" fx:id="txtree" />
<TreeView fx:id="txtree" prefHeight="154.0" prefWidth="174.0" />
<Pane fx:id="txpane" />
</items>
</SplitPane>
<CodeArea fx:id="txhex" wrapText="true" editable="false" />
<VirtualizedScrollPane>
<content>
<CodeArea fx:id="txhex" editable="false" wrapText="true" />
</content>
</VirtualizedScrollPane>
</items>
</SplitPane>
</SplitPane>