sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/04: Add a few assertions and comments. Fix mouse cursor shape during drag events.
Date Wed, 13 Jan 2021 18:12:21 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 1f50f98acdc49ee5f510f1c1f2916d3c318f8401
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jan 13 15:23:44 2021 +0100

    Add a few assertions and comments. Fix mouse cursor shape during drag events.
---
 .../java/org/apache/sis/gui/map/MapCanvas.java     | 25 ++++++++++++++++------
 .../java/org/apache/sis/gui/map/MapCanvasAWT.java  |  2 ++
 2 files changed, 21 insertions(+), 6 deletions(-)

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 a787886..e1e41c7 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
@@ -22,6 +22,7 @@ import java.util.Objects;
 import java.awt.geom.AffineTransform;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import javafx.application.Platform;
 import javafx.geometry.Bounds;
 import javafx.geometry.Point2D;
 import javafx.scene.layout.Pane;
@@ -301,7 +302,7 @@ public abstract class MapCanvas extends PlanarCanvas {
         view.setOnMouseDragged(this::onDrag);
         view.setOnMouseReleased(this::onDrag);
         view.setFocusTraversable(true);
-        view.addEventFilter(KeyEvent.KEY_PRESSED, this::onKeyTyped);
+        view.addEventHandler(KeyEvent.KEY_PRESSED, this::onKeyTyped);
         /*
          * Do not set a preferred size, otherwise `repaint()` is invoked twice: once with
the preferred size
          * and once with the actual size of the parent window. Actually the `repaint()` method
appears to be
@@ -359,6 +360,13 @@ public abstract class MapCanvas extends PlanarCanvas {
     }
 
     /**
+     * Restores the cursor to its normal state after {@link Cursor#WAIT}.
+     */
+    private void restoreCursor() {
+        floatingPane.setCursor(isDragging ? Cursor.CLOSED_HAND : Cursor.CROSSHAIR);
+    }
+
+    /**
      * Translates the map in response to user event (keyboard, mouse, track pad, touch screen).
      *
      * @param  tx       horizontal translation in pixel units.
@@ -460,8 +468,8 @@ public abstract class MapCanvas extends PlanarCanvas {
         double tx = 0, ty = 0, zoom = 1, angle = 0;
         if (event.isAltDown()) {
             switch (event.getCode()) {
-                case RIGHT: case KP_RIGHT: angle = +15; break;
-                case LEFT:  case KP_LEFT:  angle = -15; break;
+                case RIGHT: case KP_RIGHT: angle = +7.5; break;
+                case LEFT:  case KP_LEFT:  angle = -7.5; break;
                 default:                   return;
             }
         } else {
@@ -820,6 +828,7 @@ public abstract class MapCanvas extends PlanarCanvas {
 
     /**
      * Returns {@code true} if content changed since the last {@link #repaint()} execution.
+     * This is used for checking if a new call to {@link #repaint()} is necessary.
      */
     final boolean contentsChanged() {
         return contentChangeCount != renderedContentStamp;
@@ -855,6 +864,7 @@ public abstract class MapCanvas extends PlanarCanvas {
      * @see #requestRepaint()
      */
     final void repaint() {
+        assert Platform.isFxApplicationThread();
         /*
          * If a rendering is already in progress, do not send a new request now.
          * Wait for current rendering to finish; a new one will be automatically
@@ -924,7 +934,7 @@ public abstract class MapCanvas extends PlanarCanvas {
                 transform.setToIdentity();
             }
         } catch (TransformException | RenderException ex) {
-            floatingPane.setCursor(Cursor.CROSSHAIR);
+            restoreCursor();
             errorOccurred(ex);
             return;
         }
@@ -943,7 +953,7 @@ public abstract class MapCanvas extends PlanarCanvas {
                     transform.getTx(),  transform.getTy()));
         }
         /*
-         * Invoke `createRenderer()` only after we finished above configuration, because
that method
+         * Invoke `createWorker(…)` only after we finished above configuration, because
that method
          * may take a snapshot of current canvas state in preparation for use in background
threads.
          */
         final Renderer context = createRenderer();
@@ -990,8 +1000,9 @@ public abstract class MapCanvas extends PlanarCanvas {
      * It may be identity if no zoom, rotation or pan gesture has been applied since last
rendering.
      */
     final void renderingCompleted(final Task<?> task) {
+        assert Platform.isFxApplicationThread();
         renderingInProgress = null;
-        floatingPane.setCursor(Cursor.CROSSHAIR);
+        restoreCursor();
         final Point2D p = changeInProgress.transform(xPanStart, yPanStart);
         xPanStart = p.getX();
         yPanStart = p.getY();
@@ -1032,6 +1043,8 @@ public abstract class MapCanvas extends PlanarCanvas {
 
     /**
      * Invoked after {@link #REPAINT_DELAY} has been elapsed for performing the real repaint
request.
+     *
+     * @see #requestRepaint()
      */
     private void paintAfterDelay() {
         renderingInProgress = null;
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 4770d0d..8495411 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
@@ -446,6 +446,8 @@ public abstract class MapCanvasAWT extends MapCanvas {
 
         /**
          * Invoked by {@link PixelBuffer#updateBuffer(Callback)} for updating the {@link
#buffer} content.
+         * This method shall be invoked in JavaFX thread. It is user responsibility to use
this more only
+         * when the image is known to be very fast to draw.
          */
         @Override
         public Rectangle2D call(final PixelBuffer<IntBuffer> wrapper) {


Mime
View raw message