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);