refactor(show): 优化图标加载逻辑
- 优先从类路径资源中加载图标 - 如果类路径资源中不存在,再从外部路径加载图标 - 增加日志输出,方便调试- 更新项目版本号至 0.1.6.2
This commit is contained in:
parent
a0edae2137
commit
0bd6f83a44
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>org.aohe</groupId>
|
||||
<artifactId>twain-service</artifactId>
|
||||
<version>0.1.6.1</version>
|
||||
<version>0.1.6.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.aohe.show;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -9,11 +10,18 @@ import java.awt.*;
|
|||
@Slf4j
|
||||
public class IconUtil {
|
||||
public static Image getIcon() {
|
||||
String iconPath = "ah.png";
|
||||
ClassPathResource resource = new ClassPathResource("ah.png");
|
||||
if(FileUtil.exist(resource.getFile())){
|
||||
return Toolkit.getDefaultToolkit().getImage(resource.getPath());
|
||||
}
|
||||
String iconPath = "..\\ah.png";
|
||||
log.info("当前查找路径为外部:{}", FileUtil.getAbsolutePath(iconPath));
|
||||
if(!FileUtil.exist("ah.png")){
|
||||
iconPath = ResourceUtil.getResource("ah.png").getFile();
|
||||
log.info("当前查找路径为内部:{}", FileUtil.getAbsolutePath(iconPath));
|
||||
}
|
||||
log.info("当前查找路径为:{}", FileUtil.getAbsolutePath(iconPath));
|
||||
return Toolkit.getDefaultToolkit().getImage(FileUtil.getAbsolutePath(iconPath));
|
||||
|
||||
|
||||
return Toolkit.getDefaultToolkit().getImage(iconPath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue