Java Code Examples for javafx.scene.input.MouseEvent#consume()

The following examples show how to use javafx.scene.input.MouseEvent#consume() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragAndDropHandler.java    From FxDock with Apache License 2.0 6 votes vote down vote up
protected static void onDragDetected(MouseEvent ev, FxDockPane client)
{
	if(dragWindow == null)
	{
		double x = ev.getScreenX();
		double y = ev.getScreenY();
		
		Point2D p = client.screenToLocal(x, y);
		deltax = p.getX();
		deltay = p.getY(); // gets modified in createDragWindow()
		
		dragWindow = createDragWindow(client);
		dragWindow.addEventHandler(KeyEvent.KEY_PRESSED, (ke) -> cancelDrag());
		
		dragWindow.setX(x - deltax);
		dragWindow.setY(y - deltay);
		
		dragWindow.show();
		
		ev.consume();
	}
}
 
Example 2
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@FXML
public void mouseMoved(MouseEvent event) {
	if (freeformButton.isSelected()) {
		drawTempPolygonEdge(event);
	}

	if (!cursorRegion.isPresent() || cursorButton.isSelected()) return;

	final Node selected = cursorRegion.get();

	lastMouseX = event.getX() - (selected.getLayoutBounds().getWidth() / 2);
	lastMouseY = event.getY() - (selected.getLayoutBounds().getHeight() / 2);

	if (lastMouseX < 0) lastMouseX = 0;
	if (lastMouseY < 0) lastMouseY = 0;

	if (event.getX() + (selected.getLayoutBounds().getWidth() / 2) <= canvasPane.getWidth())
		selected.setLayoutX(lastMouseX - selected.getLayoutBounds().getMinX());

	if (event.getY() + (selected.getLayoutBounds().getHeight() / 2) <= canvasPane.getHeight())
		selected.setLayoutY(lastMouseY - selected.getLayoutBounds().getMinY());

	event.consume();
}
 
Example 3
Source File: NBTTreeView.java    From mcaselector with MIT License 6 votes vote down vote up
private void onDragDetected(MouseEvent e) {
	if (getTreeItem() == getTreeView().getRoot()) {
		return;
	}
	Dragboard db = startDragAndDrop(TransferMode.MOVE);
	WritableImage wi = new WritableImage((int) getWidth(), (int) getHeight());
	Image dbImg = snapshot(null, wi);
	db.setDragView(dbImg);
	if (USE_DRAGVIEW_OFFSET) {
		db.setDragViewOffsetX(getWidth() / 2);
		db.setDragViewOffsetY(getHeight() / 2);
	}
	ClipboardContent cbc = new ClipboardContent();
	cbc.put(CLIPBOARD_DATAFORMAT, true);
	db.setContent(cbc);
	dragboardContent = getTreeItem();
	e.consume();
}
 
Example 4
Source File: Rubberband.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void handleStart(final MouseEvent event)
{
    if (! event.isPrimaryButtonDown())
        return;
    active = true;

    // Event originates from a node that allows 'clicking' beyond the
    // model elements, i.e. the size of the 'parent'.
    // The 'parent', however, may be scrolled, and the rubber band needs
    // to show up in the 'parent', so convert coordinates
    // from event to the parent:
    final Point2D in_parent = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
    x0 = in_parent.getX();
    y0 = in_parent.getY();
    rect.setX(x0);
    rect.setY(y0);
    rect.setWidth(1);
    rect.setHeight(1);
    parent.getChildren().add(rect);
    event.consume();
}
 
Example 5
Source File: Rubberband.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void handleDrag(final MouseEvent event)
{
    if (! active)
        return;
    final Point2D in_parent = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
    x1 = in_parent.getX();
    y1 = in_parent.getY();
    rect.setX(Math.min(x0, x1));
    rect.setY(Math.min(y0, y1));
    rect.setWidth(Math.abs(x1 - x0));
    rect.setHeight(Math.abs(y1 - y0));
    event.consume();
}
 
