From 84bead8eae7b76fa3b16782bdd257f7332a85d30 Mon Sep 17 00:00:00 2001 From: Dominik Gruntz Date: Wed, 1 Aug 2018 23:44:55 +0200 Subject: [PATCH 1/2] Change the Editable double ListCell-Implementation - removes method replaceSelection - changes the regex for doulbes (no digits after decimal point allowed) - changes the anonymous inner class in the DoubleListCell ctor to a lambda --- .../src/main/java/de/javafxbuch/MainApp.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java b/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java index 6e79b0a..940c62b 100644 --- a/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java +++ b/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java @@ -49,19 +49,8 @@ public void replaceText(int start, int end, String text) { } } - @Override - public void replaceSelection(String text) { - final int dot = getCaretPosition(); - final int mark = getAnchor(); - int start = Math.min(dot, mark); - int end = Math.max(dot, mark); - if (validate(createPreview(start, end, text))) { - super.replaceSelection(text); - } - } - private boolean validate(String text) { - if (text.matches("[-+]?[0-9]*\\.?[0-9]+") || text == "") { + if (text.matches("[-+]?[0-9]*\\.?[0-9]*") || text == "") { System.out.println("ok"); return true; } @@ -84,18 +73,13 @@ private static class DoubleListCell extends ListCell { DoubleTextField dtf = new DoubleTextField(); public DoubleListCell() { - dtf.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - commitEdit(Double.parseDouble(dtf.getText())); - } - }); + dtf.setOnAction(e -> commitEdit(Double.parseDouble(dtf.getText()))); } @Override protected void updateItem(Double item, boolean empty) { super.updateItem(item, empty); - if (item != null & !empty) { + if (item != null && !empty) { dtf.setText(item.toString()); if (!isEditing()) { setText(item.toString()); From 570bba277efc3f94ab350b037c7dd01d70ac5be4 Mon Sep 17 00:00:00 2001 From: Dominik Gruntz Date: Wed, 1 Aug 2018 23:46:25 +0200 Subject: [PATCH 2/2] Import cleanup Two imports are no longer necessary due to the former commit --- .../src/main/java/de/javafxbuch/MainApp.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java b/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java index 940c62b..ec66744 100644 --- a/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java +++ b/Kapitel 4/4.2.7/controls-listview-cell-simple/src/main/java/de/javafxbuch/MainApp.java @@ -1,8 +1,6 @@ package de.javafxbuch; import javafx.application.Application; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.ListCell;