6363import org .fife .ui .rsyntaxtextarea .RSyntaxTextArea ;
6464import org .fife .ui .rsyntaxtextarea .Style ;
6565import org .fife .ui .rsyntaxtextarea .SyntaxScheme ;
66+ import org .fife .ui .rsyntaxtextarea .Theme ;
6667import org .fife .ui .rtextarea .Gutter ;
6768import org .fife .ui .rtextarea .GutterIconInfo ;
6869import org .fife .ui .rtextarea .RTextArea ;
@@ -837,8 +838,7 @@ public void convertSpacesToTabs() {
837838 public static final String DEFAULT_THEME = "default" ;
838839
839840 /**
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
842842 */
843843 public void loadPreferences () {
844844 if (prefService == null ) {
@@ -862,13 +862,47 @@ public void loadPreferences() {
862862 setKeylessAutoCompletion (prefService .getBoolean (getClass (), AUTOCOMPLETE_KEYLESS_PREFS , true )); // true for backwards compatibility with IJ1 macro
863863 setFallbackAutoCompletion (prefService .getBoolean (getClass (), AUTOCOMPLETE_FALLBACK_PREFS , false ));
864864 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 );
865882 }
866883 }
867884
868885 public String themeName () {
869886 return prefService .get (getClass (), THEME_PREFS , DEFAULT_THEME );
870887 }
871888
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+
872906 public String loadFolders () {
873907 return prefService .get (getClass (), FOLDERS_PREFS , System .getProperty ("user.home" ));
874908 }
0 commit comments