Example 6
Source File: CardAppleMouse.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void processMouseEvent(MouseEvent event) {
    if (event.getEventType() == MouseEvent.MOUSE_MOVED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
        Node source = (Node) event.getSource();
        updateLocation(event.getSceneX(), event.getSceneY(), source.getBoundsInLocal());
        event.consume();
    }
    if (event.getEventType() == MouseEvent.MOUSE_PRESSED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
        mousePressed(event);
        event.consume();
    } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
        mouseReleased(event);
        event.consume();
    }
}
 
Example 7
Source File: CardPileView.java    From Solitaire with GNU General Public License v2.0 5 votes vote down vote up
private EventHandler<MouseEvent> createDragDetectedHandler(final ImageView pImageView, final Card pCard)
{
	return new EventHandler<MouseEvent>() 
	{
		@Override
		public void handle(MouseEvent pMouseEvent) 
		{
			Dragboard db = pImageView.startDragAndDrop(TransferMode.ANY);
			CLIPBOARD_CONTENT.putString(CardTransfer.serialize(GameModel.instance().getSubStack(pCard, aIndex)));
			db.setContent(CLIPBOARD_CONTENT);
			pMouseEvent.consume();
		}
	};
}
 
Example 8
Source File: SearchBox.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
protected void startDrag(MouseEvent event) {
	TextField textBox = ((TextField)event.getSource());
	if(!"".equals(textBox.getSelectedText()) && textBox.getText().equals(textBox.getSelectedText())) {
        Dragboard db = textBox.startDragAndDrop(TransferMode.MOVE);
        snapshotter.setText(textBox.getText());
        db.setDragView(snapshotter.snapshot(null, null));
        ClipboardContent cc = new ClipboardContent();
        cc.put(DataFormat.PLAIN_TEXT, textBox.getSelectedText());
        db.setContent(cc);
        event.consume();
	}
}
 
Example 9
Source File: SelectionCreator.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles mouse-pressed events on any connector.
 *
 * @param event a mouse-pressed event
 */
private void handleConnectorPressed(final MouseEvent event) {

    if (!event.getButton().equals(MouseButton.PRIMARY)) {
        return;
    }

    if (!event.isShortcutDown()) {
        deselectAll();
    }

    event.consume();
}
 
Example 10
Source File: DeckBuilderWindow.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private void startDragToActiveDeck(MouseEvent event, Pane pane, CardInfoMessage message) {
this.cardBeingDragged = message;
	Dragboard db = pane.startDragAndDrop(TransferMode.MOVE);
	ClipboardContent content = new ClipboardContent();
	content.putString(message.toString());
	db.setContent(content);
event.consume();
}
 
Example 11
Source File: Rubberband.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void handleStop(final MouseEvent event)
{
    if (! active)
        return;
    final Point2D in_parent = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
    x1 = in_parent.getX();
    y1 = in_parent.getY();
    parent.getChildren().remove(rect);
    active = false;

    handler.handleSelectedRegion(new Rectangle2D(Math.min(x0, x1), Math.min(y0, y1),
                                                 Math.abs(x1 - x0), Math.abs(y1 - y0)),
                                 event.isShortcutDown());
    event.consume();
}
 
Example 12
Source File: YValueIndicator.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected void handleDragMouseEvent(final MouseEvent mouseEvent) {
    Point2D c = getChart().getPlotArea().sceneToLocal(mouseEvent.getSceneX(), mouseEvent.getSceneY());
    final double yPosData = getNumericAxis().getValueForDisplay(c.getY() - dragDelta.y);

    if (getNumericAxis().isValueOnAxis(yPosData)) {
        valueProperty().set(yPosData);
    }

    mouseEvent.consume();
}
 
Example 13
Source File: TreeConnectionSkin.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles mouse-pressed events on the connection skin to select / de-select the connection.
 *
 * @param event the mouse-pressed event
 */
private void handleMousePressed(final MouseEvent event) {

    if (event.isShortcutDown()) {
        setSelected(!isSelected());
    } else if (!isSelected()) {
        getGraphEditor().getSelectionManager().clearSelection();
        setSelected(true);
    }

    event.consume();
}
 
