From 7c46dee7842881dee542162cde4bec2b2d887242 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Fri, 13 Sep 2019 13:21:29 +0200 Subject: [PATCH] Moved and documented DraggableRowFactory --- .../es/kauron/jstudy/controller/TableController.java | 1 + .../jstudy/{controller => util}/DraggableRowFactory.java | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) rename src/main/java/es/kauron/jstudy/{controller => util}/DraggableRowFactory.java (92%) diff --git a/src/main/java/es/kauron/jstudy/controller/TableController.java b/src/main/java/es/kauron/jstudy/controller/TableController.java index 20bd8ce..847542b 100644 --- a/src/main/java/es/kauron/jstudy/controller/TableController.java +++ b/src/main/java/es/kauron/jstudy/controller/TableController.java @@ -2,6 +2,7 @@ package es.kauron.jstudy.controller; import es.kauron.jstudy.model.AppPrefs; import es.kauron.jstudy.model.TestItem; +import es.kauron.jstudy.util.DraggableRowFactory; import javafx.beans.binding.Bindings; import javafx.beans.property.*; import javafx.collections.FXCollections; diff --git a/src/main/java/es/kauron/jstudy/controller/DraggableRowFactory.java b/src/main/java/es/kauron/jstudy/util/DraggableRowFactory.java similarity index 92% rename from src/main/java/es/kauron/jstudy/controller/DraggableRowFactory.java rename to src/main/java/es/kauron/jstudy/util/DraggableRowFactory.java index c53bc70..9d237bc 100644 --- a/src/main/java/es/kauron/jstudy/controller/DraggableRowFactory.java +++ b/src/main/java/es/kauron/jstudy/util/DraggableRowFactory.java @@ -1,4 +1,4 @@ -package es.kauron.jstudy.controller; +package es.kauron.jstudy.util; import javafx.collections.ObservableList; import javafx.scene.control.TableRow; @@ -11,17 +11,18 @@ import javafx.scene.input.TransferMode; import java.util.ArrayList; import java.util.List; -class DraggableRowFactory { +// Adapted from https://stackoverflow.com/a/52437193 +public class DraggableRowFactory { private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat("application/x-java-serialized-object"); private final ObservableList data; private final List dragging = new ArrayList<>(); - DraggableRowFactory(ObservableList data) { + public DraggableRowFactory(ObservableList data) { this.data = data; } - TableRow generator(TableView table) { + public TableRow generator(TableView table) { TableRow row = new TableRow<>(); row.setOnDragDetected((event) -> { if (!row.isEmpty() && table.getItems().size() == data.size()) {