@FXML void onMouseClickGameStatus(MouseEvent mouseEvent) { GameStatus gameStatus = playerInfoBean.getGameStatus(); if (gameStatus == GameStatus.NONE) { return; } if (mouseEvent.getButton() == MouseButton.PRIMARY && mouseEvent.getClickCount() == 2) { int uid = playerInfoBean.getGameUid(); if (gameStatus == GameStatus.LOBBY || gameStatus == GameStatus.HOST) { GameInfoBean gameInfoBean = gameService.getByUid(uid); gamesController.onJoinGame( gameInfoBean, null, mouseEvent.getScreenX(), mouseEvent.getScreenY()); } else if (gameStatus == GameStatus.PLAYING) { try { replayService.runLiveReplay(uid, playerInfoBean.getUsername()); } catch (IOException e) { notificationService.addNotification( new ImmediateNotification( i18n.get("errorTitle"), i18n.get("replayCouldNotBeStarted.text"), Severity.ERROR, e, singletonList(new ReportAction(i18n, reportingService, e)))); } } } }
@Override public void handle(MouseEvent event) { EventType<? extends MouseEvent> eventType = event.getEventType(); if (eventType.equals(MouseEvent.MOUSE_CLICKED)) { if (openMenu != null) disposeOpenMenu(); MenuItem hmi = new MenuItem("Help"); hmi.setOnAction(e -> DialogService.openHelpDialog()); PhongMaterial m = new PhongMaterial(); m.setDiffuseColor(Color.GREEN); m.setSpecularColor(Color.WHITE); Box box = new Box(10, 10, 10); box.setMaterial(m); box.getTransforms().addAll(new Rotate(45, Rotate.Z_AXIS), new Rotate(45, Rotate.X_AXIS)); MenuItem imi = new MenuItem("Inspect", new ImageView(Resources.SEARCH_ICON)); imi.setOnAction( e -> { DialogService.openInspectDialog(node); }); MenuItem emi = new MenuItem("Expand / Collapse", box); emi.setOnAction( e -> { handlePrimaryClick(); }); openMenu = new ContextMenu(); openMenu.getItems().addAll(emi, imi, new SeparatorMenuItem(), hmi); openMenu.show(shape, event.getScreenX(), event.getScreenY()); } else if (eventType.equals(MouseEvent.MOUSE_ENTERED)) { manager.submitTask(() -> manager.findReferingNodes(node, true)); } else if (eventType.equals(MouseEvent.MOUSE_EXITED)) { manager.submitTask(() -> manager.findReferingNodes(node, false)); } }
@Override public void handle(final MouseEvent mouseEvent) { final EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType(); final Scene scene = this.stage.getScene(); final double mouseEventX = mouseEvent.getSceneX(), mouseEventY = mouseEvent.getSceneY(), sceneWidth = scene.getWidth(), sceneHeight = scene.getHeight(); if (MouseEvent.MOUSE_MOVED.equals(mouseEventType) == true) { if (mouseEventX < this.border && mouseEventY < this.border) { this.cursorEvent = Cursor.NW_RESIZE; } else if (mouseEventX < this.border && mouseEventY > sceneHeight - this.border) { this.cursorEvent = Cursor.SW_RESIZE; } else if (mouseEventX > sceneWidth - this.border && mouseEventY < this.border) { this.cursorEvent = Cursor.NE_RESIZE; } else if (mouseEventX > sceneWidth - this.border && mouseEventY > sceneHeight - this.border) { this.cursorEvent = Cursor.SE_RESIZE; } else if (mouseEventX < this.border) { this.cursorEvent = Cursor.W_RESIZE; } else if (mouseEventX > sceneWidth - this.border) { this.cursorEvent = Cursor.E_RESIZE; } else if (mouseEventY < this.border) { this.cursorEvent = Cursor.N_RESIZE; } else if (mouseEventY > sceneHeight - this.border) { this.cursorEvent = Cursor.S_RESIZE; } else { this.cursorEvent = Cursor.DEFAULT; } scene.setCursor(this.cursorEvent); } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType) == true) { this.startX = this.stage.getWidth() - mouseEventX; this.startY = this.stage.getHeight() - mouseEventY; } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType) == true) { this.resizing = false; if (Cursor.DEFAULT.equals(this.cursorEvent) == false) { if (Cursor.W_RESIZE.equals(this.cursorEvent) == false && Cursor.E_RESIZE.equals(this.cursorEvent) == false) { final double minHeight = this.stage.getMinHeight() > (this.border * 2) ? this.stage.getMinHeight() : (this.border * 2); if (Cursor.NW_RESIZE.equals(this.cursorEvent) == true || Cursor.N_RESIZE.equals(this.cursorEvent) == true || Cursor.NE_RESIZE.equals(this.cursorEvent) == true) { if (this.stage.getHeight() > minHeight || mouseEventY < 0) { this.resizing = true; this.stage.setHeight( this.stage.getY() - mouseEvent.getScreenY() + this.stage.getHeight()); this.stage.setY(mouseEvent.getScreenY()); } } else { if (this.stage.getHeight() > minHeight || mouseEventY + this.startY - this.stage.getHeight() > 0) { this.resizing = true; this.stage.setHeight(mouseEventY + this.startY); } } } if (Cursor.N_RESIZE.equals(this.cursorEvent) == false && Cursor.S_RESIZE.equals(this.cursorEvent) == false) { final double minWidth = this.stage.getMinWidth() > (this.border * 2) ? this.stage.getMinWidth() : (this.border * 2); if (Cursor.NW_RESIZE.equals(this.cursorEvent) == true || Cursor.W_RESIZE.equals(this.cursorEvent) == true || Cursor.SW_RESIZE.equals(this.cursorEvent) == true) { if (this.stage.getWidth() > minWidth || mouseEventX < 0) { this.resizing = true; this.stage.setWidth( this.stage.getX() - mouseEvent.getScreenX() + this.stage.getWidth()); this.stage.setX(mouseEvent.getScreenX()); } } else { if (this.stage.getWidth() > minWidth || mouseEventX + this.startX - this.stage.getWidth() > 0) { this.resizing = true; this.stage.setWidth(mouseEventX + this.startX); } } } } } }
/** * Drag to drag window * * @param event */ public void handleAppMouseDrag(MouseEvent event) { if (!OnlineQuizzingApp.getInstance().getStage().isFullScreen()) { OnlineQuizzingApp.getInstance().getStage().setX(event.getScreenX() - xOffset); OnlineQuizzingApp.getInstance().getStage().setY(event.getScreenY() - yOffset); } }
@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); } } }
void showContextMenu(MouseEvent e) { if (MouseButton.SECONDARY != e.getButton()) { return; } getContextMenu().show(canvas, e.getScreenX(), e.getScreenY()); }