improve ux when validating transaction locktime datetime field

This commit is contained in:
Craig Raw 2021-12-08 10:20:21 +02:00
parent 3c94664ac3
commit 90a2c3b89b
2 changed files with 20 additions and 1 deletions

View file

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

View file

@ -90,7 +90,7 @@
-fx-padding: 0 0 0 12;
}
.unfinalized-txid {
.unfinalized-txid, .edited > .text-field {
-fx-text-fill: #a0a1a7;
}