From e3c83fb3dffbee530cd48ef84578bde7418295cc Mon Sep 17 00:00:00 2001 From: jasondaming Date: Fri, 12 Mar 2021 14:54:44 -0600 Subject: [PATCH 1/2] creates a tooltip with the position on the field --- .../edu/wpi/first/pathweaver/FieldDisplayController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java b/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java index 92bcae0c..d0f69c18 100644 --- a/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java +++ b/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java @@ -12,6 +12,7 @@ import javafx.fxml.FXML; import javafx.scene.Group; import javafx.scene.control.TreeItem; +import javafx.scene.control.Tooltip; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; @@ -45,7 +46,8 @@ private void initialize() { field = ProjectPreferences.getInstance().getField(); Image image = field.getImage(); backgroundImage.setImage(image); - topPane.getStyleClass().add("pane"); + drawPane.setOnMouseMoved(e -> Tooltip.install(topPane, new Tooltip( + "X: " + roundToString(e.getX()) + " / Y: " + roundToString(e.getY())))); Scale scale = new Scale(); scale.xProperty().bind(Bindings.createDoubleBinding(() -> Math.min(topPane.getWidth() / image.getWidth(), topPane.getHeight() / image.getHeight()), @@ -172,4 +174,9 @@ public boolean checkBounds(double x, double y) { //Convert waypoint convention to JavaFX return drawPane.getLayoutBounds().contains(x, -y); } + + private String roundToString(Double number) { + number = Math.round(number * 100.0) / 100.0; + return String.valueOf(number); + } } From 64d882ad7c811af50da07ffd34a057eb292296c3 Mon Sep 17 00:00:00 2001 From: jasondaming Date: Thu, 25 Mar 2021 14:34:36 -0500 Subject: [PATCH 2/2] Now the tooltip is always around but it doesn't seem perfect. I am not sure if that is the update rate or if I am doing something wrong? --- .../wpi/first/pathweaver/FieldDisplayController.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java b/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java index d0f69c18..93f1e411 100644 --- a/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java +++ b/src/main/java/edu/wpi/first/pathweaver/FieldDisplayController.java @@ -21,6 +21,7 @@ import javafx.scene.input.KeyEvent; import javafx.scene.layout.Pane; import javafx.scene.transform.Scale; +import javafx.util.Duration; @SuppressWarnings("PMD.UnusedPrivateMethod") public class FieldDisplayController { @@ -46,8 +47,14 @@ private void initialize() { field = ProjectPreferences.getInstance().getField(); Image image = field.getImage(); backgroundImage.setImage(image); - drawPane.setOnMouseMoved(e -> Tooltip.install(topPane, new Tooltip( - "X: " + roundToString(e.getX()) + " / Y: " + roundToString(e.getY())))); + Tooltip tooltip = new Tooltip(); + Tooltip.install(topPane, tooltip); + tooltip.setShowDelay(Duration.seconds(0.0)); + tooltip.setHideDelay(Duration.seconds(999999.0)); + drawPane.setOnMouseMoved(e -> { + tooltip.setText("X: " + roundToString(e.getX()) + " / Y: " + roundToString(e.getY())); + tooltip.show(topPane, e.getSceneX(), e.getSceneY()); + }); Scale scale = new Scale(); scale.xProperty().bind(Bindings.createDoubleBinding(() -> Math.min(topPane.getWidth() / image.getWidth(), topPane.getHeight() / image.getHeight()),