This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits 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 e14da0d68c Allows to specify the locale when launching the JavaFX
application. This is useful for screenshots to an international audience.
e14da0d68c is described below
commit e14da0d68c39152e0450ddaea99e19c6db427b1c
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Jun 17 17:53:40 2026 +0200
Allows to specify the locale when launching the JavaFX application.
This is useful for screenshots to an international audience.
---
.../main/org/apache/sis/gui/DataViewer.java | 29 +++++--
.../main/org/apache/sis/gui/Option.java | 96 ++++++++++++++++++++++
2 files changed, 116 insertions(+), 9 deletions(-)
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/DataViewer.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/DataViewer.java
index bfe2db2034..47d6f8d7b4 100644
--- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/DataViewer.java
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/DataViewer.java
@@ -20,6 +20,7 @@ import java.io.File;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
@@ -60,9 +61,9 @@ import org.apache.sis.util.resources.Vocabulary;
/**
- * Entry point for Apache SIS application.
+ * Entry point for Apache <abbr>SIS</abbr> application.
* Current implementation shows a {@link ResourceExplorer} on which user can
drop the files to open.
- * The content shown by this {@code Main} class may change in any future
Apache SIS version.
+ * The content shown by this {@code Main} class may change in any future
Apache <abbr>SIS</abbr> version.
*
* @author Smaniotto Enzo (GSoC)
* @author Martin Desruisseaux (Geomatys)
@@ -76,17 +77,27 @@ public class DataViewer extends Application {
private static volatile DataViewer running;
/**
- * Starts the Apache SIS application.
+ * Starts the Apache <abbr>SIS</abbr> application.
+ * The following options are accepted:
*
- * @param args ignored.
+ * <ul>
+ * <li>{@code --locale}=en|fr — the application locale.</li>
+ * </ul>
+ *
+ * @param args the command-line options.
*/
+ @SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void main(final String[] args) {
+ if (args != null && args.length != 0) {
+ final var files = new ArrayList<>(Arrays.asList(args));
+ Option.parse(files.iterator());
+ // Remaining elements are files. TODO: open them.
+ if (!files.isEmpty()) {
+ System.err.println("Unexpected argument: " + files.get(0));
+ System.exit(1);
+ }
+ }
LogHandler.register(true);
- /*
- * Following line seems necessary for enabling input method framework
- * (tested on Java 14 and JavaFX 14).
- */
- java.awt.im.InputContext.getInstance();
launch(DataViewer.class, args);
}
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/Option.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/Option.java
new file mode 100644
index 0000000000..f787142f6a
--- /dev/null
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/Option.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.gui;
+
+import java.util.Locale;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.apache.sis.util.Locales;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * All command-line options allowed by the launcher.
+ * The name used on the command-line is the lower-cases variant of the
enumeration name.
+ *
+ * <p>This is a simplified version of {@link org.apache.sis.console.Option}.
+ * More options may be ported here as needed.</p>
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ */
+enum Option {
+ /**
+ * The locale for the application.
+ *
+ * @see org.apache.sis.console.Option#LOCALE
+ */
+ LOCALE;
+
+ /**
+ * The code given to {@link System#exit(int)} when the program failed
because of a unknown option.
+ *
+ * @see org.apache.sis.console.Command#INVALID_OPTION_EXIT_CODE
+ */
+ private static final int INVALID_OPTION_EXIT_CODE = 2;
+
+ /**
+ * Parses the options and removes them from the collection backing the
iterator.
+ * After this method returned, the remaining elements in the collections
can be
+ * interpreted as files to open. This method exists the <abbr>JVM</abbr>
with an
+ * error code if an unknown option is found.
+ */
+ @SuppressWarnings("UseOfSystemOutOrSystemErr")
+ static void parse(final Iterator<String> it) {
+ while (it.hasNext()) {
+ String label = it.next().trim();
+ if (label.startsWith("--")) {
+ final Option option;
+ String value = null;
+ try {
+ final int s = label.indexOf('=');
+ if (s >= 0) {
+ value = label.substring(s+1).trim();
+ label = label.substring(0, s).trim();
+ }
+ option = valueOf(label.substring(2).toUpperCase());
+ it.remove();
+ if (value == null) {
+ value = it.next().trim();
+ it.remove();
+ }
+ } catch (IllegalArgumentException e) {
+
System.err.println(Errors.format(Errors.Keys.UnknownOption_1, label));
+ System.exit(INVALID_OPTION_EXIT_CODE);
+ throw e;
+ } catch (NoSuchElementException e) {
+
System.err.println(Errors.format(Errors.Keys.MissingValueForOption_1, label));
+ System.exit(INVALID_OPTION_EXIT_CODE);
+ throw e;
+ }
+ try {
+ switch (option) {
+ case LOCALE: Locale.setDefault(Locales.parse(value));
break;
+ }
+ } catch (RuntimeException e) {
+
System.err.println(Errors.format(Errors.Keys.IllegalOptionValue_2, label,
value));
+ System.exit(INVALID_OPTION_EXIT_CODE);
+ throw e;
+ }
+ }
+ }
+ }
+}