From 12096496d46c0f814a12b761896fcb775580d256 Mon Sep 17 00:00:00 2001 From: Cody Date: Sun, 14 Jan 2024 14:05:16 -0700 Subject: [PATCH 1/2] Clear resource classes, class bytes, and files after deleting directory from resource list to clear memory. --- .../bytecodeviewer/gui/contextmenu/resourcelist/Delete.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Delete.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Delete.java index c79e0ed76..e4586a7a6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Delete.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/contextmenu/resourcelist/Delete.java @@ -5,6 +5,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuItem; import the.bytecode.club.bytecodeviewer.gui.contextmenu.ContextMenuType; +import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceTreeNode; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; /*************************************************************************** @@ -40,6 +41,10 @@ public Delete() public void actionPerformed(ActionEvent e) { BytecodeViewer.viewer.resourcePane.removeNode(tree, selPath); + BytecodeViewer.resourceContainers.get(selPath.getLastPathComponent().toString()).resourceClassBytes.clear(); + BytecodeViewer.resourceContainers.get(selPath.getLastPathComponent().toString()).resourceFiles.clear(); + BytecodeViewer.resourceContainers.get(selPath.getLastPathComponent().toString()).resourceClasses.clear(); + System.gc(); } }))); } From ab388248430d511d6c6b8a5df4f24f1ba26780bd Mon Sep 17 00:00:00 2001 From: Cody <6558800+Bl3nd@users.noreply.github.com> Date: Wed, 27 Mar 2024 21:40:30 -0600 Subject: [PATCH 2/2] Quick fix: Font size setting now updates most/every component. Note: "Refresh" button needs to be pressed to update workspace. --- .../club/bytecodeviewer/BytecodeViewer.java | 39 ++++++++++++++++--- .../bytecodeviewer/gui/MainViewerGUI.java | 34 ++++++++-------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 44f443353..236790040 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -2,14 +2,14 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; + +import java.awt.*; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; +import java.util.*; import java.util.List; -import java.util.Map; -import javax.swing.SwingUtilities; +import javax.swing.*; + import me.konloch.kontainer.io.DiskReader; import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; @@ -22,6 +22,8 @@ import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import the.bytecode.club.bytecodeviewer.gui.components.ExtendedJOptionPane; import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialog; +import the.bytecode.club.bytecodeviewer.gui.components.SearchableJTextArea; +import the.bytecode.club.bytecodeviewer.gui.components.SearchableRSyntaxTextArea; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListIconRenderer; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; @@ -751,4 +753,31 @@ public static void cleanup() * because Smali and Baksmali System.exit if it failed */ public static void exit(int i) { } + + /** + * Updates all UI components fonts. + * + * @implNote {@link SearchableRSyntaxTextArea} and {@link SearchableJTextArea} + * do not update until "Refresh" button is clicked. + * + * @param font The font to change everything to. + */ + public static void updateAllFonts(Font font) { + Enumeration enumeration = UIManager.getDefaults().keys(); + while (enumeration.hasMoreElements()) { + Object key = enumeration.nextElement(); + Object value = UIManager.get (key); + if (value instanceof Font) + UIManager.put (key, font); + } + } + + /** + * Updates all swing components. + */ + public static void updateUI() { + for (Window w : Window.getWindows()) { + SwingUtilities.updateComponentTreeUI(w); + } + } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index a7e177fba..f81342342 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -1,27 +1,15 @@ package the.bytecode.club.bytecodeviewer.gui; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.KeyboardFocusManager; +import java.awt.*; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JSeparator; -import javax.swing.JSpinner; -import javax.swing.JSplitPane; -import javax.swing.SpinnerNumberModel; -import javax.swing.SwingUtilities; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Constants; @@ -466,6 +454,18 @@ public void buildSettingsMenu() fontSpinner.setPreferredSize(new Dimension(60, 24)); fontSpinner.setMinimumSize(new Dimension(60, 24)); fontSpinner.setModel(new SpinnerNumberModel(12, 1, null, 1)); + fontSpinner.addChangeListener(e -> { + JSpinner spinner = (JSpinner) e.getSource(); + Font font = UIManager.getFont("defaultFont"); + if (font == null) { + font = UIManager.getFont("Label.font"); + } + + font = font.deriveFont((float) (int) spinner.getValue()); + + BytecodeViewer.updateAllFonts(font); + BytecodeViewer.updateUI(); + }); fontSize.add(fontSpinner); apkConversionSecondaryMenu.add(decodeAPKResources);