No.10: ①根据开发评审意见,新增SVGIconUtils工具类,之后读取图标都可以用工具类中的方法;②修改UpdateAction、MenuDef、UIButton适配工具类方法;③修改之前上传的图标读取方式以及一些初始化方式;④替换了菜单栏-单元格中的所有子项的图标research/11.0
@ -0,0 +1,62 @@ |
|||||||
|
package com.fr.base.svg; |
||||||
|
|
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Yvan |
||||||
|
* @version 10.0 |
||||||
|
* Created by Yvan on 2020/12/22 |
||||||
|
*/ |
||||||
|
public enum IconType { |
||||||
|
|
||||||
|
/** |
||||||
|
* png图片转化的Icon |
||||||
|
*/ |
||||||
|
PNG(".png", 0), |
||||||
|
/** |
||||||
|
* svg图片转化的normalIcon |
||||||
|
*/ |
||||||
|
NORMAL_SVG("_normal", 1), |
||||||
|
/** |
||||||
|
* SVG图片转化的disabledIcon |
||||||
|
*/ |
||||||
|
DISABLED_SVG("_disabled", 2), |
||||||
|
/** |
||||||
|
* SVG图片转化的selectedIcon |
||||||
|
*/ |
||||||
|
SELECTED_SVG("_selected", 3); |
||||||
|
|
||||||
|
private String iconType; |
||||||
|
private int iconCode; |
||||||
|
|
||||||
|
IconType(String iconType, int iconCode) { |
||||||
|
this.iconType = iconType; |
||||||
|
this.iconCode = iconCode; |
||||||
|
} |
||||||
|
|
||||||
|
public String getIconType() { |
||||||
|
return iconType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setIconType(String iconType) { |
||||||
|
this.iconType = iconType; |
||||||
|
} |
||||||
|
|
||||||
|
public int getIconCode() { |
||||||
|
return iconCode; |
||||||
|
} |
||||||
|
|
||||||
|
public void setIconCode(int iconCode) { |
||||||
|
this.iconCode = iconCode; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getIconType(int iconCode) { |
||||||
|
for (IconType iconType : IconType.values()) { |
||||||
|
if (iconType.getIconCode() == iconCode) { |
||||||
|
return iconType.getIconType(); |
||||||
|
} |
||||||
|
} |
||||||
|
return StringUtils.EMPTY; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,104 @@ |
|||||||
|
package com.fr.base.svg; |
||||||
|
|
||||||
|
import com.fr.general.IOUtils; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
|
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.ImageIcon; |
||||||
|
|
||||||
|
/** |
||||||
|
* 主要是用来读取svgIcon的工具类 |
||||||
|
* @author Yvan |
||||||
|
* @version 10.0 |
||||||
|
* Created by Yvan on 2020/12/23 |
||||||
|
*/ |
||||||
|
public class SVGIconUtils { |
||||||
|
|
||||||
|
private static final String ICON_SUFFIX_SVG = ".svg"; |
||||||
|
private static final String ICON_SUFFIX_PNG = ".png"; |
||||||
|
private static final String ICON_SUFFIX_GIF = ".gif"; |
||||||
|
private static final String SUFFIX_SEPARATOR = "."; |
||||||
|
|
||||||
|
public static final String ICON_TYPE_NORMAL= "_normal.svg"; |
||||||
|
public static final String ICON_TYPE_DISABLED= "_disabled.svg"; |
||||||
|
public static final String ICON_TYPE_PRESSED= "_pressed.svg"; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 可以读取SVG图标或者普通图标,并且可以读取不带扩展名的文件 |
||||||
|
* @param resource 图片路径 |
||||||
|
* @return 图标 |
||||||
|
*/ |
||||||
|
public static Icon readIcon(String resource) { |
||||||
|
// 判断是否有.XXX文件后缀
|
||||||
|
if (resource.contains(SUFFIX_SEPARATOR)) { |
||||||
|
// 判断是否以.svg结尾
|
||||||
|
if (resource.endsWith(ICON_SUFFIX_SVG)) { |
||||||
|
return SVGIcon.readSVGIcon(resource); |
||||||
|
} |
||||||
|
return IOUtils.readIcon(resource); |
||||||
|
} |
||||||
|
// 文件无后缀时
|
||||||
|
return readNoSuffixResource(resource, ICON_TYPE_NORMAL); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 尝试读取不带扩展名的图标,svg优先,其次png,最后gif,都没读到就打印错误日志,返回空白Icon |
||||||
|
* @param resource 图片路径 |
||||||
|
* @param svgIconType 针对svg来说的图标类型 |
||||||
|
* 取值为:ICON_TYPE_NORMAL、ICON_TYPE_DISABLED、ICON_TYPE_PRESSED |
||||||
|
* @return 图标 |
||||||
|
*/ |
||||||
|
private static Icon readNoSuffixResource(String resource, String svgIconType) { |
||||||
|
String svgPath = resource + svgIconType; |
||||||
|
if (IOUtils.readResource(svgPath) != null) { |
||||||
|
return SVGIcon.readSVGIcon(svgPath); |
||||||
|
} |
||||||
|
String pngPath = resource + ICON_SUFFIX_PNG; |
||||||
|
if (IOUtils.readResource(pngPath) != null) { |
||||||
|
return IOUtils.readIcon(pngPath); |
||||||
|
} |
||||||
|
String gifPath = resource + ICON_SUFFIX_GIF; |
||||||
|
if (IOUtils.readResource(gifPath) != null) { |
||||||
|
return IOUtils.readIcon(gifPath); |
||||||
|
} |
||||||
|
FineLoggerFactory.getLogger().error(resource + "对应文件不存在"); |
||||||
|
return new ImageIcon(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 读取指定类型的svgIcon |
||||||
|
* @param resource |
||||||
|
* @param svgIconType |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static Icon readSVGIcon(String resource, String svgIconType) { |
||||||
|
// 判断下是否有后缀
|
||||||
|
if (!resource.contains(SUFFIX_SEPARATOR)) { |
||||||
|
return readNoSuffixResource(resource, svgIconType); |
||||||
|
} |
||||||
|
// 如果是".png"后缀,就替换为传入的svgIconType,然后读取图标
|
||||||
|
if (resource.endsWith(ICON_SUFFIX_PNG)) { |
||||||
|
return readSpecifiedTypeIcon(resource, ICON_SUFFIX_PNG, svgIconType); |
||||||
|
} |
||||||
|
// 如果是"_XXXXXX.svg"后缀
|
||||||
|
if (resource.endsWith(ICON_TYPE_NORMAL)) { |
||||||
|
return readSpecifiedTypeIcon(resource, ICON_TYPE_NORMAL, svgIconType); |
||||||
|
} |
||||||
|
if (resource.endsWith(ICON_TYPE_DISABLED)) { |
||||||
|
return readSpecifiedTypeIcon(resource, ICON_TYPE_DISABLED, svgIconType); |
||||||
|
} |
||||||
|
if (resource.endsWith(ICON_TYPE_PRESSED)) { |
||||||
|
return readSpecifiedTypeIcon(resource, ICON_TYPE_PRESSED, svgIconType); |
||||||
|
} |
||||||
|
return readIcon(resource); |
||||||
|
} |
||||||
|
|
||||||
|
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 readIcon(resource); |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 288 B |
After Width: | Height: | Size: 530 B |
After Width: | Height: | Size: 167 B |
After Width: | Height: | Size: 433 B |
After Width: | Height: | Size: 286 B |
After Width: | Height: | Size: 208 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 791 B After Width: | Height: | Size: 791 B |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 761 B |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 768 B |
After Width: | Height: | Size: 761 B |
After Width: | Height: | Size: 766 B |
After Width: | Height: | Size: 693 B |
After Width: | Height: | Size: 678 B |
After Width: | Height: | Size: 742 B |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 562 B |
Before Width: | Height: | Size: 867 B After Width: | Height: | Size: 867 B |
After Width: | Height: | Size: 525 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 822 B |
After Width: | Height: | Size: 727 B |