diff --git a/src/main/java/com/ghostchu/peerbanhelper/BuildMeta.java b/src/main/java/com/ghostchu/peerbanhelper/BuildMeta.java index 199219521..32b5546b7 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/BuildMeta.java +++ b/src/main/java/com/ghostchu/peerbanhelper/BuildMeta.java @@ -22,7 +22,7 @@ public void loadBuildMeta(YamlConfiguration configuration) { this.commit = configuration.getString("git.commit.id.commit-id"); this.abbrev = configuration.getString("git.commit.id.abbrev"); this.os = System.getProperty("os.name"); - this.compileTime = configuration.getString("git.build.time"); + this.compileTime = configuration.getString("git.build.time", "Unknown"); } public boolean isSnapshotOrBeta() { diff --git a/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.form b/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.form index 15340b3ea..8b9ff8948 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.form +++ b/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.form @@ -22,7 +22,8 @@ - + + @@ -31,7 +32,9 @@ - + + + diff --git a/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.java b/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.java index 235074b4c..89fce9aa9 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.java +++ b/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/MainWindow.java @@ -68,7 +68,7 @@ public MainWindow(SwingGuiImpl swingGUI) { this.swingGUI = swingGUI; if (SystemInfo.isMacFullWindowContentSupported) getRootPane().putClientProperty("apple.awt.transparentTitleBar", true); - setTitle(tlUI(Lang.GUI_TITLE_LOADING, "Swing UI", Main.getMeta().getVersion(), Main.getMeta().getAbbrev())); + setTitle(tlUI(Lang.GUI_TITLE_LOADING, Main.getMeta().getVersion(), Main.getMeta().getAbbrev())); // max dimension size or 720p var maxAllowedWidth = Math.min(1280, Toolkit.getDefaultToolkit().getScreenSize().width); var maxAllowedHeight = Math.min(720, Toolkit.getDefaultToolkit().getScreenSize().height); @@ -91,6 +91,7 @@ public void windowClosing(WindowEvent e) { this.webuiTab = new WebUITab(this); } + public static void setTabTitle(JPanel tab, String title) { JTabbedPane tabbedPane = (JTabbedPane) SwingUtilities.getAncestorOfClass(JTabbedPane.class, tab); for (int tabIndex = 0; tabIndex < tabbedPane.getTabCount(); tabIndex++) { @@ -151,11 +152,14 @@ public void dispose() { tabbedPaneLogs.setLayout(new BorderLayout(0, 0)); tabbedPane.addTab("Logs", tabbedPaneLogs); loggerScrollPane = new JScrollPane(); - Font loggerScrollPaneFont = this.$$$getFont$$$("Consolas", -1, -1, loggerScrollPane.getFont()); + loggerScrollPane.setEnabled(true); + Font loggerScrollPaneFont = this.$$$getFont$$$(null, -1, -1, loggerScrollPane.getFont()); if (loggerScrollPaneFont != null) loggerScrollPane.setFont(loggerScrollPaneFont); loggerScrollPane.setVerticalScrollBarPolicy(22); tabbedPaneLogs.add(loggerScrollPane, BorderLayout.CENTER); loggerTextList = new JList(); + Font loggerTextListFont = UIManager.getFont("TextArea.font"); + if (loggerTextListFont != null) loggerTextList.setFont(loggerTextListFont); loggerScrollPane.setViewportView(loggerTextList); } @@ -184,6 +188,26 @@ public void dispose() { return mainPanel; } + /** @noinspection ALL */ + protected Font getFont(String fontName, int style, int size, Font currentFont) { + if (currentFont == null) return null; + String resultName; + if (fontName == null) { + resultName = currentFont.getName(); + } else { + Font testFont = new Font(fontName, Font.PLAIN, 10); + if (testFont.canDisplay('a') && testFont.canDisplay('1') && testFont.canDisplay('中')) { + resultName = fontName; + } else { + resultName = currentFont.getName(); + } + } + Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); + boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); + Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); + return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); + } + private void createUIComponents() { // TODO: place custom component creation code here @@ -317,11 +341,16 @@ private void deActiveBrowser(int tabPos) { * @param cefBrowser 显示开发者工具的浏览器 */ private void devToolsShow(CefBrowser cefBrowser) { + if (cefBrowser.getURL().startsWith("devtools://")) { + Thread.startVirtualThread(() -> parent.getSwingGUI().createDialog(Level.WARNING, "Cannot open devtools for a devtools page", "You cannot open PeerBanHelper devtools for a PeerBanHelper devtools page. (WHY YOU DO THAT? ARE YOU CRAZY?)")); + return; + } if (devToolsDialog_ != null) { devToolsDialog_.dispose(); } // 因为是开发者工具,不能影响内容页面的显示,所以单独新建一个窗体显示 - devToolsDialog_ = new JCEFSwingDevTools(new JFrame(), "PeerBanHelper WebUI DevTools", cefBrowser); + var title = "PeerBanHelper WebUI DevTools (" + app.getVersion().toString() + ")"; + devToolsDialog_ = new JCEFSwingDevTools(new JFrame(), title, cefBrowser); // devToolsDialog_ = new DevToolsDialog(owner_, "开发者工具", cefBrowser); var maxAllowedWidth = Math.min(1280, Toolkit.getDefaultToolkit().getScreenSize().width); var maxAllowedHeight = Math.min(720, Toolkit.getDefaultToolkit().getScreenSize().height); @@ -530,7 +559,7 @@ public LogsTab(MainWindow parent) { this.parent = parent; parent.loggerTextList.setModel(new DefaultListModel<>()); - parent.loggerTextList.setFont(new Font("微软雅黑", Font.PLAIN, 14)); + parent.loggerTextList.setFont(parent.loggerTextList.getFont().deriveFont(14f)); parent.loggerTextList.setCellRenderer(new LogEntryRenderer()); parent.loggerTextList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); parent.loggerTextList.setLayoutOrientation(JList.VERTICAL); diff --git a/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/SwingGuiImpl.java b/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/SwingGuiImpl.java index 34a3470b9..9c387222b 100644 --- a/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/SwingGuiImpl.java +++ b/src/main/java/com/ghostchu/peerbanhelper/gui/impl/swing/SwingGuiImpl.java @@ -26,10 +26,14 @@ import lombok.extern.slf4j.Slf4j; import javax.swing.*; +import javax.swing.plaf.FontUIResource; +import javax.swing.text.StyleContext; import java.awt.*; import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.Arrays; +import java.util.Enumeration; +import java.util.Locale; import java.util.StringJoiner; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -61,9 +65,19 @@ public SwingGuiImpl(String[] args) { } } + private void setUIFont(String fontName) { + Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + Object value = UIManager.get(key); + if (value instanceof FontUIResource fontUIResource) + UIManager.put(key, getFont(fontName, -1, -1, fontUIResource)); + } + } + private void updateGuiStuff() { StringBuilder builder = new StringBuilder(); - builder.append(tlUI(Lang.GUI_TITLE_LOADED, "Swing UI", Main.getMeta().getVersion(), Main.getMeta().getAbbrev())); + builder.append(tlUI(Lang.GUI_TITLE_LOADED, Main.getMeta().getVersion(), Main.getMeta().getAbbrev())); StringJoiner joiner = new StringJoiner("", " [", "]"); joiner.setEmptyValue(""); ExchangeMap.GUI_DISPLAY_FLAGS.forEach(flag -> joiner.add(flag.getContent())); @@ -166,6 +180,26 @@ public void applyLight() { } } + /** @noinspection ALL */ + private Font getFont(String fontName, int style, int size, Font currentFont) { + if (currentFont == null) return null; + String resultName; + if (fontName == null) { + resultName = currentFont.getName(); + } else { + Font testFont = new Font(fontName, Font.PLAIN, 10); + if (testFont.canDisplay('a') && testFont.canDisplay('1')) { + resultName = fontName; + } else { + resultName = currentFont.getName(); + } + } + Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); + boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); + Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); + return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); + } + @Override public void createMainWindow() { mainWindow = new MainWindow(this); @@ -281,7 +315,8 @@ public void createDialog(Level level, String title, String description) { if (Taskbar.isTaskbarSupported() && Taskbar.getTaskbar().isSupported(Taskbar.Feature.USER_ATTENTION_WINDOW)) { Taskbar.getTaskbar().requestWindowUserAttention(mainWindow); } - JOptionPane.showMessageDialog(null, description, title, msgType); + var finalMsgType = msgType; + SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null, description, title, finalMsgType)); } @Override diff --git a/src/main/resources/lang/en-us/messages.yml b/src/main/resources/lang/en-us/messages.yml index 633f33f52..b95c8938d 100644 --- a/src/main/resources/lang/en-us/messages.yml +++ b/src/main/resources/lang/en-us/messages.yml @@ -191,8 +191,8 @@ WEBAPI_INTERNAL_ERROR: "An internal server error occurred while processing the W GITHUB_PAGE: "https://github.com/PBH-BTN/PeerBanHelper" GUI_COPY_TO_CLIPBOARD_TITLE: "Copy to clipboard" GUI_COPY_TO_CLIPBOARD_DESCRIPTION: "Successfully copied to system clipboard: \n{}" -GUI_TITLE_LOADING: "PeerBanHelper ({}) - Loading, please wait..." -GUI_TITLE_LOADED: "PeerBanHelper ({}) - {} ({})" +GUI_TITLE_LOADING: "PeerBanHelper - Loading, please wait..." +GUI_TITLE_LOADED: "PeerBanHelper - {} ({})" WEBVIEW_DISABLED_WEBKIT_NOT_INCLUDED: "JavaFx Web module not found, you are using a lightweight build, WebUI tab not enabled" WEBVIEW_ENABLED: "JavaFx Web found, WebUI tab enabled" STATUS_TEXT_OK: "Currently working normally" diff --git a/src/main/resources/lang/messages_fallback.yml b/src/main/resources/lang/messages_fallback.yml index 319e9d5d5..0df0ba844 100644 --- a/src/main/resources/lang/messages_fallback.yml +++ b/src/main/resources/lang/messages_fallback.yml @@ -191,8 +191,8 @@ WEBAPI_INTERNAL_ERROR: "处理 WebAPI 请求时出现了一个内部服务器错 GITHUB_PAGE: "https://github.com/PBH-BTN/PeerBanHelper" GUI_COPY_TO_CLIPBOARD_TITLE: "复制到剪贴板" GUI_COPY_TO_CLIPBOARD_DESCRIPTION: "已成功复制到系统剪贴板: \n{}" -GUI_TITLE_LOADING: "PeerBanHelper ({}) - 正在加载,请稍候..." -GUI_TITLE_LOADED: "PeerBanHelper ({}) - {} ({})" +GUI_TITLE_LOADING: "PeerBanHelper - 正在加载,请稍候..." +GUI_TITLE_LOADED: "PeerBanHelper - {} ({})" WEBVIEW_DISABLED_WEBKIT_NOT_INCLUDED: "未找到 JavaFx Web 模块,您正在使用精简构建,WebUI 选项卡未启用" WEBVIEW_ENABLED: "已找到 JavaFx Web,WebUI 选项卡已启用" STATUS_TEXT_OK: "当前工作正常" diff --git a/src/main/resources/lang/zh-cn/messages.yml b/src/main/resources/lang/zh-cn/messages.yml index 1301c2e47..e58509dec 100644 --- a/src/main/resources/lang/zh-cn/messages.yml +++ b/src/main/resources/lang/zh-cn/messages.yml @@ -192,8 +192,8 @@ WEBAPI_INTERNAL_ERROR: "处理 WebAPI 请求时出现了一个内部服务器错 GITHUB_PAGE: "https://github.com/PBH-BTN/PeerBanHelper" GUI_COPY_TO_CLIPBOARD_TITLE: "复制到剪贴板" GUI_COPY_TO_CLIPBOARD_DESCRIPTION: "已成功复制到系统剪贴板: \n{}" -GUI_TITLE_LOADING: "PeerBanHelper ({}) - 正在加载,请稍候..." -GUI_TITLE_LOADED: "PeerBanHelper ({}) - {} ({})" +GUI_TITLE_LOADING: "PeerBanHelper - 正在加载,请稍候..." +GUI_TITLE_LOADED: "PeerBanHelper - {} ({})" WEBVIEW_DISABLED_WEBKIT_NOT_INCLUDED: "未找到 JavaFx Web 模块,您正在使用精简构建,WebUI 选项卡未启用" WEBVIEW_ENABLED: "已找到 JavaFx Web,WebUI 选项卡已启用" STATUS_TEXT_OK: "当前工作正常"