/** * Removes any previously existing mouse-drag event handlers from the connector's root JavaFX node that were added * by this class. * * @param connector the {@link GConnector} whose old handlers should be removed */ private void removeOldMouseDragHandlers(final GConnector connector) { final Node root = skinLookup.lookupConnector(connector).getRoot(); if (dragDetectedHandlers.get(connector) != null) { root.removeEventHandler(MouseEvent.DRAG_DETECTED, dragDetectedHandlers.get(connector)); } if (mouseDraggedHandlers.get(connector) != null) { root.removeEventHandler(MouseEvent.MOUSE_DRAGGED, mouseDraggedHandlers.get(connector)); } if (mouseDragEnteredHandlers.get(connector) != null) { root.removeEventHandler(MouseDragEvent.MOUSE_DRAG_ENTERED, mouseDragEnteredHandlers.get(connector)); } if (mouseDragExitedHandlers.get(connector) != null) { root.removeEventHandler(MouseDragEvent.MOUSE_DRAG_EXITED, mouseDragExitedHandlers.get(connector)); } if (mouseDragReleasedHandlers.get(connector) != null) { root.removeEventHandler(MouseDragEvent.MOUSE_DRAG_RELEASED, mouseDragReleasedHandlers.get(connector)); } }
/** * Adds mouse-drag handlers to a particular connector. * * @param connector the {@link GConnector} to which mouse-drag handlers should be added */ private void addMouseDragHandlers(final GConnector connector) { final EventHandler<MouseEvent> newDragDetectedHandler = event -> handleDragDetected(event, connector); final EventHandler<MouseEvent> newMouseDraggedHandler = event -> handleMouseDragged(event, connector); final EventHandler<MouseDragEvent> newMouseDragEnteredHandler = event -> handleDragEntered(event, connector); final EventHandler<MouseDragEvent> newMouseDragExitedHandler = event -> handleDragExited(event, connector); final EventHandler<MouseDragEvent> newMouseDragReleasedHandler = event -> handleDragReleased(event, connector); final Node root = skinLookup.lookupConnector(connector).getRoot(); root.addEventHandler(MouseEvent.DRAG_DETECTED, newDragDetectedHandler); root.addEventHandler(MouseEvent.MOUSE_DRAGGED, newMouseDraggedHandler); root.addEventHandler(MouseDragEvent.MOUSE_DRAG_ENTERED, newMouseDragEnteredHandler); root.addEventHandler(MouseDragEvent.MOUSE_DRAG_EXITED, newMouseDragExitedHandler); root.addEventHandler(MouseDragEvent.MOUSE_DRAG_RELEASED, newMouseDragReleasedHandler); }
/** * create a drag mouseEvent */ private MouseDragEvent genMouseDrag(double x, double y) { return new MouseDragEvent( MouseDragEvent.MOUSE_DRAG_ENTERED, x, y, x, y, MouseButton.PRIMARY, 1, false, false, false, false, true, //left click down false, false, false, false, new PickResult(null, x, y), genMouseClick(MouseEvent.MOUSE_PRESSED, 0, 0) //drag from origin ); }
@Override public void handleMouseDragEntered(MouseDragEvent event) { if(overDD != null) { overDD.getStyleClass().removeAll("drag-over"); } overDD = ((Node)event.getSource()); ((Node)event.getSource()).getStyleClass().add("drag-over"); }
@Override public void register(Node node) { requireNonNull(node, "Parameter 'node' is null"); node.addEventFilter(MouseEvent.MOUSE_DRAGGED, dragHandler); node.addEventFilter(MouseDragEvent.MOUSE_RELEASED, dragFinishedHandler); }
@Override public void unregister(Node node) { requireNonNull(node, "Parameter 'node' is null"); node.removeEventFilter(MouseEvent.MOUSE_DRAGGED, dragHandler); node.removeEventFilter(MouseDragEvent.MOUSE_RELEASED, dragFinishedHandler); }
/** Sets up the invisible mouse plane that is needed for the dragging of nodes on the scene using the mouse. * The index of the mouse plane should be the same as the index for enableNewFocusPoint. * @param index the index of the rectangle in a rectangle list that will be used for dragging that specific object * */ private Rectangle setupMousePlane(int index) { mousePlaneList.get(index).setLayoutX(-800 / 2); mousePlaneList.get(index).setLayoutY(-800 / 2); mousePlaneList.get(index).setOpacity(0.7); mousePlaneList.get(index).setMouseTransparent(true); mousePlaneList.get(index).setDepthTest(DepthTest.DISABLE); // this makes the plane to be picked even if there are objects closer to the camera mousePlaneList.get(index).setOnMouseDragOver(new EventHandler<MouseDragEvent>() { @Override public void handle(MouseDragEvent me) { if (me.isSecondaryButtonDown() && me.isAltDown()) { //do nothing, we are rotating on the gizmo } else if (me.isSecondaryButtonDown()) { Point3D coords = me.getPickResult().getIntersectedPoint(); mouseOldX = mousePosX; mouseOldY = mousePosY; mousePosX = coords.getX(); mousePosY = coords.getY(); double z = coords.getZ(); coords = mousePlaneList.get(index).localToParent(new Point3D(mousePosX, mousePosY, z)); //mouseplane has the same parent as the real plane and objects like cube mousePosX = coords.getX(); mousePosY = coords.getY(); mouseDeltaX = (mousePosX - mouseOldX); mouseDeltaY = (mousePosY - mouseOldY); } } }); return mousePlaneList.get(index); }
@Override public void handleMouseDragReleased(Node endRegion, MouseDragEvent event) { Region source = (Region) event.getGestureSource(); Region target = (Region) endRegion; sourceDD = null; source.getStyleClass().removeAll("drag-launch"); if(source.equals(target)) { if(preview != null) { preview.close(); } return; } if(!event.isConsumed()) { event.consume(); } else { return; } if(host.getObjects().indexOf(target) > host.getObjects().indexOf(source)) { host.getObjects().remove(source); host.getObjects().add(host.getObjects().indexOf(target)+1, source); } else { host.getObjects().remove(source); host.getObjects().add(host.getObjects().indexOf(target), source); } if(preview!=null) { preview.close(); preview = null; } host.update(); for(ActionCompletedListener acl : acls ){ acl.update(); } }
@Override public void addHandleMouseDragExited(EventHandler<MouseDragEvent> event) { dragMouseExitedEvents.add(event); }
@Override public void addHandleMouseDragEntered(EventHandler<MouseDragEvent> event) { dragMouseEnteredEvents.add(event); }
@Override public void addHandleMouseDragReleased(EventHandler<MouseDragEvent> event) { mouseDragReleasedEvents.add(event); }
@Override public void handleMouseDragExited(MouseDragEvent event) { for (EventHandler<MouseDragEvent> h : dragMouseExitedEvents) { h.handle(event); } }
@Override public void handleMouseDragEntered(MouseDragEvent event) { for (EventHandler<MouseDragEvent> h : dragMouseEnteredEvents) { h.handle(event); } }
@Override public void handleMouseDragReleased(Node endRegion, MouseDragEvent event) { for (EventHandler<MouseDragEvent> h : mouseDragReleasedEvents) { h.handle(event); } }
@FXML void compositeTokenPane_MouseDragExited(MouseDragEvent event) { }
@Override public void handleMouseDragExited(MouseDragEvent event) { }
@Override public void handleMouseDragEntered(MouseDragEvent event) { }
@Override public void handleMouseDragReleased(Node endRegion, MouseDragEvent event) { }
void handleMouseDragExited(MouseDragEvent event);
void handleMouseDragEntered(MouseDragEvent event);
void handleMouseDragReleased(Node endRegion, MouseDragEvent event);
void addHandleMouseDragExited(EventHandler<MouseDragEvent> event);
void addHandleMouseDragEntered(EventHandler<MouseDragEvent> event);
void addHandleMouseDragReleased(EventHandler<MouseDragEvent> event);