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

The following examples show how to use javafx.scene.input.MouseEvent#getButton() . 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: EditDataSet.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void performPointDrag(final MouseEvent event) {
    if (event.getButton() == MouseButton.PRIMARY && !controlDown && isPointDragActive) {
        if (mouseOriginX < 0) {
            mouseOriginX = event.getSceneX();
        }
        if (mouseOriginY < 0) {
            mouseOriginY = event.getSceneY();
        }
        final double deltaX = event.getSceneX() - mouseOriginX;
        final double deltaY = event.getSceneY() - mouseOriginY;

        // get the latest mouse coordinate.
        mouseOriginX = event.getSceneX();
        mouseOriginY = event.getSceneY();

        applyDrag(deltaX, deltaY);
        event.consume();
    } else {
        isPointDragActive = false;
    }
}
 
Example 2
Source File: RegionBaseRepresentation.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Copy PV name to clipboard when middle button clicked
 *  @param event Mouse pressed event
 */
private void hookMiddleButtonCopy(final MouseEvent event)
{
    if (event.getButton() != MouseButton.MIDDLE)
        return;

    final String pv_name = ((PVWidget)model_widget).propPVName().getValue();

    // Copy to copy/paste clipboard
    final ClipboardContent content = new ClipboardContent();
    content.putString(pv_name);
    Clipboard.getSystemClipboard().setContent(content);

    // Copy to the 'selection' buffer used by X11
    // for middle-button copy/paste
    // Note: This is AWT API!
    // JavaFX has no API, https://bugs.openjdk.java.net/browse/JDK-8088117
    if (Toolkit.getDefaultToolkit().getSystemSelection() != null)
        Toolkit.getDefaultToolkit().getSystemSelection().setContents(new StringSelection(pv_name), null);
}
 
Example 3
Source File: JFXChartUtil.java    From jfxutils with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an {@link EventHandler} that sets X and/or Y axis auto ranging when the primary mouse button is
 * double-clicked. If the click occurs inside the X axis area auto range only the X axis and similarly for Y axis. But
 * if the event is in the plot area or anywhere else, auto range both axes.
 */
public static EventHandler<MouseEvent> getDoublePrimaryClickAutoRangeHandler( final XYChartInfo chartInfo ) {
	return new EventHandler<MouseEvent>() {
		@Override
		public void handle( MouseEvent event ) {
			if ( event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY ) {
				double x = event.getX();
				double y = event.getY();
				if ( !chartInfo.getXAxisArea().contains( x, y ) )
					chartInfo.getChart().getYAxis().setAutoRanging( true );
				if ( !chartInfo.getYAxisArea().contains( x, y ) )
					chartInfo.getChart().getXAxis().setAutoRanging( true );
			}
		}
	};
}
 
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: ResultList.java    From iliasDownloaderTool with GNU General Public License v2.0 6 votes vote down vote up
private void showContextMenu(MouseEvent event) {
	menu.hide();
	final List<IliasTreeNode> selectedNodes = ((ResultList) event.getSource())
			.getSelectionModel().getSelectedItems();
	if (selectedNodes.isEmpty() || selectedNodes == null) {
		return;
	}
	if (selectedNodes.size() == 1) {
		dashboard.getCoursesTreeView().selectFile((IliasFile) selectedNodes.get(0));
	}

	if (event.getButton() == MouseButton.SECONDARY) {
		menu = new FileContextMenu(dashboard).createMenu(selectedNodes, event);
		menu.show(this, event.getScreenX(), event.getScreenY());
	}
}
 
Example 6
Source File: ImageManufacturePenController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@FXML
    @Override
    public void mouseDragged(MouseEvent event) {
        if (null == opType || imageView == null || imageView.getImage() == null) {
            return;
        }
        DoublePoint p = imageController.getImageXY(event, imageView);
        imageController.showXY(event, p);

        if (event.getButton() == MouseButton.SECONDARY || p == null) {
            return;
        }

        switch (opType) {
            case Polyline:
                if (lastX == event.getX() && lastY == event.getY()) {
                    return;
                }
                imageController.scrollPane.setPannable(false);
                imageController.maskLineData.add(p);
                lastX = event.getX();
                lastY = event.getY();
                drawPolyline();
                break;
            case DrawLines:
            case Erase:
//            case Mosaic:
//            case Frosted:
                imageController.scrollPane.setPannable(false);
                imageController.maskPenData.addPoint(p);
                lastX = event.getX();
                lastY = event.getY();
                updateMask();
        }

    }
 
