2121import java .awt .event .WindowEvent ;
2222import java .awt .geom .AffineTransform ;
2323import java .io .File ;
24- import java .io .InputStream ;
25- import java .net .URL ;
2624import java .nio .file .Files ;
2725import java .nio .file .Path ;
28- import java .nio .file .Paths ;
2926import java .util .ArrayList ;
3027import java .util .Collections ;
3128import java .util .EnumSet ;
6764import javax .swing .tree .TreePath ;
6865import javax .swing .tree .TreeSelectionModel ;
6966
70- import org .fife .ui .rsyntaxtextarea .RSyntaxTextArea ;
71- import org .fife .ui .rsyntaxtextarea .Theme ;
7267import org .jetbrains .annotations .NotNull ;
7368import org .jetbrains .annotations .Nullable ;
7469import org .slf4j .Logger ;
129124import jadx .gui .ui .action .JadxGuiAction ;
130125import jadx .gui .ui .codearea .AbstractCodeArea ;
131126import jadx .gui .ui .codearea .AbstractCodeContentPanel ;
132- import jadx .gui .ui .codearea .EditorTheme ;
133127import jadx .gui .ui .codearea .EditorViewState ;
128+ import jadx .gui .ui .codearea .theme .EditorThemeManager ;
134129import jadx .gui .ui .dialog .ADBDialog ;
135130import jadx .gui .ui .dialog .AboutDialog ;
136131import jadx .gui .ui .dialog .ExceptionDialog ;
@@ -192,6 +187,7 @@ public class MainWindow extends JFrame {
192187 private final TabsController tabsController ;
193188 private final NavigationController navController ;
194189 private final EditorSyncManager editorSyncManager ;
190+ private final EditorThemeManager editorThemeManager ;
195191
196192 private transient @ NotNull JadxProject project ;
197193
@@ -223,7 +219,6 @@ public class MainWindow extends JFrame {
223219
224220 private transient Link updateLink ;
225221 private transient ProgressPanel progressPane ;
226- private transient Theme editorTheme ;
227222
228223 private transient IssuesPanel issuesPanel ;
229224 private transient @ Nullable LogPanel logPanel ;
@@ -252,11 +247,12 @@ public MainWindow(JadxSettings settings) {
252247 this .shortcutsController = new ShortcutsController (settings );
253248 this .tabsController = new TabsController (this );
254249 this .navController = new NavigationController (this );
250+ this .editorThemeManager = new EditorThemeManager (settings );
255251
256252 JadxEventQueue .register ();
257253 resetCache ();
258254 FontUtils .registerBundledFonts ();
259- setEditorTheme (settings .getEditorThemePath ());
255+ editorThemeManager . setTheme (settings .getEditorTheme ());
260256 initUI ();
261257 this .editorSyncManager = new EditorSyncManager (this , tabbedPane );
262258 this .backgroundExecutor = new BackgroundExecutor (settings , progressPane );
@@ -1443,40 +1439,6 @@ public void setLocationAndPosition() {
14431439 setLocationRelativeTo (null );
14441440 }
14451441
1446- private void setEditorTheme (String editorThemePath ) {
1447- try {
1448- URL themeUrl = getClass ().getResource (editorThemePath );
1449- if (themeUrl != null ) {
1450- try (InputStream is = themeUrl .openStream ()) {
1451- editorTheme = Theme .load (is );
1452- return ;
1453- }
1454- }
1455- Path themePath = Paths .get (editorThemePath );
1456- if (Files .isRegularFile (themePath )) {
1457- try (InputStream is = Files .newInputStream (themePath )) {
1458- editorTheme = Theme .load (is );
1459- return ;
1460- }
1461- }
1462- } catch (Exception e ) {
1463- LOG .error ("Failed to load editor theme: {}" , editorThemePath , e );
1464- }
1465- LOG .warn ("Falling back to default editor theme: {}" , editorThemePath );
1466- editorThemePath = EditorTheme .getDefaultTheme ().getPath ();
1467- try (InputStream is = getClass ().getResourceAsStream (editorThemePath )) {
1468- editorTheme = Theme .load (is );
1469- return ;
1470- } catch (Exception e ) {
1471- LOG .error ("Failed to load default editor theme: {}" , editorThemePath , e );
1472- editorTheme = new Theme (new RSyntaxTextArea ());
1473- }
1474- }
1475-
1476- public Theme getEditorTheme () {
1477- return editorTheme ;
1478- }
1479-
14801442 private void openSettings () {
14811443 settingsOpen = true ;
14821444
@@ -1501,12 +1463,12 @@ public void loadSettings() {
15011463
15021464 private void updateUiSettings () {
15031465 LafManager .updateLaf (settings );
1466+ editorThemeManager .setTheme (settings .getEditorTheme ());
15041467
15051468 Font font = settings .getFont ();
15061469 Font largerFont = font .deriveFont (font .getSize () + 2.f );
15071470
15081471 setFont (largerFont );
1509- setEditorTheme (settings .getEditorThemePath ());
15101472 tree .setFont (largerFont );
15111473 tree .setRowHeight (-1 );
15121474
@@ -1535,6 +1497,7 @@ private void closeWindow() {
15351497 heapUsageBar .reset ();
15361498 closeAll ();
15371499
1500+ editorThemeManager .unload ();
15381501 dispose ();
15391502 System .exit (0 );
15401503 }
@@ -1754,6 +1717,10 @@ public CacheManager getCacheManager() {
17541717 return cacheManager ;
17551718 }
17561719
1720+ public EditorThemeManager getEditorThemeManager () {
1721+ return editorThemeManager ;
1722+ }
1723+
17571724 public JadxGuiEventsImpl events () {
17581725 return events ;
17591726 }
0 commit comments