sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/04: Add information about average value of image property.
Date Tue, 07 Jul 2020 17:47:46 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 d03785ab4fab32a5ca527940af2b01e65d2d3de3
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jul 7 16:18:10 2020 +0200

    Add information about average value of image property.
---
 .../apache/sis/internal/gui/ImageConverter.java    | 11 ++++--
 .../org/apache/sis/internal/gui/PropertyView.java  | 45 ++++++++++++++++++----
 2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java
index e9efc48..a5c58d0 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java
@@ -51,10 +51,13 @@ import org.apache.sis.math.Statistics;
  */
 final class ImageConverter extends Task<Statistics[]> {
     /**
-     * The maximal image width and height.
-     * This arbitrary value may change in any future version.
+     * The maximal image width and height, as an arbitrary value that may change in any future
version.
+     * This size should be a typical size expected for the JavaFX control showing the image.
+     * If the {@link ImageView} is larger than this size, the image will be rescaled by JavaFX.
+     * The quality is lower than if we had let the "resample" operation do its work at full
resolution,
+     * but {@link PropertyView} should be used only of overview anyway.
      */
-    private static final int MAX_SIZE = 400;
+    private static final int MAX_SIZE = 600;
 
     /**
      * The Java2D image to convert.
@@ -157,6 +160,8 @@ final class ImageConverter extends Task<Statistics[]> {
         writer.setPixels(0, 0, width, height, PixelFormat.getIntArgbPreInstance(), data,
0, width);
         data = null;
         canvas.setImage(destination);
+        canvas.setFitWidth (bounds.width);
+        canvas.setFitHeight(bounds.height);
     }
 
     /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java
index 933175b..2a2a19f 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java
@@ -31,6 +31,7 @@ import java.awt.Rectangle;
 import java.awt.image.RenderedImage;
 import javafx.beans.property.ObjectProperty;
 import javafx.concurrent.Task;
+import javafx.geometry.Insets;
 import javafx.scene.Node;
 import javafx.scene.text.Font;
 import javafx.scene.control.Label;
@@ -107,6 +108,12 @@ public final class PropertyView extends CompoundFormat<Object>
{
     private Label sampleValueRange;
 
     /**
+     * Mean value and standard deviation found in the image wrapped by {@link #imageView}.
+     * Created when first needed.
+     */
+    private Label meanValue;
+
+    /**
      * If the property is an image, bounds of currently visible region. May be {@code null}
is unknown,
      * in which case the whole image bounds is taken.
      */
@@ -282,11 +289,25 @@ public final class PropertyView extends CompoundFormat<Object>
{
             GridPane.setConstraints(imageCanvas, 0, 0, 2, 1);
             GridPane.setHgrow(imageCanvas, Priority.ALWAYS);
             GridPane.setVgrow(imageCanvas, Priority.ALWAYS);
+
             final Vocabulary vocabulary = Vocabulary.getResources(getLocale());
-            final Label label = new Label(vocabulary.getLabel(Vocabulary.Keys.ValueRange));
-            label.setLabelFor(sampleValueRange = new Label());
-            imagePane = Styles.createControlGrid(1, label);
+            final Label rangeLabel = new Label(vocabulary.getLabel(Vocabulary.Keys.ValueRange));
+            final Label meanLabel  = new Label(vocabulary.getLabel(Vocabulary.Keys.MeanValue));
+            rangeLabel.setLabelFor(sampleValueRange = new Label());
+            meanLabel .setLabelFor(meanValue = new Label());
+
+            Insets insets = new Insets(9, 0, 0, 9);
+            rangeLabel.setPadding(insets);
+            sampleValueRange.setPadding(insets);
+            insets = new Insets(3, 0, 9, 9);
+            meanLabel.setPadding(insets);
+            meanValue.setPadding(insets);
+
+            imagePane = Styles.createControlGrid(1, rangeLabel, meanLabel);
             imagePane.getChildren().add(imageCanvas);
+            imagePane.setPadding(Insets.EMPTY);
+            imagePane.setVgap(0);
+            imagePane.setHgap(0);
             imageView = node;
         }
         final ImageConverter converter = new ImageConverter(image, visibleImageBounds, node);
@@ -304,8 +325,9 @@ public final class PropertyView extends CompoundFormat<Object> {
      * Invoked when {@link #runningTask} completed its work, either successfully or with
a failure.
      */
     private void taskCompleted(final Statistics[] statistics) {
-        runningTask = null;
-        String text = null;
+        runningTask  = null;
+        String range = null;
+        String mean  = null;
         if (statistics != null && statistics.length != 0) {
             final Statistics s = statistics[0];
             final FieldPosition pos = new FieldPosition(0);
@@ -313,9 +335,18 @@ public final class PropertyView extends CompoundFormat<Object>
{
             final Format f = getFormat(Number.class);
             format(f, s.minimum(), buffer, pos); buffer.append(" … ");
             format(f, s.maximum(), buffer, pos);
-            text = buffer.toString();
+            range = buffer.toString();
+
+            buffer.setLength(0);
+            format(f, s.mean(), buffer, pos); buffer.append(" ± ");
+            format(f, s.standardDeviation(false), buffer, pos);
+
+            final Vocabulary vocabulary = Vocabulary.getResources(getLocale());
+            buffer.append(" (").append(vocabulary.getString(Vocabulary.Keys.StandardDeviation)).append(')');
+            mean = buffer.toString();
         }
-        sampleValueRange.setText(text);
+        sampleValueRange.setText(range);
+        meanValue.setText(mean);
     }
 
     /**


Mime
View raw message