Skip to content

Commit 84be06e

Browse files
committed
Fix drag and drop for tests case violations
1 parent 64b89c6 commit 84be06e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/util/controls/DragAndDropUtil.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package net.sourceforge.pmd.util.fxdesigner.util.controls;
66

7+
import java.io.Serializable;
78
import java.util.function.Consumer;
89

910
import org.reactfx.Subscription;
@@ -22,6 +23,19 @@ public final class DragAndDropUtil {
2223

2324
// since dragboard contents must be Serializable we
2425
// put a TextRegion in the dragboard and not a Node
26+
private static class SerializableTextRegion implements Serializable {
27+
private final int startOffset;
28+
private final int length;
29+
30+
private SerializableTextRegion(TextRegion region) {
31+
startOffset = region.getStartOffset();
32+
length = region.getLength();
33+
}
34+
35+
private TextRegion toRegion() {
36+
return TextRegion.fromOffsetLength(startOffset, length);
37+
}
38+
}
2539

2640
/** Style class for {@linkplain #registerAsNodeDragTarget(javafx.scene.Node, Consumer, DesignerRoot) node drag over.} */
2741
public static final String NODE_DRAG_OVER = "node-drag-over";
@@ -41,7 +55,7 @@ public static Subscription registerAsNodeDragSource(javafx.scene.Node source, No
4155
// drag and drop
4256
Dragboard db = source.startDragAndDrop(TransferMode.LINK);
4357
ClipboardContent content = new ClipboardContent();
44-
content.put(NODE_RANGE_DATA_FORMAT, data.getTextRegion());
58+
content.put(NODE_RANGE_DATA_FORMAT, new SerializableTextRegion(data.getTextRegion()));
4559
db.setContent(content);
4660
root.getService(DesignerRoot.IS_NODE_BEING_DRAGGED).setValue(true);
4761
evt.consume();
@@ -102,7 +116,7 @@ public static void registerAsNodeDragTarget(javafx.scene.Node target, Consumer<T
102116

103117
Dragboard db = evt.getDragboard();
104118
if (db.hasContent(NODE_RANGE_DATA_FORMAT)) {
105-
TextRegion content = (TextRegion) db.getContent(NODE_RANGE_DATA_FORMAT);
119+
TextRegion content = ((SerializableTextRegion) db.getContent(NODE_RANGE_DATA_FORMAT)).toRegion();
106120
nodeRangeConsumer.accept(content);
107121
success = true;
108122
}

0 commit comments

Comments
 (0)