feat(util): 添加托盘工具类并初始化托盘
- 新增 Tray 类用于加载默认托盘系统 - 在主程序启动时初始化托盘 - 托盘包含以下功能: - 显示主窗口 - 启动 Jar 查看器 - 启动 HTML 查看器 - 退出程序 - 优化了 RegisterTray 类,增加 addItem 方法支持动态添加菜单项
This commit is contained in:
1
.idea/encodings.xml
generated
1
.idea/encodings.xml
generated
@@ -3,6 +3,7 @@
|
|||||||
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="GBK">
|
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="GBK">
|
||||||
<file url="file://$PROJECT_DIR$/language" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/language" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/plug-in/python/Testing/main.py" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/plug-in/python/Testing/main.py" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/Cpp/LM/org_tzd_lm_LM.cpp" charset="GBK" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java/com/axis/innovators/box/gui/FridaWindow.java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/main/java/com/axis/innovators/box/gui/FridaWindow.java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java/org/tzd/lm/LM.java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/main/java/org/tzd/lm/LM.java" charset="UTF-8" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java/org/tzd/lm/LMApi.java" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/src/main/java/org/tzd/lm/LMApi.java" charset="UTF-8" />
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@@ -12,11 +12,9 @@ import com.axis.innovators.box.register.RegistrationSettingsItem;
|
|||||||
import com.axis.innovators.box.register.RegistrationTool;
|
import com.axis.innovators.box.register.RegistrationTool;
|
||||||
import com.axis.innovators.box.register.RegistrationTopic;
|
import com.axis.innovators.box.register.RegistrationTopic;
|
||||||
import com.axis.innovators.box.register.LanguageManager;
|
import com.axis.innovators.box.register.LanguageManager;
|
||||||
import com.axis.innovators.box.tools.ArgsParser;
|
import com.axis.innovators.box.tools.*;
|
||||||
import com.axis.innovators.box.tools.LibraryLoad;
|
|
||||||
import com.axis.innovators.box.tools.StateManager;
|
|
||||||
import com.axis.innovators.box.tools.SystemInfoUtil;
|
|
||||||
import com.axis.innovators.box.util.PythonResult;
|
import com.axis.innovators.box.util.PythonResult;
|
||||||
|
import com.axis.innovators.box.util.Tray;
|
||||||
import com.axis.innovators.box.util.UserLocalInformation;
|
import com.axis.innovators.box.util.UserLocalInformation;
|
||||||
import com.axis.innovators.box.verification.UserTags;
|
import com.axis.innovators.box.verification.UserTags;
|
||||||
import com.formdev.flatlaf.FlatLightLaf;
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
@@ -380,6 +378,14 @@ public class AxisInnovatorsBox {
|
|||||||
|
|
||||||
main.progressBarManager.close();
|
main.progressBarManager.close();
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Tray.init();
|
||||||
|
} catch (RegisterTray.TrayException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}, "TrayThread").start();
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
main.ex = new MainWindow();
|
main.ex = new MainWindow();
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ModernJarViewer extends JFrame {
|
|||||||
|
|
||||||
public ModernJarViewer(Frame owner) {
|
public ModernJarViewer(Frame owner) {
|
||||||
setTitle("Jar反编译工具");
|
setTitle("Jar反编译工具");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
initComponents();
|
initComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class RegisterTray {
|
|||||||
* 托盘菜单项构建器(流畅接口)
|
* 托盘菜单项构建器(流畅接口)
|
||||||
*/
|
*/
|
||||||
public static class MenuBuilder {
|
public static class MenuBuilder {
|
||||||
private final List<Item> items = new ArrayList<>();
|
private List<Item> items = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加菜单项
|
* 添加菜单项
|
||||||
@@ -42,6 +42,27 @@ public class RegisterTray {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加菜单项
|
||||||
|
* @param id 菜单项唯一标识符(需大于0)
|
||||||
|
* @param label 菜单显示文本
|
||||||
|
* @param onClick 点击事件处理器
|
||||||
|
* @return 当前构建器实例
|
||||||
|
*/
|
||||||
|
public MenuBuilder addItem(MenuBuilder builder,int id, String label, MenuItemClickListener onClick) {
|
||||||
|
this.items = builder.items;
|
||||||
|
items.add(new Item(
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
"", "", "",
|
||||||
|
(Event) combinedId -> {
|
||||||
|
int itemId = (int)(combinedId >> 32);
|
||||||
|
onClick.onClick(itemId);
|
||||||
|
}
|
||||||
|
));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建菜单项列表
|
* 构建菜单项列表
|
||||||
* @return 可用于注册的菜单项集合
|
* @return 可用于注册的菜单项集合
|
||||||
@@ -219,15 +240,11 @@ public class RegisterTray {
|
|||||||
.register();
|
.register();
|
||||||
|
|
||||||
// 程序主循环
|
// 程序主循环
|
||||||
while (true) {
|
//while (true) {
|
||||||
Thread.sleep(1000);
|
// Thread.sleep(1000);
|
||||||
}
|
//}
|
||||||
} catch (RegisterTray.TrayException | InterruptedException e) {
|
} catch (RegisterTray.TrayException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//static {
|
|
||||||
// System.loadLibrary("RegisterTray");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
128
src/main/java/com/axis/innovators/box/util/Tray.java
Normal file
128
src/main/java/com/axis/innovators/box/util/Tray.java
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package com.axis.innovators.box.util;
|
||||||
|
|
||||||
|
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||||
|
import com.axis.innovators.box.browser.MainApplication;
|
||||||
|
import com.axis.innovators.box.decompilation.gui.ModernJarViewer;
|
||||||
|
import com.axis.innovators.box.tools.RegisterTray;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载默认托盘系统
|
||||||
|
* @author tzdwindows 7
|
||||||
|
*/
|
||||||
|
public class Tray {
|
||||||
|
private static final Random random = new Random();
|
||||||
|
private static final String trayName = "轴创工具箱 v1.1";
|
||||||
|
private static final String trayDescription = "轴创工具箱";
|
||||||
|
private static final String trayIcon =System.getProperty("user.dir") + "/logo.ico";
|
||||||
|
private static List<RegisterTray.Item> menuItems = null;
|
||||||
|
private static final List<Integer> idx = new ArrayList<>();
|
||||||
|
private static final List<TrayLabels> trayLabelsList = new ArrayList<>();
|
||||||
|
private static final List<Runnable> actions = new ArrayList<>();
|
||||||
|
private static RegisterTray.MenuBuilder menuBuilders = null;
|
||||||
|
private static long trayAddress = -1;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
actions.add(() -> {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
AxisInnovatorsBox.getMain().getMainWindow().setVisible(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
load(new TrayLabels("启动 Jar 查看器", () -> SwingUtilities.invokeLater(() -> {
|
||||||
|
ModernJarViewer viewer = new ModernJarViewer(null);
|
||||||
|
viewer.setVisible(true);
|
||||||
|
})));
|
||||||
|
|
||||||
|
load(new TrayLabels("启动 HTML 查看器", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
MainApplication.popupHTMLWindow("");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
load(new TrayLabels("退出程序", () -> AxisInnovatorsBox.getMain().quit()));
|
||||||
|
} catch (RegisterTray.TrayException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册加载托盘
|
||||||
|
* @param trayLabels 托盘信息
|
||||||
|
* @throws RegisterTray.TrayException 抛出错误
|
||||||
|
*/
|
||||||
|
public static void load(TrayLabels trayLabels) throws RegisterTray.TrayException {
|
||||||
|
if (trayLabels == null || trayLabelsList.contains(trayLabels)){
|
||||||
|
System.err.println("trayLabels is null or trayLabelsList contains trayLabels");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
trayLabelsList.add(trayLabels);
|
||||||
|
|
||||||
|
if (menuBuilders == null) {
|
||||||
|
RegisterTray.MenuBuilder menuBuilder = new RegisterTray.MenuBuilder()
|
||||||
|
.addItem(trayLabels.id, trayLabels.name, itemId -> trayLabels.action.run());
|
||||||
|
menuBuilders = menuBuilder;
|
||||||
|
menuItems = menuBuilder.build();
|
||||||
|
} else {
|
||||||
|
menuBuilders = new RegisterTray.MenuBuilder()
|
||||||
|
.addItem(menuBuilders, trayLabels.id, trayLabels.name, itemId -> trayLabels.action.run());
|
||||||
|
menuItems = menuBuilders.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addAction(Runnable action){
|
||||||
|
actions.add(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() throws RegisterTray.TrayException {
|
||||||
|
//if (trayAddress == -1) {
|
||||||
|
trayAddress = new RegisterTray.TrayConfig()
|
||||||
|
.title(trayName)
|
||||||
|
.icon(trayIcon)
|
||||||
|
.tooltip(trayDescription)
|
||||||
|
.menu(menuItems)
|
||||||
|
.onClick(trayId -> {
|
||||||
|
for (Runnable action : actions) {
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.register();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TrayLabels {
|
||||||
|
private final String name;
|
||||||
|
//private final String description;
|
||||||
|
private final Runnable action;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
public TrayLabels(String name/*, String description*/, Runnable action) {
|
||||||
|
this.name = name;
|
||||||
|
//this.description = description;
|
||||||
|
this.action = action;
|
||||||
|
this.id = getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取随机id
|
||||||
|
* @return 获取随机id
|
||||||
|
*/
|
||||||
|
public static int getId(){
|
||||||
|
int id = random.nextInt();
|
||||||
|
if(idx.contains(id)){
|
||||||
|
return getId();
|
||||||
|
}
|
||||||
|
idx.add(id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user