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

The following examples show how to use javafx.scene.input.MouseEvent#isPrimaryButtonDown() . 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: Fx3DStageController.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public void handleMouseDragged(MouseEvent me) {
  double rotateFactor = 0.12;
  mousePosX = me.getSceneX();
  mousePosY = me.getSceneY();
  if (me.isPrimaryButtonDown()) {
    rotateX.setAngle(rotateX.getAngle() + rotateFactor * (mousePosY - mouseOldY));
    rotateY.setAngle(rotateY.getAngle() - rotateFactor * (mousePosX - mouseOldX));
  }
  if (me.isSecondaryButtonDown()) {
    translateX.setX(translateX.getX() + (mousePosX - mouseOldX));
    translateY.setY(translateY.getY() + (mousePosY - mouseOldY));

  }
  mouseOldX = mousePosX;
  mouseOldY = mousePosY;
}
 
Example 2
Source File: OverviewPanel.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method that is used to determine if resizing operations need
 * to be handled.
 *
 * This method changes the cursor to inform the user that resizing can
 * occur.
 *
 * @param t The triggered mouse event.
 *
 * @see MouseEvent
 */
private void handleResizing(final MouseEvent t) {
    // Determine if the cursor is currently hovering over the left border:
    if ((rect.getX() - BUFFER) <= t.getX() && t.getX() <= (rect.getX() + BUFFER)) {
        rect.setCursor(Cursor.W_RESIZE);

        // Switch on resizing left flags if is a primary mouse:
        if (t.isPrimaryButtonDown()) {
            isResizingLeft = true;
            isResizingRight = false;
        }
    } // Determine if the cursor is currently hovering over the right border:
    else if ((rect.getX() + rect.getWidth() - BUFFER) <= t.getX()
            && t.getX() <= (rect.getX() + rect.getWidth() + BUFFER)) {
        rect.setCursor(Cursor.E_RESIZE);

        // Switch on resizing right flags if is a primary mouse click:
        if (t.isPrimaryButtonDown()) {
            isResizingLeft = false;
            isResizingRight = true;
        }
    } // Not hovering over a border:
    else {
        rect.setCursor(Cursor.NONE);
    }
}
 
Example 3
Source File: AutoScrollingWindow.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handles mouse-dragged events.
 *
 * <p>
 * The event object is stored to be re-fired later. When we pan the window, we re-fire the previous drag event on
 * its target so that even if the cursor is no longer moving, the dragged-object will continue to move smoothly
 * along as the window auto-scrolls.
 * </p>
 *
 * @param event the mouse-dragged event object
 */
private void handleMouseDragged(final MouseEvent event) {

    if (event.isPrimaryButtonDown() && event.getTarget() instanceof Node) {

        currentDragEvent = event;
        dragEventTarget = (Node) event.getTarget();

        jumpDistance = getDistanceToJump(event.getX(), event.getY());

        if (jumpDistance == null) {
            jumpsTaken = 0;
        } else if (!isScrolling && isAutoScrollingEnabled()) {
            startScrolling();
        }
    }
}
 
Example 4
Source File: ResizableBox.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Processes the current mouse position, updating the cursor accordingly.
 *
 * @param event the latest {@link MouseEvent} for the mouse entering or moving inside the rectangle
 */
private void processMousePosition(final MouseEvent event) {

    if (event.isPrimaryButtonDown()) {
        return;
    }

    final RectangleMouseRegion mouseRegion = getMouseRegion(event.getX(), event.getY());

    if (!mouseRegion.equals(RectangleMouseRegion.INSIDE)) {
        mouseInPositionForResize = true;
    } else {
        mouseInPositionForResize = false;
    }

    updateCursor(mouseRegion);
}
 
