[アップデート]
最後に自分で管理しました:
/* The 'sceneRoot' object is the root Node of the scene graph
* stage.setScene(new Scene(sceneRoot, 1280, 1024));
*/
private ImageView dragImageView = new ImageView();
private Node dragItem;
_
rightPane.setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
public void handle(MouseDragEvent e) {
rightPane.setStyle("-fx-border-color:red;-fx-border-width:2;-fx-border-style:solid;");
e.consume();
}
});
rightPane.setOnMouseDragExited(new EventHandler<MouseDragEvent>() {
public void handle(MouseDragEvent e) {
rightPane.setStyle("-fx-border-style:none;");
e.consume();
}
});
rightPane.setOnMouseDragReleased(new EventHandler<MouseDragEvent>() {
public void handle(MouseDragEvent e) {
//TODO: add new instance of dragItem to rightPane
e.consume();
}
});
_
private void addGesture(final Node node) {
node.setOnDragDetected(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
SnapshotParameters snapParams = new SnapshotParameters();
snapParams.setFill(Color.TRANSPARENT);
dragImageView.setImage(node.snapshot(snapParams, null));
sceneRoot.getChildren().add(dragImageView);
dragImageView.startFullDrag();
e.consume();
}
});
node.setOnMouseDragged(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
Point2D localPoint = sceneRoot.sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY()));
dragImageView.relocate(
(int)(localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2),
(int)(localPoint.getY() - dragImageView.getBoundsInLocal().getHeight() / 2)
);
e.consume();
}
});
node.setOnMouseEntered(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
node.setCursor(Cursor.HAND);
}
});
node.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
dragItem = node;
dragImageView.setMouseTransparent(true);
node.setMouseTransparent(true);
node.setCursor(Cursor.CLOSED_HAND);
}
});
node.setOnMouseReleased(new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
dragItem = null;
dragImageView.setMouseTransparent(false);
node.setMouseTransparent(false);
node.setCursor(Cursor.DEFAULT);
sceneRoot.getChildren().remove(dragImageView);
}
});
}