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 fe09604  Add an "Open URL" menu item.
fe09604 is described below

commit fe09604bbe7701d8e51d3df02518dc919a426b91
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Tue Mar 22 11:08:10 2022 +0100

    Add an "Open URL" menu item.
---
 .../main/java/org/apache/sis/gui/DataViewer.java   | 48 ++++++++++++++++++++--
 .../main/java/org/apache/sis/gui/RecentFiles.java  |  2 +-
 .../org/apache/sis/internal/gui/RecentChoices.java | 30 +++++++++++++-
 .../org/apache/sis/internal/gui/Resources.java     | 10 +++++
 .../apache/sis/internal/gui/Resources.properties   |  2 +
 .../sis/internal/gui/Resources_fr.properties       |  2 +
 6 files changed, 88 insertions(+), 6 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
index e868d6c..bc70d32 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
@@ -17,7 +17,10 @@
 package org.apache.sis.gui;
 
 import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -31,6 +34,9 @@ import javafx.scene.control.Menu;
 import javafx.scene.control.MenuBar;
 import javafx.scene.control.MenuItem;
 import javafx.scene.control.SeparatorMenuItem;
+import javafx.scene.control.TextInputDialog;
+import javafx.scene.control.DialogPane;
+import javafx.scene.control.ListView;
 import javafx.scene.input.KeyCombination;
 import javafx.scene.layout.BorderPane;
 import javafx.stage.FileChooser;
@@ -39,6 +45,7 @@ import javafx.stage.Screen;
 import javafx.stage.Stage;
 import org.apache.sis.gui.dataset.ResourceExplorer;
 import org.apache.sis.internal.gui.BackgroundThreads;
+import org.apache.sis.internal.gui.ExceptionReporter;
 import org.apache.sis.internal.gui.LogHandler;
 import org.apache.sis.internal.gui.Resources;
 import org.apache.sis.internal.gui.RecentChoices;
