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 941ef8aa1adbe7670f9d5ea6baae1671f219f168
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Nov 8 19:40:37 2019 +0100

    Handle small image loading in a separated class for making easier to share.
---
 .../org/apache/sis/gui/dataset/ResourceTree.java   |  2 +-
 .../apache/sis/gui/metadata/MetadataSummary.java   | 18 +++----------
 .../java/org/apache/sis/internal/gui/Styles.java   | 30 ++++++++++++++++++++++
 3 files changed, 34 insertions(+), 16 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
index 47b6167..8a03e46 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
@@ -415,7 +415,7 @@ public class ResourceTree extends TreeView<Resource> {
         }
 
         /**
-         * Invoked when a new resource need to be shown in the tree view.
+         * Invoked when a new resource needs to be shown in the tree view.
          * This method sets the text to a title that describe the resource.
          *
          * @param resource  the resource to show.
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java
index 2838eb3..a90e99d 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java
@@ -16,8 +16,6 @@
  */
 package org.apache.sis.gui.metadata;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.text.DateFormat;
 import java.text.NumberFormat;
 import java.util.Collection;
@@ -40,16 +38,15 @@ import javafx.scene.layout.VBox;
 import org.opengis.metadata.Metadata;
 import org.opengis.util.ControlledVocabulary;
 import org.opengis.util.InternationalString;
-import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.gui.BackgroundThreads;
 import org.apache.sis.internal.gui.ExceptionReporter;
 import org.apache.sis.internal.gui.Resources;
+import org.apache.sis.internal.gui.Styles;
 import org.apache.sis.internal.util.Strings;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.Resource;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.iso.Types;
-import org.apache.sis.util.logging.Logging;
 
 
 /**
@@ -315,17 +312,8 @@ public class MetadataSummary {
     static Image getWorldMap() {
         assert Platform.isFxApplicationThread();
         if (!worldMapLoaded) {
-            worldMapLoaded = true;                  // Set now for avoiding 
retries in case of failure.
-            Exception error;
-            try (InputStream in = 
MetadataSummary.class.getResourceAsStream("WorldMap360x180.png")) {
-                worldMap = new Image(in);
-                error = worldMap.getException();
-            } catch (IOException e) {
-                error = e;
-            }
-            if (error != null) {
-                
Logging.unexpectedException(Logging.getLogger(Modules.APPLICATION), 
MetadataSummary.class, "getWorldMap", error);
-            }
+            worldMapLoaded = true;              // Set now for avoiding 
retries in case of failure.
+            worldMap = Styles.loadIcon(MetadataSummary.class, "getWorldMap", 
"WorldMap360x180.png");
         }
         return worldMap;
     }
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
index 4ac30ec..18a2770 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
@@ -16,7 +16,12 @@
  */
 package org.apache.sis.internal.gui;
 
+import java.io.IOException;
+import java.io.InputStream;
 import javafx.scene.paint.Color;
+import javafx.scene.image.Image;
+import org.apache.sis.util.logging.Logging;
+import org.apache.sis.internal.system.Modules;
 
 
 /**
@@ -55,4 +60,29 @@ public final class Styles {
      */
     private Styles() {
     }
+
+    /**
+     * Loads an image of the given name.
+     * This method should be used only for relatively small images.
+     *
+     * @param  caller  class to use for fetching resource. Also used for 
logging.
+     * @param  method  the method invoking this method. Used only in case of 
logging.
+     * @param  file    filename of the image to load.
+     * @return the image, or {@code null} if the operation failed.
+     */
+    public static Image loadIcon(final Class<?> caller, final String method, 
final String file) {
+        Image image;
+        Exception error;
+        try (InputStream in = caller.getResourceAsStream(file)) {
+            image = new Image(in);
+            error = image.getException();
+        } catch (IOException e) {
+            image = null;
+            error = e;
+        }
+        if (error != null) {
+            
Logging.unexpectedException(Logging.getLogger(Modules.APPLICATION), caller, 
method, error);
+        }
+        return image;
+    }
 }

Reply via email to