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)
- Extras:
- `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
`FlatSplitPane`.
- Native libraries: Added API version check to test whether native library

View File

@@ -63,6 +63,7 @@ public class FlatSVGIcon
extends ImageIcon
implements DisabledIconProvider
{
private static boolean loggingEnabled = true;
private static boolean svgCacheEnabled = true;
// 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<>();
@@ -273,7 +274,8 @@ public class FlatSVGIcon
if( document == null ) {
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 ) {
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 );
return;
}
@@ -508,7 +511,8 @@ public class FlatSVGIcon
SVGDocument document = svgLoader.load( url );
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;
}
@@ -707,6 +711,16 @@ public class FlatSVGIcon
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 */
public static boolean isSVGDocumentEnabled() {
return svgCacheEnabled;