import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.PopupWindow.AnchorLocation;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class JDK8248140TooltipDoesNotFollowParentWindowOnDragging extends Application {

  public static void main(String[] args) {

    launch(JDK8248140TooltipDoesNotFollowParentWindowOnDragging.class, args);
  }

  @Override
  public void start(Stage primaryStage) throws Exception {

    Screen screen = Screen.getPrimary();
    Rectangle2D screenBounds = screen.getVisualBounds();
    double width = screenBounds.getWidth() / 2;
    primaryStage.setWidth(width);
    double height = screenBounds.getHeight() / 2;
    primaryStage.setHeight(height);
    primaryStage.setTitle("JDK-8248140 Move this window and watch the tooltip");
    VBox root = new VBox();
    Label label = new Label(
        "IMHO a tooltip should follow the window it is attached to when that window is moved around on the screen. "
            + "This does work on MacOS but is not working on Windows what is IMHO an obvious bug of OpenJFX not "
            + "fixed for more than 3 years now! Feel free to argue that the MacOS implementation of OpenJFX is buggy, "
            + "but then also give advice how to create an additional tooltip that follows the window it is 'attached' to. "
            + "I need this to implement validation feedback and therefore cannot misuse standard tooltips as they are already "
            + "needed to give hints about the input field and should appear in a different style."
            + "The name OpenJFX implies to be an open project, but the way bugs are reported without the ability "
            + "to add comments by non-OpenJDK certified members is actively preventing collaboration! "
            + "Just look how any other OSS project is working on github and notice the big difference. "
            + "Thanks for reading and considering my words.");
    label.setWrapText(true);
    root.getChildren().add(label);
    TextField textField = new TextField();
    textField.setPromptText("Please enter some data");
    HBox.setHgrow(textField, Priority.ALWAYS);
    root.getChildren().add(textField);
    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.show();
    Tooltip tooltip = new Tooltip("I am a tooltip that should move with the window it is attached to!");
    tooltip.setAutoFix(true);
    tooltip.getStyleClass().add("validation-failure");
    tooltip.setAnchorLocation(AnchorLocation.WINDOW_TOP_RIGHT);
    tooltip.show(primaryStage, width, height);
  }

}
