Java Code Examples for javafx.scene.input.MouseButton#PRIMARY
The following examples show how to use
javafx.scene.input.MouseButton#PRIMARY .
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 |
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: MouseCoordinateTrackerTest.java From paintera with GNU General Public License v2.0 | 6 votes |
private static final MouseEvent createEvent(EventType<MouseEvent> type, double x, double y) { return new MouseEvent( type, x, y, 0.0, 0.0, MouseButton.PRIMARY, 1, false, false, false, false, true, false, false, false, false, false, null); }
Example 3
Source File: TicTacToe.java From games_oop_javafx with Apache License 2.0 | 6 votes |
private EventHandler<MouseEvent> buildMouseEvent(Group panel) { return event -> { Figure3T rect = (Figure3T) event.getTarget(); if (this.checkState()) { if (event.getButton() == MouseButton.PRIMARY) { rect.take(true); panel.getChildren().add( this.buildMarkX(rect.getX(), rect.getY(), 50) ); } else { rect.take(false); panel.getChildren().add( this.buildMarkO(rect.getX(), rect.getY(), 50) ); } this.checkWinner(); this.checkState(); } }; }
Example 4
Source File: NodeGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { final Node node = (Node) event.getSource(); double offsetX = event.getScreenX() + dragContext.x; double offsetY = event.getScreenY() + dragContext.y; // adjust the offset in case we are zoomed final double scale = graph.getScale(); offsetX /= scale; offsetY /= scale; node.relocate(offsetX, offsetY); } }
Example 5
Source File: CardAppleMouse.java From jace with GNU General Public License v2.0 | 5 votes |
public void mousePressed(MouseEvent me) { MouseButton button = me.getButton(); if (button == MouseButton.PRIMARY || button == MouseButton.MIDDLE) { button0press = true; } if (button == MouseButton.SECONDARY || button == MouseButton.MIDDLE) { button1press = true; } }
Example 6
Source File: WSRecorder.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public void recordClick2(final RFXComponent r, MouseEvent e, boolean withCellInfo) { final JSONObject event = new JSONObject(); event.put("type", "click"); 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)); double x = e.getX(); double y = e.getY(); Node source = (Node) e.getSource(); Node target = r.getComponent(); Point2D sts = source.localToScreen(new Point2D(0, 0)); Point2D tts = target.localToScreen(new Point2D(0, 0)); x = e.getX() - tts.getX() + sts.getX(); y = e.getY() - tts.getY() + sts.getY(); event.put("x", x); event.put("y", y); if (withCellInfo) { event.put("cellinfo", r.getCellInfo()); } 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 7
Source File: ClickableBitcoinAddress.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@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 8
Source File: ReadSymbolsFromMobileStyleFileController.java From arcgis-runtime-samples-java with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: ListWidgetBase.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
/** * Selects the {@link ListWidgetElement} which belongs to the given {@link E innerElement} * * @param innerElement The inner element */ public void select(E innerElement) { final MouseEvent event = new MouseEvent( MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, MouseButton.PRIMARY, 1, false, false, false, false, false, false, false, false, false, false, null); select(innerElement, event); }
Example 10
Source File: FXEventQueueDevice.java From marathonv5 with Apache License 2.0 | 5 votes |
private void storeMouseDown(MouseButton button) { if (button == MouseButton.PRIMARY) { button1Pressed = true; } if (button == MouseButton.MIDDLE) { button2Pressed = true; } if (button == MouseButton.SECONDARY) { button3Pressed = true; } }
Example 11
Source File: IDevice.java From marathonv5 with Apache License 2.0 | 5 votes |
public MouseButton getMouseButton() { if (button == 0) { return MouseButton.PRIMARY; } else if (button == 1) { return MouseButton.MIDDLE; } else { return MouseButton.SECONDARY; } }
Example 12
Source File: ClickableBitcoinAddress.java From green_android with GNU General Public License v3.0 | 5 votes |
@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: ImageMaskController.java From MyBox with Apache License 2.0 | 5 votes |
protected void doubleClickedCircle(MouseEvent event) { if (maskCircleLine == null || !maskCircleLine.isVisible()) { return; } DoublePoint p = getImageXY(event, imageView); if (p == null) { return; } double x = p.getX(); double y = p.getY(); if (event.getButton() == MouseButton.PRIMARY) { maskCircleData.setCenterX(x); maskCircleData.setCenterY(y); drawMaskCircleLine(); } else if (event.getButton() == MouseButton.SECONDARY) { if (x != maskCircleData.getCenterX() || y != maskCircleData.getCenterY()) { double dx = x - maskCircleData.getCenterX(); double dy = y - maskCircleData.getCenterY(); maskCircleData.setRadius(Math.sqrt(dx * dx + dy * dy)); drawMaskCircleLine(); } } }
Example 14
Source File: AbstractListCell.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Update hide status. */ @FxThread private void processHide(@NotNull final MouseEvent event) { event.consume(); if (event.getButton() != MouseButton.PRIMARY) { return; } processHideImpl(); }
Example 15
Source File: WolfensteinCheats.java From jace with GNU General Public License v2.0 | 5 votes |
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 16
Source File: WSRecorder.java From marathonv5 with Apache License 2.0 | 5 votes |
@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 17
Source File: AutocompletePopupSkin.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void handleClick(final MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { logger.log(Level.FINE, () -> "Clicked in list"); runSelectedAction(); } }
Example 18
Source File: GUIConsoleInput.java From Jupiter with GNU General Public License v3.0 | 4 votes |
/** * Creates a new GUI console input. * * @param area GUI text area */ public GUIConsoleInput(InlineCssTextArea area) { this.area = area; initialPos = -1; inputText = null; area.setEditable(false); queue = new ArrayBlockingQueue<>(1); listener = new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent e) { switch (e.getCode()) { case UP: case KP_UP: case PAGE_UP: area.moveTo(initialPos); e.consume(); break; case DOWN: case KP_DOWN: case PAGE_DOWN: area.moveTo(area.getLength()); e.consume(); break; // ensure always that caret position is >= initialPos case LEFT: case KP_LEFT: case BACK_SPACE: if (area.getCaretPosition() == initialPos) e.consume(); break; // return user response case ENTER: // after user release enter key return response if (e.getEventType() == KeyEvent.KEY_RELEASED) returnResponse(); break; // nothing default: // change area input color if (initialPos < area.getLength()) { area.setStyle(initialPos, area.getLength(), "-fx-fill: #4a148c;"); } break; } } }; mouseListener = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { EventType<? extends MouseEvent> type = e.getEventType(); // disable mouse selection if (type == MouseEvent.DRAG_DETECTED || type == MouseEvent.MOUSE_DRAGGED) e.consume(); // control caret position if (type == MouseEvent.MOUSE_CLICKED || type == MouseEvent.MOUSE_RELEASED || type == MouseEvent.MOUSE_PRESSED) { if (e.getButton() == MouseButton.PRIMARY) { if (area.getCaretPosition() < initialPos) { area.setDisable(true); area.moveTo(initialPos); area.setDisable(false); } } else { e.consume(); } } } }; stopListener = new ChangeListener<Boolean>() { @Override public void changed(ObservableValue obs, Boolean oldValue, Boolean newValue) { if (!newValue) { returnResponse(); } } }; }
Example 19
Source File: PrinceOfPersiaCheats.java From jace with GNU General Public License v2.0 | 4 votes |
public void mouseClicked(MouseButton button) { Double x = mouseX; // Offset y by three pixels to account for tiles above Double y = mouseY - 0.015625; // Now we have the x and y coordinates ranging from 0 to 1.0, scale to POP values int row = y < 0 ? -1 : (int) (y * 3); int col = (int) (x * 10); // Do a check if we are at the bottom of the tile, the user might have been clicking on the tile to the right. // This accounts for the isometric view and allows a little more flexibility, not to mention warping behind gates // that are on the left edge of the screen! int yCoor = ((int) (y * 192) % 63); if (yCoor >= 47) { double yOffset = 1.0 - ((yCoor - 47.0) / 16.0); int xCoor = ((int) (x * 280) % 28); double xOffset = xCoor / 28.0; if (xOffset <= yOffset) { col--; } } // Note: POP uses a 255-pixel horizontal axis, Pixels 0-57 are offscreen to the left // and 198-255 offscreen to the right. // System.out.println("Clicked on " + col + "," + row + " -- screen " + (x * 280) + "," + (y * 192)); RAM128k mem = (RAM128k) computer.getMemory(); PagedMemory auxMem = mem.getAuxMemory(); if (button == MouseButton.PRIMARY) { // Left click hacks // See if there is an opponent we can kill off. int opponentX = auxMem.readByte(ShadBlockX); int opponentY = auxMem.readByte(ShadBlockY); int opponentLife = auxMem.readByte(ShadLife); // If there is a guy near where the user clicked and he's alive, then kill 'em. if (opponentLife != 0 && opponentY == row && Math.abs(col - opponentX) <= 1) { // System.out.println("Enemy at " + opponentX + "," + opponentY + "; life=" + opponentLife); // Occasionally, if the code is at the right spot this will cause the special effect of a hit to appear auxMem.writeByte(ChgOppStr, (byte) -opponentLife); // And this will kill the dude pretty much right away. auxMem.writeByte(ShadLife, (byte) 0); } else if (row >= 0 && col >= 0) { // Try to perform actions on the block clicked as well as to the left and right of it. // This opens gates and exits. performAction(row, col, 1); performAction(row, col - 1, 1); performAction(row, col + 1, 1); } } else { // Right/middle click == warp byte warpX = (byte) (x * 140 + 58); // This aliases the Y coordinate so the prince is on the floor at the correct spot. byte warpY = (byte) ((row * 63) + 54); // System.out.println("Warping to " + warpX + "," + warpY); auxMem.writeByte(KidX, warpX); auxMem.writeByte(KidY, warpY); auxMem.writeByte(KidBlockX, (byte) col); auxMem.writeByte(KidBlockY, (byte) row); // Set action to bump into a wall so it can reset the kid's feet on the ground correctly. // Not sure if this has any real effect but things seem to be working (so I'll just leave this here...) auxMem.writeByte(KidAction, (byte) 5); } }
Example 20
Source File: DragSupport.java From scenic-view with GNU General Public License v3.0 | 2 votes |
/** * Creates DragSupport instance that attaches EventHandlers to the given * scene and responds to mouse and keyboard events in order to change given * property values according to mouse drag events of given orientation * * @param target scene * @param modifier null if no modifier needed * @param orientation vertical or horizontal * @param property number property to control * @see #DragSupport(javafx.scene.Scene, javafx.scene.input.KeyCode, * javafx.geometry.Orientation, javafx.beans.property.Property, double) */ public DragSupport(Node target, final KeyCode modifier, final Orientation orientation, final Property<Number> property) { this(target, modifier, MouseButton.PRIMARY, orientation, property, 1); }