Commit 7b264ef2 authored by Skylot's avatar Skylot

gui: add font selection dialog

parent 5a6600f7
......@@ -178,3 +178,4 @@ Icons copied from several places:
- Eclipse Project (JDT UI) - licensed under EPL v1.0 (http://www.eclipse.org/legal/epl-v10.html)
- famfamfam silk icon set (http://www.famfamfam.com/lab/icons/silk/) - licensed under Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/)
JFontChooser Component - http://sourceforge.jp/projects/jfontchooser/
......@@ -7,6 +7,7 @@ dependencies {
compile(project(":jadx-cli"))
compile 'com.fifesoft:rsyntaxtextarea:2.5.6'
compile 'com.google.code.gson:gson:2.3.1'
compile files('libs/jfontchooser-1.0.5.jar')
}
applicationDistribution.with {
......
......@@ -2,6 +2,8 @@ package jadx.gui.settings;
import jadx.cli.JadxCLIArgs;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
......@@ -13,6 +15,8 @@ public class JadxSettings extends JadxCLIArgs {
private static final String USER_HOME = System.getProperty("user.home");
private static final int RECENT_FILES_COUNT = 15;
private static final Font DEFAULT_FONT = new JLabel().getFont();
static final Set<String> SKIP_FIELDS = new HashSet<String>(Arrays.asList(
"files", "input", "outputDir", "printHelp"
));
......@@ -22,6 +26,7 @@ public class JadxSettings extends JadxCLIArgs {
private boolean flattenPackage = false;
private boolean checkForUpdates = true;
private List<String> recentFiles = new ArrayList<String>();
private String fontStr = "";
public void sync() {
JadxSettingsAdapter.store(this);
......@@ -126,4 +131,28 @@ public class JadxSettings extends JadxCLIArgs {
public void setDeobfuscationForceSave(boolean deobfuscationForceSave) {
this.deobfuscationForceSave = deobfuscationForceSave;
}
public Font getFont() {
if (fontStr.isEmpty()) {
return DEFAULT_FONT;
}
return Font.decode(fontStr);
}
public void setFont(Font font) {
this.fontStr = font.getFontName() + addStyleName(font.getStyle()) + "-" + font.getSize();
}
private static String addStyleName(int style) {
switch (style) {
case Font.BOLD:
return "-BOLD";
case Font.PLAIN:
return "-PLAIN";
case Font.ITALIC:
return "-ITALIC";
default:
return "";
}
}
}
......@@ -2,6 +2,7 @@ package jadx.gui.settings;
import jadx.gui.ui.MainWindow;
import jadx.gui.utils.NLS;
import say.swing.JFontChooser;
import javax.swing.BorderFactory;
import javax.swing.Box;
......@@ -20,6 +21,7 @@ import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
......@@ -28,10 +30,17 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JadxSettingsWindow extends JDialog {
private static final long serialVersionUID = -1804570470377354148L;
private static final Logger LOG = LoggerFactory.getLogger(JadxSettingsWindow.class);
private final MainWindow mainWindow;
private final JadxSettings settings;
private final String startSettings;
......@@ -204,6 +213,22 @@ public class JadxSettingsWindow extends JDialog {
}
});
JButton fontBtn = new JButton(NLS.str("preferences.select_font"));
fontBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JFontChooser fontChooser = new JFontChooser();
fontChooser.setSelectedFont(settings.getFont());
int result = fontChooser.showDialog(JadxSettingsWindow.this);
if (result == JFontChooser.OK_OPTION) {
Font font = fontChooser.getSelectedFont();
LOG.info("Selected Font : {}", font);
settings.setFont(font);
mainWindow.updateFont(font);
}
}
});
SettingsGroup other = new SettingsGroup(NLS.str("preferences.other"));
other.addRow(NLS.str("preferences.check_for_updates"), update);
other.addRow(NLS.str("preferences.threads"), threadsCount);
......@@ -212,6 +237,7 @@ public class JadxSettingsWindow extends JDialog {
other.addRow(NLS.str("preferences.skipResourcesDecode"), resourceDecode);
other.addRow(NLS.str("preferences.cfg"), cfg);
other.addRow(NLS.str("preferences.raw_cfg"), rawCfg);
other.addRow(NLS.str("preferences.font"), fontBtn);
return other;
}
......
package jadx.gui.ui;
import jadx.api.CodePosition;
import jadx.gui.settings.JadxSettings;
import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JNode;
import jadx.gui.utils.Position;
......@@ -45,6 +46,7 @@ class ContentArea extends RSyntaxTextArea {
setBackground(BACKGROUND);
setAntiAliasingEnabled(true);
setEditable(false);
loadSettings();
Caret caret = getCaret();
if (caret instanceof DefaultCaret) {
((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
......@@ -66,6 +68,11 @@ class ContentArea extends RSyntaxTextArea {
setText(node.getContent());
}
public void loadSettings() {
JadxSettings settings = contentPanel.getTabbedPane().getMainWindow().getSettings();
setFont(settings.getFont());
}
private boolean isJumpToken(Token token) {
if (token.getType() == TokenTypes.IDENTIFIER) {
// fast skip
......
......@@ -48,6 +48,7 @@ import javax.swing.tree.TreeSelectionModel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
......@@ -574,6 +575,15 @@ public class MainWindow extends JFrame {
setSize((int) (w * WINDOW_RATIO), (int) (h * WINDOW_RATIO));
}
public void updateFont(Font font) {
setFont(font);
tabbedPane.loadSettings();
}
public JadxSettings getSettings() {
return settings;
}
private class OpenListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
openFile();
......
......@@ -234,4 +234,10 @@ class TabbedPane extends JTabbedPane {
closeCodePanel(panel);
}
}
public void loadSettings() {
for (ContentPanel panel : openTabs.values()) {
panel.getContentArea().loadSettings();
}
}
}
......@@ -55,6 +55,8 @@ preferences.skipResourcesDecode=Don't decode resources
preferences.threads=Processing threads count
preferences.cfg=Generate methods CFG graphs (in 'dot' format)
preferences.raw_cfg=Generate RAW CFG graphs
preferences.font=Editor font
preferences.select_font=Select
preferences.deobfuscation_on=Enable deobfuscation
preferences.deobfuscation_force=Force rewrite deobfuscation map file
preferences.deobfuscation_min_len=Minimum name length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment