Skip to content

Commit

Permalink
Merge pull request #490 from Bl3nd/master
Browse files Browse the repository at this point in the history
UI Font Size
  • Loading branch information
Konloch authored Apr 9, 2024
2 parents 13bf3cd + 7971450 commit c2f516a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
39 changes: 34 additions & 5 deletions src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Object> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c2f516a

Please sign in to comment.