diff --git a/designer-base/src/main/java/com/fine/theme/icon/JsonIconSet.java b/designer-base/src/main/java/com/fine/theme/icon/JsonIconSet.java index a7b774d0f4..fc769c7557 100644 --- a/designer-base/src/main/java/com/fine/theme/icon/JsonIconSet.java +++ b/designer-base/src/main/java/com/fine/theme/icon/JsonIconSet.java @@ -58,37 +58,49 @@ public class JsonIconSet extends AbstractIconSet { */ private void applyIcon(String key, Object value) { if (value instanceof String) { - String path = (String) value; - if (IconManager.isSvgIcon(path)) { - // 默认字符串提供正常图和灰化图 - addIcon(new SvgIconSource(key, - base + path, - IconManager.findDisablePath(base + path), - null - )); - } else if (IconManager.isImageIcon(path)) { - addIcon(new ImageIconSource(key, base + path)); - } - // 其他无法识别格式不处理 + dealWithIconString(key, (String) value); } else if (value instanceof Map) { - Map iconObj = (Map) value; - String normalPath = (String) iconObj.get(IconType.normal.name()); - String disablePath = (String) iconObj.get(IconType.disable.name()); - String whitePath = (String) iconObj.get(IconType.white.name()); - // 暂不支持混合格式,每个id的格式需要保持一致 - if (IconManager.isSvgIcon(normalPath)) { - addIcon(new SvgIconSource(key, - base + normalPath, - StringUtils.isNotBlank(disablePath) ? base + disablePath : null, - StringUtils.isNotBlank(whitePath) ? base + whitePath : null - )); - } else if (IconManager.isImageIcon(normalPath)) { - addIcon(new ImageIconSource(key, - base + normalPath, - StringUtils.isNotBlank(disablePath) ? base + disablePath : null, - StringUtils.isNotBlank(whitePath) ? base + whitePath : null - )); - } + dealWithIconMap(key, (Map) value); + } + } + + /** + * 处理字符串格式的icon配置 + */ + private void dealWithIconString(String key, String value) { + if (IconManager.isSvgIcon(value)) { + // 默认字符串提供正常图和灰化图 + addIcon(new SvgIconSource(key, + base + value, + IconManager.findDisablePath(base + value), + null + )); + } else if (IconManager.isImageIcon(value)) { + addIcon(new ImageIconSource(key, base + value)); + } + // 其他无法识别格式不处理 + } + + /** + * 处理object形式的icon配置 + */ + private void dealWithIconMap(String key, Map value) { + String normalPath = (String) value.get(IconType.normal.name()); + String disablePath = (String) value.get(IconType.disable.name()); + String whitePath = (String) value.get(IconType.white.name()); + // 暂不支持混合格式,每个id的格式需要保持一致 + if (IconManager.isSvgIcon(normalPath)) { + addIcon(new SvgIconSource(key, + base + normalPath, + StringUtils.isNotBlank(disablePath) ? base + disablePath : null, + StringUtils.isNotBlank(whitePath) ? base + whitePath : null + )); + } else if (IconManager.isImageIcon(normalPath)) { + addIcon(new ImageIconSource(key, + base + normalPath, + StringUtils.isNotBlank(disablePath) ? base + disablePath : null, + StringUtils.isNotBlank(whitePath) ? base + whitePath : null + )); } } diff --git a/designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java b/designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java index 11b46b647d..eee575d50b 100644 --- a/designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java +++ b/designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java @@ -49,9 +49,12 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon { private final IconResource resource; private final IconType type; - private final static NullableLazyValue defaultDoc = NullableLazyValue.createValue(SvgIcon::loadDefault); - private final NullableLazyValue svgDocument = NullableLazyValue.createValue(() -> load(IconType.normal)); - private final NullableLazyValue whiteSvgDocument = NullableLazyValue.createValue(() -> load(IconType.white)); + private final static NullableLazyValue DEFAULT_ICON_DOC = + NullableLazyValue.createValue(SvgIcon::loadDefault); + private final NullableLazyValue svgDocument = + NullableLazyValue.createValue(() -> load(IconType.normal)); + private final NullableLazyValue whiteSvgDocument = + NullableLazyValue.createValue(() -> load(IconType.white)); public SvgIcon(IconResource resource, Dimension size, IconType type) { this.resource = resource; @@ -130,7 +133,7 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon { } // 由于 weisj 库中加载svg描述出现问题,则返回一个Null,这里补充一个默认图标 if (document == null) { - document = defaultDoc.getValue(); + document = DEFAULT_ICON_DOC.getValue(); } document.render((JComponent) c, (Graphics2D) g, new ViewBox(x, y, scaleSize.width, scaleSize.height)); } catch (Exception e) { @@ -186,10 +189,19 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon { /** - * 用于回退绘制的类 + * 用于回退渲染的回调类 */ @FunctionalInterface interface FallbackRender { + /** + * 渲染图标 + * + * @param c 待绘制组件 + * @param g 抽象画板 + * @param x 起点横坐标 + * @param y 起点纵坐标 + * @return 是否使用了回退渲染 + */ boolean render(Component c, Graphics g, int x, int y); } }