FlatSVGIcon: use log level CONFIG instead of SEVERE and allow disabling logging (issue #823)

This commit is contained in:
Karl Tauber
2024-03-24 17:29:57 +01:00
parent 1068884bce
commit 36e4071b7f
2 changed files with 19 additions and 3 deletions

View File

@@ -13,6 +13,8 @@ FlatLaf Change Log
(issue 809) (issue 809)
- Extras: - Extras:
- `FlatSVGIcon` color filters now support linear gradients. (PR #817) - `FlatSVGIcon` color filters now support linear gradients. (PR #817)
- `FlatSVGIcon`: Use log level `CONFIG` instead of `SEVERE` and allow
disabling logging. (issue #823)
- Added support for `JSplitPane.expandableSide` client property to - Added support for `JSplitPane.expandableSide` client property to
`FlatSplitPane`. `FlatSplitPane`.
- Native libraries: Added API version check to test whether native library - Native libraries: Added API version check to test whether native library

View File

@@ -63,6 +63,7 @@ public class FlatSVGIcon
extends ImageIcon extends ImageIcon
implements DisabledIconProvider implements DisabledIconProvider
{ {
private static boolean loggingEnabled = true;
private static boolean svgCacheEnabled = true; private static boolean svgCacheEnabled = true;
// cache that uses soft references for values, which allows freeing SVG documents if no longer used // cache that uses soft references for values, which allows freeing SVG documents if no longer used
private static final SoftCache<String, SVGDocument> svgCache = new SoftCache<>(); private static final SoftCache<String, SVGDocument> svgCache = new SoftCache<>();
@@ -273,7 +274,8 @@ public class FlatSVGIcon
if( document == null ) { if( document == null ) {
loadFailed = true; loadFailed = true;
LoggingFacade.INSTANCE.logSevere( "FlatSVGIcon: failed to load SVG icon from input stream", null ); if( loggingEnabled )
LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: failed to load SVG icon from input stream", null );
} }
} }
} }
@@ -477,6 +479,7 @@ public class FlatSVGIcon
if( url == null ) { if( url == null ) {
loadFailed = true; loadFailed = true;
if( loggingEnabled )
LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: resource '" + name + "' not found (if using Java modules, check whether icon package is opened in module-info.java)", null ); LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: resource '" + name + "' not found (if using Java modules, check whether icon package is opened in module-info.java)", null );
return; return;
} }
@@ -508,7 +511,8 @@ public class FlatSVGIcon
SVGDocument document = svgLoader.load( url ); SVGDocument document = svgLoader.load( url );
if( document == null ) { if( document == null ) {
LoggingFacade.INSTANCE.logSevere( "FlatSVGIcon: failed to load '" + url + "'", null ); if( loggingEnabled )
LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: failed to load '" + url + "'", null );
return null; return null;
} }
@@ -707,6 +711,16 @@ public class FlatSVGIcon
darkLaf = FlatLaf.isLafDark(); darkLaf = FlatLaf.isLafDark();
} }
/** @since 3.4.1 */
public static boolean isLoggingEnabled() {
return loggingEnabled;
}
/** @since 3.4.1 */
public static void setLoggingEnabled( boolean loggingEnabled ) {
FlatSVGIcon.loggingEnabled = loggingEnabled;
}
/** @since 3.4.1 */ /** @since 3.4.1 */
public static boolean isSVGDocumentEnabled() { public static boolean isSVGDocumentEnabled() {
return svgCacheEnabled; return svgCacheEnabled;