package shop;

import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.Pane;


/**
 * Static utility that allows a node to be attached to the cursor (and thus move with it).
 * 
 * @author Nathan Prabhu
 *
 */

public class CursorBinder {

    private static double previousX = 0;
    private static double previousY = 0;

    /**
     * Binds the cursor to the node. Binding will be disabled, and the node will be removed from the
     * scene, when the appropriate key is pressed.
     * 
     * @param node Node to be bound
     * @param scene Scene of the node
     * @param key Disabling key
     * @return
     */
    public static Node bindCursor (Node node, Scene scene, KeyCode key) {
        final Group wrapGroup = new Group(node);

        scene.setOnMouseMoved(mouseEvent -> {
            double currentX = mouseEvent.getSceneX() + CenterOffset.getX(node);
            double currentY = mouseEvent.getSceneY() + CenterOffset.getY(node);

            wrapGroup.relocate(currentX, currentY);

            previousX = currentX;
            previousY = currentY;
        });

        // TODO: figure out why keyPressed caller must be scene, and not pane or node
        // AND why node not deleted if deleted while on flowpane
        scene.setOnKeyPressed(keyEvent -> {
            if (keyEvent.getCode() == key) {
                scene.setOnMouseMoved(mouseEvent -> {
                });
                ((Group) node.getParent()).getChildren().remove(node);
            }
        });

        return wrapGroup;
    }
}

@@ -8,16 +8,39 @@
  shop;%0A%0A
+import java.util.List;%0A
 import j
@@ -63,16 +63,16 @@
 oint2D;%0A
-
 import j
@@ -112,24 +112,52 @@
 scene.Node;%0A
+import javafx.scene.Parent;%0A
 import javaf
@@ -202,24 +202,24 @@
 ut.KeyCode;%0A
-
 import javaf
@@ -239,16 +239,51 @@
 t.Pane;%0A
+import javafx.scene.layout.Region;%0A
 %0A%0A/**%0A *
@@ -1372,73 +1372,8 @@
 ode%0A
-        // AND why node not deleted if deleted while on flowpane%0A
     
@@ -1547,16 +1547,63 @@
         
+wrapGroup.setVisible(false);%0A                //
 ((Group)
@@ -1708,10 +1708,299 @@
 ;%0A    %7D%0A
+    %0A    private static void redrawScene(Node node)%7B%0A        List%3CNode%3E children = node.getScene().getRoot().getChildrenUnmodifiable();%0A        Pane pane = (Pane) node.getScene().getRoot();%0A        pane.getChildren().removeAll(children);%0A        pane.getChildren().addAll(children);%0A    %7D%0A
 %7D%0A

fix escape bug #32