diff --git a/CHANGELOG.md b/CHANGELOG.md index 33934cb6..cda7a198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ FlatLaf Change Log scrollable. - Added system property `flatlaf.useNativeLibrary` to allow disabling loading of FlatLaf native library. (issue #674) +- IntelliJ Themes: Reduced memory footprint and improved setup speed by ignoring + IntelliJ UI properties that are not used in FlatLaf. #### Fixed bugs diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java index 2869fcf3..52ce3fb0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java @@ -23,10 +23,12 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -61,9 +63,9 @@ public class IntelliJTheme private final boolean isMaterialUILite; - private final Map colors; - private final Map ui; - private final Map icons; + private Map colors; + private Map ui; + private Map icons; private Map namedColors = Collections.emptyMap(); @@ -261,6 +263,11 @@ public class IntelliJTheme defaults.put( key, value ); } + + // let Java release memory + colors = null; + ui = null; + icons = null; } private Map removeThemeSpecificDefaults( UIDefaults defaults ) { @@ -334,8 +341,6 @@ public class IntelliJTheme if( "".equals( value ) ) return; // ignore empty value - uiKeys.add( key ); - // ignore some properties that affect sizes if( key.endsWith( ".border" ) || key.endsWith( ".rowHeight" ) || @@ -350,6 +355,16 @@ public class IntelliJTheme if( key.isEmpty() ) return; // ignore key + // exclude properties + int dot = key.indexOf( '.' ); + if( dot > 0 && uiKeyExcludes.contains( key.substring( 0, dot + 1 ) ) ) + return; + + if( uiKeyDoNotOverride.contains( key ) && uiKeys.contains( key ) ) + return; + + uiKeys.add( key ); + String valueStr = value.toString(); // map named colors @@ -576,15 +591,56 @@ public class IntelliJTheme defaults.put( destKey, defaults.get( srcKey ) ); } + private static final Set uiKeyExcludes; + private static final Set uiKeyDoNotOverride; /** Rename UI default keys (key --> value). */ private static final Map uiKeyMapping = new HashMap<>(); /** Copy UI default keys (value --> key). */ - private static final Map uiKeyCopying = new HashMap<>(); + private static final Map uiKeyCopying = new LinkedHashMap<>(); private static final Map uiKeyInverseMapping = new HashMap<>(); private static final Map checkboxKeyMapping = new HashMap<>(); private static final Map checkboxDuplicateColors = new HashMap<>(); static { + // IntelliJ UI properties that are not used in FlatLaf + uiKeyExcludes = new HashSet<>( Arrays.asList( + "ActionButton.", "ActionToolbar.", "ActionsList.", "AppInspector.", "AssignedMnemonic.", "Autocomplete.", + "AvailableMnemonic.", + "BigSpinner.", "Bookmark.", "BookmarkIcon.", "BookmarkMnemonicAssigned.", "BookmarkMnemonicAvailable.", + "BookmarkMnemonicCurrent.", "BookmarkMnemonicIcon.", "Borders.", "Breakpoint.", + "Canvas.", "CodeWithMe.", "ComboBoxButton.", "CompletionPopup.", "ComplexPopup.", "Content.", + "CurrentMnemonic.", "Counter.", + "Debugger.", "DebuggerPopup.", "DebuggerTabs.", "DefaultTabs.", "Dialog.", "DialogWrapper.", "DragAndDrop.", + "Editor.", "EditorGroupsTabs.", "EditorTabs.", + "FileColor.", "FlameGraph.", "Focus.", + "Git.", "Github.", "GotItTooltip.", "Group.", "Gutter.", "GutterTooltip.", + "HeaderColor.", "HelpTooltip.", "Hg.", + "IconBadge.", "InformationHint.", "InplaceRefactoringPopup.", + "Lesson.", "Link.", "LiveIndicator.", + "MainMenu.", "MainToolbar.", "MemoryIndicator.", "MlModelBinding.", "MnemonicIcon.", + "NavBar.", "NewClass.", "NewPSD.", "Notification.", "Notifications.", "NotificationsToolwindow.", + "OnePixelDivider.", "OptionButton.", "Outline.", + "ParameterInfo.", "Plugins.", "ProgressIcon.", "PsiViewer.", + "ReviewList.", "RunWidget.", + "ScreenView.", "SearchEverywhere.", "SearchFieldWithExtension.", "SearchMatch.", "SearchOption.", + "SearchResults.", "SegmentedButton.", "Settings.", "SidePanel.", "Space.", "SpeedSearch.", "StateWidget.", + "StatusBar.", + "Tag.", "TipOfTheDay.", "ToolbarComboWidget.", "ToolWindow.", + "UIDesigner.", "UnattendedHostStatus.", + "ValidationTooltip.", "VersionControl.", + "WelcomeScreen.", + + // lower case + "darcula.", "dropArea.", "icons.", "intellijlaf.", "macOSWindow.", "material.", "tooltips.", + + // possible typos in .theme.json files + "Checkbox.", "Toolbar.", "Tooltip.", "UiDesigner.", "link." + ) ); + + uiKeyDoNotOverride = new HashSet<>( Arrays.asList( + "TabbedPane.selectedForeground" + ) ); + // ComboBox uiKeyMapping.put( "ComboBox.background", "" ); // ignore uiKeyMapping.put( "ComboBox.nonEditableBackground", "ComboBox.background" ); @@ -644,9 +700,9 @@ public class IntelliJTheme uiKeyCopying.put( "Spinner.buttonDisabledSeparatorColor", "Component.disabledBorderColor" ); // TabbedPane - uiKeyCopying.put( "TabbedPane.selectedBackground", "DefaultTabs.underlinedTabBackground" ); - uiKeyCopying.put( "TabbedPane.selectedForeground", "DefaultTabs.underlinedTabForeground" ); - uiKeyCopying.put( "TabbedPane.inactiveUnderlineColor", "DefaultTabs.inactiveUnderlineColor" ); + uiKeyMapping.put( "DefaultTabs.underlinedTabBackground", "TabbedPane.selectedBackground" ); + uiKeyMapping.put( "DefaultTabs.underlinedTabForeground", "TabbedPane.selectedForeground" ); + uiKeyMapping.put( "DefaultTabs.inactiveUnderlineColor", "TabbedPane.inactiveUnderlineColor" ); // TitlePane uiKeyCopying.put( "TitlePane.inactiveBackground", "TitlePane.background" );