mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
support loading FlatLaf properties files from named Java modules without the need to open that package in module-info.java (issue #1026)
This commit is contained in:
@@ -3,6 +3,13 @@ FlatLaf Change Log
|
|||||||
|
|
||||||
## 3.7-SNAPSHOT
|
## 3.7-SNAPSHOT
|
||||||
|
|
||||||
|
#### New features and improvements
|
||||||
|
|
||||||
|
- If using `FlatLaf.registerCustomDefaultsSource( "com.myapp.themes" )` and
|
||||||
|
named Java modules, it is no longer necessary to add `opens com.myapp.themes;`
|
||||||
|
to `module-info.java`. (issue #1026)
|
||||||
|
|
||||||
|
|
||||||
#### Fixed bugs
|
#### Fixed bugs
|
||||||
|
|
||||||
- Tree and List: Fixed painting of rounded drop backgrounds. (issue #1023)
|
- Tree and List: Fixed painting of rounded drop backgrounds. (issue #1023)
|
||||||
|
|||||||
@@ -911,8 +911,7 @@ public abstract class FlatLaf
|
|||||||
* <p>
|
* <p>
|
||||||
* Invoke this method before setting the look and feel.
|
* Invoke this method before setting the look and feel.
|
||||||
* <p>
|
* <p>
|
||||||
* If using Java modules, the package must be opened in {@code module-info.java}.
|
* If using Java modules, it is not necessary to open the package in {@code module-info.java}.
|
||||||
* Otherwise, use {@link #registerCustomDefaultsSource(URL)}.
|
|
||||||
*
|
*
|
||||||
* @param packageName a package name (e.g. "com.myapp.resources")
|
* @param packageName a package name (e.g. "com.myapp.resources")
|
||||||
*/
|
*/
|
||||||
@@ -959,9 +958,9 @@ public abstract class FlatLaf
|
|||||||
* <p>
|
* <p>
|
||||||
* See {@link #registerCustomDefaultsSource(String)} for details.
|
* See {@link #registerCustomDefaultsSource(String)} for details.
|
||||||
* <p>
|
* <p>
|
||||||
* This method is useful if using Java modules and the package containing the properties files
|
|
||||||
* is not opened in {@code module-info.java}.
|
|
||||||
* E.g. {@code FlatLaf.registerCustomDefaultsSource( MyApp.class.getResource( "/com/myapp/themes/" ) )}.
|
* E.g. {@code FlatLaf.registerCustomDefaultsSource( MyApp.class.getResource( "/com/myapp/themes/" ) )}.
|
||||||
|
* <p>
|
||||||
|
* If using Java modules, it is not necessary to open the package in {@code module-info.java}.
|
||||||
*
|
*
|
||||||
* @param packageUrl a package URL
|
* @param packageUrl a package URL
|
||||||
* @since 2
|
* @since 2
|
||||||
|
|||||||
@@ -205,20 +205,37 @@ class UIDefaultsLoader
|
|||||||
if( classLoader != null && !addonClassLoaders.contains( classLoader ) )
|
if( classLoader != null && !addonClassLoaders.contains( classLoader ) )
|
||||||
addonClassLoaders.add( classLoader );
|
addonClassLoaders.add( classLoader );
|
||||||
|
|
||||||
packageName = packageName.replace( '.', '/' );
|
|
||||||
if( classLoader == null )
|
if( classLoader == null )
|
||||||
classLoader = FlatLaf.class.getClassLoader();
|
classLoader = FlatLaf.class.getClassLoader();
|
||||||
|
|
||||||
|
// Get package URL using ClassLoader.getResource(...) because this works
|
||||||
|
// also in named Java modules, even without opening the package in module-info.java.
|
||||||
|
// This extra step is necessary because ClassLoader.getResource("<package>/<file>.properties")
|
||||||
|
// does not work for named Java modules.
|
||||||
|
URL url = classLoader.getResource( packageName.replace( '.', '/' ) );
|
||||||
|
if( url == null ) {
|
||||||
|
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to find package '"
|
||||||
|
+ packageName + "' to load properties files.", null );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String packageUrl = url.toExternalForm();
|
||||||
|
if( !packageUrl.endsWith( "/" ) )
|
||||||
|
packageUrl = packageUrl.concat( "/" );
|
||||||
|
|
||||||
for( Class<?> lafClass : lafClasses ) {
|
for( Class<?> lafClass : lafClasses ) {
|
||||||
String propertiesName = packageName + '/' + simpleClassName( lafClass ) + ".properties";
|
URL propertiesUrl = new URL( packageUrl + simpleClassName( lafClass ) + ".properties" );
|
||||||
try( InputStream in = classLoader.getResourceAsStream( propertiesName ) ) {
|
|
||||||
if( in != null )
|
try( InputStream in = propertiesUrl.openStream() ) {
|
||||||
properties.load( in );
|
properties.load( in );
|
||||||
|
} catch( FileNotFoundException ex ) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( source instanceof URL ) {
|
} else if( source instanceof URL ) {
|
||||||
// load from package URL
|
// load from package URL
|
||||||
URL packageUrl = (URL) source;
|
String packageUrl = ((URL)source).toExternalForm();
|
||||||
|
if( !packageUrl.endsWith( "/" ) )
|
||||||
|
packageUrl = packageUrl.concat( "/" );
|
||||||
for( Class<?> lafClass : lafClasses ) {
|
for( Class<?> lafClass : lafClasses ) {
|
||||||
URL propertiesUrl = new URL( packageUrl + simpleClassName( lafClass ) + ".properties" );
|
URL propertiesUrl = new URL( packageUrl + simpleClassName( lafClass ) + ".properties" );
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
<listEntry value="4"/>
|
<listEntry value="4"/>
|
||||||
</listAttribute>
|
</listAttribute>
|
||||||
|
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
|
||||||
|
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;flatlaf-core&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;flatlaf-testing-modular-app&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> </sourceContainers> </sourceLookupDirector> "/>
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
|
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
|
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
|
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
|
||||||
@@ -17,11 +19,11 @@
|
|||||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="-Ddummy=dummy"/>
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="-Ddummy=dummy"/>
|
||||||
<listAttribute key="org.eclipse.jdt.launching.MODULEPATH">
|
<listAttribute key="org.eclipse.jdt.launching.MODULEPATH">
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17/" path="4" type="4"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17/" path="4" type="4"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-testing-modular-app/build/libs/flatlaf-testing-modular-app-3.0-SNAPSHOT.jar" path="4" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-testing-modular-app/run/flatlaf-testing-modular-app-999-SNAPSHOT.jar" path="4" type="2"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-core/build/libs/flatlaf-3.0-SNAPSHOT.jar" path="4" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-testing-modular-app/run/flatlaf-999-SNAPSHOT.jar" path="4" type="2"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-extras/build/libs/flatlaf-extras-3.0-SNAPSHOT.jar" path="4" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-testing-modular-app/run/flatlaf-extras-999-SNAPSHOT.jar" path="4" type="2"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-fonts-inter/build/libs/flatlaf-fonts-inter-3.19-SNAPSHOT.jar" path="4" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-testing-modular-app/run/flatlaf-fonts-inter-999-SNAPSHOT.jar" path="4" type="2"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry externalArchive="C:/Users/charly/.gradle/caches/modules-2/files-2.1/com.formdev/svgSalamander/1.1.4/e61742cb8baaf9ecf57a9779763d1de21ca9db5a/svgSalamander-1.1.4.jar" path="4" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/flatlaf-testing-modular-app/run/jsvg-999.jar" path="4" type="2"/> "/>
|
||||||
</listAttribute>
|
</listAttribute>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="flatlaf-testing-modular-app"/>
|
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="flatlaf-testing-modular-app"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-m com.formdev.flatlaf.testing.modular.app/com.formdev.flatlaf.testing.modular.app.FlatModularAppTest"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-m com.formdev.flatlaf.testing.modular.app/com.formdev.flatlaf.testing.modular.app.FlatModularAppTest"/>
|
||||||
|
|||||||
@@ -30,3 +30,20 @@ flatlafModuleInfo {
|
|||||||
dependsOn( ":flatlaf-extras:jar" )
|
dependsOn( ":flatlaf-extras:jar" )
|
||||||
dependsOn( ":flatlaf-fonts-inter:jar" )
|
dependsOn( ":flatlaf-fonts-inter:jar" )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
register( "build-for-debugging" ) {
|
||||||
|
group = "build"
|
||||||
|
|
||||||
|
dependsOn( "build" )
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
copy {
|
||||||
|
from( project.tasks["jar"].outputs )
|
||||||
|
from( configurations.runtimeClasspath )
|
||||||
|
into( "run" )
|
||||||
|
rename( "-[0-9][0-9.]*[0-9]", "-999" )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,8 +38,12 @@ public class FlatModularAppTest
|
|||||||
SwingUtilities.invokeLater( () -> {
|
SwingUtilities.invokeLater( () -> {
|
||||||
FlatInterFont.installBasic();
|
FlatInterFont.installBasic();
|
||||||
|
|
||||||
|
FlatLaf.registerCustomDefaultsSource( "com.formdev.flatlaf.testing.modular.app.themes" );
|
||||||
|
FlatLaf.registerCustomDefaultsSource( "com.formdev.flatlaf.testing.modular.app.themes2",
|
||||||
|
FlatModularAppTest.class.getClassLoader() );
|
||||||
FlatLaf.registerCustomDefaultsSource(
|
FlatLaf.registerCustomDefaultsSource(
|
||||||
FlatModularAppTest.class.getResource( "/com/formdev/flatlaf/testing/modular/app/themes/" ) );
|
FlatModularAppTest.class.getResource( "/com/formdev/flatlaf/testing/modular/app/themes3" ) );
|
||||||
|
|
||||||
FlatLightLaf.setup();
|
FlatLightLaf.setup();
|
||||||
|
|
||||||
JButton button1 = new JButton( "Hello" );
|
JButton button1 = new JButton( "Hello" );
|
||||||
|
|||||||
@@ -14,7 +14,4 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
@background = #fff
|
|
||||||
@foreground = #f00
|
@foreground = #f00
|
||||||
|
|
||||||
ButtonUI = com.formdev.flatlaf.testing.modular.app.plaf.MyButtonUI
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2025 FormDev Software GmbH
|
||||||
|
#
|
||||||
|
# Licensed 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
|
||||||
|
#
|
||||||
|
# https://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.
|
||||||
|
#
|
||||||
|
|
||||||
|
@background = #efe
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2025 FormDev Software GmbH
|
||||||
|
#
|
||||||
|
# Licensed 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
|
||||||
|
#
|
||||||
|
# https://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.
|
||||||
|
#
|
||||||
|
|
||||||
|
ButtonUI = com.formdev.flatlaf.testing.modular.app.plaf.MyButtonUI
|
||||||
Reference in New Issue
Block a user