gui: add Hack font

This commit is contained in:
Skylot
2018-05-24 16:55:39 +03:00
parent 1931e78367
commit 6df315017c
5 changed files with 41 additions and 7 deletions
@@ -16,6 +16,8 @@ import org.slf4j.LoggerFactory;
import jadx.api.JadxArgs;
import jadx.cli.JadxCLIArgs;
import static jadx.gui.utils.Utils.FONT_HACK;
public class JadxSettings extends JadxCLIArgs {
private static final Logger LOG = LoggerFactory.getLogger(JadxSettings.class);
@@ -23,7 +25,7 @@ public class JadxSettings extends JadxCLIArgs {
private static final int RECENT_FILES_COUNT = 15;
private static final int CURRENT_SETTINGS_VERSION = 1;
private static final Font DEFAULT_FONT = new RSyntaxTextArea().getFont();
private static final Font DEFAULT_FONT = FONT_HACK != null ? FONT_HACK : new RSyntaxTextArea().getFont();
static final Set<String> SKIP_FIELDS = new HashSet<>(Arrays.asList(
"files", "input", "outputDir", "verbose", "printHelp"
@@ -19,6 +19,8 @@ import say.swing.JFontChooser;
import jadx.gui.ui.MainWindow;
import jadx.gui.utils.NLS;
import static jadx.gui.utils.Utils.FONT_HACK;
public class JadxSettingsWindow extends JDialog {
private static final long serialVersionUID = -1804570470377354148L;
@@ -37,6 +39,7 @@ public class JadxSettingsWindow extends JDialog {
this.startSettings = JadxSettingsAdapter.makeString(settings);
initUI();
registerBundledFonts();
setTitle(NLS.str("preferences.title"));
setSize(400, 550);
@@ -46,6 +49,13 @@ public class JadxSettingsWindow extends JDialog {
pack();
}
public static void registerBundledFonts() {
GraphicsEnvironment grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (FONT_HACK != null) {
grEnv.registerFont(FONT_HACK);
}
}
private void initUI() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
@@ -1,18 +1,26 @@
package jadx.gui.utils;
import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import java.net.URL;
import javax.swing.*;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.utils.exceptions.JadxRuntimeException;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
private static final ImageIcon ICON_STATIC = Utils.openIcon("static_co");
private static final ImageIcon ICON_FINAL = Utils.openIcon("final_co");
private static final ImageIcon ICON_ABSTRACT = Utils.openIcon("abstract_co");
private static final ImageIcon ICON_NATIVE = Utils.openIcon("native_co");
private static final ImageIcon ICON_STATIC = openIcon("static_co");
private static final ImageIcon ICON_FINAL = openIcon("final_co");
private static final ImageIcon ICON_ABSTRACT = openIcon("abstract_co");
private static final ImageIcon ICON_NATIVE = openIcon("native_co");
public static final Font FONT_HACK = openFontTTF("Hack-Regular");
private Utils() {
}
@@ -26,6 +34,18 @@ public class Utils {
return new ImageIcon(resource);
}
@Nullable
public static Font openFontTTF(String name) {
String fontPath = "/fonts/" + name + ".ttf";
try (InputStream is = Utils.class.getResourceAsStream(fontPath)) {
Font font = Font.createFont(Font.TRUETYPE_FONT, is);
return font.deriveFont(12f);
} catch (Exception e) {
LOG.error("Failed load font by path: {}", fontPath, e);
return null;
}
}
public static void addKeyBinding(JComponent comp, KeyStroke key, String id, Action action) {
comp.getInputMap().put(key, id);
comp.getActionMap().put(id, action);