Example 5
Source File: Fx3DStageController.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void handleMouseDragged(MouseEvent me) {
    double rotateFactor = 0.12;
    mousePosX = me.getSceneX();
    mousePosY = me.getSceneY();
    if (me.isPrimaryButtonDown()) {
        rotateX.setAngle(rotateX.getAngle()
                + rotateFactor * (mousePosY - mouseOldY));
        rotateY.setAngle(rotateY.getAngle()
                - rotateFactor * (mousePosX - mouseOldX));
    }
    if (me.isSecondaryButtonDown()) {
        translateX.setX(translateX.getX() + (mousePosX - mouseOldX));
        translateY.setY(translateY.getY() + (mousePosY - mouseOldY));

    }
    mouseOldX = mousePosX;
    mouseOldY = mousePosY;
}
 
Example 6
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 7
Source File: WolfensteinCheats.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void processMouseEvent(MouseEvent evt) {
    if (evt.isPrimaryButtonDown() || evt.isSecondaryButtonDown()) {
        Node source = (Node) evt.getSource();
        double mouseX = evt.getSceneX() / source.getBoundsInLocal().getWidth();
        double mouseY = evt.getSceneY() / source.getBoundsInLocal().getHeight();
        int x = Math.max(0, Math.min(7, (int) ((mouseX - 0.148) * 11)));
        int y = Math.max(0, Math.min(7, (int) ((mouseY - 0.101) * 11)));
        int location = x + (y << 3);
        if (evt.getButton() == MouseButton.PRIMARY) {
            killEnemyAt(location);
        } else {
            teleportTo(location);
        }
    }
}
 
Example 8
Source File: ImagePlot.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** setOnMouseMoved */
private void mouseMove(final MouseEvent e)
{
    final Point2D current = new Point2D(e.getX(), e.getY());
    mouse_current = Optional.of(current);

    // While zooming, when mouse is quickly dragged outside the widget
    // and then released, the 'mouseUp' event is sometimes missing.
    // --> When seeing an active mouse move w/o button press,
    //     treat that just like a release.
    if (mouse_mode.ordinal() >= MouseMode.ZOOM_IN_X.ordinal()  &&  !e.isPrimaryButtonDown())
    {
        mouseUp(e);
        return;
    }

    PlotCursors.setCursor(this, mouse_mode);

    final Point2D start = mouse_start.orElse(null);
    switch (mouse_mode)
    {
    case PAN_PLOT:
        if (start != null)
        {
            x_axis.pan(mouse_start_x_range, x_axis.getValue((int)start.getX()), x_axis.getValue((int)current.getX()));
            y_axis.pan(mouse_start_y_range, y_axis.getValue((int)start.getY()), y_axis.getValue((int)current.getY()));
        }
        break;
    case ZOOM_IN_X:
    case ZOOM_IN_Y:
    case ZOOM_IN_PLOT:
        // Show mouse feedback for ongoing zoom
        requestRedraw();
        break;
    default:
    }
    if (! crosshair)
        updateLocationInfo(e.getX(), e.getY());
}
 
Example 9
Source File: RFXComponent.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected void mousePressed(MouseEvent me) {
    if (me.isPrimaryButtonDown() && me.getClickCount() == 1 && !me.isAltDown() && !me.isMetaDown() && !me.isControlDown()) {
        mouseButton1Pressed(me);
    } else {
        recorder.recordClick2(this, me, true);
    }
}
 
Example 10
Source File: JaceUIController.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void showControlOverlay(MouseEvent evt) {
    if (!evt.isPrimaryButtonDown() && !evt.isSecondaryButtonDown()) {
        delayTimer.stop();
        menuButtonPane.setVisible(false);
        controlOverlay.setVisible(true);
        FadeTransition ft = new FadeTransition(Duration.millis(500), controlOverlay);
        ft.setFromValue(0.0);
        ft.setToValue(1.0);
        ft.play();
        rootPane.requestFocus();
    }
}
 
Example 11
Source File: JaceUIController.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void showMenuButton(MouseEvent evt) {
    if (!evt.isPrimaryButtonDown() && !evt.isSecondaryButtonDown() && !controlOverlay.isVisible()) {
        resetMenuButtonTimer();
        if (!menuButtonPane.isVisible()) {
            menuButtonPane.setVisible(true);
            FadeTransition ft = new FadeTransition(Duration.millis(500), menuButtonPane);
            ft.setFromValue(0.0);
            ft.setToValue(1.0);
            ft.play();
        }
    }
    rootPane.requestFocus();
}
 
