Java Code Examples for javafx.scene.Node#addEventFilter()
The following examples show how to use
javafx.scene.Node#addEventFilter() .
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: Account.java From DashboardFx with GNU General Public License v3.0 | 7 votes |
private void addEffect(Node node){ node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> { rotateTransition.play(); Pulse pulse = new Pulse(node.getParent()); pulse.setDelay(Duration.millis(100)); pulse.setSpeed(5); pulse.play(); node.getParent().setStyle("-icon-color : -success; -fx-border-color : -success"); }); node.focusedProperty().addListener((observable, oldValue, newValue) -> { if(!node.isFocused()) node.getParent().setStyle("-icon-color : -dark-gray; -fx-border-color : transparent"); else node.getParent().setStyle("-icon-color : -success; -fx-border-color : -success"); }); }
Example 2
Source File: login.java From DashboardFx with GNU General Public License v3.0 | 6 votes |
private void addEffect(Node node){ node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> { rotateTransition.play(); Pulse pulse = new Pulse(node.getParent()); pulse.setDelay(Duration.millis(100)); pulse.setSpeed(5); pulse.play(); node.getParent().setStyle("-icon-color : -success; -fx-border-color : -success"); }); node.focusedProperty().addListener((observable, oldValue, newValue) -> { if(!node.isFocused()) node.getParent().setStyle("-icon-color : -dark-gray; -fx-border-color : transparent"); else node.getParent().setStyle("-icon-color : -success; -fx-border-color : -success"); }); }
Example 3
Source File: IncDecSlider.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override protected Skin<?> createDefaultSkin() { final SliderSkin skin = (SliderSkin) super.createDefaultSkin(); // SliderSkin is accessible, but the more interesting // com.sun.javafx.scene.control.behavior.SliderBehavior // is not. // Work around this by locating 'track'... for (Node node : skin.getChildren()) if (node.getStyleClass().contains("track")) { // Capture mouse clicks, use to inc/dec instead of jumping there node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> handleTrackClick(node, event)); // Disable mouse drag, which by default also jumps to mouse node.setOnMouseDragged(null); break; } return skin; }
Example 4
Source File: MouseCoordinateTracker.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public void installInto(Node node) { node.addEventFilter(MouseEvent.MOUSE_MOVED, movedTracker); node.addEventFilter(MouseEvent.MOUSE_DRAGGED, draggedTracker); node.addEventFilter(MouseEvent.MOUSE_ENTERED, enteredTracker); node.addEventFilter(MouseEvent.MOUSE_EXITED, exitedTracker); }
Example 5
Source File: CheckListItemVBoxer.java From marathonv5 with Apache License 2.0 | 5 votes |
protected void setMouseListener(Node node) { node.addEventFilter(MouseEvent.MOUSE_CLICKED, (e) -> { e.consume(); if (selectedItem != null) { selectedItem.deselect(); } selectedItem = CheckListItemVBoxer.this; CheckListItemVBoxer.this.select(); }); }
Example 6
Source File: Rubberband.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Create rubber * @param event_source Node that will react to mouse click/drag/release, * where the user will be able to 'start' a rubber band selection * @param parent Parent in which rubber band is displayed * @param rubberband_handler Handler that will be invoked with the selected region * */ public Rubberband(final Node event_source, final Group parent, final RubberbandHandler rubberband_handler) { this.parent = parent; this.handler = rubberband_handler; event_source.addEventHandler(MouseEvent.MOUSE_PRESSED, this::handleStart); event_source.addEventFilter(MouseEvent.MOUSE_DRAGGED, this::handleDrag); event_source.addEventFilter(MouseEvent.MOUSE_RELEASED, this::handleStop); rect = new Rectangle(0, 0, 0, 0); rect.setArcWidth(5); rect.setArcHeight(5); rect.getStyleClass().add("rubberband"); }
Example 7
Source File: JFXNodeUtils.java From JFoenix with Apache License 2.0 | 5 votes |
public static void addPressAndHoldFilter(Node node, Duration holdTime, EventHandler<MouseEvent> handler) { Wrapper<MouseEvent> eventWrapper = new Wrapper<>(); PauseTransition holdTimer = new PauseTransition(holdTime); holdTimer.setOnFinished(event -> handler.handle(eventWrapper.content)); node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> { eventWrapper.content = event; holdTimer.playFromStart(); }); node.addEventFilter(MouseEvent.MOUSE_RELEASED, event -> holdTimer.stop()); node.addEventFilter(MouseEvent.DRAG_DETECTED, event -> holdTimer.stop()); }
Example 8
Source File: ProjectDirectoryNotSpecifiedDialog.java From paintera with GNU General Public License v2.0 | 4 votes |
public Optional<String> showDialog(final String contentText) throws ProjectDirectoryNotSpecified { if (this.defaultToTempDirectory) { return Optional.of(tmpDir()); } final StringProperty projectDirectory = new SimpleStringProperty(null); final ButtonType specifyProject = new ButtonType("Specify Project", ButtonData.OTHER); final ButtonType noProject = new ButtonType("No Project", ButtonData.OK_DONE); final Dialog<String> dialog = new Dialog<>(); dialog.setResultConverter(bt -> { return ButtonType.CANCEL.equals(bt) ? null : noProject.equals(bt) ? tmpDir() : projectDirectory.get(); }); dialog.getDialogPane().getButtonTypes().setAll(specifyProject, noProject, ButtonType.CANCEL); dialog.setTitle("Paintera"); dialog.setHeaderText("Specify Project Directory"); dialog.setContentText(contentText); final Node lookupProjectButton = dialog.getDialogPane().lookupButton(specifyProject); if (lookupProjectButton instanceof Button) { ((Button) lookupProjectButton).setTooltip(new Tooltip("Look up project directory.")); } Optional .ofNullable(dialog.getDialogPane().lookupButton(noProject)) .filter(b -> b instanceof Button) .map(b -> (Button) b) .ifPresent(b -> b.setTooltip(new Tooltip("Create temporary project in /tmp."))); Optional .ofNullable(dialog.getDialogPane().lookupButton(ButtonType.CANCEL)) .filter(b -> b instanceof Button) .map(b -> (Button) b) .ifPresent(b -> b.setTooltip(new Tooltip("Do not start Paintera."))); lookupProjectButton.addEventFilter(ActionEvent.ACTION, event -> { final DirectoryChooser chooser = new DirectoryChooser(); final Optional<String> d = Optional.ofNullable(chooser.showDialog(dialog.getDialogPane().getScene() .getWindow())).map( File::getAbsolutePath); if (d.isPresent()) { projectDirectory.set(d.get()); } else { // consume on cancel, so that parent dialog does not get closed. event.consume(); } }); dialog.setResizable(true); final Optional<String> returnVal = dialog.showAndWait(); if (!returnVal.isPresent()) { throw new ProjectDirectoryNotSpecified(); } return returnVal; }
Example 9
Source File: MyApp.java From marathonv5 with Apache License 2.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { TreeViewSample root = new TreeViewSample(); primaryStage.setScene(new Scene(root)); // primaryStage.getScene().getRoot().addEventFilter(MouseEvent.MOUSE_CLICKED, // new EventHandler<Event>() { // @Override // public void handle(Event event) { // Node source = (Node) event.getSource(); // MouseEvent me = (MouseEvent) event ; // EventTarget target = event.getTarget(); // Node hit = getTarget((Node) event.getSource(), me.getX(), me.getY()); // if(hit != target) { // System.err.println("Did not match"); // System.err.println("event-target = " + target); // System.err.println("hit-target = " + hit); // } // } // // private Node getTarget(Node source, double x, double y) { // List<Node> hits = new ArrayList(); // if(!(source instanceof Parent)) // return source; // ObservableList<Node> children = ((Parent) // source).getChildrenUnmodifiable(); // for (Node child : children) { // Bounds boundsInParent = child.getBoundsInParent(); // x -= boundsInParent.getMinX(); // y -= boundsInParent.getMinY(); // if (x < 0.0 || y < 0.0) // continue; // checkHit(child, x, y, hits); // } // return hits.size() > 0 ? hits.get(hits.size() - 1) : source; // } // // private void checkHit(Node child, double x, double y, List<Node> // hits) { // Bounds boundsInParent = child.getBoundsInParent(); // if(boundsInParent.contains(x, y)) { // hits.add(child); // if(!(child instanceof Parent)) // return ; // x -= boundsInParent.getMinX(); // y -= boundsInParent.getMinY(); // ObservableList<Node> childrenUnmodifiable = // ((Parent)child).getChildrenUnmodifiable(); // for (Node node : childrenUnmodifiable) { // checkHit(node, x, y, hits); // } // } // } // }); primaryStage.show(); Set<Node> lookupAll = root.lookupAll(".text"); System.out.println("MyApp.start(): " + lookupAll.size()); for (Node node : lookupAll) { node.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() { @Override public void handle(Event event) { MouseEvent me = (MouseEvent) event; System.out.println("Bounds: " + ((Node) me.getSource()).getBoundsInParent()); System.out.println("Source Coords: " + me.getX() + ", " + me.getY()); System.out.println("Scene Coords: " + me.getSceneX() + ", " + me.getSceneY()); System.out.println("Screen Coords: " + me.getScreenX() + ", " + me.getScreenY()); } }); } }
Example 10
Source File: Globe.java From mars-sim with GNU General Public License v3.0 | 4 votes |
protected void handleMouse(Node scene) {//, final Node root) { /* scene.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent me) { mousePosX = me.getSceneX(); mousePosY = me.getSceneY(); mouseOldX = me.getSceneX(); mouseOldY = me.getSceneY(); } }); */ scene.addEventFilter(MouseEvent.MOUSE_PRESSED, me -> { mousePosX = me.getSceneX(); mousePosY = me.getSceneY(); mouseOldX = me.getSceneX(); mouseOldY = me.getSceneY(); }); scene.addEventFilter(MouseEvent.MOUSE_DRAGGED, me -> { if (mousePosX > root.getLayoutX() && mousePosX < root.getLayoutX() + SpinningGlobe.WIDTH && mousePosY > root.getLayoutY() && mousePosY < root.getLayoutY() + SpinningGlobe.HEIGHT) { mouseOldX = mousePosX; mouseOldY = mousePosY; mousePosX = me.getSceneX(); mousePosY = me.getSceneY(); mouseDeltaX = -(mousePosX - mouseOldX); mouseDeltaY = -(mousePosY - mouseOldY); double modifier = 0.05; double modifierFactor = 3.5; if (me.isControlDown()) { modifier = 0.1; } if (me.isShiftDown()) { modifier = 10.0; } if (me.isPrimaryButtonDown()) { cameraXform.ry.setAngle(cameraXform.ry.getAngle() - mouseDeltaX * modifierFactor * modifier * 1.0); // + cameraXform.rx.setAngle(cameraXform.rx.getAngle() + mouseDeltaY * modifierFactor * modifier * 1.0); // - } else if (me.isSecondaryButtonDown()) { double z = camera.getTranslateZ(); double newZ = z + mouseDeltaX * modifierFactor * modifier; camera.setTranslateZ(newZ); } else if (me.isMiddleButtonDown()) { cameraXform2.t.setX(cameraXform2.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3); // - cameraXform2.t.setY(cameraXform2.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3); // - } } }); /* scene.setOnMouseDragged(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent me) { if (mousePosX > root.getLayoutX() && mousePosX < root.getLayoutX() + SpinningGlobe.WIDTH && mousePosY > root.getLayoutY() && mousePosY < root.getLayoutY() + SpinningGlobe.HEIGHT) { mouseOldX = mousePosX; mouseOldY = mousePosY; mousePosX = me.getSceneX(); mousePosY = me.getSceneY(); mouseDeltaX = -(mousePosX - mouseOldX); mouseDeltaY = -(mousePosY - mouseOldY); double modifier = 0.05; double modifierFactor = 3.5; if (me.isControlDown()) { modifier = 0.1; } if (me.isShiftDown()) { modifier = 10.0; } if (me.isPrimaryButtonDown()) { cameraXform.ry.setAngle(cameraXform.ry.getAngle() - mouseDeltaX * modifierFactor * modifier * 1.0); // + cameraXform.rx.setAngle(cameraXform.rx.getAngle() + mouseDeltaY * modifierFactor * modifier * 1.0); // - } else if (me.isSecondaryButtonDown()) { double z = camera.getTranslateZ(); double newZ = z + mouseDeltaX * modifierFactor * modifier; camera.setTranslateZ(newZ); } else if (me.isMiddleButtonDown()) { cameraXform2.t.setX(cameraXform2.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3); // - cameraXform2.t.setY(cameraXform2.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3); // - } } } }); */ }
Example 11
Source File: PointerEventHandler.java From jfxvnc with Apache License 2.0 | 3 votes |
public void register(Node node) { node.addEventFilter(ScrollEvent.SCROLL, scrollEventHandler); node.addEventFilter(MouseEvent.MOUSE_PRESSED, mouseEventHandler); node.addEventFilter(MouseEvent.MOUSE_MOVED, mouseEventHandler); node.addEventFilter(MouseEvent.MOUSE_DRAGGED, mouseEventHandler); node.addEventFilter(MouseEvent.MOUSE_RELEASED, mouseEventHandler); }