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

The following examples show how to use javafx.scene.input.MouseEvent#isControlDown() . 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: PageActionModifier.java    From Open-Lowcode with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param event a mouse event
 * @return true if the mouse event corresponds to the modifier
 */
public boolean isActionWithModifier(MouseEvent event) {
	if (event.getClickCount()==1) {
		boolean modifier = false;
		if (event.isControlDown()) {
			modifier = true;
			if (type == TYPE_CTRLPRESSED) return true;
		} 
		
		if (event.isShiftDown()) {
			modifier =true;
			if (type == TYPE_SHIFTPRESSED) return true;
		}
		
		if (!modifier) {
			if (type == TYPE_NOTHINGPRESSED) return true;
		}
		
	}
	return false;
}
 
Example 2
Source File: DiagramCanvasController.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private void mouseDragged(MouseEvent pEvent)
{
	Point mousePoint = getMousePoint(pEvent);
	if(aDragMode == DragMode.DRAG_MOVE && !aSelectionModel.isEmpty() ) 
	{
		// The second condition in the if is necessary in the case where a single 
		// element is selected with the Ctrl button is down, which immediately deselects it.
		Point pointToReveal = computePointToReveal(mousePoint);
		moveSelection(mousePoint);
		aHandler.interactionTo(pointToReveal);
	}
	else if(aDragMode == DragMode.DRAG_LASSO)
	{
		aLastMousePoint = mousePoint;
		if( !pEvent.isControlDown() )
		{
			aSelectionModel.clearSelection();
		}
		aSelectionModel.activateLasso(computeLasso(), aCanvas.getDiagram());
	}
	else if(aDragMode == DragMode.DRAG_RUBBERBAND)
	{
		aLastMousePoint = mousePoint;
		aSelectionModel.activateRubberband(computeRubberband());
	}
}
 
Example 3
Source File: WSRecorder.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private String buildModifiersText(MouseEvent e) {
    StringBuilder sb = new StringBuilder();
    if (e.isAltDown()) {
        sb.append("Alt+");
    }
    if (e.isControlDown()) {
        sb.append("Ctrl+");
    }
    if (e.isMetaDown()) {
        sb.append("Meta+");
    }
    if (e.isShiftDown()) {
        sb.append("Shift+");
    }
    if (sb.length() > 0) {
        sb.setLength(sb.length() - 1);
    }
    String mtext = sb.toString();
    return mtext;
}
 
Example 4
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 5
Source File: AbstractMouseHandlerFX.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the specified mouse event has modifier
 * keys that match this handler.
 * 
 * @param e  the mouse event (<code>null</code> not permitted).
 * 
 * @return A boolean. 
 */
@Override
public boolean hasMatchingModifiers(MouseEvent e) {
    boolean b = true;
    b = b && (this.altKey == e.isAltDown());
    b = b && (this.ctrlKey == e.isControlDown());
    b = b && (this.metaKey == e.isMetaDown());
    b = b && (this.shiftKey == e.isShiftDown());
    return b;
}
 
Example 6
Source File: AbstractMouseHandlerFX.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the specified mouse event has modifier
 * keys that match this handler.
 * 
 * @param e  the mouse event (<code>null</code> not permitted).
 * 
 * @return A boolean. 
 */
@Override
public boolean hasMatchingModifiers(MouseEvent e) {
    boolean b = true;
    b = b && (this.altKey == e.isAltDown());
    b = b && (this.ctrlKey == e.isControlDown());
    b = b && (this.metaKey == e.isMetaDown());
    b = b && (this.shiftKey == e.isShiftDown());
    return b;
}
 
Example 7
Source File: TaAbstractMouseHandlerFX.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns {@code true} if the specified mouse event has modifier
 * keys that match this handler.
 *
 * @param e  the mouse event ({@code null} not permitted).
 *
 * @return A boolean.
 */
@Override
public boolean hasMatchingModifiers(MouseEvent e) {
    boolean b = true;
    b = b && (this.altKey == e.isAltDown());
    b = b && (this.ctrlKey == e.isControlDown());
    b = b && (this.metaKey == e.isMetaDown());
    b = b && (this.shiftKey == e.isShiftDown());
    return b;
}
 
