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 0daa2b6ab49625fc52c15a286acf88b551ad2d8a Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sun Oct 17 21:14:06 2021 +0200 Reduce the amount of repaint events when resizing windows. --- .../main/java/org/apache/sis/gui/map/MapCanvas.java | 18 ++++++++++++++++++ .../main/java/org/apache/sis/gui/map/MapCanvasAWT.java | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java index 288bfda..f8241bb 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java @@ -358,11 +358,29 @@ public abstract class MapCanvas extends PlanarCanvas { } /** + * Returns the bounds of the content in {@link #floatingPane} coordinates, or {@code null} if unknown. + * Some subclasses may compute a larger image than the widget size for better visual transition during + * pan or zoom-out. If such margin exists, it may not be necessary to repaint the canvas on size change. + */ + Bounds getBoundsInParent() { + return null; + } + + /** * Invoked when the size of the {@linkplain #floatingPane} has changed. * This method requests a new repaint after a short wait, in order to collect more resize events. */ private void onSizeChanged() { sizeChanged = true; + final Bounds bp = getBoundsInParent(); + if (bp != null) { + if (bp.getMinX() <= 0 && bp.getMinY() <= 0 && + bp.getMaxX() >= floatingPane.getWidth() && + bp.getMaxY() >= floatingPane.getHeight()) + { + return; + } + } requestRepaint(); } 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 3fd42b7..863cbcb 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 @@ -30,6 +30,7 @@ import java.awt.image.RenderedImage; import java.awt.image.BufferedImage; import java.awt.image.VolatileImage; import javafx.application.Platform; +import javafx.geometry.Bounds; import javafx.geometry.Insets; import javafx.geometry.Rectangle2D; import javafx.scene.image.ImageView; @@ -154,6 +155,15 @@ public abstract class MapCanvasAWT extends MapCanvas { } /** + * Returns the image bounds. This is used for determining if a + * repaint is necessary after {@link MapCanvas} size changed. + */ + @Override + final Bounds getBoundsInParent() { + return image.getBoundsInParent(); + } + + /** * Clears {@link #buffer} and all support fields. */ private void clearBuffer() {