diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 59a79a48..0266c3ba 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -32,6 +32,8 @@ import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; @@ -52,6 +54,7 @@ import java.net.*; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.time.*; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -320,6 +323,9 @@ public class HeadersController extends TransactionFormController implements Init locktimeDate.setFormat(LOCKTIME_DATE_FORMAT); locktimeDate.dateTimeValueProperty().addListener((obs, oldValue, newValue) -> { + int caret = locktimeDate.getEditor().getCaretPosition(); + locktimeDate.getEditor().setText(newValue.format(DateTimeFormatter.ofPattern(locktimeDate.getFormat()))); + locktimeDate.getEditor().positionCaret(caret); tx.setLocktime(newValue.toEpochSecond(OffsetDateTime.now(ZoneId.systemDefault()).getOffset())); futureDateWarning.setVisible(newValue.isAfter(LocalDateTime.now())); if(oldValue != null) { @@ -327,6 +333,19 @@ public class HeadersController extends TransactionFormController implements Init } }); + locktimeDate.getEditor().textProperty().addListener((observable, oldValue, newValue) -> { + String controlValue = locktimeDate.getDateTimeValue().format(DateTimeFormatter.ofPattern(locktimeDate.getFormat())); + if(!controlValue.equals(newValue) && !locktimeDate.getStyleClass().contains("edited")) { + locktimeDate.getStyleClass().add("edited"); + } + }); + + locktimeDate.addEventFilter(KeyEvent.ANY, event -> { + if(event.getCode() == KeyCode.ENTER) { + locktimeDate.getStyleClass().remove("edited"); + } + }); + boolean locktimeEnabled = headersForm.getTransaction().isLocktimeSequenceEnabled(); locktimeNoneType.setDisable(!headersForm.isEditable() || !locktimeEnabled); locktimeBlockType.setDisable(!headersForm.isEditable() || !locktimeEnabled); diff --git a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css index 63635692..5b56f847 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css +++ b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css @@ -90,7 +90,7 @@ -fx-padding: 0 0 0 12; } -.unfinalized-txid { +.unfinalized-txid, .edited > .text-field { -fx-text-fill: #a0a1a7; }