Example 14
Source File: SimpleHSBColorPicker.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public SimpleHSBColorPicker() {
    getChildren().addAll(hsbRect,lightRect);
    lightRect.setStroke(Color.GRAY);
    lightRect.setStrokeType(StrokeType.OUTSIDE);
    EventHandler<MouseEvent> ml = new EventHandler<MouseEvent>() {
        @Override public void handle(MouseEvent e) {
            double w = getWidth();
            double h = getHeight();
            double x = Math.min(w, Math.max(0, e.getX()));
            double y = Math.min(h, Math.max(0, e.getY()));
            double hue = (360/w)*x;
            double vert = (1/h)*y;
            double sat = 0;
            double bright = 0;
            if (vert<0.5) {
                bright = 1;
                sat = vert * 2;
            } else {
                bright = sat = 1- ((vert-0.5)*2);
            }
            // convert back to color
            Color c =  Color.hsb((int)hue,sat,bright);
            color.set(c);
            e.consume();
        }
    };
    lightRect.setOnMouseDragged(ml);
    lightRect.setOnMouseClicked(ml);
}
 
Example 15
Source File: ConnectorDragManager.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handles drag-exited events on the given connector.
 *
 * @param event a drag-exited event
 * @param connector the {@link GConnector} on which this event occured
 */
private void handleDragExited(final MouseEvent event, final GConnector connector) {

    skinLookup.lookupConnector(connector).applyStyle(GConnectorStyle.DEFAULT);
    repositionAllowed = true;

    if (event.getButton().equals(MouseButton.PRIMARY)) {
        tailManager.updatePosition(event);
    }

    event.consume();
}
 
Example 16
Source File: JFXMouseUpListenerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handle(MouseEvent event) {
	if(!this.control.isIgnoreEvents()) {
		this.onMouseUp(new UIMouseEvent(this.control, new UIPosition((float)event.getX(), (float)event.getY()), JFXMouseButton.getMouseButton(event.getButton())));
		
		event.consume();
	}
}
 
Example 17
Source File: JFXMouseDragListenerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handle(MouseEvent event) {
	if(!this.control.isIgnoreEvents() && this.startPosition != null ) {
		float dragX = (float)(event.getX()  - this.startPosition.getX());
		float dragY = (float)(event.getY()  - this.startPosition.getY());
		
		this.onMouseDrag(new UIMouseEvent(this.control, new UIPosition(dragX, dragY), JFXMouseButton.getMouseButton(event.getButton())));
		
		event.consume();
	}
}
 
Example 18
Source File: XValueIndicator.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected void handleDragMouseEvent(final MouseEvent mouseEvent) {
    Point2D c = getChart().getPlotArea().sceneToLocal(mouseEvent.getSceneX(), mouseEvent.getSceneY());
    final double xPosData = getNumericAxis().getValueForDisplay(c.getX() + dragDelta.x);
    if (getNumericAxis().isValueOnAxis(xPosData)) {
        valueProperty().set(xPosData);
    }

    mouseEvent.consume();
    layoutChildren();
}
 
