提交 d44dd0de 编写于 作者: S Skylot

fix(gui): show current font in preferences

上级 db1b027d
......@@ -18,6 +18,7 @@ import jadx.cli.JadxCLIArgs;
import jadx.gui.ui.codearea.EditorTheme;
import jadx.gui.utils.LangLocale;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;
import static jadx.gui.utils.Utils.FONT_HACK;
......@@ -263,7 +264,14 @@ public class JadxSettings extends JadxCLIArgs {
}
public void setFont(Font font) {
this.fontStr = font.getFontName() + addStyleName(font.getStyle()) + "-" + font.getSize();
StringBuilder sb = new StringBuilder();
sb.append(font.getFontName());
String fontStyleName = Utils.getFontStyleName(font.getStyle()).replaceAll(" ", "");
if (!fontStyleName.isEmpty()) {
sb.append('-').append(fontStyleName.toUpperCase());
}
sb.append('-').append(font.getSize());
this.fontStr = sb.toString();
}
public String getEditorThemePath() {
......@@ -274,19 +282,6 @@ public class JadxSettings extends JadxCLIArgs {
this.editorThemePath = editorThemePath;
}
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 "";
}
}
private void upgradeSettings(int fromVersion) {
LOG.debug("upgrade settings from version: {} to {}", fromVersion, CURRENT_SETTINGS_VERSION);
if (fromVersion == 0) {
......
......@@ -16,6 +16,7 @@ import jadx.gui.ui.MainWindow;
import jadx.gui.ui.codearea.EditorTheme;
import jadx.gui.utils.LangLocale;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;
public class JadxSettingsWindow extends JDialog {
private static final long serialVersionUID = -1804570470377354148L;
......@@ -164,21 +165,6 @@ public class JadxSettingsWindow extends JDialog {
private SettingsGroup makeEditorGroup() {
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.debug("Selected Font: {}", font);
settings.setFont(font);
mainWindow.updateFont(font);
mainWindow.loadSettings();
}
}
});
EditorTheme[] editorThemes = EditorTheme.getAllThemes();
JComboBox<EditorTheme> themesCbx = new JComboBox<>(editorThemes);
......@@ -196,11 +182,34 @@ public class JadxSettingsWindow extends JDialog {
});
SettingsGroup other = new SettingsGroup(NLS.str("preferences.editor"));
other.addRow(NLS.str("preferences.font"), fontBtn);
JLabel fontLabel = other.addRow(getFontLabelStr(), fontBtn);
other.addRow(NLS.str("preferences.theme"), themesCbx);
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.debug("Selected Font: {}", font);
settings.setFont(font);
mainWindow.updateFont(font);
mainWindow.loadSettings();
fontLabel.setText(getFontLabelStr());
}
}
});
return other;
}
private String getFontLabelStr() {
Font font = settings.getFont();
String fontStyleName = Utils.getFontStyleName(font.getStyle());
return NLS.str("preferences.font") + ": " + font.getFontName() + " " + fontStyleName + " " + font.getSize();
}
private SettingsGroup makeDecompilationGroup() {
JCheckBox fallback = new JCheckBox();
fallback.setSelected(settings.isFallbackMode());
......@@ -342,11 +351,11 @@ public class JadxSettingsWindow extends JDialog {
c.weighty = 1.0;
}
public void addRow(String label, JComponent comp) {
addRow(label, null, comp);
public JLabel addRow(String label, JComponent comp) {
return addRow(label, null, comp);
}
public void addRow(String label, String tooltip, JComponent comp) {
public JLabel addRow(String label, String tooltip, JComponent comp) {
c.gridy = row++;
JLabel jLabel = new JLabel(label);
jLabel.setLabelFor(comp);
......@@ -371,6 +380,7 @@ public class JadxSettingsWindow extends JDialog {
add(comp, c);
comp.addPropertyChangeListener("enabled", evt -> jLabel.setEnabled((boolean) evt.getNewValue()));
return jLabel;
}
public void end() {
......
......@@ -8,6 +8,7 @@ import java.awt.datatransfer.Transferable;
import java.io.InputStream;
import java.net.URL;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -175,4 +176,19 @@ public class Utils {
LOG.error("Failed copy string '{}' to clipboard", text, e);
}
}
@NotNull
public static String getFontStyleName(int style) {
if (style == 0) {
return "plain";
}
StringBuilder sb = new StringBuilder();
if ((style & Font.BOLD) != 0) {
sb.append("bold");
}
if ((style & Font.ITALIC) != 0) {
sb.append(" italic");
}
return sb.toString().trim();
}
}
......@@ -99,7 +99,7 @@ preferences.raw_cfg=Generate RAW CFG graphs
preferences.font=Editor font
preferences.theme=Editor theme
preferences.start_jobs=Auto start background decompilation
preferences.select_font=Select
preferences.select_font=Change
preferences.deobfuscation_on=Enable deobfuscation
preferences.deobfuscation_force=Force rewrite deobfuscation map file
preferences.deobfuscation_min_len=Minimum name length
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册