Example 12
Source File: DragResizerUtil.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected void resetNodeSize(final MouseEvent evt) {
    if (!evt.isPrimaryButtonDown() || evt.getClickCount() < 2) {
        return;
    }

    if (!(node instanceof Region)) {
        return;
    }

    ((Region) node).setPrefWidth(Region.USE_COMPUTED_SIZE);
    ((Region) node).setPrefHeight(Region.USE_COMPUTED_SIZE);
}
 
Example 13
Source File: ImagePlot.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** onMousePressed */
private void mouseDown(final MouseEvent e)
{
    // Don't start mouse actions when user invokes context menu
    if (! e.isPrimaryButtonDown()  ||  (PlatformInfo.is_mac_os_x && e.isControlDown()))
        return;

    // Received a click while a tacker is active
    // -> User clicked outside of tracker. Remove it.
    if (roi_tracker != null)
    {
        removeROITracker();
        // Don't cause accidental 'zoom out' etc.
        // User needs to click again for that.
        return;
    }

    // Select any tracker
    final Point2D current = new Point2D(e.getX(), e.getY());
    for (RegionOfInterest roi : rois)
        if (roi.isVisible()  &&  roi.isInteractive())
        {
            final Rectangle rect = roiToScreen(roi);
            if (rect.contains(current.getX(), current.getY()))
            {   // Check if complete ROI is visible,
                // because otherwise tracker would extend beyond the
                // current image viewport
                final Rectangle2D image_rect = GraphicsUtils.convert(image_area);
                if (image_rect.contains(rect.x, rect.y, rect.width, rect.height))
                {
                    roi_tracker = new Tracker(image_rect);
                    roi_tracker.setPosition(rect.x, rect.y, rect.width, rect.height);
                    ChildCare.addChild(getParent(), roi_tracker);
                    final int index = rois.indexOf(roi);
                    roi_tracker.setListener((old_pos, new_pos) -> updateRoiFromScreen(index, new_pos));
                    return;
                }
            }
        }

    mouse_start = mouse_current = Optional.of(current);

    final int clicks = e.getClickCount();

    if (mouse_mode == MouseMode.NONE)
    {
        if (crosshair)
        {
            updateLocationInfo(e.getX(), e.getY());
            requestRedraw();
        }
    }
    else if (mouse_mode == MouseMode.PAN)
    {   // Determine start of 'pan'
        mouse_start_x_range = x_axis.getValueRange();
        mouse_start_y_range = y_axis.getValueRange();
        mouse_mode = MouseMode.PAN_PLOT;
    }
    else if (mouse_mode == MouseMode.ZOOM_IN  &&  clicks == 1)
    {   // Determine start of 'rubberband' zoom.
        // Reset cursor from SIZE* to CROSS.
        if (y_axis.getBounds().contains(current.getX(), current.getY()))
        {
            mouse_mode = MouseMode.ZOOM_IN_Y;
            PlotCursors.setCursor(this, mouse_mode);
        }
        else if (image_area.contains(current.getX(), current.getY()))
        {
            mouse_mode = MouseMode.ZOOM_IN_PLOT;
            PlotCursors.setCursor(this, mouse_mode);
        }
        else if (x_axis.getBounds().contains(current.getX(), current.getY()))
        {
            mouse_mode = MouseMode.ZOOM_IN_X;
            PlotCursors.setCursor(this, mouse_mode);
        }
    }
    else if ((mouse_mode == MouseMode.ZOOM_IN && clicks == 2)  ||  mouse_mode == MouseMode.ZOOM_OUT)
        zoomInOut(current.getX(), current.getY(), ZOOM_FACTOR);
}
 
