Java Code Examples for javafx.scene.Node#setOnMouseEntered()

The following examples show how to use javafx.scene.Node#setOnMouseEntered() . 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: CellGestures.java    From fxgraph with Do What The F*ck You Want To Public License 6 votes vote down vote up
private static void setUpDragging(Node node, Wrapper<Point2D> mouseLocation, Cursor hoverCursor) {
	node.setOnMouseEntered(event -> {
		node.getParent().setCursor(hoverCursor);
	});
	node.setOnMouseExited(event -> {
		node.getParent().setCursor(Cursor.DEFAULT);
	});
	node.setOnDragDetected(event -> {
		node.getParent().setCursor(Cursor.CLOSED_HAND);
		mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY());
	});

	node.setOnMouseReleased(event -> {
		node.getParent().setCursor(Cursor.DEFAULT);
		mouseLocation.value = null;
	});
}
 
Example 2
Source File: Main.java    From DashboardFx with GNU General Public License v3.0 5 votes vote down vote up
private void addEvents(){
    VBox drawerContent;

    for (Node node : drawer.getChildren()) { // root
        if (node instanceof ScrollPane){

            drawerContent = (VBox) ((ScrollPane) node).getContent();

            for(Node child : drawerContent.getChildren()){
                if(child instanceof Button){
                    child.setOnMouseEntered(e -> {
                        popup.setAutoHide(true);
                        if(popup.isShowing())
                            popup.hide();
                    });
                }

                else if(child instanceof TitledPane){
                    addEvent(child);
                }
            }
        }

        else {
            // for others layouts
        }
    }
}
 
Example 3
Source File: PosGraphController.java    From Motion_Profile_Generator with MIT License 5 votes vote down vote up
private void setOnPointEvent( XYChart.Data data )
{
    Node node = data.getNode();

    node.setOnMouseEntered( event ->
    {
        node.setCursor( Cursor.HAND );
    });

    node.setOnMouseDragged( event ->
    {
        // get pixel location
        Point2D mouseSceneCoords = new Point2D( event.getSceneX(), event.getSceneY() );
        double xLocal = axisPosX.sceneToLocal( mouseSceneCoords ).getX();
        double yLocal = axisPosY.sceneToLocal( mouseSceneCoords ).getY();

        // get location in units (ft, m, in)
        double raw_x = axisPosX.getValueForDisplay( xLocal ).doubleValue();
        double raw_y = axisPosY.getValueForDisplay( yLocal ).doubleValue();

        // round location
        double rnd_x;
        double rnd_y;

        // Snap to grid
        if( vars.getUnit() == Units.FEET )
        {
            rnd_x = Mathf.round( raw_x, 0.5 );
            rnd_y = Mathf.round( raw_y, 0.5 );
        }
        else if( vars.getUnit() == Units.METERS )
        {
            rnd_x = Mathf.round( raw_x, 0.25 );
            rnd_y = Mathf.round( raw_y, 0.25 );
        }
        else // Inches
        {
            rnd_x = Mathf.round( raw_x, 6.0 );
            rnd_y = Mathf.round( raw_y, 6.0 );
        }

        if( rnd_x >= axisPosX.getLowerBound() && rnd_x <= axisPosX.getUpperBound() )
        {

            data.setXValue( rnd_x );

        }

        if( rnd_y >= axisPosY.getLowerBound() && rnd_y <= axisPosY.getUpperBound() )
        {
            data.setYValue( rnd_y );
        }
    });

    node.setOnMouseReleased( event ->
    {
        int index = Integer.parseInt( node.getId() );

        Waypoint tmp = backend.getWaypoint( index  );
        tmp.setX( (Double) data.getXValue() );
        tmp.setY( (Double) data.getYValue() );
    });
}
 
Example 4
Source File: ManageGroupsManager.java    From youtube-comment-suite with MIT License 5 votes vote down vote up
private void installDataTooltip(Tooltip tooltip, Node node, LineChart.Data<?, ?> dataPoint) {
    node.setStyle("-fx-background-color: transparent;");
    node.setOnMouseEntered(e -> node.setStyle("-fx-background-color: orangered;"));
    node.setOnMouseExited(e -> node.setStyle("-fx-background-color: transparent;"));

    Tooltip.install(node, tooltip);

    dataPoint.setNode(node);
}
 
Example 5
Source File: PopOver.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 指定されたノードへポップアップを設定します
 *
 * @param anchorNode アンカーノード
 * @param userData ユーザーデータ
 */
public void install(Node anchorNode, T userData) {
    anchorNode.setOnMouseEntered(this::setOnMouseEntered);
    anchorNode.setOnMouseMoved(this::setOnMouseMoved);
    anchorNode.setOnMouseExited(this::setOnMouseExited);
    this.userData.put(anchorNode, userData);
}
 
Example 6
Source File: EmojiSelectorController.java    From ChatRoom-JavaFX with Apache License 2.0 4 votes vote down vote up
/**
 * 创建emoji节点stackpane,并给其添加事件监听器
 * @param emoji
 * @return
 */
