mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
FlatSVGIcon:
- setColorFilter() now returns `this` - added method to enable/disable and clear SVGDocument cache - do not filter red color in `paintSvgError()`
This commit is contained in:
@@ -63,6 +63,7 @@ public class FlatSVGIcon
|
||||
extends ImageIcon
|
||||
implements DisabledIconProvider
|
||||
{
|
||||
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<>();
|
||||
private static final SVGLoader svgLoader = new SVGLoader();
|
||||
@@ -450,8 +451,9 @@ public class FlatSVGIcon
|
||||
* @param colorFilter The color filter
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setColorFilter( ColorFilter colorFilter ) {
|
||||
public FlatSVGIcon setColorFilter( ColorFilter colorFilter ) {
|
||||
this.colorFilter = colorFilter;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void update() {
|
||||
@@ -485,6 +487,9 @@ public class FlatSVGIcon
|
||||
}
|
||||
|
||||
static synchronized SVGDocument loadSVG( URL url ) {
|
||||
if( !svgCacheEnabled )
|
||||
return loadSVGUncached( url );
|
||||
|
||||
// get from our cache
|
||||
String cacheKey = url.toString();
|
||||
SVGDocument document = svgCache.get( cacheKey );
|
||||
@@ -492,15 +497,21 @@ public class FlatSVGIcon
|
||||
return document;
|
||||
|
||||
// load SVG document
|
||||
document = svgLoader.load( url );
|
||||
document = loadSVGUncached( url );
|
||||
|
||||
svgCache.put( cacheKey, document );
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
private static SVGDocument loadSVGUncached( URL url ) {
|
||||
SVGDocument document = svgLoader.load( url );
|
||||
|
||||
if( document == null ) {
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatSVGIcon: failed to load '" + url + "'", null );
|
||||
return null;
|
||||
}
|
||||
|
||||
svgCache.put( cacheKey, document );
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -612,6 +623,9 @@ public class FlatSVGIcon
|
||||
}
|
||||
|
||||
private void paintSvgError( Graphics2D g, int x, int y ) {
|
||||
if( g instanceof GraphicsFilter )
|
||||
((GraphicsFilter)g).setColorUnfiltered( Color.red );
|
||||
else
|
||||
g.setColor( Color.red );
|
||||
g.fillRect( x, y, getIconWidth(), getIconHeight() );
|
||||
}
|
||||
@@ -693,6 +707,24 @@ public class FlatSVGIcon
|
||||
darkLaf = FlatLaf.isLafDark();
|
||||
}
|
||||
|
||||
/** @since 3.5 */
|
||||
public static boolean isSVGDocumentEnabled() {
|
||||
return svgCacheEnabled;
|
||||
}
|
||||
|
||||
/** @since 3.5 */
|
||||
public static void setSVGDocumentEnabled( boolean svgCacheEnabled ) {
|
||||
FlatSVGIcon.svgCacheEnabled = svgCacheEnabled;
|
||||
|
||||
if( !svgCacheEnabled )
|
||||
clearSVGDocumentCache();
|
||||
}
|
||||
|
||||
/** @since 3.5 */
|
||||
public static void clearSVGDocumentCache() {
|
||||
svgCache.clear();
|
||||
}
|
||||
|
||||
//---- class ColorFilter --------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -979,6 +1011,10 @@ public class FlatSVGIcon
|
||||
super.setColor( filterColor( c ) );
|
||||
}
|
||||
|
||||
void setColorUnfiltered( Color c ) {
|
||||
super.setColor( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaint( Paint paint ) {
|
||||
if( paint instanceof Color )
|
||||
|
||||
Reference in New Issue
Block a user