List of usage examples for javafx.scene.input MouseEvent consume
public void consume()
From source file:de.pixida.logtest.designer.automaton.Graph.java
public void onMousePressed(final BaseObject baseObject, final MouseEvent event) { if (this.showConfigFrameOfObject(baseObject)) { event.consume(); }//from w w w.j a v a 2 s . c om if (baseObject instanceof BaseNode) { final BaseNode baseNode = (BaseNode) baseObject; this.dragPressedPoint = new Point2D(event.getX(), event.getY()); this.dragOriginalObjectPosition = baseNode.getPosition(); } }
From source file:Main.java
private Node makeDraggable(final Node node) { final DragContext dragContext = new DragContext(); final Group wrapGroup = new Group(node); wrapGroup.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() { public void handle(final MouseEvent mouseEvent) { if (dragModeActiveProperty.get()) { // disable mouse events for all children mouseEvent.consume(); }/*from ww w . j av a 2 s .c o m*/ } }); wrapGroup.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { public void handle(final MouseEvent mouseEvent) { if (dragModeActiveProperty.get()) { // remember initial mouse cursor coordinates // and node position dragContext.mouseAnchorX = mouseEvent.getX(); dragContext.mouseAnchorY = mouseEvent.getY(); dragContext.initialTranslateX = node.getTranslateX(); dragContext.initialTranslateY = node.getTranslateY(); } } }); wrapGroup.addEventFilter(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() { public void handle(final MouseEvent mouseEvent) { if (dragModeActiveProperty.get()) { // shift node from its initial position by delta // calculated from mouse cursor movement node.setTranslateX( dragContext.initialTranslateX + mouseEvent.getX() - dragContext.mouseAnchorX); node.setTranslateY( dragContext.initialTranslateY + mouseEvent.getY() - dragContext.mouseAnchorY); } } }); return wrapGroup; }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); root.getChildren().addAll(source, target); source.setOnDragDetected(new EventHandler<MouseEvent>() { public void handle(MouseEvent event) { /* drag was detected, start a drag-and-drop gesture*/ /* allow any transfer mode */ Dragboard db = source.startDragAndDrop(TransferMode.ANY); /* Put a string on a dragboard */ ClipboardContent content = new ClipboardContent(); content.putString(source.getText()); db.setContent(content);//from w w w .j a v a 2 s.c om event.consume(); } }); target.setOnDragOver(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data is dragged over the target */ /* accept it only if it is not dragged from the same node * and if it has a string data */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { /* allow for moving */ event.acceptTransferModes(TransferMode.MOVE); } event.consume(); } }); target.setOnDragEntered(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture entered the target */ /* show to the user that it is an actual gesture target */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { target.setFill(Color.GREEN); } event.consume(); } }); target.setOnDragExited(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* mouse moved away, remove the graphical cues */ target.setFill(Color.BLACK); event.consume(); } }); target.setOnDragDropped(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data dropped */ /* if there is a string data on dragboard, read it and use it */ Dragboard db = event.getDragboard(); boolean success = false; if (db.hasString()) { target.setText(db.getString()); success = true; } /* let the source know whether the string was successfully * transferred and used */ event.setDropCompleted(success); event.consume(); } }); source.setOnDragDone(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag and drop gesture ended */ /* if the data was successfully moved, clear it */ if (event.getTransferMode() == TransferMode.MOVE) { source.setText(""); } event.consume(); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("Hello Drag And Drop"); Group root = new Group(); Scene scene = new Scene(root, 400, 200); scene.setFill(Color.LIGHTGREEN); final Text source = new Text(50, 100, "DRAG ME"); source.setScaleX(2.0);// w ww . j a va2 s . co m source.setScaleY(2.0); final Text target = new Text(250, 100, "DROP HERE"); target.setScaleX(2.0); target.setScaleY(2.0); source.setOnDragDetected(new EventHandler<MouseEvent>() { public void handle(MouseEvent event) { /* drag was detected, start drag-and-drop gesture*/ System.out.println("onDragDetected"); /* allow any transfer mode */ Dragboard db = source.startDragAndDrop(TransferMode.ANY); /* put a string on dragboard */ ClipboardContent content = new ClipboardContent(); content.putString(source.getText()); db.setContent(content); event.consume(); } }); target.setOnDragOver(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data is dragged over the target */ System.out.println("onDragOver"); /* accept it only if it is not dragged from the same node * and if it has a string data */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { /* allow for both copying and moving, whatever user chooses */ event.acceptTransferModes(TransferMode.COPY_OR_MOVE); } event.consume(); } }); target.setOnDragEntered(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture entered the target */ System.out.println("onDragEntered"); /* show to the user that it is an actual gesture target */ if (event.getGestureSource() != target && event.getDragboard().hasString()) { target.setFill(Color.GREEN); } event.consume(); } }); target.setOnDragExited(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* mouse moved away, remove the graphical cues */ target.setFill(Color.BLACK); event.consume(); } }); target.setOnDragDropped(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* data dropped */ System.out.println("onDragDropped"); /* if there is a string data on dragboard, read it and use it */ Dragboard db = event.getDragboard(); boolean success = false; if (db.hasString()) { target.setText(db.getString()); success = true; } /* let the source know whether the string was successfully * transferred and used */ event.setDropCompleted(success); event.consume(); } }); source.setOnDragDone(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture ended */ System.out.println("onDragDone"); /* if the data was successfully moved, clear it */ if (event.getTransferMode() == TransferMode.MOVE) { source.setText(""); } event.consume(); } }); root.getChildren().add(source); root.getChildren().add(target); stage.setScene(scene); stage.show(); }
From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java
private void loadImages(File dir) { // Clear Details panel clearDetails();/*from ww w . j a v a 2s . c o m*/ currentDirectory = dir; File[] files = dir.listFiles(ImageUtil.SUPPORTED_FILENAME_FILTER); Task<Void> task = new Task<Void>() { @Override public Void call() { for (File file : files) { Path filePath = file.toPath(); if (loadOverlaysThread.isInterrupted()) { Platform.runLater(() -> overlayViewFlowPane.getChildren().clear()); break; } try { ToggleButton overlayButton = new ToggleButton(); ImageView imageViewNode = ImageUtil.getOverlayThumb(new ImageView(), filePath); overlayButton.getStyleClass().add("overlay-toggle-button"); overlayButton.setGraphic(imageViewNode); overlayButton.setUserData(file); overlayButton.setToggleGroup(overlayToggleGroup); overlayButton.addEventHandler(ActionEvent.ACTION, event -> { // No modifier keys used so add toggle group back to all buttons resetToggleGroup(); // Also set button to selected due to resetting toggle groups & no unselecting needed, makes for better interface IMO overlayButton.setSelected(true); // Update the Details panel with the last selected overlay File overlayFile = (File) overlayButton.getUserData(); updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), overlayButton.isSelected()); // Consume the event, no more logic needed event.consume(); }); overlayButton.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // Allow multiple selections if shortcutKey+left_mouse is pressed if (event.getButton().equals(MouseButton.PRIMARY) && event.isShortcutDown()) { // Update the Details panel with the last selected overlay File overlayFile = (File) overlayButton.getUserData(); updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), true); // Remove the toggle group to allow multiple toggle button selection overlayButton.setToggleGroup(null); // Select the button overlayButton.setSelected(true); // Consume the event, no more logic needed event.consume(); } } }); Platform.runLater(() -> overlayViewFlowPane.getChildren().add(overlayButton)); } catch (IOException e) { log.error("Loading image: " + filePath.getFileName(), e); } } return null; } }; loadOverlaysThread.interrupt(); executorService.execute(task); }
From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java
@FXML public void onClickTreeItem(MouseEvent event) { if (event.getClickCount() == 2) { TreeItem<TreeNode> selectedItem = this.root.getSelectionModel().getSelectedItem(); if (selectedItem != null) { if (getParentController().getAllFilesViewerController().handleClick(selectedItem.getValue())) { event.consume(); }//from www. ja v a 2s. c om } } }
From source file:de.pixida.logtest.designer.automaton.Graph.java
public void onMouseClicked(final BaseObject baseObject, final MouseEvent event) { Validate.notNull(baseObject);//from w w w .jav a 2 s .c om this.contextMenu.hide(); if (event.getButton() == MouseButton.PRIMARY) { if (this.connectorSourceNode != null) { Validate.notNull(this.connector); if (baseObject == this.currentConnectorTargetNode) { this.connector.attach(this.connectorSourceNode, this.currentConnectorTargetNode); this.connector = null; this.connectorSourceNode = null; this.currentConnectorTargetNode = null; this.handleChange(); } } event.consume(); } else if (event.getButton() == MouseButton.SECONDARY) { final ContextMenu objectContextMenu = baseObject.createContextMenu(); if (objectContextMenu != null) { Node contextMenuOwner = baseObject.getActionHandler(); if (contextMenuOwner == null) { contextMenuOwner = this.pane; } objectContextMenu.show(contextMenuOwner, event.getScreenX(), event.getScreenY()); event.consume(); } } }
From source file:ijfx.ui.plugin.overlay.OverlayPanel.java
public void onGearClicked(MouseEvent e) { if (!optionsPane.isShowing()) { RotateTransition rotate = new RotateTransition(Duration.millis(500), gearIcon); rotate.setByAngle(180);//from w w w. j a v a 2 s . c om rotate.play(); optionsPane.show(gearIcon); } else { RotateTransition rotate = new RotateTransition(Duration.millis(500), gearIcon); rotate.setByAngle(-180); rotate.play(); optionsPane.hide(); } e.consume(); }
From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java
@FXML void onTableClicked(MouseEvent event) { if (event.getClickCount() != 2) return;//www.j a va 2 s .c o m TableView tableView = ((TableView) event.getSource()); TableView.TableViewFocusModel focusModel = (TableView.TableViewFocusModel) tableView.focusModelProperty() .getValue(); TablePosition position = focusModel.getFocusedCell(); if (position.getTableColumn() == null) return; ObservableValue value = position.getTableColumn().getCellObservableValue(position.getRow()); String valueStr = value.getValue().toString(); Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setHeaderText(String.format("Value at ID:%d %s", ((LIMSData) tableView.getItems().get(position.getRow())).getId(), position.getTableColumn().getText())); if (valueStr.length() > 300) alert.setContentText(valueStr.substring(0, 300) + "..."); else alert.setContentText(valueStr); TextArea textArea = new TextArea(valueStr); textArea.setEditable(false); alert.getDialogPane().setExpandableContent(textArea); event.consume(); alert.show(); }
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
@FXML void tokenImageView_OnDragDetected(MouseEvent event) { Dragboard db = tokenImageView.startDragAndDrop(TransferMode.ANY); ClipboardContent content = new ClipboardContent(); boolean saveAsToken = false; try {/* w ww .j a v a2s . c o m*/ File tempTokenFile = fileSaveUtil.getTempFileName(saveAsToken, useFileNumberingCheckbox.isSelected(), fileNameTextField.getText(), fileNameSuffixTextField); writeTokenImage(tempTokenFile); content.putFiles(java.util.Collections.singletonList(tempTokenFile)); tempTokenFile.deleteOnExit(); } catch (Exception e) { log.error(e); } finally { content.putImage(tokenImageView.getImage()); db.setContent(content); event.consume(); } }