sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 04/04: More robust computation of space needed for showing sample values.
Date Thu, 02 Jul 2020 16:52:25 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 1792a41078b8df9a7238770f8a96298af77a6b4d
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Jul 2 16:49:50 2020 +0200

    More robust computation of space needed for showing sample values.
---
 .../org/apache/sis/gui/map/ValuesUnderCursor.java  | 26 ++++++++++------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
index f0d2e84..6d3bb4c 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
@@ -264,12 +264,16 @@ public abstract class ValuesUnderCursor {
 
         /**
          * The text to show when cursor is outside coverage area. It should contain dimension
names,
-         * for example "(SST)". A {@code null} value means that {@link #onBandSelectionChanged()}
-         * needs to be invoked.
+         * for example "(SST)". May be {@code null} if {@link #onBandSelectionChanged()}
needs to be invoked.
          */
         private String outsideText;
 
         /**
+         * {@code true} if {@link #onBandSelectionChanged()} needs to be invoked again.
+         */
+        private boolean needsBandRefresh;
+
+        /**
          * Creates a new provider of textual values for a {@link GridCoverage}.
          */
         public FromCoverage() {
@@ -409,9 +413,7 @@ public abstract class ValuesUnderCursor {
                 });
             }
             valueChoices.getItems().setAll(menuItems);
-            if (!onBandSelectionChanged()) {
-                outsideText = null;             // For forcing a new computation after canvas
is added to scene graph.
-            }
+            onBandSelectionChanged();
         }
 
         /**
@@ -466,9 +468,7 @@ public abstract class ValuesUnderCursor {
             item.setSelected(selectedBands.get(index));
             item.selectedProperty().addListener((p,o,n) -> {
                 selectedBands.set(index, n);
-                if (!onBandSelectionChanged()) {
-                    outsideText = null;                         // Will be recomputed on
next `evaluate(…)` call.
-                }
+                onBandSelectionChanged();
             });
             return item;
         }
@@ -484,7 +484,7 @@ public abstract class ValuesUnderCursor {
          */
         @Override
         public String evaluate(final DirectPosition point) {
-            if (outsideText == null && evaluator != null) {
+            if (needsBandRefresh && evaluator != null) {
                 onBandSelectionChanged();
             }
             if (point != null) {
@@ -556,14 +556,12 @@ public abstract class ValuesUnderCursor {
          * when the bands selection changed, either because of selection in contextual menu
or because
          * {@link ValuesUnderCursor} is providing data for a new coverage.
          *
-         * <p>We use {@link #outsideText} null value as a flag meaning meaning that
this method needs
+         * <p>We use {@link #needsBandRefresh} as a flag meaning meaning that this
method needs
          * to be invoked. This method invocation sometime needs to be delayed because calculation
of
          * text width may be wrong (produce 0 values) if invoked before {@link StatusBar#sampleValues}
          * label is added in the scene graph.</p>
-         *
-         * @return {@code true} on success, or {@code false} if this method should be invoked
again.
          */
-        private boolean onBandSelectionChanged() {
+        private void onBandSelectionChanged() {
             final ObservableList<MenuItem> menus = valueChoices.getItems();
             final List<SampleDimension>    bands = evaluator.getCoverage().getSampleDimensions();
             final StringBuilder            names = new StringBuilder().append('(');
@@ -607,7 +605,7 @@ public abstract class ValuesUnderCursor {
                     others.add(other.getValue());
                 }
             }
-            return prototype(text, others);
+            needsBandRefresh = !prototype(text, others);
         }
     }
 


Mime
View raw message