Example 7
Source File: RecordingListController.java    From archivo with GNU General Public License v3.0 5 votes vote down vote up
private void archiveOnDoubleClick(MouseEvent event) {
    if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() > 1) {
        int numRecordings = recordingSelection.getRecordingsWithChildren().size();
        // If the user double-clicks a group header, just expand/collapse it, don't archive everything in it
        if (recordingSelection.isArchivableProperty().get() && numRecordings == 1) {
            mainApp.archiveSelection();
        }
    }
}
 
Example 8
Source File: WSRecorder.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void recordRawMouseEvent(final RFXComponent r, MouseEvent e) {
    final JSONObject event = new JSONObject();
    event.put("type", "click_raw");
    int button = e.getButton() == MouseButton.PRIMARY ? java.awt.event.MouseEvent.BUTTON1 : java.awt.event.MouseEvent.BUTTON3;
    event.put("button", button);
    event.put("clickCount", e.getClickCount());
    event.put("modifiersEx", buildModifiersText(e));
    Node source = (Node) e.getSource();
    Node target = r.getComponent();
    Point2D sts = source.localToScene(new Point2D(e.getX(), e.getY()));
    Point2D tts = target.sceneToLocal(sts);
    event.put("x", tts.getX());
    event.put("y", tts.getY());
    final JSONObject o = new JSONObject();
    o.put("event", event);
    fill(r, o);
    if (e.getClickCount() == 1) {
        clickTimer = new Timer();
        clickTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                sendRecordMessage(o);
            }
        }, timerinterval.intValue());
    } else if (e.getClickCount() == 2) {
        if (clickTimer != null) {
            clickTimer.cancel();
            clickTimer = null;
        }
        sendRecordMessage(o);
    }
}
 
Example 9
Source File: ClickableBitcoinAddress.java    From devcoretalk with GNU General Public License v2.0 5 votes vote down vote up
@FXML
protected void requestMoney(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || (event.getButton() == MouseButton.PRIMARY && event.isMetaDown())) {
        // User right clicked or the Mac equivalent. Show the context menu.
        addressMenu.show(addressLabel, event.getScreenX(), event.getScreenY());
    } else {
        // User left clicked.
        try {
            Desktop.getDesktop().browse(URI.create(uri()));
        } catch (IOException e) {
            GuiUtils.informationalAlert("Opening wallet app failed", "Perhaps you don't have one installed?");
        }
    }
}
 
Example 10
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 11
Source File: ClickableBitcoinAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@FXML
protected void requestMoney(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || (event.getButton() == MouseButton.PRIMARY && event.isMetaDown())) {
        // User right clicked or the Mac equivalent. Show the context menu.
        addressMenu.show(addressLabel, event.getScreenX(), event.getScreenY());
    } else {
        // User left clicked.
        try {
            Desktop.getDesktop().browse(URI.create(uri()));
        } catch (IOException e) {
            GuiUtils.informationalAlert("Opening wallet app failed", "Perhaps you don't have one installed?");
        }
    }
}
 
Example 12
Source File: ClickableBitcoinAddress.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@FXML
protected void requestMoney(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || (event.getButton() == MouseButton.PRIMARY && event.isMetaDown())) {
        // User right clicked or the Mac equivalent. Show the context menu.
        addressMenu.show(addressLabel, event.getScreenX(), event.getScreenY());
    } else {
        // User left clicked.
        try {
            Desktop.getDesktop().browse(URI.create(uri()));
        } catch (IOException e) {
            GuiUtils.informationalAlert("Opening wallet app failed", "Perhaps you don't have one installed?");
        }
    }
}
 
Example 13
Source File: UICanvas.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	MouseButton btn = event.getButton();
	if (!(event.getTarget() instanceof Canvas)) {
		return;
	}

	Canvas c = (Canvas) event.getTarget();
	Point2D p = c.sceneToLocal(event.getSceneX(), event.getSceneY());
	int mousex = (int) p.getX();
	int mousey = (int) p.getY();

	if (event.getEventType() == MouseEvent.MOUSE_MOVED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
		canvas.mouseMoved(mousex, mousey);
		canvas.setLastMousePosition(mousex, mousey);
		if (mouseDown) {
			this.canvas.requestPaint();
		}
	} else {
		if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
			mouseDown = true;
			canvas.mousePressed(mousex, mousey, btn);
		} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
			canvas.mouseReleased(mousex, mousey, btn);
			mouseDown = false;
			canvas.requestPaint();
		}
	}

}
 
Example 14
Source File: MainViewController.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Handle tree item clicked
 *
 * @param mouseEvent
 */
