Browse Source

无jira任务 代码质量

newui
vito 5 months ago
parent
commit
8a4b2a3c1c
  1. 36
      designer-base/src/main/java/com/fine/theme/icon/JsonIconSet.java
  2. 22
      designer-base/src/main/java/com/fine/theme/icon/svg/SvgIcon.java

36
designer-base/src/main/java/com/fine/theme/icon/JsonIconSet.java

@ -58,23 +58,36 @@ public class JsonIconSet extends AbstractIconSet {
*/ */
private void applyIcon(String key, Object value) { private void applyIcon(String key, Object value) {
if (value instanceof String) { if (value instanceof String) {
String path = (String) value; dealWithIconString(key, (String) value);
if (IconManager.isSvgIcon(path)) { } else if (value instanceof Map) {
dealWithIconMap(key, (Map<String, Object>) value);
}
}
/**
* 处理字符串格式的icon配置
*/
private void dealWithIconString(String key, String value) {
if (IconManager.isSvgIcon(value)) {
// 默认字符串提供正常图和灰化图 // 默认字符串提供正常图和灰化图
addIcon(new SvgIconSource(key, addIcon(new SvgIconSource(key,
base + path, base + value,
IconManager.findDisablePath(base + path), IconManager.findDisablePath(base + value),
null null
)); ));
} else if (IconManager.isImageIcon(path)) { } else if (IconManager.isImageIcon(value)) {
addIcon(new ImageIconSource(key, base + path)); addIcon(new ImageIconSource(key, base + value));
} }
// 其他无法识别格式不处理 // 其他无法识别格式不处理
} else if (value instanceof Map) { }
Map<String, Object> iconObj = (Map<String, Object>) value;
String normalPath = (String) iconObj.get(IconType.normal.name()); /**
String disablePath = (String) iconObj.get(IconType.disable.name()); * 处理object形式的icon配置
String whitePath = (String) iconObj.get(IconType.white.name()); */
private void dealWithIconMap(String key, Map<String, Object> 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的格式需要保持一致 // 暂不支持混合格式,每个id的格式需要保持一致
if (IconManager.isSvgIcon(normalPath)) { if (IconManager.isSvgIcon(normalPath)) {
addIcon(new SvgIconSource(key, addIcon(new SvgIconSource(key,
@ -90,7 +103,6 @@ public class JsonIconSet extends AbstractIconSet {
)); ));
} }
} }
}
@Override @Override

22
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 IconResource resource;
private final IconType type; private final IconType type;
private final static NullableLazyValue<SVGDocument> defaultDoc = NullableLazyValue.createValue(SvgIcon::loadDefault); private final static NullableLazyValue<SVGDocument> DEFAULT_ICON_DOC =
private final NullableLazyValue<SVGDocument> svgDocument = NullableLazyValue.createValue(() -> load(IconType.normal)); NullableLazyValue.createValue(SvgIcon::loadDefault);
private final NullableLazyValue<SVGDocument> whiteSvgDocument = NullableLazyValue.createValue(() -> load(IconType.white)); private final NullableLazyValue<SVGDocument> svgDocument =
NullableLazyValue.createValue(() -> load(IconType.normal));
private final NullableLazyValue<SVGDocument> whiteSvgDocument =
NullableLazyValue.createValue(() -> load(IconType.white));
public SvgIcon(IconResource resource, Dimension size, IconType type) { public SvgIcon(IconResource resource, Dimension size, IconType type) {
this.resource = resource; this.resource = resource;
@ -130,7 +133,7 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon {
} }
// 由于 weisj 库中加载svg描述出现问题,则返回一个Null,这里补充一个默认图标 // 由于 weisj 库中加载svg描述出现问题,则返回一个Null,这里补充一个默认图标
if (document == 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)); document.render((JComponent) c, (Graphics2D) g, new ViewBox(x, y, scaleSize.width, scaleSize.height));
} catch (Exception e) { } catch (Exception e) {
@ -186,10 +189,19 @@ public class SvgIcon implements DisabledIcon, WhiteIcon, Icon {
/** /**
* 用于回退绘制的 * 用于回退渲染的回调
*/ */
@FunctionalInterface @FunctionalInterface
interface FallbackRender { interface FallbackRender {
/**
* 渲染图标
*
* @param c 待绘制组件
* @param g 抽象画板
* @param x 起点横坐标
* @param y 起点纵坐标
* @return 是否使用了回退渲染
*/
boolean render(Component c, Graphics g, int x, int y); boolean render(Component c, Graphics g, int x, int y);
} }
} }

Loading…
Cancel
Save