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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 12e93072e8 Initialize new window to the same interpolation and color 
ramp than the original window.
12e93072e8 is described below

commit 12e93072e8d729c60fb4336868cc699acd729cbb
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Jun 13 18:00:01 2022 +0200

    Initialize new window to the same interpolation and color ramp than the 
original window.
---
 .../apache/sis/gui/coverage/CoverageControls.java  | 37 ++++++++++++++++++++--
 .../apache/sis/gui/coverage/CoverageExplorer.java  | 12 ++++++-
 .../apache/sis/gui/coverage/CoverageStyling.java   |  8 +++++
 .../org/apache/sis/internal/gui/GUIUtilities.java  | 12 +++++++
 4 files changed, 65 insertions(+), 4 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
index 0fbfcaf717..bae6ea669e 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
@@ -24,6 +24,7 @@ import javafx.scene.layout.Region;
 import javafx.scene.layout.VBox;
 import javafx.scene.layout.Priority;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.Label;
 import javafx.scene.control.TableView;
 import javafx.scene.control.Tooltip;
@@ -33,6 +34,8 @@ import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.storage.GridCoverageResource;
 import org.apache.sis.gui.dataset.WindowHandler;
 import org.apache.sis.gui.map.MapMenu;
+import org.apache.sis.image.Interpolation;
+import org.apache.sis.internal.gui.GUIUtilities;
 import org.apache.sis.internal.gui.control.ValueColorMapper;
 import org.apache.sis.internal.gui.Styles;
 import org.apache.sis.internal.gui.Resources;
@@ -63,6 +66,21 @@ final class CoverageControls extends ViewAndControls {
      */
     private final TableView<Category> categoryTable;
 
+    /**
+     * The control used for selecting a color ramp for a given category.
+     */
+    private final CoverageStyling styling;
+
+    /**
+     * The control used for selecting a color stretching mode.
+     */
+    private final ChoiceBox<Stretching> stretching;
+
+    /**
+     * The control used for selecting the interpolation method.
+     */
+    private final ChoiceBox<Interpolation> interpolation;
+
     /**
      * The renderer of isolines.
      */
@@ -104,13 +122,15 @@ final class CoverageControls extends ViewAndControls {
              *   - Interpolation
              *   - Color stretching
              */
+            interpolation = InterpolationConverter.button(view);
+            stretching = Stretching.createButton((p,o,n) -> 
view.setStyling(n));
             final GridPane valuesControl = Styles.createControlGrid(0,
-                label(vocabulary, Vocabulary.Keys.Interpolation, 
InterpolationConverter.button(view)),
-                label(vocabulary, Vocabulary.Keys.Stretching, 
Stretching.createButton((p,o,n) -> view.setStyling(n))));
+                label(vocabulary, Vocabulary.Keys.Interpolation, 
interpolation),
+                label(vocabulary, Vocabulary.Keys.Stretching, stretching));
             /*
              * Creates a "Categories" section with the category table.
              */
-            final CoverageStyling styling = new CoverageStyling(view);
+            styling = new CoverageStyling(view);
             categoryTable = styling.createCategoryTable(resources, vocabulary);
             VBox.setVgrow(categoryTable, Priority.ALWAYS);
             /*
@@ -195,4 +215,15 @@ final class CoverageControls extends ViewAndControls {
     final void load(final ImageRequest request) {
         view.setImage(request);
     }
+
+    /**
+     * Copies the styling configuration from the given controls.
+     * This is invoked when the user click on "New window" button.
+     */
+    final void copyStyling(final CoverageControls c) {
+        styling.copyStyling(c.styling);
+        view.setCategoryColors(c.view.getCategoryColors() == null ? null : 
styling);
+        GUIUtilities.copySelection(c.stretching, stretching);
+        GUIUtilities.copySelection(c.interpolation, interpolation);
+    }
 }
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
index ae6a3ba058..03a16c0e5b 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
@@ -270,6 +270,9 @@ public class CoverageExplorer extends Widget {
         window = PrivateAccess.newWindowHandler.apply(source.window, this);
         source.getImageRequest().ifPresent(this::setCoverage);
         PrivateAccess.finishWindowHandler.accept(window);
+        if (getViewType() == View.IMAGE) {
+            getCoverageControls().copyStyling(source.getCoverageControls());
+        }
     }
 
     /**
@@ -303,7 +306,14 @@ public class CoverageExplorer extends Widget {
      * @since 1.2
      */
     public final CoverageCanvas getCanvas() {
-        return ((CoverageControls) getViewAndControls(View.IMAGE, false)).view;
+        return getCoverageControls().view;
+    }
+
+    /**
+     * Returns the controls on the canvas where the image is shown.
+     */
+    private CoverageControls getCoverageControls() {
+        return (CoverageControls) getViewAndControls(View.IMAGE, false);
     }
 
     /**
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
index 7ffdc2f703..5afcc38344 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java
@@ -85,6 +85,14 @@ final class CoverageStyling extends 
ColorColumnHandler<Category> implements Func
         fallback = Colorizer.GRAYSCALE;
     }
 
+    /**
+     * Copy styling information from the given source.
+     * This is used when the user clicks on "New window" button.
+     */
+    final void copyStyling(final CoverageStyling source) {
+        customizedColors.putAll(source.customizedColors);
+    }
+
     /**
      * Resets all colors to their default values.
      *
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/GUIUtilities.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/GUIUtilities.java
index 8e4d75ed6e..e8fb7bf958 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/GUIUtilities.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/GUIUtilities.java
@@ -25,6 +25,7 @@ import javafx.beans.value.ObservableValue;
 import javafx.collections.ObservableList;
 import javafx.scene.Node;
 import javafx.scene.Scene;
+import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.MenuItem;
 import javafx.scene.control.TreeItem;
@@ -211,6 +212,17 @@ walk:   for (final T search : path) {
         item.setValue(value);
     }
 
+    /**
+     * Sets the selected value or {@code target} to the same item than the 
selected item of {@code source}.
+     *
+     * @param <T>     type of items.
+     * @param source  the control from which to copy the selected item.
+     * @param target  the control where to set the selected item.
+     */
+    public static <T> void copySelection(final ChoiceBox<T> source, final 
ChoiceBox<T> target) {
+        
target.getSelectionModel().select(source.getSelectionModel().getSelectedItem());
+    }
+
     /**
      * Copies all elements from the given source list to the specified target 
list,
      * but with the application of insertion and removal operations only.

Reply via email to