refactor(window): 重构窗口相关代码并优化主题设置
-将 gui 包名改为 window,统一窗口相关代码 - 在 RegistrationTopic 中添加 isDarkMode 方法判断主题是否为暗黑模式 - 在 WindowsJDialog 中添加 isTopicDarkMode 方法检测当前主题 - 优化 AxisInnovatorsBox 中的主题注册和设置逻辑 - 更新相关类和方法以适应新的包结构和主题设置逻辑
This commit is contained in:
@@ -3,7 +3,7 @@ package com.axis.innovators.box;
|
||||
import com.axis.innovators.box.events.GlobalEventBus;
|
||||
import com.axis.innovators.box.events.OpenFileEvents;
|
||||
import com.axis.innovators.box.events.StartupEvent;
|
||||
import com.axis.innovators.box.gui.*;
|
||||
import com.axis.innovators.box.window.*;
|
||||
import com.axis.innovators.box.plugins.PluginDescriptor;
|
||||
import com.axis.innovators.box.plugins.PluginLoader;
|
||||
import com.axis.innovators.box.plugins.PluginPyLoader;
|
||||
@@ -16,8 +16,6 @@ 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.verification.UserTags;
|
||||
import com.formdev.flatlaf.FlatDarkLaf;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
|
||||
import com.formdev.flatlaf.themes.FlatMacLightLaf;
|
||||
import com.sun.management.HotSpotDiagnosticMXBean;
|
||||
@@ -726,25 +724,28 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("default_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("default_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:default_theme"
|
||||
"system:default_theme",
|
||||
isDarkMode // 检测系统当前是否为暗黑模式
|
||||
);
|
||||
|
||||
// 2. Metal (Java默认主题)
|
||||
// 2. Metal (Java默认主题) - 浅色主题
|
||||
main.registrationTopic.addTopic(
|
||||
"javax.swing.plaf.metal.MetalLookAndFeel",
|
||||
LanguageManager.getLoadedLanguages().getText("metal_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("metal_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:metal_theme"
|
||||
"system:metal_theme",
|
||||
false
|
||||
);
|
||||
|
||||
// 3. Motif (UNIX风格)
|
||||
// 3. Motif (UNIX风格) - 通常为浅色主题
|
||||
main.registrationTopic.addTopic(
|
||||
"com.sun.java.swing.plaf.motif.MotifLookAndFeel",
|
||||
LanguageManager.getLoadedLanguages().getText("motif_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("motif_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:motif_theme"
|
||||
"system:motif_theme",
|
||||
false
|
||||
);
|
||||
|
||||
// 4. FlatLaf 主题注册
|
||||
@@ -754,7 +755,8 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("flatLight_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("flatLight_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:flatLight_theme"
|
||||
"system:flatLight_theme",
|
||||
false
|
||||
);
|
||||
|
||||
// 4.2 FlatDark (默认深色)
|
||||
@@ -763,7 +765,8 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("flatDark_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("flatDark_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:flatDark_theme"
|
||||
"system:flatDark_theme",
|
||||
true
|
||||
);
|
||||
|
||||
// 4.3 FlatIntelliJ (类似IDEA浅色)
|
||||
@@ -772,7 +775,8 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("flatIntelliJ_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("flatIntelliJ_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:flatIntelliJ_theme"
|
||||
"system:flatIntelliJ_theme",
|
||||
false
|
||||
);
|
||||
|
||||
// 4.4 FlatDarcula (类似IDEA深色)
|
||||
@@ -781,7 +785,8 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("flatDarcula_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("flatDarcula_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:flatDarcula_theme"
|
||||
"system:flatDarcula_theme",
|
||||
true
|
||||
);
|
||||
|
||||
// 4.5 FlatMacLight (macOS风格浅色)
|
||||
@@ -790,7 +795,8 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("flatMacLight_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("flatMacLight_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:flatMacLight_theme"
|
||||
"system:flatMacLight_theme",
|
||||
false
|
||||
);
|
||||
|
||||
// 4.6 FlatMacDark (macOS风格深色)
|
||||
@@ -799,7 +805,8 @@ public class AxisInnovatorsBox {
|
||||
LanguageManager.getLoadedLanguages().getText("flatMacDark_theme.system.topicName"),
|
||||
LanguageManager.getLoadedLanguages().getText("flatMacDark_theme.default.tip"),
|
||||
LoadIcon.loadIcon(MainWindow.class, "logo.png", 64),
|
||||
"system:flatMacDark_theme"
|
||||
"system:flatMacDark_theme",
|
||||
true
|
||||
);
|
||||
|
||||
LookAndFeel defaultLaf = isDarkMode ? new FlatMacDarkLaf() : new FlatMacLightLaf();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.axis.innovators.box.decompilation.gui;
|
||||
|
||||
import com.axis.innovators.box.gui.LoadIcon;
|
||||
import com.axis.innovators.box.window.LoadIcon;
|
||||
import com.axis.innovators.box.util.AdvancedJFileChooser;
|
||||
import com.github.javaparser.JavaParser;
|
||||
import com.github.javaparser.ParseResult;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.axis.innovators.box.events;
|
||||
|
||||
import com.axis.innovators.box.gui.MainWindow;
|
||||
import com.axis.innovators.box.window.MainWindow;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.axis.innovators.box.events;
|
||||
|
||||
import com.axis.innovators.box.gui.WindowsJDialog;
|
||||
import com.axis.innovators.box.window.WindowsJDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.axis.innovators.box.python;
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
import com.axis.innovators.box.gui.MainWindow;
|
||||
import com.axis.innovators.box.window.MainWindow;
|
||||
import com.axis.innovators.box.register.LanguageManager;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.axis.innovators.box.register;
|
||||
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
import com.axis.innovators.box.gui.LoadIcon;
|
||||
import com.axis.innovators.box.gui.WindowsJDialog;
|
||||
import com.axis.innovators.box.window.LoadIcon;
|
||||
import com.axis.innovators.box.window.WindowsJDialog;
|
||||
import com.axis.innovators.box.plugins.PluginDescriptor;
|
||||
import com.axis.innovators.box.plugins.PluginLoader;
|
||||
import com.axis.innovators.box.plugins.PluginPyLoader;
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.axis.innovators.box.register;
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
import com.axis.innovators.box.browser.MainApplication;
|
||||
import com.axis.innovators.box.gui.FridaWindow;
|
||||
import com.axis.innovators.box.gui.JarApiProfilingWindow;
|
||||
import com.axis.innovators.box.gui.MainWindow;
|
||||
import com.axis.innovators.box.window.FridaWindow;
|
||||
import com.axis.innovators.box.window.JarApiProfilingWindow;
|
||||
import com.axis.innovators.box.window.MainWindow;
|
||||
import com.axis.innovators.box.plugins.PluginDescriptor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -28,6 +28,7 @@ public class RegistrationTopic {
|
||||
private final List<LookAndFeel> topicsClassesLookAndFeel = new ArrayList<>();
|
||||
private final List<String> topicsName = new ArrayList<>();
|
||||
private final List<String> registeredNameList = new ArrayList<>();
|
||||
private final List<Boolean> isDarkModeList = new ArrayList<>();
|
||||
private final List<Icon> iconList = new ArrayList<>();
|
||||
private final List<String> tipList = new ArrayList<>();
|
||||
private final AxisInnovatorsBox axisInnovatorsBox;
|
||||
@@ -52,7 +53,7 @@ public class RegistrationTopic {
|
||||
* @param registeredName 主题注册名
|
||||
* @throws RegistrationError 如果注册名已存在,则抛出异常
|
||||
*/
|
||||
public void addTopic(String topicClass, String topicName, String tip ,Icon icon, String registeredName) {
|
||||
public void addTopic(String topicClass, String topicName, String tip ,Icon icon, String registeredName, boolean isDarkMode) {
|
||||
if (!axisInnovatorsBox.isWindow()) {
|
||||
if (registeredNameList.contains(registeredName)) {
|
||||
throw new RegistrationError(registeredName + " duplicate registered names");
|
||||
@@ -63,6 +64,7 @@ public class RegistrationTopic {
|
||||
tipList.add(tip);
|
||||
iconList.add(icon);
|
||||
registeredNameList.add(registeredName);
|
||||
isDarkModeList.add(isDarkMode);
|
||||
} else {
|
||||
logger.warn("Wrong time to add topics");
|
||||
}
|
||||
@@ -78,7 +80,7 @@ public class RegistrationTopic {
|
||||
* @param registeredName 主题注册名
|
||||
* @throws RegistrationError 如果注册名已存在,则抛出异常
|
||||
*/
|
||||
public void addTopic(LookAndFeel topicClass, String topicName, String tip ,Icon icon, String registeredName) {
|
||||
public void addTopic(LookAndFeel topicClass, String topicName, String tip ,Icon icon, String registeredName, boolean isDarkMode) {
|
||||
if (!axisInnovatorsBox.isWindow()) {
|
||||
if (registeredNameList.contains(registeredName)) {
|
||||
throw new RegistrationError(registeredName + " duplicate registered names");
|
||||
@@ -89,6 +91,7 @@ public class RegistrationTopic {
|
||||
tipList.add(tip);
|
||||
iconList.add(icon);
|
||||
registeredNameList.add(registeredName);
|
||||
isDarkModeList.add(isDarkMode);
|
||||
} else {
|
||||
logger.warn("Wrong time to add topics");
|
||||
}
|
||||
@@ -107,6 +110,23 @@ public class RegistrationTopic {
|
||||
return Objects.equals(loading, loadTopics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前加载的主题是否是暗黑模式
|
||||
* @return true 如果是暗黑模式,false 如果是浅色模式
|
||||
*/
|
||||
public boolean isDarkMode() {
|
||||
if (loadTopics.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = registeredNameList.indexOf(loadTopics);
|
||||
if (index >= 0 && index < isDarkModeList.size()) {
|
||||
return isDarkModeList.get(index);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前加载的主题。
|
||||
*
|
||||
|
||||
@@ -37,13 +37,10 @@ public class SystemInfoUtil {
|
||||
*/
|
||||
public static boolean isSystemDarkMode() {
|
||||
try {
|
||||
// macOS 检测
|
||||
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
|
||||
// 通过 Apple 脚本检测 macOS 深色模式
|
||||
Process process = Runtime.getRuntime().exec("defaults read -g AppleInterfaceStyle");
|
||||
return process.waitFor() == 0; // 命令成功返回表示深色模式
|
||||
}
|
||||
// Windows 检测 (Windows 10/11)
|
||||
else if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
String cmd = "reg query HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize "
|
||||
+ "/v AppsUseLightTheme";
|
||||
@@ -52,11 +49,10 @@ public class SystemInfoUtil {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.contains("REG_DWORD") && line.contains("0x0")) {
|
||||
return true; // 0x0 表示深色模式
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Linux (GNOME) 检测
|
||||
else if (System.getenv("XDG_CURRENT_DESKTOP") != null
|
||||
&& System.getenv("XDG_CURRENT_DESKTOP").toLowerCase().contains("gnome")) {
|
||||
Process process = Runtime.getRuntime().exec("gsettings get org.gnome.desktop.interface color-scheme");
|
||||
@@ -67,7 +63,7 @@ public class SystemInfoUtil {
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to detect system dark mode", e);
|
||||
}
|
||||
return false; // 默认浅色模式
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.axis.innovators.box.util;
|
||||
|
||||
import com.axis.innovators.box.gui.JarApiProfilingWindow;
|
||||
import com.axis.innovators.box.window.JarApiProfilingWindow;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
import org.tzd.debug.ClassDebug;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import org.fife.ui.autocomplete.BasicCompletion;
|
||||
import org.fife.ui.autocomplete.DefaultCompletionProvider;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.gui.renderer.DarculaCompletionCellRenderer;
|
||||
import com.axis.innovators.box.window.renderer.DarculaCompletionCellRenderer;
|
||||
import com.axis.innovators.box.util.AdvancedJFileChooser;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.decompilation.gui.JavaPseudocodeGenerator;
|
||||
import com.axis.innovators.box.util.AdvancedJFileChooser;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.verification.OnlineVerification;
|
||||
import com.axis.innovators.box.verification.UserTags;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
import com.axis.innovators.box.events.*;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import org.tzd.debug.ClassDebug;
|
||||
import org.tzd.debug.GetInstance;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.axis.innovators.box.gui;
|
||||
package com.axis.innovators.box.window;
|
||||
|
||||
import com.axis.innovators.box.AxisInnovatorsBox;
|
||||
import com.axis.innovators.box.register.LanguageManager;
|
||||
import com.axis.innovators.box.register.RegistrationTopic;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -9,6 +10,7 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
/**
|
||||
* 窗口
|
||||
* @author tzdwindows 7
|
||||
*/
|
||||
public class WindowsJDialog extends JDialog {
|
||||
@@ -48,4 +50,14 @@ public class WindowsJDialog extends JDialog {
|
||||
AxisInnovatorsBox.getMain().clearWindow(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测当前窗口的主题是否处于暗黑模式
|
||||
* @return true 处于暗黑模式,false 处于浅色模式
|
||||
*/
|
||||
public boolean isTopicDarkMode(){
|
||||
AxisInnovatorsBox axisInnovatorsBox = AxisInnovatorsBox.getMain();
|
||||
RegistrationTopic registrationTopic = axisInnovatorsBox.getRegistrationTopic();
|
||||
return registrationTopic.isDarkMode();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.axis.innovators.box.gui.renderer;
|
||||
package com.axis.innovators.box.window.renderer;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.AbstractBorder;
|
||||
Reference in New Issue
Block a user