Example 19
Source File: JFXDecorator.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
private void handleDragEventOnDecoratorPane(MouseEvent mouseEvent) {
    isDragging = true;
    if (!mouseEvent.isPrimaryButtonDown() || (xOffset == -1 && yOffset == -1)) {
        return;
    }
    /*
     * Long press generates drag event!
     */
    if (primaryStage.isFullScreen() || mouseEvent.isStillSincePress() || primaryStage.isMaximized() || maximized) {
        return;
    }

    newX = mouseEvent.getScreenX();
    newY = mouseEvent.getScreenY();


    double deltax = newX - initX;
    double deltay = newY - initY;
    Cursor cursor = this.getCursor();

    if (Cursor.E_RESIZE.equals(cursor)) {
        setStageWidth(initWidth + deltax);
        mouseEvent.consume();
    } else if (Cursor.NE_RESIZE.equals(cursor)) {
        if (setStageHeight(initHeight - deltay)) {
            primaryStage.setY(initStageY + deltay);
        }
        setStageWidth(initWidth + deltax);
        mouseEvent.consume();
    } else if (Cursor.SE_RESIZE.equals(cursor)) {
        setStageWidth(initWidth + deltax);
        setStageHeight(initHeight + deltay);
        mouseEvent.consume();
    } else if (Cursor.S_RESIZE.equals(cursor)) {
        setStageHeight(initHeight + deltay);
        mouseEvent.consume();
    } else if (Cursor.W_RESIZE.equals(cursor)) {
        if (setStageWidth(initWidth - deltax)) {
            primaryStage.setX(initStageX + deltax);
        }
        mouseEvent.consume();
    } else if (Cursor.SW_RESIZE.equals(cursor)) {
        if (setStageWidth(initWidth - deltax)) {
            primaryStage.setX(initStageX + deltax);
        }
        setStageHeight(initHeight + deltay);
        mouseEvent.consume();
    } else if (Cursor.NW_RESIZE.equals(cursor)) {
        if (setStageWidth(initWidth - deltax)) {
            primaryStage.setX(initStageX + deltax);
        }
        if (setStageHeight(initHeight - deltay)) {
            primaryStage.setY(initStageY + deltay);
        }
        mouseEvent.consume();
    } else if (Cursor.N_RESIZE.equals(cursor)) {
        if (setStageHeight(initHeight - deltay)) {
            primaryStage.setY(initStageY + deltay);
        }
        mouseEvent.consume();
    } else if (allowMove) {
        primaryStage.setX(mouseEvent.getScreenX() - xOffset);
        primaryStage.setY(mouseEvent.getScreenY() - yOffset);
        mouseEvent.consume();
    }
}
 
Example 20
Source File: PosGraphController.java    From Motion_Profile_Generator with MIT License 4 votes vote down vote up
@FXML
private void addPointOnClick( MouseEvent event )
{
    if( settings.isAddPointOnClick() )
    {
        // Only add a point if mouse has not moved since clicking. This filters out the mouse event from dragging a point.
        if ( event.isStillSincePress() )
        {
            // get pixel location
            Point2D mouseSceneCoords = new Point2D( event.getSceneX(), event.getSceneY() );
            double xLocal = axisPosX.sceneToLocal( mouseSceneCoords ).getX();
            double yLocal = axisPosY.sceneToLocal( mouseSceneCoords ).getY();

            // get location in units (ft, m, in)
            double raw_x = axisPosX.getValueForDisplay( xLocal ).doubleValue();
            double raw_y = axisPosY.getValueForDisplay( yLocal ).doubleValue();

            // round location
            double rnd_x;
            double rnd_y;

            if( vars.getUnit() == Units.FEET )
            {
                rnd_x = Mathf.round( raw_x, 0.5 );
                rnd_y = Mathf.round( raw_y, 0.5 );
            }
            else if( vars.getUnit() == Units.METERS )
            {
                rnd_x = Mathf.round( raw_x, 0.25 );
                rnd_y = Mathf.round( raw_y, 0.25 );
            }
            else if( vars.getUnit() == Units.INCHES )
            {
                rnd_x = Mathf.round( raw_x, 6.0 );
                rnd_y = Mathf.round( raw_y, 6.0 );
            }
            else
            {
                rnd_x = Mathf.round( raw_x, 2 );
                rnd_y = Mathf.round( raw_y, 2 );
            }

            if( ( rnd_x >= axisPosX.getLowerBound() && rnd_x <= axisPosX.getUpperBound() )
             && ( rnd_y >= axisPosY.getLowerBound() && rnd_y <= axisPosY.getUpperBound() ) )
            {

                // Clicking to add point not working on Mac???
                if ( OSValidator.isMac() )
                {
                    Optional<Waypoint> result;
                    result = DialogFactory.createWaypointDialog( String.valueOf( rnd_x ), String.valueOf( rnd_y ) ).showAndWait();
                    result.ifPresent( ( Waypoint w ) -> backend.addPoint( w ) );
                }
                else
                {
                    backend.addPoint( rnd_x, rnd_y, 0.0 );
                }
            }
        }
        else
        {
            event.consume();
        }
    }
    else
    {
        event.consume();
    }

}