Browse Source

无jira任务 优化报错信息

newui
vito 8 months ago
parent
commit
0c27d45923
  1. 22
      designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java
  2. 1
      designer-base/src/main/resources/com/fine/theme/light/ui/fine_light.icon.json

22
designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java

@ -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);
}
}

1
designer-base/src/main/resources/com/fine/theme/light/ui/fine_light.icon.json

@ -134,7 +134,6 @@
"image": "insert/image.svg",
"bias": "insert/bias.svg",
"sub_report": "insert/sub_report.svg",
"chart_line": "chart/chart_line.svg",
"popup": {
"normal": "popup/popup.svg"
},

Loading…
Cancel
Save