From 53750cffa22e59488f3250fe7da08c8a04b71330 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Thu, 5 Aug 2021 12:24:46 +0200 Subject: [PATCH 1/3] Prevent empty popup menu from showing if menu has no child items --- .../translation/components/TranslatedJMenu.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/translation/components/TranslatedJMenu.java b/src/main/java/the/bytecode/club/bytecodeviewer/translation/components/TranslatedJMenu.java index e5f77be9..e0a78a86 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/translation/components/TranslatedJMenu.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/translation/components/TranslatedJMenu.java @@ -44,4 +44,10 @@ public class TranslatedJMenu extends JMenu componentReference.translate(); } } + + @Override + public boolean isEnabled() + { + return super.isEnabled() && getMenuComponentCount() > 0; + } } \ No newline at end of file From 3ab009dc5bb7c8ebe885741638c0ec4ee817887a Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Thu, 5 Aug 2021 12:35:23 +0200 Subject: [PATCH 2/3] Set empty border on VisibleComponent VisibleComponent is a JInternalFrame but never used in a JDesktopPane. Darklaf adds a shadow border around the frame which looks odd in this case. Explicitly setting an empty border solves this issue. --- .../gui/components/VisibleComponent.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/VisibleComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/VisibleComponent.java index 813ef2e7..4c348673 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/VisibleComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/VisibleComponent.java @@ -3,8 +3,10 @@ package the.bytecode.club.bytecodeviewer.gui.components; import com.github.weisj.darklaf.icons.ThemedSVGIcon; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.Workspace; +import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme; import the.bytecode.club.bytecodeviewer.resources.IconResources; +import javax.swing.BorderFactory; import javax.swing.JInternalFrame; /*************************************************************************** @@ -40,7 +42,16 @@ public abstract class VisibleComponent extends JInternalFrame super(title, false, false, false, false); this.setDefaultIcon(); } - + + @Override + public void updateUI() { + if (Configuration.lafTheme != LAFTheme.SYSTEM) + setBorder(BorderFactory.createEmptyBorder()); + else + setBorder(null); + super.updateUI(); + } + public void setDefaultIcon() { try { From 758d6b7dcd480a3b37cd07806d31bd56a6b40ec4 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Thu, 5 Aug 2021 12:54:49 +0200 Subject: [PATCH 3/3] Fix issue with darklaf JMenuBar. --- .../club/bytecodeviewer/BytecodeViewer.java | 2 +- .../bytecodeviewer/plugin/PluginWriter.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 12156ba7..8e15cf6b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -84,7 +84,7 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * * TODO DarkLAF Specific Bugs: * + Resource List creates swing lag with large project - * + JMenuBar can only be displayed on a JFrame, a work around is needed for this + * + JMenuBar can only be displayed on a JFrame, a work around is needed for this (Partially solved) * * TODO IN-PROGRESS: * + Resource Exporter/Save/Decompile As Zip needs to be rewritten diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java index e8871789..c2f982c0 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java @@ -6,7 +6,6 @@ import org.apache.commons.compress.utils.FileNameUtils; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ComponentViewer; -import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme; import the.bytecode.club.bytecodeviewer.resources.IconResources; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.components.SearchableRSyntaxTextArea; @@ -18,6 +17,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage; import javax.swing.*; +import javax.swing.border.LineBorder; import java.awt.*; import java.io.File; import java.io.IOException; @@ -123,16 +123,18 @@ public class PluginWriter extends JFrame JPanel p = new JPanel(new BorderLayout()); JPanel p2 = new JPanel(new BorderLayout()); - p.add(p2, BorderLayout.NORTH); p.add(component, BorderLayout.CENTER); - - if(Configuration.lafTheme == LAFTheme.SYSTEM) - p2.add(getJMenuBar(), BorderLayout.CENTER); - else //TODO DarkLAF wont display the jMenuBar due to how it handles them, instead display the menu - //TODO make the menu interactable and display the menu manually - p2.add(getJMenuBar().getMenu(0), BorderLayout.CENTER); - + + JMenuBar menuBar = getJMenuBar(); + // As the Darklaf windows decorations steal the menu bar from the frame + // it sets the preferred size to (0,0). Because we want to steal the menu bar ourselves. + // we have to revert this change. + // Remove when https://github.com/weisJ/darklaf/issues/258 is fixed and available in a + // release. + menuBar.setPreferredSize(null); + p2.add(menuBar, BorderLayout.CENTER); + ComponentViewer.addComponentAsTab(pluginName, p); } else