Example 8
Source File: FileTreeCell.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Determines the {@link TransferMode} based on the state of the modifier key.
 * This method must consider the
 * operating system as the identity of the modifier key varies (alt/option on Mac OS, ctrl on the rest).
 * @param event The mouse event containing information on key press.
 * @return {@link TransferMode#COPY} if modifier key is pressed, otherwise {@link TransferMode#MOVE}.
 */
private TransferMode getTransferMode(MouseEvent event){
    if(event.isControlDown() && (PlatformInfo.is_linux || PlatformInfo.isWindows || PlatformInfo.isUnix)){
        return TransferMode.COPY;
    }
    else if(event.isAltDown() && PlatformInfo.is_mac_os_x){
        return TransferMode.COPY;
    }
    return TransferMode.MOVE;
}
 
Example 9
Source File: AbstractMouseHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns {@code true} if the specified mouse event has modifier
 * keys that match this handler.
 * 
 * @param e  the mouse event ({@code null} not permitted).
 * 
 * @return A boolean. 
 */
@Override
public boolean hasMatchingModifiers(MouseEvent e) {
    boolean b = true;
    b = b && (this.altKey == e.isAltDown());
    b = b && (this.ctrlKey == e.isControlDown());
    b = b && (this.metaKey == e.isMetaDown());
    b = b && (this.shiftKey == e.isShiftDown());
    return b;
}
 
Example 10
Source File: DiagramCanvasController.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private void handleSelection(MouseEvent pEvent)
{
	Optional<? extends DiagramElement> element = getSelectedElement(pEvent);
	if(element.isPresent()) 
	{
		if(pEvent.isControlDown())
		{
			if(!aSelectionModel.contains(element.get()))
			{
				aSelectionModel.addToSelection(element.get());
			}
			else
			{
				aSelectionModel.removeFromSelection(element.get());
			}
		}
		else if(!aSelectionModel.contains(element.get()))
		{
			// The test is necessary to ensure we don't undo multiple selections
			aSelectionModel.set(element.get());
		}
		// Reorder the selected nodes to ensure that they appear on the top
		for(Node pSelected: aSelectionModel.getSelectedNodes()) 
		{
			aCanvas.getDiagram().placeOnTop(pSelected);
		}
		aDragMode = DragMode.DRAG_MOVE;
		aMoveTracker.startTrackingMove(aSelectionModel);
	}
	else // Nothing is selected
	{
		if(!pEvent.isControlDown()) 
		{
			aSelectionModel.clearSelection();
		}
		aDragMode = DragMode.DRAG_LASSO;
	}
}
 
Example 11
Source File: AbstractMouseHandlerFX.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the specified mouse event has modifier
 * keys that match this handler.
 * 
 * @param e  the mouse event (<code>null</code> not permitted).
 * 
 * @return A boolean. 
 */
@Override
public boolean hasMatchingModifiers(MouseEvent e) {
    boolean b = true;
    b = b && (this.altKey == e.isAltDown());
    b = b && (this.ctrlKey == e.isControlDown());
    b = b && (this.metaKey == e.isMetaDown());
    b = b && (this.shiftKey == e.isShiftDown());
    return b;
}
 
Example 12
Source File: EventQueueDeviceTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected static String getModifiersExText(MouseEvent event) {
    StringBuffer buf = new StringBuffer();
    if (event.isMetaDown()) {
        buf.append("Meta");
        buf.append("+");
    }
    if (event.isControlDown()) {
        buf.append("Ctrl");
        buf.append("+");
    }
    if (event.isAltDown()) {
        buf.append("Alt");
        buf.append("+");
    }
    if (event.isShiftDown()) {
        buf.append("Shift");
        buf.append("+");
    }
    if (event.getButton() == MouseButton.PRIMARY) {
        buf.append("Button1");
        buf.append("+");
    }
    if (event.getButton() == MouseButton.MIDDLE) {
        buf.append("Button2");
        buf.append("+");
    }
    if (event.getButton() == MouseButton.SECONDARY) {
        buf.append("Button3");
        buf.append("+");
    }
    return buf.toString();
}
 
Example 13
Source File: WebViewEventDispatcher.java    From oim-fx with MIT License 5 votes vote down vote up
private void processMouseEvent(MouseEvent ev) {
    if (page == null) {
        return;
    }

    // RT-24511
    EventType<? extends MouseEvent> type = ev.getEventType();
    double x = ev.getX();
    double y = ev.getY();
    double screenX = ev.getScreenX();
    double screenY = ev.getScreenY();
    if (type == MouseEvent.MOUSE_EXITED) {
        type = MouseEvent.MOUSE_MOVED;
        x = Short.MIN_VALUE;
        y = Short.MIN_VALUE;
        Point2D screenPoint = webView.localToScreen(x, y);
        if (screenPoint == null) {
            return;
        }
        screenX = screenPoint.getX();
        screenY = screenPoint.getY();
    }

    final Integer id = idMap.get(type);
    if (id == null) {
        // not supported by webkit
        return;
    }
    WCMouseEvent mouseEvent =
            new WCMouseEvent(id, idMap.get(ev.getButton()),
                ev.getClickCount(), (int) x, (int) y,
                (int) screenX, (int) screenY,
                System.currentTimeMillis(),
                ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(),
                ev.isMetaDown(), ev.isPopupTrigger());
    page.dispatchMouseEvent(mouseEvent);
    ev.consume();
}
 
Example 14
Source File: FX.java    From FxDock with Apache License 2.0 5 votes vote down vote up
/** sometimes MouseEvent.isPopupTrigger() is not enough */
public static boolean isPopupTrigger(MouseEvent ev)
{
	if(ev.getButton() == MouseButton.SECONDARY)
	{
		if(CPlatform.isMac())
		{
			if
			(
				!ev.isAltDown() &&
				!ev.isMetaDown() &&
				!ev.isShiftDown()
			)
			{
				return true;
			}
		}
		else
		{
			if
			(
				!ev.isAltDown() &&
				!ev.isControlDown() &&
				!ev.isMetaDown() &&
				!ev.isShiftDown()
			)
			{
				return true;
			}
		}
	}
	return false;
}
 
Example 15
Source File: RFXTreeTableView.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
protected void mouseClicked(MouseEvent me) {
    if (me.isControlDown() || me.isAltDown() || me.isMetaDown() || onCheckBox((Node) me.getTarget()))
        return;
    recorder.recordClick2(this, me, true);
}
 
Example 16
Source File: RFXTreeView.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
protected void mouseClicked(MouseEvent me) {
    if (me.isControlDown() || me.isAltDown() || me.isMetaDown() || onCheckBox((Node) me.getTarget()))
        return;
    recorder.recordClick2(this, me, true);
}
 
Example 17
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 18
Source File: MouseEventsHelper.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public static boolean modifierKeysUp(final MouseEvent event) {
    return !event.isAltDown() && !event.isControlDown() && !event.isMetaDown() && !event.isShiftDown();
}
 
Example 19
Source File: MouseEventsHelper.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public static boolean isOnlyCtrlModifierDown(final MouseEvent event) {
    return event.isControlDown() && !event.isAltDown() && !event.isMetaDown() && !event.isShiftDown();
}
 
Example 20
Source File: ResizeTranslateFirstAnchorageOnHandleDragHandler.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if the given {@link MouseEvent} should trigger
 * resize and translate. Otherwise returns <code>false</code>. Per default
 * returns <code>true</code> if <code>&lt;Control&gt;</code> is not pressed
 * and there is not more than single anchorage.
 *
 * @param event
 *            The {@link MouseEvent} in question.
 * @return <code>true</code> if the given {@link MouseEvent} should trigger
 *         resize and translate, otherwise <code>false</code>.
 */
protected boolean isResizeTranslate(MouseEvent event) {
	return !event.isControlDown() && !isMultiSelection();
}