Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module-info descriptors and ResourcesProvider #720

Merged
merged 11 commits into from
Sep 27, 2024
2 changes: 1 addition & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<properties>
<main.class.name>com.oracle.javafx.scenebuilder.app.SceneBuilderApp</main.class.name>
<main.class.name>com.gluonhq.scenebuilder.app/com.oracle.javafx.scenebuilder.app.SceneBuilderApp</main.class.name>
<!-- For about.properties file -->
<buildDate>${maven.build.timestamp}</buildDate>
<buildDateFormat>${maven.build.timestamp.format}</buildDateFormat>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -33,14 +34,11 @@

import java.text.MessageFormat;
import java.util.ResourceBundle;
import com.oracle.javafx.scenebuilder.kit.i18n.I18NControl;

public class I18N {

private static ResourceBundle bundle;

private static ResourceBundle.Control utf8EncodingControl = new I18NControl();

public static String getString(String key) {
return getBundle().getString(key);
}
Expand All @@ -53,7 +51,7 @@ public static String getString(String key, Object... arguments) {
public static synchronized ResourceBundle getBundle() {
if (bundle == null) {
final String packageName = I18N.class.getPackage().getName();
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderApp",utf8EncodingControl); //NOI18N
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderApp"); //NOI18N
}

return bundle;
Expand Down
58 changes: 58 additions & 0 deletions app/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle Corporation and Gluon nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

module com.gluonhq.scenebuilder.app {
requires javafx.web;
requires javafx.fxml;
requires javafx.media;
requires javafx.swing;
requires com.gluonhq.scenebuilder.kit;
Oliver-Loeffler marked this conversation as resolved.
Show resolved Hide resolved
requires java.logging;
requires java.prefs;
requires javax.json.api;

opens com.oracle.javafx.scenebuilder.app to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.about to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.i18n to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.menubar to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.message to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.preferences to javafx.fxml;
Oliver-Loeffler marked this conversation as resolved.
Show resolved Hide resolved
opens com.oracle.javafx.scenebuilder.app.registration to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.report to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.tracking to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.util to javafx.fxml;
opens com.oracle.javafx.scenebuilder.app.welcomedialog;

uses com.oracle.javafx.scenebuilder.kit.i18n.spi.I18NResourcesProvider;

exports com.oracle.javafx.scenebuilder.app;
Oliver-Loeffler marked this conversation as resolved.
Show resolved Hide resolved
Oliver-Loeffler marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -41,8 +42,6 @@ public class I18N {

private static ResourceBundle bundle;

private static ResourceBundle.Control utf8EncodingControl = new I18NControl();

public static String getString(String key) {
return getBundle().getString(key);
}
Expand All @@ -55,7 +54,7 @@ public static String getString(String key, Object... arguments) {
public static synchronized ResourceBundle getBundle() {
if (bundle == null) {
final String packageName = I18N.class.getPackage().getName();
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderKit",utf8EncodingControl); //NOI18N
bundle = ResourceBundle.getBundle(packageName + ".SceneBuilderKit"); //NOI18N
}

return bundle;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle Corporation and Gluon nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.oracle.javafx.scenebuilder.kit.i18n.spi;

import java.util.spi.ResourceBundleProvider;

public interface I18NResourcesProvider extends ResourceBundleProvider { }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Gluon and/or its affiliates.
* Copyright (c) 2024, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
Expand All @@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle Corporation nor the names of its
* - Neither the name of Oracle Corporation and Gluon nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
Expand All @@ -29,26 +29,32 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.oracle.javafx.scenebuilder.kit.i18n;
package com.oracle.javafx.scenebuilder.kit.i18n.spi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.spi.AbstractResourceBundleProvider;

public class I18NResourcesProviderImpl extends AbstractResourceBundleProvider implements I18NResourcesProvider {

public class I18NControl extends ResourceBundle.Control {
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) {
public ResourceBundle getBundle(String baseName, Locale locale) {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
try (InputStream is = loader.getResourceAsStream(resourceName);
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
String resourceName = ResourceBundle.Control
jperedadnr marked this conversation as resolved.
Show resolved Hide resolved
.getControl(ResourceBundle.Control.FORMAT_DEFAULT)
.toResourceName(bundleName, "properties");
try (InputStream is = Files.newInputStream(Path.of(resourceName));
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(isr)) {
return new PropertyResourceBundle(reader);
} catch (IOException e) {
Expand Down
Loading