@@ -148,15 +155,17 @@ public class DataViewer extends Application {
         final MenuBar menus = new MenuBar();
         final Menu file = new Menu(vocabulary.getString(Vocabulary.Keys.File));
         {   // For keeping variables locale.
-            final MenuItem open, close;
+            final MenuItem open, oUrl, close;
             final Menu recentFiles = RecentFiles.create(content, localized);
             file.getItems().addAll(
-                    open  = localized.menu(Resources.Keys.Open,  (e) -> 
showOpenFileDialog()), recentFiles,
-                    close = localized.menu(Resources.Keys.Close, (e) -> 
closeSelectedFile()),
+                    open  = localized.menu(Resources.Keys.Open,    (e) -> 
showOpenFileDialog()),
+                    oUrl  = localized.menu(Resources.Keys.OpenURL, (e) -> 
showOpenURLDialog()), recentFiles,
+                    close = localized.menu(Resources.Keys.Close,   (e) -> 
closeSelectedFile()),
                     new SeparatorMenuItem(),
                     localized.menu(Resources.Keys.Exit, (e) -> 
Platform.exit()));
 
             open.setAccelerator(KeyCombination.keyCombination("Shortcut+O"));
+            oUrl.setAccelerator(KeyCombination.keyCombination("Shortcut+U"));
             close.setDisable(true);
             content.selectedResourceProperty().addListener((e,o,n) -> {
                 close.setDisable(!(n instanceof DataStore));
@@ -284,6 +293,39 @@ public class DataViewer extends Application {
     }
 
     /**
+     * Invoked when the user selects "File" ▶ "Open URL" menu.
+     */
+    private void showOpenURLDialog() {
+        final TextInputDialog  chooser = new TextInputDialog();
+        final ListView<String> recents = new ListView<>();
+        RecentChoices.getURLs(recents.getItems());
+        recents.setPrefWidth (500);
+        recents.setPrefHeight(200);
+        recents.getSelectionModel().selectedItemProperty().addListener((p,o,n) 
-> chooser.getEditor().setText(n));
+        final DialogPane pane = chooser.getDialogPane();
+        pane.setHeaderText(Resources.format(Resources.Keys.EnterURL));
+        pane.setExpandableContent(recents);
+        pane.setExpanded(true);
+        chooser.setTitle(Resources.format(Resources.Keys.OpenDataFile));
+        chooser.initOwner(window);
+        chooser.showAndWait().ifPresent((choice) -> {
+            try {
+                final URI url = new URI(choice);
+                final Set<String> save = new LinkedHashSet<>(16);
+                save.add(url.toString());
+                for (final String old : recents.getItems()) {
+                    save.add(old);
+                    if (save.size() >= RecentFiles.MAX_COUNT) break;
+                }
+                RecentChoices.setURLs(save);
+                content.loadResources(Collections.singleton(url));
+            } catch (URISyntaxException e) {
+                ExceptionReporter.canNotReadFile(content.getView(), choice, e);
+            }
+        });
+    }
+
+    /**
      * Shows system logs in a separated window.
      */
     private void showSystemLogsWindow() {
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/RecentFiles.java 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/RecentFiles.java
index 7f5b16c..2893c45 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/RecentFiles.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/RecentFiles.java
@@ -43,7 +43,7 @@ final class RecentFiles implements EventHandler<ActionEvent> {
     /**
      * Maximum number of items to show.
      */
-    private static final int MAX_COUNT = 10;
+    static final int MAX_COUNT = 10;
 
     /**
      * Menu items for each recently opened file.
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
index b151a7d..9e37d18 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/RecentChoices.java
@@ -19,6 +19,7 @@ package org.apache.sis.internal.gui;
 import java.io.File;
 import java.util.List;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.prefs.Preferences;
 import javafx.scene.control.ComboBox;
 import javafx.collections.ObservableList;
@@ -30,7 +31,7 @@ import org.apache.sis.util.collection.FrequencySortedSet;
  * Stores recent user choices, for example the last directory opened.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
@@ -61,6 +62,11 @@ public final class RecentChoices {
     private static final String FILES = "RecentFiles";
 
     /**
+     * The node where to store recently opened URLs.
+     */
+    private static final String URLS = "RecentURLs";
+
+    /**
      * The node where to store authority (usually EPSG) codes of most recently 
used coordinate reference systems.
      */
     private static final String CRS = "ReferenceSystems";
@@ -108,7 +114,7 @@ public final class RecentChoices {
     /**
      * Returns recently opened files.
      *
-     * @return recently opened files.
+     * @return recently opened files, or an empty array if none.
      */
     public static CharSequence[] getFiles() {
         return CharSequences.splitOnEOL(NODE.get(FILES, null));
@@ -125,6 +131,26 @@ public final class RecentChoices {
     }
 
     /**
+     * Returns recently opened URLs.
+     *
+     * @param  addTo  the list where to add recent URLs.
+     */
+    public static void getURLs(final Collection<String> addTo) {
+        for (CharSequence url : CharSequences.splitOnEOL(NODE.get(URLS, 
null))) {
+            addTo.add(url.toString());
+        }
+    }
+
+    /**
+     * Sets the list of recently opened URLs.
+     *
+     * @param files recently opened URLs.
+     */
+    public static void setURLs(final Collection<String> files) {
+        NODE.put(URLS, String.join(System.lineSeparator(), files));
+    }
+
+    /**
      * Returns the authority codes of most recently used reference systems.
      *
      * @return authority codes, or an empty array if none.
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
index 4bacb51..61dbcf4 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
@@ -187,6 +187,11 @@ public final class Resources extends IndexedResourceBundle 
{
         public static final short DownloadDetails_3 = 59;
 
         /**
+         * Enter the URL of the file to open.
+         */
+        public static final short EnterURL = 71;
+
+        /**
          * An error occurred at the following location:
          */
         public static final short ErrorAt = 53;
@@ -318,6 +323,11 @@ public final class Resources extends IndexedResourceBundle 
{
         public static final short OpenRecentFile = 54;
 
         /**
+         * Open URL…
+         */
+        public static final short OpenURL = 70;
+
+        /**
          * Orthographic
          */
         public static final short Orthographic = 52;
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
index 23f0bce..fb4077b 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
@@ -46,6 +46,7 @@ DisplayStart           = Display start
 DoesNotCoverAOI        = Does not cover the area of interest.
 DownloadAndInstall_1   = Download and install {0} database?
 DownloadDetails_3      = This geodetic dataset is required for the support of 
Coordinate Reference Systems defined by {0} codes. The database will use {1} Mb 
in the \u201c{2}\u201d directory.
+EnterURL               = Enter the URL of the file to open.
 ErrorDetails           = Details about error
 ErrorExportingData     = Error exporting data
 ErrorOpeningFile       = Error opening file
@@ -69,6 +70,7 @@ MainWindow             = Main window
 NewWindow              = New window
 NoFeatureTypeInfo      = No feature type information.
 Open                   = Open\u2026
+OpenURL                = Open URL\u2026
 OpenContainingFolder   = Open containing folder
 OpenDataFile           = Open data file
 OpenRecentFile         = Open recent file
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
index a31f6bc..678d1a2 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
@@ -51,6 +51,7 @@ DisplayStart           = D\u00e9but de l\u2019affichage
 DoesNotCoverAOI        = Ne couvre pas la r\u00e9gion d\u2019int\u00e9r\u00eat.
 DownloadAndInstall_1   = T\u00e9l\u00e9charger et installer la base de 
donn\u00e9es {0}?
 DownloadDetails_3      = Cette base de donn\u00e9es est n\u00e9cessaire pour 
le support des syst\u00e8mes de r\u00e9f\u00e9rences d\u00e9finis par des codes 
{0}. La base occupera {1} Mo dans le r\u00e9pertoire 
\u00ab\u202f{2}\u202f\u00bb.
+EnterURL               = Entrez l\u2019URL du fichier \u00e0 ouvrir.
 ErrorDetails           = D\u00e9tails \u00e0 propos de l\u2019erreur
 ErrorExportingData     = Erreur \u00e0 l\u2019exportation de donn\u00e9es
 ErrorOpeningFile       = Erreur \u00e0 l\u2019ouverture du fichier
@@ -74,6 +75,7 @@ MainWindow             = Fen\u00eatre principale
 NewWindow              = Nouvelle fen\u00eatre
 NoFeatureTypeInfo      = Pas d\u2019information sur le type d\u2019entit\u00e9.
 Open                   = Ouvrir\u2026
+OpenURL                = Ouvrir un URL\u2026
 OpenContainingFolder   = Ouvrir le dossier contenant
 OpenDataFile           = Ouvrir un fichier de donn\u00e9es
 OpenRecentFile         = Ouvrir un fichier r\u00e9cent

Reply via email to