From 48f8cafae0281005ce794cea304bd01eb1e104db Mon Sep 17 00:00:00 2001 From: Sylvain Bertrand Date: Tue, 11 Jul 2023 18:21:10 -0500 Subject: [PATCH] Trying to fix SceneBuilder. --- .../java/com/jfoenix/controls/JFXTooltip.java | 4 +- .../com/jfoenix/skins/JFXProgressBarSkin.java | 3 +- .../com/jfoenix/skins/JFXSpinnerSkin.java | 44 +++++++++++++++---- .../com/jfoenix/utils/JFXHighlighter.java | 3 +- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/jfoenix/src/main/java/com/jfoenix/controls/JFXTooltip.java b/jfoenix/src/main/java/com/jfoenix/controls/JFXTooltip.java index ff94cd21..85882cd8 100644 --- a/jfoenix/src/main/java/com/jfoenix/controls/JFXTooltip.java +++ b/jfoenix/src/main/java/com/jfoenix/controls/JFXTooltip.java @@ -23,7 +23,6 @@ import com.jfoenix.transitions.JFXKeyFrame; import com.jfoenix.transitions.JFXKeyValue; import com.sun.javafx.event.EventHandlerManager; -import com.sun.javafx.scene.NodeHelper; import javafx.animation.KeyFrame; import javafx.animation.Timeline; @@ -619,8 +618,7 @@ private void ensureHoveredNodeIsVisible(Runnable visibleRunnable) final Window owner = getWindow(hoveredNode); if (owner != null && owner.isShowing()) { - final boolean treeVisible = NodeHelper.isTreeVisible(hoveredNode); - if (treeVisible) + if (hoveredNode.isVisible()) { visibleRunnable.run(); } diff --git a/jfoenix/src/main/java/com/jfoenix/skins/JFXProgressBarSkin.java b/jfoenix/src/main/java/com/jfoenix/skins/JFXProgressBarSkin.java index b0e8f5c1..e3380f5f 100644 --- a/jfoenix/src/main/java/com/jfoenix/skins/JFXProgressBarSkin.java +++ b/jfoenix/src/main/java/com/jfoenix/skins/JFXProgressBarSkin.java @@ -21,7 +21,6 @@ import com.jfoenix.controls.JFXProgressBar; import com.jfoenix.utils.JFXNodeUtils; -import com.sun.javafx.scene.NodeHelper; import javafx.animation.Animation; import javafx.animation.Interpolator; @@ -144,7 +143,7 @@ protected void layoutChildren(double x, double y, double w, double h) if (getSkinnable().isIndeterminate()) { createIndeterminateTimeline(); - if (NodeHelper.isTreeShowing(getSkinnable())) + if (getSkinnable().isVisible() && getSkinnable().getScene() != null) { indeterminateTransition.play(); } diff --git a/jfoenix/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java b/jfoenix/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java index 9c4f98f4..f8923c18 100644 --- a/jfoenix/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java +++ b/jfoenix/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java @@ -20,13 +20,14 @@ package com.jfoenix.skins; import com.jfoenix.controls.JFXSpinner; -import com.sun.javafx.scene.NodeHelper; import javafx.animation.Interpolator; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; +import javafx.beans.binding.Bindings; import javafx.scene.Group; +import javafx.scene.Node; import javafx.scene.control.ProgressIndicator; import javafx.scene.control.SkinBase; import javafx.scene.layout.Region; @@ -94,6 +95,7 @@ public JFXSpinnerSkin(JFXSpinner control) fillRect = new Rectangle(); fillRect.setFill(Color.TRANSPARENT); text = new Text(); + text.setStyle("-fx-font-size:null"); text.getStyleClass().setAll("text", "percentage"); final Group group = new Group(fillRect, track, arc, text); group.setManaged(false); @@ -104,7 +106,7 @@ public JFXSpinnerSkin(JFXSpinner control) // register listeners registerChangeListener(control.indeterminateProperty(), obs -> initialize()); registerChangeListener(control.progressProperty(), obs -> updateProgress()); - // registerChangeListener(NodeHelper.treeShowingProperty(control), obs -> updateAnimation()); + registerChangeListener(Bindings.selectBoolean(control.sceneProperty(), "window", "showing"), obs -> updateAnimation()); registerChangeListener(control.sceneProperty(), obs -> updateAnimation()); } @@ -115,7 +117,7 @@ private void initialize() if (timeline == null) { createTransition(); - if (NodeHelper.isTreeShowing(getSkinnable())) + if (isShowing(getSkinnable())) { timeline.play(); } @@ -170,7 +172,8 @@ private void pauseTimeline(boolean pause) private void updateAnimation() { ProgressIndicator control = getSkinnable(); - final boolean isTreeShowing = NodeHelper.isTreeShowing(control) && control.getScene() != null; + final boolean isTreeShowing = isShowing(control); + if (timeline != null) { pauseTimeline(!isTreeShowing); @@ -181,6 +184,17 @@ else if (isTreeShowing) } } + // TODO Not sure if Node.isVisible() actually accounts for a parent not visible + private boolean isShowing(Node control) + { + return control.isVisible() && control.getScene() != null; + } + + private double computeSize() + { + return control.getRadius() * 2 + arc.getStrokeWidth() * 2; + } + @Override protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { @@ -190,7 +204,7 @@ protected double computeMaxHeight(double width, double topInset, double rightIns } else { - return control.getRadius() * 2 + arc.getStrokeWidth() * 2; + return computeSize(); } } @@ -203,20 +217,34 @@ protected double computeMaxWidth(double height, double topInset, double rightIns } else { - return control.getRadius() * 2 + arc.getStrokeWidth() * 2; + return computeSize(); } } @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { - return arcPane.prefWidth(-1); + if (Region.USE_COMPUTED_SIZE == control.getRadius()) + { + return arcPane.prefWidth(-1); + } + else + { + return computeSize(); + } } @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { - return arcPane.prefHeight(-1); + if (Region.USE_COMPUTED_SIZE == control.getRadius()) + { + return arcPane.prefHeight(-1); + } + else + { + return computeSize(); + } } /** diff --git a/jfoenix/src/main/java/com/jfoenix/utils/JFXHighlighter.java b/jfoenix/src/main/java/com/jfoenix/utils/JFXHighlighter.java index 7c516adb..4d3f3618 100644 --- a/jfoenix/src/main/java/com/jfoenix/utils/JFXHighlighter.java +++ b/jfoenix/src/main/java/com/jfoenix/utils/JFXHighlighter.java @@ -30,7 +30,6 @@ import java.util.Set; import com.sun.javafx.geom.RectBounds; -import com.sun.javafx.scene.NodeHelper; import com.sun.javafx.scene.text.TextLayout; import com.sun.javafx.scene.text.TextLine; @@ -106,7 +105,7 @@ public synchronized void highlight(Parent pane, String query) { Text text = ((Text) node); final int beginIndex = text.getText().toLowerCase().indexOf(query.toLowerCase()); - if (beginIndex > -1 && NodeHelper.isTreeVisible(node)) + if (beginIndex > -1 && node.isVisible() && node.getScene() != null) { ArrayList boundingBoxes = getMatchingBounds(query, text); ArrayList rectangles = new ArrayList<>();