Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Font Size #490

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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