mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
FlatDefaultsAddon: added default implementation to getDefaults() because most subclasses use the same implementation
This commit is contained in:
@@ -23,11 +23,11 @@ import java.io.InputStream;
|
|||||||
*
|
*
|
||||||
* Allows loading of additional .properties files from addon JARs.
|
* Allows loading of additional .properties files from addon JARs.
|
||||||
* {@link java.util.ServiceLoader} is used to load extensions of this class from addon JARs.
|
* {@link java.util.ServiceLoader} is used to load extensions of this class from addon JARs.
|
||||||
*
|
* <p>
|
||||||
* If you extend this class in a addon JAR, you also have to add a text file named
|
* If you extend this class in a addon JAR, you also have to add a text file named
|
||||||
* {@code META-INF/services/com.formdev.flatlaf.FlatDefaultsAddon}
|
* {@code META-INF/services/com.formdev.flatlaf.FlatDefaultsAddon}
|
||||||
* to the addon JAR. The file must contain a single line with the class name.
|
* to the addon JAR. The file must contain a single line with the class name.
|
||||||
*
|
* <p>
|
||||||
* See 'flatlaf-swingx' addon for an example
|
* See 'flatlaf-swingx' addon for an example
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -37,6 +37,16 @@ public abstract class FlatDefaultsAddon
|
|||||||
/**
|
/**
|
||||||
* Finds an addon .properties file for the given LaF class and returns
|
* Finds an addon .properties file for the given LaF class and returns
|
||||||
* it as input stream. Or {@code null} if not found.
|
* it as input stream. Or {@code null} if not found.
|
||||||
|
* <p>
|
||||||
|
* This default implementation finds addon .properties file for the given LaF class
|
||||||
|
* in the same package as the subclass.
|
||||||
|
* <p>
|
||||||
|
* Override this method to load addon .properties files from other locations.
|
||||||
*/
|
*/
|
||||||
public abstract InputStream getDefaults( Class<?> lafClass );
|
public InputStream getDefaults( Class<?> lafClass ) {
|
||||||
|
Class<?> addonClass = this.getClass();
|
||||||
|
String propertiesName = "/" + addonClass.getPackage().getName().replace( '.', '/' )
|
||||||
|
+ '/' + lafClass.getSimpleName() + ".properties";
|
||||||
|
return addonClass.getResourceAsStream( propertiesName );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,7 @@ public class FlatJideOssDefaultsAddon
|
|||||||
LookAndFeelFactory.registerDefaultInitializer( FlatLaf.class.getName(), FlatJideUIDefaultsCustomizer.class.getName() );
|
LookAndFeelFactory.registerDefaultInitializer( FlatLaf.class.getName(), FlatJideUIDefaultsCustomizer.class.getName() );
|
||||||
LookAndFeelFactory.registerDefaultCustomizer( FlatLaf.class.getName(), FlatJideUIDefaultsCustomizer.class.getName() );
|
LookAndFeelFactory.registerDefaultCustomizer( FlatLaf.class.getName(), FlatJideUIDefaultsCustomizer.class.getName() );
|
||||||
|
|
||||||
Class<?> addonClass = this.getClass();
|
return super.getDefaults( lafClass );
|
||||||
String propertiesName = "/" + addonClass.getPackage().getName().replace( '.', '/' )
|
|
||||||
+ '/' + lafClass.getSimpleName() + ".properties";
|
|
||||||
return addonClass.getResourceAsStream( propertiesName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatJideUIDefaultsCustomizer ---------------------------------
|
//---- class FlatJideUIDefaultsCustomizer ---------------------------------
|
||||||
|
|||||||
@@ -16,26 +16,17 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.swingx;
|
package com.formdev.flatlaf.swingx;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import com.formdev.flatlaf.FlatDefaultsAddon;
|
import com.formdev.flatlaf.FlatDefaultsAddon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SwingX addon for FlatLaf.
|
* SwingX addon for FlatLaf.
|
||||||
|
* <p>
|
||||||
|
* Finds SwingX addon .properties file for the given LaF class
|
||||||
|
* in the same package as this class.
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatSwingXDefaultsAddon
|
public class FlatSwingXDefaultsAddon
|
||||||
extends FlatDefaultsAddon
|
extends FlatDefaultsAddon
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Finds SwingX addon .properties file for the given LaF class
|
|
||||||
* in the same package as this class.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public InputStream getDefaults( Class<?> lafClass ) {
|
|
||||||
Class<?> addonClass = this.getClass();
|
|
||||||
String propertiesName = "/" + addonClass.getPackage().getName().replace( '.', '/' )
|
|
||||||
+ '/' + lafClass.getSimpleName() + ".properties";
|
|
||||||
return addonClass.getResourceAsStream( propertiesName );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,26 +16,17 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.testing.swingx;
|
package com.formdev.flatlaf.testing.swingx;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import com.formdev.flatlaf.FlatDefaultsAddon;
|
import com.formdev.flatlaf.FlatDefaultsAddon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SwingX addon for FlatLaf for testing.
|
* SwingX addon for FlatLaf for testing.
|
||||||
|
* <p>
|
||||||
|
* Finds SwingX addon .properties file for the given LaF class
|
||||||
|
* in the same package as this class.
|
||||||
*
|
*
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatSwingXDefaultsTestAddon
|
public class FlatSwingXDefaultsTestAddon
|
||||||
extends FlatDefaultsAddon
|
extends FlatDefaultsAddon
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Finds SwingX addon .properties file for the given LaF class
|
|
||||||
* in the same package as this class.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public InputStream getDefaults( Class<?> lafClass ) {
|
|
||||||
Class<?> addonClass = this.getClass();
|
|
||||||
String propertiesName = "/" + addonClass.getPackage().getName().replace( '.', '/' )
|
|
||||||
+ '/' + lafClass.getSimpleName() + ".properties";
|
|
||||||
return addonClass.getResourceAsStream( propertiesName );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user