@FXML
public void handleTreeClicked(MouseEvent mouseEvent) {
    rightClickDevicesTreeMenu.ifPresent(ContextMenu::hide);
    CustomTreeItem selected = (CustomTreeItem) devicesTree.getSelectionModel().getSelectedItem();
    if (selected != null) {
        if (mouseEvent.getButton() == MouseButton.SECONDARY) {
            updateContextMenuState();
            rightClickDevicesTreeMenu = Optional.ofNullable(selected.getMenu());
            rightClickDevicesTreeMenu.ifPresent(contextMenu -> {
                contextMenu.show(devicesTree, mouseEvent.getScreenX(), mouseEvent.getScreenY());
            });
        }
    }
}
 
Example 15
Source File: ImageManufacturePenController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@FXML
    @Override
    public void mousePressed(MouseEvent event) {
        if (null == opType || imageView == null || imageView.getImage() == null) {
            return;
        }
        DoublePoint p = imageController.getImageXY(event, imageView);
        imageController.showXY(event, p);

        if (event.getButton() == MouseButton.SECONDARY || p == null) {
            return;
        }

        switch (opType) {
            case Polyline:
                if (lastX == event.getX() && lastY == event.getY()) {
                    return;
                }
                imageController.scrollPane.setPannable(false);
                imageController.maskLineData.add(p);
                lastX = event.getX();
                lastY = event.getY();
                drawPolyline();
                break;
            case DrawLines:
            case Erase:
//            case Mosaic:
//            case Frosted:
                imageController.scrollPane.setPannable(false);
                imageController.maskPenData.startLine(p);
                lastX = event.getX();
                lastY = event.getY();
                updateMask();
        }

    }
 
Example 16
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 17
Source File: ImageMaskController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected void doubleClickedRectangle(MouseEvent event) {
    if (maskRectangleLine == null || !maskRectangleLine.isVisible()) {
        return;
    }
    DoublePoint p = getImageXY(event, imageView);
    if (p != null) {
        double x = p.getX();
        double y = p.getY();
        if (event.getButton() == MouseButton.PRIMARY) {

            if (x < maskRectangleData.getBigX() && y < maskRectangleData.getBigY()) {
                maskRectangleData.setSmallX(x);
                maskRectangleData.setSmallY(y);
                drawMaskRectangleLine();
            }

        } else if (event.getButton() == MouseButton.SECONDARY) {

            if (x > maskRectangleData.getSmallX() && y > maskRectangleData.getSmallY()) {
                maskRectangleData.setBigX(x);
                maskRectangleData.setBigY(y);
                drawMaskRectangleLine();
            }

        }
    }
}
 
Example 18
Source File: CGrid.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	MouseButton button = event.getButton();

	if (button == MouseButton.PRIMARY) {
		if (event.getClickCount() == 1 && (event.isShiftDown())) {

			if (thisobjectgrid.isinlineupdate)
				if (!thisobjectgrid.updatemodeactive) { // currently, table in read mode, move to
					logger.fine("moving tableview " + thisobjectgrid.name + " to update mode");
					thisobjectgrid.tableview.setEditable(true);
					thisobjectgrid.tableview.getSelectionModel().setCellSelectionEnabled(true);
					thisobjectgrid.updatemodeactive = true;
					thisobjectgrid.startupdate.setDisable(true);
					thisobjectgrid.commitupdate.setDisable(false);
					return;
				}
		}
		if (thisobjectgrid.isinlineupdate)
			if (thisobjectgrid.updatemodeactive)
				if (event.getClickCount() == 1) {
					if (thisobjectgrid.tableview.getEditingCell() == null) {
						@SuppressWarnings("unchecked")
						TablePosition<CObjectGridLine<String>, ?> focusedCellPosition = thisobjectgrid.tableview
								.getFocusModel().getFocusedCell();
						thisobjectgrid.tableview.edit(focusedCellPosition.getRow(),
								focusedCellPosition.getTableColumn());

					}
				}
		if (thisobjectgrid.iscellaction)
			if (event.getClickCount() > 1) {
				// trigger the action on double click only if updatemode is not active
				if (!thisobjectgrid.updatemodeactive) {
					logger.info("Single action click detected");
					pageactionmanager.getMouseHandler().handle(event);
				}
			}
	}
}
 
Example 19
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 20
Source File: FX.java    From FxDock with Apache License 2.0 4 votes vote down vote up
public static boolean isLeftButton(MouseEvent ev)
{
	return (ev.getButton() == MouseButton.PRIMARY);
}