private Node addEmojiNodeListener(Emoji emoji) {
	// 是否需要光标设置
	Node stackPane = EmojiDisplayer.createEmojiNode(emoji, 32, 3);
	if (stackPane instanceof StackPane) {
		// 设置光标手势
		stackPane.setCursor(Cursor.HAND);
		ScaleTransition st = new ScaleTransition(Duration.millis(90), stackPane);
		// 设置提示
		Tooltip tooltip = new Tooltip(emoji.getShortname());
		Tooltip.install(stackPane, tooltip);
		// 设置光标的触发事件
		stackPane.setOnMouseEntered(e -> {
			// stackPane.setStyle("-fx-background-color: #a6a6a6;
			// -fx-background-radius: 3;");
			stackPane.setEffect(new DropShadow());
			st.setToX(1.2);
			st.setToY(1.2);
			st.playFromStart();
			if (searchTextField.getText().isEmpty())
				searchTextField.setPromptText(emoji.getShortname());
		});
		// 设置光标的离开事件
		stackPane.setOnMouseExited(e -> {
			// stackPane.setStyle("");
			stackPane.setEffect(null);
			st.setToX(1.);
			st.setToY(1.);
			st.playFromStart();
		});
		// 设置光标的点击事件
		stackPane.setOnMouseClicked(e -> {
			// 获得emoji简称
			String shortname = emoji.getShortname();
			chatController.getMessageBoxTextArea().appendText(shortname);
			// 关闭emoji选择器
			if (getLocalStage().isShowing()) {
				closeLocalStage();
			}
		});
	}
	return stackPane;
}
 
Example 7
Source File: CrewEditorFX.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Makes a stage draggable using a given node.
 * 
 * @param stage
 * @param byNode
 */
public void makeDraggable(final Stage stage, final Node byNode) {
	final Delta dragDelta = new Delta();
	byNode.setOnMousePressed(mouseEvent -> {
		// record a delta distance for the drag and drop operation.
		dragDelta.x = stage.getX() - mouseEvent.getScreenX();
		dragDelta.y = stage.getY() - mouseEvent.getScreenY();
		byNode.setCursor(Cursor.MOVE);
	});
	final BooleanProperty inDrag = new SimpleBooleanProperty(false);

	byNode.setOnMouseReleased(mouseEvent -> {
		byNode.setCursor(Cursor.HAND);

		if (inDrag.get()) {
			stage.hide();

			Timeline pause = new Timeline(new KeyFrame(Duration.millis(50), event -> {
				background.setImage(copyBackground(stage));
				layout.getChildren().set(0, background);

				scenarioConfigEditorFX.getMainMenu().setMonitor(stage);
				stage.show();

			}));
			pause.play();
		}

		inDrag.set(false);
	});
	byNode.setOnMouseDragged(mouseEvent -> {
		stage.setX(mouseEvent.getScreenX() + dragDelta.x);
		stage.setY(mouseEvent.getScreenY() + dragDelta.y);

		layout.getChildren().set(0, makeSmoke(stage));

		inDrag.set(true);
	});
	byNode.setOnMouseEntered(mouseEvent -> {
		if (!mouseEvent.isPrimaryButtonDown()) {
			byNode.setCursor(Cursor.HAND);
		}
	});
	byNode.setOnMouseExited(mouseEvent -> {
		if (!mouseEvent.isPrimaryButtonDown()) {
			byNode.setCursor(Cursor.DEFAULT);
		}
	});
}
 
Example 8
Source File: FrostyTech.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void makeDraggable(final Stage stage, final Node byNode) {
    final Delta dragDelta = new Delta();
    byNode.setOnMousePressed(mouseEvent -> {
        // record a delta distance for the drag and drop operation.
        dragDelta.x = stage.getX() - mouseEvent.getScreenX();
        dragDelta.y = stage.getY() - mouseEvent.getScreenY();
        byNode.setCursor(Cursor.MOVE);
    });
    final BooleanProperty inDrag = new SimpleBooleanProperty(false);

    byNode.setOnMouseReleased(mouseEvent -> {
        byNode.setCursor(Cursor.HAND);

        if (inDrag.get()) {
            stage.hide();

            Timeline pause = new Timeline(new KeyFrame(Duration.millis(50), event -> {
                background.setImage(copyBackground(stage));
                layout.getChildren().set(
                        0,
                        background
                );
                stage.show();
            }));
            pause.play();
        }

        inDrag.set(false);
    });
    byNode.setOnMouseDragged(mouseEvent -> {
        stage.setX(mouseEvent.getScreenX() + dragDelta.x);
        stage.setY(mouseEvent.getScreenY() + dragDelta.y);

        layout.getChildren().set(
                0,
                makeSmoke(stage)
        );

        inDrag.set(true);
    });
    byNode.setOnMouseEntered(mouseEvent -> {
        if (!mouseEvent.isPrimaryButtonDown()) {
            byNode.setCursor(Cursor.HAND);
        }
    });
    byNode.setOnMouseExited(mouseEvent -> {
        if (!mouseEvent.isPrimaryButtonDown()) {
            byNode.setCursor(Cursor.DEFAULT);
        }
    });
}
 
Example 9
Source File: PickerLabel.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setupEvents(Node node) {
    node.setOnMouseEntered(e -> node.getScene().setCursor(Cursor.HAND));
    node.setOnMouseExited(e -> node.getScene().setCursor(Cursor.DEFAULT));
}