perf:优化图片加载方法并支持插件自定义图标

- 修改了 LoadIcon 类,增加了通用的 loadIcon 方法和插件专用的 pluginsLoadIcon 方法
-优化了图片加载逻辑,能够根据不同的类加载资源
- 在 LM 类中将 CUDA 默认值改为 false,提高了代码的可维护性
This commit is contained in:
tzdwindows 7
2025-02-10 23:18:41 +08:00
parent 4387f32f70
commit fcc4115638
3 changed files with 38 additions and 6 deletions

View File

@@ -102,8 +102,6 @@ public class Main {
event.content().add(placeholder, BorderLayout.CENTER);
}
public static void main(String[] args) {
main = new Main(args);
// 注册事件

View File

@@ -1,5 +1,7 @@
package com.axis.innovators.box.gui;
import com.axis.innovators.box.plugins.PluginDescriptor;
import com.axis.innovators.box.plugins.PluginLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -15,10 +17,42 @@ import java.net.URL;
public class LoadIcon {
private static final Logger logger = LogManager.getLogger(LoadIcon.class);
private static final String ICON_PATH = "/icons/";
public static ImageIcon loadIcon(String filename, int size) {
/**
* 加载图片
* @param filename 图片名
* @param size 图片大小
* @return ImageIcon对象
*/
static ImageIcon loadIcon(String filename, int size) {
return loadIcon(LoadIcon.class, filename, size);
}
/**
* 专门留给插件的加载图片方法
* @param filename 图片在resources中的位置
* @param size 图片大小
* @return ImageIcon对象
*/
public static ImageIcon pluginsLoadIcon(String filename, int size) {
for (int i = 0; i < PluginLoader.getLoadedPlugins().size(); i++) {
PluginDescriptor plugin = PluginLoader.getLoadedPlugins().get(i);
return loadIcon(plugin.getInstance().getClass(), filename, size);
}
return null;
}
/**
* 加载图片
* @param clazz resources包所在的jar
* @param filename 图片名
* @param size 图片大小
* @return ImageIcon对象
*/
public static ImageIcon loadIcon(Class<?> clazz ,String filename, int size) {
try {
String fullPath = ICON_PATH + filename;
URL imgUrl = LoadIcon.class.getResource(fullPath);
URL imgUrl = clazz.getResource(fullPath);
if (imgUrl == null) {
return createPlaceholderIcon(size);
}

View File

@@ -10,7 +10,7 @@ import org.apache.logging.log4j.Logger;
* @author tzdwindows 7
*/
public class LM {
public static boolean CUDA = true;
public static boolean CUDA = false;
public final static String DEEP_SEEK = FolderCreator.getModelFolder() + "\\DeepSeek-R1-Distill-Qwen-1.5B-Q8_0.gguf";
private static final Logger logger = LogManager.getLogger(LM.class);
@@ -31,7 +31,7 @@ public class LM {
LibraryLoad.loadLibrary("cuda/ggml");
LibraryLoad.loadLibrary("cuda/llama");
} catch (Exception e) {
logger.error("Wrong cuda Settings", e);
CUDA = false;
logger.warn("The cuda library could not be loaded, the cpu will be used for inference");
LibraryLoad.loadLibrary("cpu/ggml-base");
LibraryLoad.loadLibrary("cpu/ggml-cpu");