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

The following examples show how to use javafx.scene.input.MouseEvent#isStillSincePress() . 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: MouseEventNotificator.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Use this method to process a click event and send a special GUI event by the means of the message system.
 * @param event MouseEvent. A click event
 */
void notifyClickEvent(MouseEvent event) {
    if (!event.isStillSincePress()) {
        return;
    }

    Map<String, Object> m = new HashMap<>();
    m.put("screenX", event.getScreenX());
    m.put("screenY", event.getScreenY());
    m.put("nodeX", event.getScreenX() - sender.getLayoutX());
    m.put("nodeY", event.getScreenY() - sender.getLayoutY());
    m.put("nodeWidth", sender.getLayoutBounds().getWidth());
    m.put("nodeHeight", sender.getLayoutBounds().getHeight());

    StringBuilder eventMessage = new StringBuilder("gui-events:").append(senderName).append("-");
    if (event.getButton() == MouseButton.PRIMARY) {
        if (event.getClickCount() == 2) {
            eventMessage.append("double");
        } else {
            eventMessage.append("left");
        }
    } else if (event.getButton() == MouseButton.SECONDARY) {
        eventMessage.append("right");
    } else if (event.getButton() == MouseButton.MIDDLE) {
        eventMessage.append("middle");
    } else {
        return;
    }
    eventMessage.append("-click");

    Main.getInstance().getPluginProxy().sendMessage(eventMessage.toString(), m);
}
 
Example 2
Source File: ReadSymbolsFromMobileStyleFileController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
/**
 * Adds graphics to the map view on mouse clicks.
 *
 * @param e mouse button click event
 */
@FXML
private void handleMouseClicked(MouseEvent e) {
  if (e.getButton() == MouseButton.PRIMARY && e.isStillSincePress()) {
    // convert clicked point to a map point
    Point mapPoint = mapView.screenToLocation(new Point2D(e.getX(), e.getY()));

    // create a new graphic with the point and symbol
    Graphic graphic = new Graphic(mapPoint, faceSymbol);
    graphicsOverlay.getGraphics().add(graphic);
  }
}
 
Example 3
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();
    }

}
 
Example 4
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 5
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();
    }
}