From e3205930851155650b06e3427c35378da691a0e2 Mon Sep 17 00:00:00 2001 From: litwak913 Date: Fri, 8 Nov 2024 23:52:55 +0800 Subject: [PATCH 1/4] feat: tray lookandfeel --- core/src/cn/harryh/arkpets/tray/HostTray.java | 3 +++ core/src/cn/harryh/arkpets/tray/MemberTray.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/src/cn/harryh/arkpets/tray/HostTray.java b/core/src/cn/harryh/arkpets/tray/HostTray.java index 4c342c3b..6c8c6cd6 100644 --- a/core/src/cn/harryh/arkpets/tray/HostTray.java +++ b/core/src/cn/harryh/arkpets/tray/HostTray.java @@ -32,6 +32,9 @@ public class HostTray { private static HostTray instance; static { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception ignored) {} Const.FontsConfig.loadFontsToSwing(); } diff --git a/core/src/cn/harryh/arkpets/tray/MemberTray.java b/core/src/cn/harryh/arkpets/tray/MemberTray.java index 1ebb6153..7e8de110 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTray.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTray.java @@ -21,6 +21,9 @@ public abstract class MemberTray { protected final String name; static { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception ignored) {} Const.FontsConfig.loadFontsToSwing(); } From c61b78a5f5a67c0a3f63274aaa4cf83d62dd74e0 Mon Sep 17 00:00:00 2001 From: litwak913 Date: Sun, 10 Nov 2024 02:17:11 +0800 Subject: [PATCH 2/4] fix: tray left space and thread --- core/src/cn/harryh/arkpets/tray/HostTray.java | 16 +++++++++++--- .../cn/harryh/arkpets/tray/MemberTray.java | 22 ++++++++++++++++--- .../harryh/arkpets/tray/MemberTrayImpl.java | 2 ++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/core/src/cn/harryh/arkpets/tray/HostTray.java b/core/src/cn/harryh/arkpets/tray/HostTray.java index 6c8c6cd6..a2922c70 100644 --- a/core/src/cn/harryh/arkpets/tray/HostTray.java +++ b/core/src/cn/harryh/arkpets/tray/HostTray.java @@ -32,9 +32,17 @@ public class HostTray { private static HostTray instance; static { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception ignored) {} + // Avoid AWT Thread problem. + SwingUtilities.invokeLater(() -> { + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + if (laf.contains("WindowsLookAndFeel")) { + UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); + UIManager.put("Menu.margin",new Insets(2,-15,2,2)); + } + } catch (Exception ignored) {} + }); Const.FontsConfig.loadFontsToSwing(); } @@ -90,6 +98,8 @@ public void mouseClicked(MouseEvent e) { showStage(); } }); + SwingUtilities.updateComponentTreeUI(popMenu); + popMenu.pack(); } else { Logger.error("HostTray", "Tray is not supported."); } diff --git a/core/src/cn/harryh/arkpets/tray/MemberTray.java b/core/src/cn/harryh/arkpets/tray/MemberTray.java index 7e8de110..d243bb10 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTray.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTray.java @@ -7,6 +7,7 @@ import cn.harryh.arkpets.concurrent.SocketData; import javax.swing.*; +import java.awt.*; import java.util.UUID; @@ -21,9 +22,17 @@ public abstract class MemberTray { protected final String name; static { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception ignored) {} + // Avoid AWT Thread problem. + SwingUtilities.invokeLater(() -> { + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + if (laf.contains("WindowsLookAndFeel")) { + UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); + UIManager.put("Menu.margin",new Insets(2,-15,2,2)); + } + } catch (Exception ignored) {} + }); Const.FontsConfig.loadFontsToSwing(); } @@ -47,6 +56,13 @@ public MemberTray(String name) { optTransparentDis .addActionListener(e -> sendOperation(SocketData.Operation.NO_TRANSPARENT_MODE)); optChangeStage .addActionListener(e -> sendOperation(SocketData.Operation.CHANGE_STAGE)); optExit .addActionListener(e -> sendOperation(SocketData.Operation.LOGOUT)); + + optKeepAnimEn .setIcon(null); + optKeepAnimDis .setIcon(null); + optTransparentEn .setIcon(null); + optTransparentDis .setIcon(null); + optChangeStage .setIcon(null); + optExit .setIcon(null); } abstract public void onExit(); diff --git a/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java b/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java index 98bb4293..144b8ede 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java @@ -69,6 +69,8 @@ public void firePopupMenuWillBecomeInvisible() { onDisconnected(); client.connectWithRetry(onConnected, session); } + SwingUtilities.updateComponentTreeUI(popMenu); + popMenu.pack(); } private static String getName(ArkPets boundArkPets) { From 4e452a16e0d3adea292d981e255eeb34cb8f995d Mon Sep 17 00:00:00 2001 From: litwak913 Date: Sun, 10 Nov 2024 09:27:04 +0800 Subject: [PATCH 3/4] fix: laf order --- core/src/cn/harryh/arkpets/tray/HostTray.java | 2 +- core/src/cn/harryh/arkpets/tray/MemberTray.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/cn/harryh/arkpets/tray/HostTray.java b/core/src/cn/harryh/arkpets/tray/HostTray.java index a2922c70..7503b512 100644 --- a/core/src/cn/harryh/arkpets/tray/HostTray.java +++ b/core/src/cn/harryh/arkpets/tray/HostTray.java @@ -36,11 +36,11 @@ public class HostTray { SwingUtilities.invokeLater(() -> { try { String laf = UIManager.getSystemLookAndFeelClassName(); - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); if (laf.contains("WindowsLookAndFeel")) { UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); UIManager.put("Menu.margin",new Insets(2,-15,2,2)); } + UIManager.setLookAndFeel(laf); } catch (Exception ignored) {} }); Const.FontsConfig.loadFontsToSwing(); diff --git a/core/src/cn/harryh/arkpets/tray/MemberTray.java b/core/src/cn/harryh/arkpets/tray/MemberTray.java index d243bb10..57e0f3ec 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTray.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTray.java @@ -26,11 +26,11 @@ public abstract class MemberTray { SwingUtilities.invokeLater(() -> { try { String laf = UIManager.getSystemLookAndFeelClassName(); - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); if (laf.contains("WindowsLookAndFeel")) { UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); UIManager.put("Menu.margin",new Insets(2,-15,2,2)); } + UIManager.setLookAndFeel(laf); } catch (Exception ignored) {} }); Const.FontsConfig.loadFontsToSwing(); From 6467fdaea17800c642f10f3feb2eaea2bb5c618d Mon Sep 17 00:00:00 2001 From: litwak913 Date: Sun, 10 Nov 2024 23:38:51 +0800 Subject: [PATCH 4/4] fix: member tray laf --- .../src/cn/harryh/arkpets/tray/MemberTray.java | 18 ++++++++---------- .../cn/harryh/arkpets/tray/MemberTrayImpl.java | 2 -- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core/src/cn/harryh/arkpets/tray/MemberTray.java b/core/src/cn/harryh/arkpets/tray/MemberTray.java index 57e0f3ec..e3a9bcf4 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTray.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTray.java @@ -23,16 +23,14 @@ public abstract class MemberTray { static { // Avoid AWT Thread problem. - SwingUtilities.invokeLater(() -> { - try { - String laf = UIManager.getSystemLookAndFeelClassName(); - if (laf.contains("WindowsLookAndFeel")) { - UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); - UIManager.put("Menu.margin",new Insets(2,-15,2,2)); - } - UIManager.setLookAndFeel(laf); - } catch (Exception ignored) {} - }); + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + if (laf.contains("WindowsLookAndFeel")) { + UIManager.put("MenuItem.margin", new Insets(2, -15, 2, 2)); + UIManager.put("Menu.margin", new Insets(2, -15, 2, 2)); + } + UIManager.setLookAndFeel(laf); + } catch (Exception ignored) {} Const.FontsConfig.loadFontsToSwing(); } diff --git a/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java b/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java index 144b8ede..98bb4293 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java @@ -69,8 +69,6 @@ public void firePopupMenuWillBecomeInvisible() { onDisconnected(); client.connectWithRetry(onConnected, session); } - SwingUtilities.updateComponentTreeUI(popMenu); - popMenu.pack(); } private static String getName(ArkPets boundArkPets) {