Example 14
Source File: CreateCurveOnDragHandler.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void startDrag(MouseEvent event) {
	// create new curve
	GeometricCurve curve = new GeometricCurve(new Point[] { new Point(), new Point() },
			MvcLogoExample.GEF_COLOR_GREEN, MvcLogoExample.GEF_STROKE_WIDTH, MvcLogoExample.GEF_DASH_PATTERN, null);
	curve.addSourceAnchorage(getShapePart().getContent());

	// create using CreationPolicy from root part
	CreationPolicy creationPolicy = getHost().getRoot().getAdapter(CreationPolicy.class);
	init(creationPolicy);
	curvePart = (GeometricCurvePart) creationPolicy.create(curve, getHost().getRoot(),
			HashMultimap.<IContentPart<? extends Node>, String> create());
	commit(creationPolicy);

	// disable refresh visuals for the curvePart
	storeAndDisableRefreshVisuals(curvePart);

	// move curve to pointer location
	curvePart.getVisual().setEndPoint(getLocation(event));

	// build operation to deselect all but the new curve part
	List<IContentPart<? extends Node>> toBeDeselected = new ArrayList<>(
			getHost().getRoot().getViewer().getAdapter(SelectionModel.class).getSelectionUnmodifiable());
	toBeDeselected.remove(curvePart);
	DeselectOperation deselectOperation = new DeselectOperation(getHost().getRoot().getViewer(), toBeDeselected);
	// execute on stack
	try {
		getHost().getRoot().getViewer().getDomain().execute(deselectOperation, new NullProgressMonitor());
	} catch (ExecutionException e) {
		throw new RuntimeException(e);
	}

	// find bend target part
	bendTargetPart = findBendTargetPart(curvePart, event.getTarget());
	if (bendTargetPart != null) {
		dragPolicies = bendTargetPart.getAdapters(ClickDragGesture.ON_DRAG_POLICY_KEY);
	}
	if (dragPolicies != null) {
		MouseEvent dragEvent = new MouseEvent(event.getSource(), event.getTarget(), MouseEvent.MOUSE_DRAGGED,
				event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), event.getButton(),
				event.getClickCount(), event.isShiftDown(), event.isControlDown(), event.isAltDown(),
				event.isMetaDown(), event.isPrimaryButtonDown(), event.isMiddleButtonDown(),
				event.isSecondaryButtonDown(), event.isSynthesized(), event.isPopupTrigger(),
				event.isStillSincePress(), event.getPickResult());
		for (IOnDragHandler dragPolicy : dragPolicies.values()) {
			dragPolicy.startDrag(event);
			// XXX: send initial drag event so that the end position is set
			dragPolicy.drag(dragEvent, new Dimension());
		}
	}
}
 
Example 15
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 16
Source File: TreeNodeSkin.java    From graph-editor with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Stops the node being dragged if it isn't selected.
 * 
 * @param event a mouse-dragged event on the node
 */
private void filterMouseDragged(final MouseEvent event) {
    if (event.isPrimaryButtonDown() && !isSelected()) {
        event.consume();
    }
}
 
Example 17
Source File: TitledNodeSkin.java    From graph-editor with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Stops the node being dragged if it isn't selected.
 * 
 * @param event a mouse-dragged event on the node
 */
private void filterMouseDragged(final MouseEvent event) {
    if (event.isPrimaryButtonDown() && !isSelected()) {
        event.consume();
    }
}
 
Example 18
Source File: MouseEventsHelper.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public static boolean isOnlySecondaryButtonDown(final MouseEvent event) {
    return event.getButton() == SECONDARY && !event.isPrimaryButtonDown() && !event.isMiddleButtonDown();
}
 
Example 19
Source File: MouseEventsHelper.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public static boolean isOnlyMiddleButtonDown(final MouseEvent event) {
    return event.isMiddleButtonDown() && !event.isPrimaryButtonDown() && !event.isSecondaryButtonDown();
}
 
Example 20
Source File: DefaultNodeSkin.java    From graph-editor with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Stops the node being dragged if it isn't selected.
 * 
 * @param event a mouse-dragged event on the node
 */
private void filterMouseDragged(final MouseEvent event) {
    if (event.isPrimaryButtonDown() && !isSelected()) {
        event.consume();
    }
}