@ -2,9 +2,15 @@ package com.fr.base.svg;
import com.fr.general.IOUtils ;
import com.fr.log.FineLoggerFactory ;
import com.fr.stable.bridge.StableFactory ;
import com.fr.stable.fun.ResourcePathTransformer ;
import com.fr.stable.plugin.ExtraClassManagerProvider ;
import javax.swing.Icon ;
import javax.swing.ImageIcon ;
import java.util.Arrays ;
import java.util.HashSet ;
import java.util.Set ;
/ * *
* 主要是用来读取svgIcon的工具类
@ -36,7 +42,7 @@ public class IconUtils {
// 判断是否以.svg结尾
if ( resource . endsWith ( ICON_SUFFIX_SVG ) ) {
if ( IOUtils . readResource ( resource ) ! = null ) {
return SVGIcon . readSVGIcon ( resource ) ;
return SVGIcon . readSVGIcon ( transformPath ( resource ) ) ;
}
// 适配插件
return adjustPluginsPng ( resource ) ;
@ -68,15 +74,15 @@ public class IconUtils {
private static Icon readNoSuffixResource ( String resource , String svgIconType ) {
String svgPath = resource + svgIconType ;
if ( IOUtils . readResource ( svgPath ) ! = null ) {
return SVGIcon . readSVGIcon ( svgPath ) ;
return SVGIcon . readSVGIcon ( transformPath ( svgPath ) ) ;
}
String pngPath = resource + ICON_SUFFIX_PNG ;
if ( IOUtils . readResource ( pngPath ) ! = null ) {
return IOUtils . readIcon ( pngPath ) ;
return IOUtils . readIcon ( transformPath ( pngPath ) ) ;
}
String gifPath = resource + ICON_SUFFIX_GIF ;
if ( IOUtils . readResource ( gifPath ) ! = null ) {
return IOUtils . readIcon ( gifPath ) ;
return IOUtils . readIcon ( transformPath ( gifPath ) ) ;
}
FineLoggerFactory . getLogger ( ) . error ( "File not exists:{}" , resource ) ;
return new ImageIcon ( ) ;
@ -113,8 +119,30 @@ public class IconUtils {
private static Icon readSpecifiedTypeIcon ( String resource , String oldSuffix , String newSuffix ) {
String iconPath = resource . replace ( oldSuffix , newSuffix ) ;
if ( IOUtils . readResource ( iconPath ) ! = null ) {
return SVGIcon . readSVGIcon ( iconPath ) ;
return SVGIcon . readSVGIcon ( transformPath ( iconPath ) ) ;
}
return readIcon ( resource ) ;
}
private static String transformPath ( String path ) {
Set < ResourcePathTransformer > set = getResourcePathTransformers ( ) ;
for ( ResourcePathTransformer transformer : set ) {
if ( transformer . accept ( path ) ) {
return transformer . transform ( path ) ;
}
}
return path ;
}
private static Set < ResourcePathTransformer > getResourcePathTransformers ( ) {
Set < ResourcePathTransformer > set = new HashSet < ResourcePathTransformer > ( ) ;
ExtraClassManagerProvider provider = StableFactory . getExtraClassManager ( ) ;
if ( provider ! = null ) {
Set < ResourcePathTransformer > pluginProvided = provider . getArray ( ResourcePathTransformer . MARK_STRING ) ;
set . addAll ( pluginProvided ) ;
}
ResourcePathTransformer [ ] oemSet = StableFactory . getMarkedObjectsFromCollection ( ResourcePathTransformer . MARK_STRING , ResourcePathTransformer . class ) ;
set . addAll ( Arrays . asList ( oemSet ) ) ;
return set ;
}
}