private void kochPanelMouseDragged(MouseEvent event) { zoomTranslateX = zoomTranslateX + event.getX() - lastDragX; zoomTranslateY = zoomTranslateY + event.getY() - lastDragY; lastDragX = event.getX(); lastDragY = event.getY(); kochManager.drawEdges(); }
private void kochPanelMouseClicked(MouseEvent event) { if (Math.abs(event.getX() - startPressedX) < 1.0 && Math.abs(event.getY() - startPressedY) < 1.0) { double originalPointClickedX = (event.getX() - zoomTranslateX) / zoom; double originalPointClickedY = (event.getY() - zoomTranslateY) / zoom; if (event.getButton() == MouseButton.PRIMARY) { zoom *= 2.0; } else if (event.getButton() == MouseButton.SECONDARY) { zoom /= 2.0; } zoomTranslateX = (int) (event.getX() - originalPointClickedX * zoom); zoomTranslateY = (int) (event.getY() - originalPointClickedY * zoom); kochManager.drawEdges(); } }
@Override protected void handleClick(MouseEvent e) { double worldX = getViewModel().screenToWorldX(e.getX()); double worldY = getViewModel().screenToWorldY(e.getY()); double worldZ = getViewModel().getCurrentZLevel(); getUserInputHandler().worldPointClicked(worldX, worldY, worldZ, e); e.consume(); }
@FXML private void evtMouseClick(MouseEvent evt) throws Exception { if (evt.getButton() == MouseButton.SECONDARY) { showContextMenu(evt.getX(), evt.getY()); evt.consume(); } else if (contextMenu != null) { contextMenu.hide(); } }
/** * 处理鼠标移动和退出事件 * * @param event */ protected void preMouseEvent(Event event) { if (!(event instanceof MouseEvent)) return; MouseEvent me = (MouseEvent) event; if (event.getEventType() == MouseEvent.MOUSE_MOVED) { mouse = new Point((int) me.getX(), (int) me.getY()); } else if (event.getEventType() == MouseEvent.MOUSE_EXITED) { mouse = null; } }
private void mouseDragged(MouseEvent ev) { if (this.mouseDragging && this.getSelectionModel().getSelectedItem() != null) { double currentMouseX = ev.getX(); double currentMouseY = ev.getY(); double mouseMoveX = currentMouseX - this.mousePressX; double mouseMoveY = currentMouseY - this.mousePressY; // Yの移動量が一定量以下の時は、タブの順番を変えるだけ if (mouseMoveY < 30 && mouseMoveY > -30) { if (ev.getPickResult().getIntersectedNode() instanceof LabeledText) { // マウスの下にあるタブのラベルを取得 LabeledText label = (LabeledText) ev.getPickResult().getIntersectedNode(); DockableTab currentTab = (DockableTab) this.getSelectionModel().getSelectedItem(); // 自分のタブの上でない場合 if (!label.getText().equals(this.getSelectionModel().getSelectedItem().getText())) { Tab overTab; if (mouseMoveX > 0) { overTab = this.findAfterTab(label.getText(), this.getSelectionModel().getSelectedIndex()); } else { overTab = this.findBeforeTab(label.getText(), this.getSelectionModel().getSelectedIndex()); } int overTabIndex = this.getTabs().indexOf(overTab); if (overTabIndex >= 0) { this.cutTab(); this.insertTab(overTabIndex, currentTab); this.getSelectionModel().select(currentTab); this.mousePressX = ev.getX(); } } } } // ドッキングを試みる else { this.parent.startShowDockingBorder(ev); } } }
@Override public void mouseClicked(final MouseEvent e) { if (mousebutton == MouseButton.PRIMARY) { // add a coordinate final AffineTransform2D trs = map.getCanvas().getObjectiveToDisplay(); try { final AffineTransform dispToObj = trs.createInverse(); final double[] crds = new double[] {e.getX(), e.getY()}; dispToObj.transform(crds, 0, crds, 0, 1); coords.add(new Coordinate(crds[0], crds[1])); updateGeometry(); } catch (NoninvertibleTransformException ex) { Loggers.JAVAFX.log(Level.WARNING, null, ex); } } else if (mousebutton == MouseButton.SECONDARY) { // erase coordiantes coords.clear(); updateGeometry(); } }
private void kochPanelMousePressed(MouseEvent event) { startPressedX = event.getX(); startPressedY = event.getY(); lastDragX = event.getX(); lastDragY = event.getY(); }
@Override public void handle(MouseEvent event) { if (event.getEventType() == MouseEvent.MOUSE_PRESSED) { if (dockNode.isFloating() && event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY) { dockNode.setMaximized(!dockNode.isMaximized()); } else { // drag detected is used in place of mouse pressed so there is some threshold for the // dragging which is determined by the default drag detection threshold dragStart = new Point2D(event.getX(), event.getY()); } } else if (event.getEventType() == MouseEvent.DRAG_DETECTED) { if (!dockNode.isFloating()) { // if we are not using a custom title bar and the user // is not forcing the default one for floating and // the dock node does have native window decorations // then we need to offset the stage position by // the height of this title bar if (!dockNode.isCustomTitleBar() && dockNode.isDecorated()) { dockNode.setFloating(true, new Point2D(0, DockTitleBar.this.getHeight())); } else { dockNode.setFloating(true); } // TODO: Find a better solution. // Temporary work around for nodes losing the drag event when removed from // the scene graph. // A possible alternative is to use "ghost" panes in the DockPane layout // while making DockNode simply an overlay stage that is always shown. // However since flickering when popping out was already eliminated that would // be overkill and is not a suitable solution for native decorations. // Bug report open: https://bugs.openjdk.java.net/browse/JDK-8133335 DockPane dockPane = this.getDockNode().getDockPane(); if (dockPane != null) { dockPane.addEventFilter(MouseEvent.MOUSE_DRAGGED, this); dockPane.addEventFilter(MouseEvent.MOUSE_RELEASED, this); } } else if (dockNode.isMaximized()) { double ratioX = event.getX() / this.getDockNode().getWidth(); double ratioY = event.getY() / this.getDockNode().getHeight(); // Please note that setMaximized is ruined by width and height changes occurring on the // stage and there is currently a bug report filed for this though I did not give them an // accurate test case which I should and wish I would have. This was causing issues in the // original release requiring maximized behavior to be implemented manually by saving the // restored bounds. The problem was that the resize functionality in DockNode.java was // executing at the same time canceling the maximized change. // https://bugs.openjdk.java.net/browse/JDK-8133334 // restore/minimize the window after we have obtained its dimensions dockNode.setMaximized(false); // scale the drag start location by our restored dimensions dragStart = new Point2D(ratioX * dockNode.getWidth(), ratioY * dockNode.getHeight()); } dragging = true; event.consume(); } else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) { if (dockNode.isFloating() && event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY) { event.setDragDetect(false); event.consume(); return; } if (!dragging) return; Stage stage = dockNode.getStage(); Insets insetsDelta = this.getDockNode().getBorderPane().getInsets(); // dragging this way makes the interface more responsive in the event // the system is lagging as is the case with most current JavaFX // implementations on Linux stage.setX(event.getScreenX() - dragStart.getX() - insetsDelta.getLeft()); stage.setY(event.getScreenY() - dragStart.getY() - insetsDelta.getTop()); // TODO: change the pick result by adding a copyForPick() DockEvent dockEnterEvent = new DockEvent( this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_ENTER, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null); DockEvent dockOverEvent = new DockEvent( this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_OVER, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null); DockEvent dockExitEvent = new DockEvent( this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_EXIT, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null); EventTask eventTask = new EventTask() { @Override public void run(Node node, Node dragNode) { executions++; if (dragNode != node) { Event.fireEvent(node, dockEnterEvent.copyFor(DockTitleBar.this, node)); if (dragNode != null) { // fire the dock exit first so listeners // can actually keep track of the node we // are currently over and know when we // aren't over any which DOCK_OVER // does not provide Event.fireEvent(dragNode, dockExitEvent.copyFor(DockTitleBar.this, dragNode)); } dragNodes.put(node.getScene().getWindow(), node); } Event.fireEvent(node, dockOverEvent.copyFor(DockTitleBar.this, node)); } }; this.pickEventTarget( new Point2D(event.getScreenX(), event.getScreenY()), eventTask, dockExitEvent); } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) { dragging = false; DockEvent dockReleasedEvent = new DockEvent( this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_RELEASED, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode()); EventTask eventTask = new EventTask() { @Override public void run(Node node, Node dragNode) { executions++; if (dragNode != node) { Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node)); } Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node)); } }; this.pickEventTarget(new Point2D(event.getScreenX(), event.getScreenY()), eventTask, null); dragNodes.clear(); // Remove temporary event handler for bug mentioned above. DockPane dockPane = this.getDockNode().getDockPane(); if (dockPane != null) { dockPane.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this); dockPane.removeEventFilter(MouseEvent.MOUSE_RELEASED, this); } } }
private void mousePressed(MouseEvent ev) { this.mousePressX = ev.getX(); this.mousePressY = ev.getY(); this.mouseDragging = true; }
@Override public void handle(MouseEvent e) { if (e.isPrimaryButtonDown()) { // If in bounds of the map if (e.getX() > mp.mapOutline.getX() && e.getY() > mp.mapOutline.getY() && e.getX() < mp.mapOutline.getX() + mp.mapOutline.getWidth() && e.getY() < mp.mapOutline.getY() + mp.mapOutline.getHeight()) { // Get the right tile from tileSet int tileRow = 0; int tileCol = 0; int selectionIndex = mp.currentTile; while (selectionIndex > mp.numTileColumns - 1) { selectionIndex = selectionIndex - mp.numTileColumns; tileRow++; } tileCol = selectionIndex; Image image = SwingFXUtils.toFXImage(mp.tileSet[tileRow][tileCol], null); ImageView imageView = new ImageView(image); // Save the currentTile to the map // int type-casting rounds x/y down -> tile placement on the map "grid" // This overwrites any previous tile number in the map matrix int mapCol = (int) (e.getX() - mp.mapOutline.getX()) / mp.tileSize; int mapRow = (int) (e.getY() - mp.mapOutline.getY()) / mp.tileSize; mp.map[mapRow][mapCol] = mp.currentTile; // Add the selected tile to the screen double imageX = mp.mapOutline.getX() + mapCol * mp.tileSize; double imageY = mp.mapOutline.getY() + mapRow * mp.tileSize; imageView.setX(imageX); imageView.setY(imageY); imageView.setFitWidth(mp.tileSize); imageView.setFitHeight(mp.tileSize); mp.updateConstructedMap(imageView); } // End if mouse inside map // Else if mouse inside tilePane // Not working yet because tileMap can't gain focus // and MapPane loses focus upon mouse leaving /*else if (e.getY() > mp.getHeight() - mp.tileSize*mp.numTileRows){ int col = (int) e.getX()/mp.tileSize; int row = (int) e.getY()/mp.tileSize; mp.currentTile = col + row*col; mp.updateCurrentTile(); } */ } // End if mouse is left button else if (e.isSecondaryButtonDown()) { if (e.getX() > mp.mapOutline.getX() && e.getY() > mp.mapOutline.getY() && e.getX() < mp.mapOutline.getX() + mp.mapOutline.getWidth() && e.getY() < mp.mapOutline.getY() + mp.mapOutline.getHeight()) { // Get the empty image Image image = SwingFXUtils.toFXImage(mp.tileSet[0][0], null); ImageView imageView = new ImageView(image); // Save to map int mapCol = (int) (e.getX() - mp.mapOutline.getX()) / mp.tileSize; int mapRow = (int) (e.getY() - mp.mapOutline.getY()) / mp.tileSize; mp.map[mapRow][mapCol] = 0; // Add the selected tile to the screen double imageX = mp.mapOutline.getX() + mapCol * mp.tileSize; double imageY = mp.mapOutline.getY() + mapRow * mp.tileSize; imageView.setX(imageX); imageView.setY(imageY); imageView.setFitWidth(mp.tileSize); imageView.setFitHeight(mp.tileSize); mp.updateConstructedMap(imageView); } // End if mouse inside map } // End else if } // End handle
@FXML private void onCanvasMouseRelease(MouseEvent e) { System.out.println("Release\tX = " + e.getX() + "\tY = " + e.getY()); drawShape(context, startX, startY, e.getX(), e.getY()); }
@FXML private void onCanvasMouseDrag(MouseEvent e) { System.out.println(e); drawShape(tempContext, startX, startY, e.getX(), e.getY()); }
@FXML private void onCanvasMousePress(MouseEvent e) { System.out.println("Press\tX = " + e.getX() + "\tY = " + e.getY()); startX = e.getX(); startY = e.getY(); }