|
|
|
@ -81,19 +81,24 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon {
|
|
|
|
|
/** |
|
|
|
|
* 用于fallback渲染disable图像,这段代码来自异常分支,使用率要保持较低水平 |
|
|
|
|
*/ |
|
|
|
|
private void fallbackRender(Component c, Graphics g, int x, int y) { |
|
|
|
|
private boolean fallbackRender(Component c, Graphics g, int x, int y) { |
|
|
|
|
if (resource instanceof UrlIconResource) { |
|
|
|
|
String path = ((UrlIconResource) resource).getPath(); |
|
|
|
|
String[] names = path.split(IconManager.ICON_DISABLE_SUFFIX); |
|
|
|
|
if (path.contains(IconManager.ICON_DISABLE_SUFFIX) && names.length == 2) { |
|
|
|
|
int index = path.lastIndexOf(IconManager.ICON_DISABLE_SUFFIX); |
|
|
|
|
if (path.contains(IconManager.ICON_DISABLE_SUFFIX) && index > 0) { |
|
|
|
|
SVGLoader loader = new SVGLoader(); |
|
|
|
|
SVGDocument document = loader.load(new UrlIconResource(names[0] + names[1]).getInputStream()); |
|
|
|
|
SVGDocument document = loader.load( |
|
|
|
|
new UrlIconResource(path.substring(0, index) + |
|
|
|
|
path.substring(index + IconManager.ICON_DISABLE_SUFFIX.length())) |
|
|
|
|
.getInputStream()); |
|
|
|
|
if (document != null) { |
|
|
|
|
document.render((JComponent) c, grayGraphics(g), |
|
|
|
|
new ViewBox(x, y, scaleSize.width, scaleSize.height)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Graphics2D grayGraphics(Graphics g) { |
|
|
|
@ -123,13 +128,18 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon {
|
|
|
|
|
} else { |
|
|
|
|
document = svgDocument.getValue(); |
|
|
|
|
} |
|
|
|
|
// 由于 weisj 库中加载svg描述出现问题,则返回一个Null,这里补充一个默认图标
|
|
|
|
|
if (document == null) { |
|
|
|
|
document = defaultDoc.getValue(); |
|
|
|
|
} |
|
|
|
|
document.render((JComponent) c, (Graphics2D) g, new ViewBox(x, y, scaleSize.width, scaleSize.height)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
boolean rendered = fallbackRender.render(c, g, x, y); |
|
|
|
|
if (rendered) { |
|
|
|
|
FineLoggerFactory.getLogger().warn("SvgIcon from url: " + resource + " paint with fallbackRender"); |
|
|
|
|
} else { |
|
|
|
|
FineLoggerFactory.getLogger().error("SvgIcon from url: " + resource + "can not paint.", e); |
|
|
|
|
fallbackRender.render(c, g, x, y); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -177,6 +187,6 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon {
|
|
|
|
|
|
|
|
|
|
@FunctionalInterface |
|
|
|
|
interface FallbackRender { |
|
|
|
|
void render(Component c, Graphics g, int x, int y); |
|
|
|
|
boolean render(Component c, Graphics g, int x, int y); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|