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

The following examples show how to use javafx.scene.input.MouseEvent#isMiddleButtonDown() . 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: PointerEventHandler.java    From jfxvnc with Apache License 2.0 6 votes vote down vote up
private void sendMouseEvents(MouseEvent event) {

    xPosProperty.set((int) Math.floor(event.getX() / zoomLevel));
    yPosProperty.set((int) Math.floor(event.getY() / zoomLevel));

    byte buttonMask = 0;
    if (event.getEventType() == MouseEvent.MOUSE_PRESSED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
      if (event.isMiddleButtonDown()) {
        buttonMask = 2;
      } else if (event.isSecondaryButtonDown()) {
        buttonMask = 4;
      } else {
        buttonMask = 1;
      }
      fire(new PointerEvent(buttonMask, xPosProperty.get(), yPosProperty.get()));
    } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED || event.getEventType() == MouseEvent.MOUSE_MOVED) {
      buttonMask = 0;
    }

    fire(new PointerEvent(buttonMask, xPosProperty.get(), yPosProperty.get()));

  }
 
Example 2
Source File: SlideCheckBoxBehavior.java    From JFX8CustomControls with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked when a mouse press has occurred over the button. In addition to
 * potentially arming the Button, this will transfer focus to the button
 */
@Override public void mousePressed(MouseEvent e) {
    final ButtonBase button = getControl();
    super.mousePressed(e);
    // if the button is not already focused, then request the focus
    if (! button.isFocused() && button.isFocusTraversable()) {
        button.requestFocus();
    }

    // arm the button if it is a valid mouse event
    // Note there appears to be a bug where if I press and hold and release
    // then there is a clickCount of 0 on the release, whereas a quick click
    // has a release clickCount of 1. So here I'll check clickCount <= 1,
    // though it should really be == 1 I think.
    boolean valid = (e.getButton() == MouseButton.PRIMARY &&
        ! (e.isMiddleButtonDown() || e.isSecondaryButtonDown() ||
            e.isShiftDown() || e.isControlDown() || e.isAltDown() || e.isMetaDown()));

    if (! button.isArmed() && valid) {
        button.arm();
    }
}
 
Example 3
Source File: OSFXUtils.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static String mouseEventGetModifiersExText(MouseEvent event) {
    StringBuffer sb = new StringBuffer();

    if (event.isControlDown()) {
        sb.append("Ctrl+");
    }
    if (event.isMetaDown()) {
        sb.append("Meta+");
    }
    if (event.isAltDown()) {
        sb.append("Alt+");
    }
    if (event.isShiftDown()) {
        sb.append("Shift+");
    }
    if (event.isPrimaryButtonDown()) {
        sb.append("Button1+");
    }
    if (event.isMiddleButtonDown()) {
        sb.append("Button2+");
    }
    if (event.isSecondaryButtonDown()) {
        sb.append("Button3+");
    }
    String text = sb.toString();
    if (text.equals("")) {
        return text;
    }
    return text.substring(0, text.length() - 1);
}
 
Example 4
Source File: JavaFxRecorderHook.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static String mouseEventGetModifiersExText(MouseEvent event) {
    StringBuffer sb = new StringBuffer();
    if (event.isControlDown()) {
        sb.append("Ctrl+");
    }
    if (event.isMetaDown()) {
        sb.append("Meta+");
    }
    if (event.isAltDown()) {
        sb.append("Alt+");
    }
    if (event.isShiftDown()) {
        sb.append("Shift+");
    }
    if (event.isPrimaryButtonDown()) {
        sb.append("Button1+");
    }
    if (event.isMiddleButtonDown()) {
        sb.append("Button2+");
    }
    if (event.isSecondaryButtonDown()) {
        sb.append("Button3+");
    }
    String text = sb.toString();
    if (text.equals("")) {
        return text;
    }
    return text.substring(0, text.length() - 1);
}
 
Example 5
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 6
Source File: MouseEventsHelper.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public static boolean isOnlyPrimaryButtonDown(final MouseEvent event) {
    return event.getButton() == PRIMARY && !event.isMiddleButtonDown() && !event.isSecondaryButtonDown();
}
 
Example 7
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 8
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());
		}
	}
}