63
63
import org .fife .ui .rsyntaxtextarea .RSyntaxTextArea ;
64
64
import org .fife .ui .rsyntaxtextarea .Style ;
65
65
import org .fife .ui .rsyntaxtextarea .SyntaxScheme ;
66
+ import org .fife .ui .rsyntaxtextarea .Theme ;
66
67
import org .fife .ui .rtextarea .Gutter ;
67
68
import org .fife .ui .rtextarea .GutterIconInfo ;
68
69
import org .fife .ui .rtextarea .RTextArea ;
@@ -837,8 +838,7 @@ public void convertSpacesToTabs() {
837
838
public static final String DEFAULT_THEME = "default" ;
838
839
839
840
/**
840
- * Loads and applies the preferences for the tab (theme excluded).
841
- * @see TextEditor#applyTheme(String)
841
+ * Loads and applies the preferences for the tab
842
842
*/
843
843
public void loadPreferences () {
844
844
if (prefService == null ) {
@@ -862,13 +862,47 @@ public void loadPreferences() {
862
862
setKeylessAutoCompletion (prefService .getBoolean (getClass (), AUTOCOMPLETE_KEYLESS_PREFS , true )); // true for backwards compatibility with IJ1 macro
863
863
setFallbackAutoCompletion (prefService .getBoolean (getClass (), AUTOCOMPLETE_FALLBACK_PREFS , false ));
864
864
setMarkOccurrences (prefService .getBoolean (getClass (), MARK_OCCURRENCES_PREFS , false ));
865
+ applyTheme (themeName ());
866
+ }
867
+ }
868
+
869
+ /**
870
+ * Applies a theme to this pane.
871
+ *
872
+ * @param theme either "default", "dark", "druid", "eclipse", "idea", "monokai",
873
+ * "vs"
874
+ * @throws IllegalArgumentException If {@code theme} is not a valid option, or
875
+ * the resource could not be loaded
876
+ */
877
+ public void applyTheme (final String theme ) throws IllegalArgumentException {
878
+ try {
879
+ applyTheme (getTheme (theme ));
880
+ } catch (final Exception ex ) {
881
+ throw new IllegalArgumentException (ex );
865
882
}
866
883
}
867
884
868
885
public String themeName () {
869
886
return prefService .get (getClass (), THEME_PREFS , DEFAULT_THEME );
870
887
}
871
888
889
+ private void applyTheme (final Theme th ) throws IllegalArgumentException {
890
+ // themes include font size, so we'll need to reset that
891
+ final float existingFontSize = getFontSize ();
892
+ th .apply (this );
893
+ setFontSize (existingFontSize );
894
+ updateBookmarkIcon (); // update bookmark icon color
895
+ }
896
+
897
+ private static Theme getTheme (final String theme ) throws IllegalArgumentException {
898
+ try {
899
+ return Theme
900
+ .load (TextEditor .class .getResourceAsStream ("/org/fife/ui/rsyntaxtextarea/themes/" + theme + ".xml" ));
901
+ } catch (final Exception ex ) {
902
+ throw new IllegalArgumentException (ex );
903
+ }
904
+ }
905
+
872
906
public String loadFolders () {
873
907
return prefService .get (getClass (), FOLDERS_PREFS , System .getProperty ("user.home" ));
874
908
}
0 commit comments