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 ae63253c7fa86f311f8573d5c81708b070eab198
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Jun 20 11:03:14 2022 +0200

    Adjust cursor position in the target canvas when the map in source canvas 
moved without a change in mouse position.
---
 .../org/apache/sis/gui/map/GestureFollower.java    | 57 +++++++++++-----------
 .../org/apache/sis/portrayal/CanvasFollower.java   |  2 +
 .../apache/sis/portrayal/TransformChangeEvent.java |  2 +-
 3 files changed, 32 insertions(+), 29 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/GestureFollower.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/GestureFollower.java
index 6f4e97bd09..b5744dba25 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/GestureFollower.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/GestureFollower.java
@@ -17,6 +17,8 @@
 package org.apache.sis.gui.map;
 
 import java.awt.geom.Point2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
 import java.util.logging.Logger;
 import javafx.scene.layout.Pane;
 import javafx.scene.paint.Color;
@@ -191,16 +193,14 @@ public class GestureFollower extends CanvasFollower 
implements EventHandler<Mous
      * of {@link #cursorSourcePosition}.
      */
     private void updateCursorPosition() {
-        if (cursor.isVisible()) {
-            final MathTransform2D tr = getDisplayTransform().orElse(null);
-            if (tr != null) try {
-                final Point2D  p = tr.transform(cursorSourcePosition, 
cursorTargetPosition);
-                cursor.setTranslateX(p.getX());
-                cursor.setTranslateY(p.getY());
-            } catch (TransformException e) {
-                
Logging.recoverableException(Logger.getLogger(Modules.APPLICATION), 
GestureFollower.class, "handle", e);
-                cursor.setVisible(false);
-            }
+        final MathTransform2D tr = getDisplayTransform().orElse(null);
+        if (tr != null) try {
+            final Point2D  p = tr.transform(cursorSourcePosition, 
cursorTargetPosition);
+            cursor.setTranslateX(p.getX());
+            cursor.setTranslateY(p.getY());
+        } catch (TransformException e) {
+            
Logging.recoverableException(Logger.getLogger(Modules.APPLICATION), 
GestureFollower.class, "handle", e);
+            cursor.setVisible(false);
         }
     }
 
@@ -219,30 +219,31 @@ public class GestureFollower extends CanvasFollower 
implements EventHandler<Mous
 
     /**
      * Invoked after the source "objective to display" transform has been 
updated.
+     * This implementation adjusts the cursor position for compensating the 
relative change in mouse position.
      *
-     * @hidden
+     * <div class="note"><b>Details:</b>
+     * If the map moved in the {@linkplain #source source} canvas without a 
change of mouse cursor position
+     * (for example if the user navigates using the keyboard), then the mouse 
position changed relatively to
+     * the map, so the cursor position on the {@linkplain #target target} 
canvas needs to be updated accordingly.
+     * This is a temporary change applied until the next {@link MouseEvent} 
gives us new mouse coordinates relative
+     * to the map.</div>
      */
     @Override
     protected void transformedSource(final TransformChangeEvent event) {
         super.transformedSource(event);
-        if (event.getReason() != TransformChangeEvent.Reason.INTERIM) {
-            event.getDisplayChange2D().ifPresent((change) -> {
+        if (cursor != null) {
+            final AffineTransform change = 
event.getDisplayChange2D().orElse(null);
+            if (change == null) {
+                cursor.setVisible(false);
+            } else if (event.getReason() != 
TransformChangeEvent.Reason.INTERIM) {
                 change.transform(cursorSourcePosition, cursorSourcePosition);
-            });
-        }
-    }
-
-    /**
-     * Invoked after the target "objective to display" transform has been 
updated.
-     * This method recomputes the cursor position.
-     *
-     * @hidden
-     */
-    @Override
-    protected void transformedTarget(final TransformChangeEvent event) {
-        super.transformedTarget(event);
-        if (event.getReason() != TransformChangeEvent.Reason.INTERIM) {
-            updateCursorPosition();
+                updateCursorPosition();
+            } else try {
+                change.inverseTransform(cursorSourcePosition, 
cursorSourcePosition);
+                updateCursorPosition();
+            } catch (NoninvertibleTransformException e) {
+                cursor.setVisible(false);
+            }
         }
     }
 
diff --git 
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/CanvasFollower.java 
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/CanvasFollower.java
index a2161d7717..c8c0880d31 100644
--- 
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/CanvasFollower.java
+++ 
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/CanvasFollower.java
@@ -422,6 +422,7 @@ public class CanvasFollower implements 
PropertyChangeListener, Disposable {
 
     /**
      * Invoked after the source "objective to display" transform has been 
updated.
+     * This method is invoked automatically by {@link 
#propertyChange(PropertyChangeEvent)}.
      * The default implementation does nothing.
      * Subclasses can override if they need to transform additional data.
      *
@@ -432,6 +433,7 @@ public class CanvasFollower implements 
PropertyChangeListener, Disposable {
 
     /**
      * Invoked after the target "objective to display" transform has been 
updated.
+     * This method is invoked automatically by {@link 
#propertyChange(PropertyChangeEvent)}.
      * The default implementation does nothing.
      * Subclasses can override if they need to transform additional data.
      *
diff --git 
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/TransformChangeEvent.java
 
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/TransformChangeEvent.java
index 30aacbcf00..9c058e681d 100644
--- 
a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/TransformChangeEvent.java
+++ 
b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/TransformChangeEvent.java
@@ -116,7 +116,7 @@ public class TransformChangeEvent extends 
PropertyChangeEvent {
          * in viewing area, without change in the data themselves or in the 
map projection.
          */
         final boolean isNavigation() {
-            return ordinal() >= ASSIGNMENT.ordinal();
+            return ordinal() >= ASSIGNMENT.ordinal() && ordinal() < 
INTERIM.ordinal();
         }
     }
 

Reply via email to