mirror of
https://github.com/skylot/jadx.git
synced 2025-02-20 04:51:49 +00:00
fix(gui): collect FlatLaf themes without reflection
This commit is contained in:
parent
5fc27c1136
commit
cf918a897f
@ -19,7 +19,6 @@ dependencies {
|
||||
implementation 'com.formdev:flatlaf-intellij-themes:1.6.1'
|
||||
implementation 'com.formdev:flatlaf-extras:1.6.1'
|
||||
implementation 'com.formdev:svgSalamander:1.1.2.4'
|
||||
implementation 'org.reflections:reflections:0.10.2'
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.8.9'
|
||||
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||
|
@ -43,7 +43,7 @@ public class JadxSettings extends JadxCLIArgs {
|
||||
|
||||
private static final Path USER_HOME = Paths.get(System.getProperty("user.home"));
|
||||
private static final int RECENT_PROJECTS_COUNT = 15;
|
||||
private static final int CURRENT_SETTINGS_VERSION = 13;
|
||||
private static final int CURRENT_SETTINGS_VERSION = 14;
|
||||
|
||||
private static final Font DEFAULT_FONT = new RSyntaxTextArea().getFont();
|
||||
|
||||
@ -62,10 +62,10 @@ public class JadxSettings extends JadxCLIArgs {
|
||||
private String fontStr = "";
|
||||
private String smaliFontStr = "";
|
||||
private String editorThemePath = "";
|
||||
private String lafTheme = LafManager.SYSTEM_THEME_NAME;
|
||||
private String lafTheme = LafManager.INITIAL_THEME_NAME;
|
||||
private LangLocale langLocale = NLS.defaultLocale();
|
||||
private boolean autoStartJobs = false;
|
||||
protected String excludedPackages = "";
|
||||
private String excludedPackages = "";
|
||||
private boolean autoSaveProject = false;
|
||||
|
||||
private boolean showHeapUsageBar = false;
|
||||
@ -130,6 +130,14 @@ public class JadxSettings extends JadxCLIArgs {
|
||||
}
|
||||
}
|
||||
|
||||
public int getSettingsVersion() {
|
||||
return settingsVersion;
|
||||
}
|
||||
|
||||
public void setSettingsVersion(int settingsVersion) {
|
||||
this.settingsVersion = settingsVersion;
|
||||
}
|
||||
|
||||
public String getCmdSelectClass() {
|
||||
return cmdSelectClass;
|
||||
}
|
||||
@ -635,6 +643,10 @@ public class JadxSettings extends JadxCLIArgs {
|
||||
alwaysSelectOpened = false;
|
||||
fromVersion++;
|
||||
}
|
||||
if (fromVersion == 13) {
|
||||
lafTheme = LafManager.INITIAL_THEME_NAME;
|
||||
fromVersion++;
|
||||
}
|
||||
if (fromVersion != CURRENT_SETTINGS_VERSION) {
|
||||
throw new JadxRuntimeException("Incorrect settings upgrade");
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public class JadxSettingsAdapter {
|
||||
return JadxSettings.SKIP_FIELDS.contains(f.getName())
|
||||
|| f.hasModifier(Modifier.PUBLIC)
|
||||
|| f.hasModifier(Modifier.TRANSIENT)
|
||||
|| f.hasModifier(Modifier.STATIC)
|
||||
|| (f.getAnnotation(GsonExclude.class) != null);
|
||||
}
|
||||
|
||||
|
@ -1,31 +1,29 @@
|
||||
package jadx.gui.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.formdev.flatlaf.FlatDarculaLaf;
|
||||
import com.formdev.flatlaf.FlatDarkLaf;
|
||||
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
|
||||
import com.formdev.flatlaf.intellijthemes.FlatAllIJThemes;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
|
||||
import jadx.cli.LogHelper;
|
||||
import jadx.gui.settings.JadxSettings;
|
||||
|
||||
public class LafManager {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LafManager.class);
|
||||
|
||||
public static final String SYSTEM_THEME_NAME = "default";
|
||||
public static final String INITIAL_THEME_NAME = FlatLightLaf.NAME;
|
||||
|
||||
private static final Map<String, String> THEMES_MAP = initThemesMap();
|
||||
|
||||
public static void init(JadxSettings settings) {
|
||||
@ -66,30 +64,20 @@ public class LafManager {
|
||||
private static Map<String, String> initThemesMap() {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put(SYSTEM_THEME_NAME, SYSTEM_THEME_NAME);
|
||||
for (FlatLaf flatLafTheme : collectFlatLafThemes()) {
|
||||
map.put(flatLafTheme.getName(), flatLafTheme.getClass().getName());
|
||||
|
||||
// default flatlaf themes
|
||||
map.put(FlatLightLaf.NAME, FlatLightLaf.class.getName());
|
||||
map.put(FlatDarkLaf.NAME, FlatDarkLaf.class.getName());
|
||||
map.put(FlatIntelliJLaf.NAME, FlatIntelliJLaf.class.getName());
|
||||
map.put(FlatDarculaLaf.NAME, FlatDarculaLaf.class.getName());
|
||||
|
||||
// themes from flatlaf-intellij-themes
|
||||
for (FlatAllIJThemes.FlatIJLookAndFeelInfo themeInfo : FlatAllIJThemes.INFOS) {
|
||||
map.put(themeInfo.getName(), themeInfo.getClassName());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static List<FlatLaf> collectFlatLafThemes() {
|
||||
LogHelper.setLevelForPackage("org.reflections", Level.WARN);
|
||||
Reflections reflections = new Reflections("com.formdev.flatlaf");
|
||||
Set<Class<? extends FlatLaf>> lafClasses = reflections.getSubTypesOf(FlatLaf.class);
|
||||
|
||||
List<FlatLaf> themes = new ArrayList<>(lafClasses.size());
|
||||
for (Class<? extends FlatLaf> lafClass : lafClasses) {
|
||||
try {
|
||||
themes.add(lafClass.getDeclaredConstructor().newInstance());
|
||||
} catch (Exception e) {
|
||||
// some classes not themes, ignore them
|
||||
LOG.trace("Failed make instance for class: {}", lafClass.getName(), e);
|
||||
}
|
||||
}
|
||||
themes.sort(Comparator.comparing(LookAndFeel::getName));
|
||||
return themes;
|
||||
}
|
||||
|
||||
private static boolean applyLaf(String theme) {
|
||||
try {
|
||||
FlatAnimatedLafChange.showSnapshot();
|
||||
|
Loading…
x
Reference in New Issue
Block a user