List of usage examples for javafx.scene.input MouseEvent MOUSE_PRESSED
EventType MOUSE_PRESSED
To view the source code for javafx.scene.input MouseEvent MOUSE_PRESSED.
Click Source Link
From source file:Main.java
public static java.awt.event.MouseEvent toAwt(final MouseEvent event) { final EventType type = event.getEventType(); if (null == type) { return null; }// w ww. ja va 2 s .com final int id; if (MouseEvent.MOUSE_MOVED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_MOVED; } else if (MouseEvent.MOUSE_DRAGGED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_DRAGGED; } else if (MouseEvent.MOUSE_CLICKED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_CLICKED; } else if (MouseEvent.MOUSE_PRESSED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_PRESSED; } else if (MouseEvent.MOUSE_RELEASED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_RELEASED; } else if (MouseEvent.MOUSE_ENTERED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_ENTERED; } else if (MouseEvent.MOUSE_EXITED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_EXITED; } else { return null; } final int button; if (event.isPrimaryButtonDown()) { button = java.awt.event.MouseEvent.BUTTON1; } else if (event.isMiddleButtonDown()) { button = java.awt.event.MouseEvent.BUTTON2; } else if (event.isSecondaryButtonDown()) { button = java.awt.event.MouseEvent.BUTTON3; } else { button = java.awt.event.MouseEvent.NOBUTTON; } final long when = -1; final int modifiers = modifiers(event); final int x = (int) event.getX(); final int y = (int) event.getY(); final int xAbs = Integer.MAX_VALUE; final int yAbs = Integer.MAX_VALUE; final int count = event.getClickCount(); boolean popup = event.isPopupTrigger(); if (MouseEvent.MOUSE_CLICKED.equals(type) && event.isMetaDown()) { // mack books use meta flag for right-clicks popup = true; } return new java.awt.event.MouseEvent(empty, id, when, modifiers, x, y, xAbs, yAbs, count, popup, button); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Text Fonts"); Group g = new Group(); Scene scene = new Scene(g, 550, 250); Arc arc = new Arc(); arc.setCenterX(50.0f);//from w w w .jav a 2 s .c om arc.setCenterY(50.0f); arc.setRadiusX(25.0f); arc.setRadiusY(25.0f); arc.setStartAngle(45.0f); arc.setLength(270.0f); arc.setType(ArcType.ROUND); arc.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { System.out.println("left"); } }); g.getChildren().add(arc); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); TextField textBox = new TextField(); textBox.setPromptText("Write here"); // Define an event filter EventHandler filter = new EventHandler<InputEvent>() { public void handle(InputEvent event) { System.out.println("Filtering out event " + event.getEventType()); event.consume();//w w w . j a va 2 s. c o m } }; // Register the same filter for two different nodes scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter); // Register the filter for another event type scene.addEventFilter(KeyEvent.KEY_PRESSED, filter); root.getChildren().add(textBox); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); TextField textBox = new TextField(); textBox.setPromptText("Write here"); // Define an event filter EventHandler filter = new EventHandler<InputEvent>() { public void handle(InputEvent event) { System.out.println("Filtering out event " + event.getEventType()); event.consume();//from w w w. j av a 2 s .c om } }; // Register the same filter for two different nodes scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter); // Register the filter for another event type scene.addEventFilter(KeyEvent.KEY_PRESSED, filter); scene.removeEventFilter(MouseEvent.MOUSE_PRESSED, filter); root.getChildren().add(textBox); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Imported Fruits"); stage.setWidth(500);/*from w w w . java 2 s . c o m*/ stage.setHeight(500); ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList( new PieChart.Data("Grapefruit", 13), new PieChart.Data("Oranges", 25), new PieChart.Data("Plums", 10), new PieChart.Data("Pears", 22), new PieChart.Data("Apples", 30)); final PieChart chart = new PieChart(pieChartData); chart.setTitle("Imported Fruits"); final Label caption = new Label(""); caption.setTextFill(Color.DARKORANGE); caption.setStyle("-fx-font: 24 arial;"); for (final PieChart.Data data : chart.getData()) { data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { caption.setTranslateX(e.getSceneX()); caption.setTranslateY(e.getSceneY()); caption.setText(String.valueOf(data.getPieValue()) + "%"); } }); } ((Group) scene.getRoot()).getChildren().addAll(chart, caption); stage.setScene(scene); //scene.getStylesheets().add("piechartsample/Chart.css"); stage.show(); }
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 ava2 s.com*/ } } }); 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:ijfx.ui.plugin.panel.OverlayPanel.java
public OverlayPanel() throws IOException { super();/*from w ww . ja va 2s. c o m*/ FXUtilities.injectFXML(this); keyColumn.setCellValueFactory(new PropertyValueFactory("name")); valueColumn.setCellValueFactory(new PropertyValueFactory("value")); tableView.setItems(entries); entries.add(new MyEntry("nothing", 0d)); overlayNameField.setPromptText(EMPTY_FIELD); overlayNameField.textProperty().addListener(this::onOverlayNameChanged); overlayProperty.addListener(this::onOverlaySelectionChanged); chartVBox.getChildren().removeAll(areaChart, lineChart); overlayOptions = new OverlayOptions(); optionsPane = new PopOver(overlayOptions); optionsPane.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP); optionsPane.setDetachable(true); optionsPane.setAutoHide(false); optionsPane.titleProperty().setValue("Overlay settings"); optionsPane.setConsumeAutoHidingEvents(false); gearIcon = GlyphsDude.createIcon(FontAwesomeIcon.GEAR, "15"); gearIcon.setOpacity(BASAL_OPACITY); gearIcon.setOnMouseEntered(e -> gearIcon.setOpacity(1.0)); gearIcon.setOnMouseExited(e -> gearIcon.setOpacity(BASAL_OPACITY)); gearIcon.addEventHandler(MouseEvent.MOUSE_CLICKED, this::onGearClicked); gearIcon.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> { e.consume(); }); gearIcon.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> { e.consume(); }); chartTitledPane.setGraphic(gearIcon); chartTitledPane.setContentDisplay(ContentDisplay.RIGHT); chartTitledPane.graphicTextGapProperty().setValue(TEXT_GAP); }
From source file:ijfx.ui.plugin.overlay.OverlayPanel.java
public OverlayPanel() throws IOException { super();//from w w w . j ava2 s . c om FXUtilities.injectFXML(this); keyColumn.setCellValueFactory(new PropertyValueFactory("name")); valueColumn.setCellValueFactory(new PropertyValueFactory("value")); tableView.setItems(entries); entries.add(new MyEntry("nothing", 0d)); overlayNameField.setPromptText(EMPTY_FIELD); overlayNameField.textProperty().addListener(this::onOverlayNameChanged); overlayProperty.addListener(this::onOverlaySelectionChanged); chartVBox.getChildren().removeAll(areaChart, lineChart); overlayOptions = new OverlayOptions(); optionsPane = new PopOver(overlayOptions); optionsPane.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP); optionsPane.setDetachable(true); optionsPane.setAutoHide(false); optionsPane.titleProperty().setValue("Overlay settings"); optionsPane.setConsumeAutoHidingEvents(false); gearIcon = GlyphsDude.createIcon(FontAwesomeIcon.GEAR, "15"); gearIcon.setOpacity(BASAL_OPACITY); gearIcon.setOnMouseEntered(e -> gearIcon.setOpacity(1.0)); gearIcon.setOnMouseExited(e -> gearIcon.setOpacity(BASAL_OPACITY)); gearIcon.addEventHandler(MouseEvent.MOUSE_CLICKED, this::onGearClicked); gearIcon.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> { e.consume(); }); gearIcon.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> { e.consume(); }); chartTitledPane.setGraphic(gearIcon); chartTitledPane.setContentDisplay(ContentDisplay.RIGHT); chartTitledPane.graphicTextGapProperty().setValue(TEXT_GAP); // channeling all the DataViewUpdatedEvent so it updates the // current selected overlay eventBus.getStream(OverlayUpdatedEvent.class) .filter(event -> event.getObject().equals(overlayProperty.getValue())) .subscribe(event -> Platform.runLater(this::updateStats)); eventBus.getStream(DataViewUpdatedEvent.class).map(event -> event.getView()) .filter(view -> view instanceof OverlayView).cast(OverlayView.class) .filter(view -> view.isSelected()).throttleWithTimeout(1000, TimeUnit.MILLISECONDS) .subscribe(overlay -> { overlayProperty.setValue(overlay.getData()); }); eventBus.getStream(DataViewUpdatedEvent.class).filter(event -> event.getView() instanceof DatasetView) .map(event -> event.getView()).cast(DatasetView.class).map(view -> { return view; }).filter(view -> currentDisplay().contains(view)).throttleWithTimeout(100, TimeUnit.MILLISECONDS) .subscribe(event -> Platform.runLater(this::updateStats)); eventBus.getStream(DisplayUpdatedEvent.class).filter(event -> event.getDisplay() instanceof ImageDisplay) .subscribe(this::checkCurrentOverlay); }
From source file:edu.kit.trufflehog.view.jung.visualization.FXVisualizationViewer.java
public FXVisualizationViewer(INetworkViewPort port) { this.port = port; // create canvas this.setStyle("-fx-background-color: #213245"); for (double divide = .25; divide < 1; divide += .25) { final Line line = new Line(0, 200, this.getWidth(), this.getHeight()); line.setFill(null);/*from w w w . ja v a 2 s . co m*/ line.setStroke(Color.web("0x385172")); line.setStrokeWidth(1.3); line.getStrokeDashArray().addAll(5d, 10d); line.startYProperty().bind(this.heightProperty().multiply(divide)); line.endXProperty().bind(this.widthProperty()); line.endYProperty().bind(this.heightProperty().multiply(divide)); this.getChildren().add(line); } for (double divide = .25; divide < 1; divide += .25) { final Line line = new Line(0, 0, this.getWidth(), this.getHeight()); line.setFill(null); line.setStroke(Color.web("0x385172")); line.setStrokeWidth(1.3); line.getStrokeDashArray().addAll(5d, 10d); line.startXProperty().bind(this.widthProperty().multiply(divide)); line.endXProperty().bind(this.widthProperty().multiply(divide)); line.endYProperty().bind(this.heightProperty()); this.getChildren().add(line); } //StackPane spane = new StackPane(); //spane.setBackground(new Background(new BackgroundFill(Color.BEIGE, null, null))); Pane ghost = new Pane(); canvas = new PannableCanvas(ghost); Pane parent = new Pane(); parent.getChildren().add(ghost); parent.getChildren().add(canvas); SceneGestures sceneGestures = new SceneGestures(parent, canvas); addEventFilter(MouseEvent.MOUSE_PRESSED, sceneGestures.getOnMousePressedEventHandler()); addEventFilter(MouseEvent.MOUSE_DRAGGED, sceneGestures.getOnMouseDraggedEventHandler()); addEventFilter(ScrollEvent.ANY, sceneGestures.getOnScrollEventHandler()); new RubberBandSelection(this); // TODO make canvas transparent //canvas.setStyle("-fx-background-color: #1d1d1d"); // we don't want the canvas on the top/left in this example => just // translate it a bit //canvas.setTranslateX(100); //canvas.setTranslateY(100); // create sample nodes which can be dragged nodeGestures = new NodeGestures(); //this.getChildren().add(spane); this.getChildren().add(parent); this.layout = port.getDelegate(); //this.layout.getGraph().getVertices().forEach(v -> Platform.runLater(() -> this.initVertex(v))); //this.layout.getGraph().getEdges().forEach(e -> Platform.runLater(() -> this.initEdge(e))); this.layout.getObservableGraph().addGraphEventListener(e -> { //Platform.runLater(() -> { switch (e.getType()) { case VERTEX_ADDED: final INode node = ((GraphEvent.Vertex<INode, IConnection>) e).getVertex(); Platform.runLater(() -> initVertex(node)); break; case EDGE_ADDED: final IConnection edge = ((GraphEvent.Edge<INode, IConnection>) e).getEdge(); Platform.runLater(() -> initEdge(edge)); break; case VERTEX_CHANGED: break; case EDGE_CHANGED: final IConnection changedEdge = ((GraphEvent.Edge<INode, IConnection>) e).getEdge(); Platform.runLater(() -> changedEdge.getComponent(ViewComponent.class).getRenderer().animate()); break; } //}); }); }
From source file:edu.kit.trufflehog.view.jung.visualization.FXVisualizationViewer.java
synchronized private void initEdge(IConnection edge) { final Pair<INode> pair = this.layout.getGraph().getEndpoints(edge); if (pair.getSecond().getAddress().isMulticast()) { // TODO check or do something with this (generify the getShape command?) final Circle destCircle = (Circle) pair.getFirst().getComponent(ViewComponent.class).getRenderer() .getShape();// w w w.j a va 2s . c o m final Shape shape = edge.getComponent(ViewComponent.class).getRenderer().getShape(); shape.layoutXProperty().bind(destCircle.layoutXProperty()); shape.layoutYProperty().bind(destCircle.layoutYProperty()); canvas.getChildren().add(shape); shape.setPickOnBounds(false); shape.setMouseTransparent(true); return; } // source and destination shape final Shape srcShape = pair.getFirst().getComponent(ViewComponent.class).getRenderer().getShape(); final Shape destShape = pair.getSecond().getComponent(ViewComponent.class).getRenderer().getShape(); // the positions of the shapes final DoubleBinding srcX = srcShape.layoutXProperty().add(srcShape.translateXProperty()); final DoubleBinding srcY = srcShape.layoutYProperty().add(srcShape.translateYProperty()); final DoubleBinding destX = destShape.layoutXProperty().add(destShape.translateXProperty()); final DoubleBinding destY = destShape.layoutYProperty().add(destShape.translateYProperty()); // the direction vector from source to destination (deltaX, deltaY) final DoubleBinding deltaX = destX.subtract(srcX); final DoubleBinding deltaY = destY.subtract(srcY); // the length of the direction vector final DoubleBinding length = MyBindings .sqrt(Bindings.add(MyBindings.pow2(deltaX), MyBindings.pow2(deltaY))); // the normalized direction vector final DoubleBinding normalX = deltaX.divide(length); final DoubleBinding normalY = deltaY.divide(length); // cast the shapes to circles (because right now i know they are circles) //TODO make this for arbitrary shapes final Circle destCircle = (Circle) destShape; final Circle srcCircle = (Circle) srcShape; // get the real source by multiplying the normal with the radius and the scale of the shape final DoubleBinding realSoureX = srcX .add(normalX.multiply(srcCircle.radiusProperty().multiply(srcShape.scaleXProperty()))); final DoubleBinding realSoureY = srcY .add(normalY.multiply(srcCircle.radiusProperty().multiply(srcShape.scaleYProperty()))); // get the real destination by multipling the normal vector with the length minus the radius and scale of the destination shape final DoubleBinding realDestX = srcX.add(normalX .multiply(length.subtract(destCircle.radiusProperty().multiply(destShape.scaleXProperty())))); final DoubleBinding realDestY = srcY.add(normalY .multiply(length.subtract(destCircle.radiusProperty().multiply(destShape.scaleYProperty())))); final IEdgeRenderer edgeRenderer = (IEdgeRenderer) edge.getComponent(ViewComponent.class).getRenderer(); edgeRenderer.getArrowShape().layoutXProperty().bind(realDestX); edgeRenderer.getArrowShape().layoutYProperty().bind(realDestY); final QuadCurve curve = edgeRenderer.getLine(); curve.setCacheHint(CacheHint.SPEED); curve.addEventFilter(MouseEvent.MOUSE_PRESSED, edgeGestures.getOnMousePressedEventHandler(edge)); curve.addEventFilter(MouseEvent.MOUSE_RELEASED, edgeGestures.getOnMouseReleasedEventHandler(edge)); edgeRenderer.getArrowShape().addEventFilter(MouseEvent.MOUSE_PRESSED, edgeGestures.getOnMousePressedEventHandler(edge)); edgeRenderer.getArrowShape().addEventFilter(MouseEvent.MOUSE_RELEASED, edgeGestures.getOnMouseReleasedEventHandler(edge)); /* // make the edge clickable curve.setOnMouseClicked(e -> { if (e.getButton() != MouseButton.PRIMARY) { return; } logger.debug(edge.getSrc().getComponent(NodeInfoComponent.class).toString() + " --[" + edge.getComponent(EdgeStatisticsComponent.class).getTraffic() + "]-->" + edge.getDest().getComponent(NodeInfoComponent.class).toString()); // edge.getComponent(ViewComponent.class).getRenderer().togglePicked(); }); edgeRenderer.getArrowShape().setOnMouseClicked(e -> { if (e.getButton() != MouseButton.PRIMARY) { return; } logger.debug(edge.getSrc().getComponent(NodeInfoComponent.class).toString() + " --[" + edge.getComponent(EdgeStatisticsComponent.class).getTraffic() + "]-->" + edge.getDest().getComponent(NodeInfoComponent.class).toString()); // edge.getComponent(ViewComponent.class).getRenderer().togglePicked(); });*/ //get the edge size binding by dividing the total traffic with the local traffic DoubleBinding edgeSize = MyBindings .divideIntToDouble(edge.getComponent(EdgeStatisticsComponent.class).getTrafficProperty(), port.getMaxConnectionSizeProperty()) .multiply(8).add(2); curve.strokeWidthProperty().bind(edgeSize.multiply(edgeRenderer.edgeWidthMultiplierProperty())); // bind the ending to the real destionaion point curve.endXProperty().bind(realDestX); curve.endYProperty().bind(realDestY); // bind the source to the real source point curve.startXProperty().bind(realSoureX); curve.startYProperty().bind(realSoureY); NumberBinding normalVectorX = Bindings.subtract(realDestY, realSoureY).negate(); NumberBinding normalVectorY = Bindings.subtract(realDestX, realSoureX); NumberBinding centerPointX = Bindings.divide(Bindings.add(curve.endXProperty(), curve.startXProperty()), 2); NumberBinding centerPointY = Bindings.divide(Bindings.add(curve.endYProperty(), curve.startYProperty()), 2); NumberBinding normalLength = MyBindings .sqrt(Bindings.add(normalVectorX.multiply(normalVectorX), normalVectorY.multiply(normalVectorY))); NumberBinding normalizedNVX = normalVectorX.divide(normalLength); NumberBinding normalizedNVY = normalVectorY.divide(normalLength); NumberBinding bezierPointOffset = length.multiply(.1); curve.controlXProperty().bind(Bindings.add(centerPointX, normalizedNVX.multiply(bezierPointOffset))); curve.controlYProperty().bind(Bindings.add(centerPointY, normalizedNVY.multiply(bezierPointOffset))); // TODO do this in component curve.setFill(null); canvas.getChildren().add(edgeRenderer.getArrowShape()); // add the edge to the canvas canvas.getChildren().add(curve); }