sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Allow `imageMargin` to be null if there is no margin to apply.
Date Wed, 13 Jan 2021 23:27:43 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 2041caf2153d01b36496d0a78129e0176252821e
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jan 13 20:24:50 2021 +0100

    Allow `imageMargin` to be null if there is no margin to apply.
---
 .../apache/sis/gui/coverage/CoverageCanvas.java    | 11 ++++++----
 .../java/org/apache/sis/gui/map/MapCanvasAWT.java  | 25 ++++++++++++----------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
index 8210001..46f4b08 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
@@ -211,6 +211,7 @@ public class CoverageCanvas extends MapCanvasAWT {
         coverageProperty     .addListener((p,o,n) -> onImageSpecified());
         sliceExtentProperty  .addListener((p,o,n) -> onImageSpecified());
         interpolationProperty.addListener((p,o,n) -> onInterpolationSpecified(n));
+        imageMargin.set(new Insets(64));
     }
 
     /**
@@ -596,10 +597,12 @@ public class CoverageCanvas extends MapCanvasAWT {
                 resampledImage = canvas.resampledImage;
             }
             final Insets margin = canvas.imageMargin.get();
-            displayBounds.x      -= margin.getLeft();
-            displayBounds.width  += margin.getLeft() + margin.getRight();
-            displayBounds.y      -= margin.getTop();
-            displayBounds.height += margin.getTop() + margin.getBottom();
+            if (margin != null) {
+                displayBounds.x      -= margin.getLeft();
+                displayBounds.width  += margin.getLeft() + margin.getRight();
+                displayBounds.y      -= margin.getTop();
+                displayBounds.height += margin.getTop() + margin.getBottom();
+            }
             if (canvas.isolines != null) {
                 isolines = canvas.isolines.prepare();
             }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java
index 13f73ed..1553a93 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java
@@ -34,9 +34,9 @@ import javafx.scene.image.PixelBuffer;
 import javafx.scene.image.PixelFormat;
 import javafx.scene.image.WritableImage;
 import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleObjectProperty;
 import javafx.concurrent.Task;
 import javafx.util.Callback;
-import org.apache.sis.internal.gui.NonNullObjectProperty;
 import org.apache.sis.internal.coverage.j2d.ColorModelFactory;
 
 
@@ -65,8 +65,7 @@ public abstract class MapCanvasAWT extends MapCanvas {
     /**
      * Number of additional pixels to paint on each sides of the image, outside the viewing
area.
      * Computing a larger image reduces the black borders that user sees during translations
or
-     * during zoom out before the new image is repainted.
-     * This property value can not be null but can be {@link Insets#EMPTY}.
+     * during zoom out before the new image is repainted. The default value is {@code null}.
      */
     public final ObjectProperty<Insets> imageMargin;
 
@@ -129,7 +128,7 @@ public abstract class MapCanvasAWT extends MapCanvas {
      */
     public MapCanvasAWT(final Locale locale) {
         super(locale);
-        imageMargin = new NonNullObjectProperty<>(this, "imageMargin", new Insets(128));
+        imageMargin = new SimpleObjectProperty<>(this, "imageMargin");
         image = new ImageView();
         image.setPreserveRatio(true);
         floatingPane.getChildren().add(image);
@@ -215,13 +214,17 @@ public abstract class MapCanvasAWT extends MapCanvas {
          * @param  buffer  value of {@link #buffer}.
          */
         private boolean isValid(final Insets margin, final BufferedImage buffer) {
-            final int right, bottom;
-            top    = clamp(margin.getTop());
-            right  = clamp(margin.getRight());
-            bottom = clamp(margin.getBottom());
-            left   = clamp(margin.getLeft());
-            width  = Math.addExact(getWidth(), left + right);
-            height = Math.addExact(getHeight(), top + bottom);
+            width  = getWidth();
+            height = getHeight();
+            if (margin != null) {
+                final int right, bottom;
+                top    = clamp(margin.getTop());
+                right  = clamp(margin.getRight());
+                bottom = clamp(margin.getBottom());
+                left   = clamp(margin.getLeft());
+                width  = Math.addExact(width, left + right);
+                height = Math.addExact(height, top + bottom);
+            }
             return (buffer != null)
                     && buffer.getWidth()  == width
                     && buffer.getHeight() == height;


Mime
View raw message