From 4016a923a6eff39f08c9181b1118ea45bcb399c9 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 30 Jul 2019 10:58:03 +0200 Subject: [PATCH] LafManager topic GitOrigin-RevId: 30fc34f546fd0846eb77afdfabee45fb8ba1e61c --- .../src/com/intellij/util/messages/Topic.java | 4 ++ .../ide/navigationToolbar/NavBarListener.java | 42 ++++++++++--------- .../src/com/intellij/ide/ui/LafManager.java | 31 ++++++-------- .../intellij/ide/ui/LafManagerListener.java | 21 +++------- .../execution/impl/ConsoleViewUtil.java | 21 ++-------- .../ide/actions/QuickChangeLookAndFeel.java | 9 ++-- .../ide/plugins/newui/PluginLogo.java | 15 ++++--- .../intellij/ide/ui/laf/LafManagerImpl.java | 23 +++++----- .../intellij/internal/GrayFilterConfig.java | 14 +++++-- .../internal/TextGrayFilterConfig.java | 4 +- .../openapi/ui/impl/ShadowPainter.java | 7 ++-- .../openapi/wm/impl/IdeFrameImpl.java | 6 +-- .../openapi/wm/impl/ToolWindowIcon.java | 15 +++---- .../intellij/ui/javafx/JavaFxHtmlPanel.java | 9 +--- .../settings/MarkdownApplicationSettings.java | 26 +++++------- .../intellij/uiDesigner/palette/Palette.java | 18 ++------ .../PropertyInspectorTable.java | 17 +++++++- 17 files changed, 132 insertions(+), 150 deletions(-) diff --git a/platform/core-api/src/com/intellij/util/messages/Topic.java b/platform/core-api/src/com/intellij/util/messages/Topic.java index a3f803a6b7ca..341b5a90c0fa 100644 --- a/platform/core-api/src/com/intellij/util/messages/Topic.java +++ b/platform/core-api/src/com/intellij/util/messages/Topic.java @@ -18,6 +18,10 @@ public class Topic { this(displayName, listenerClass, BroadcastDirection.TO_CHILDREN); } + public Topic(@NotNull Class listenerClass) { + this(listenerClass.getSimpleName(), listenerClass, BroadcastDirection.TO_CHILDREN); + } + public Topic(@NonNls @NotNull String displayName, @NotNull Class listenerClass, @NotNull BroadcastDirection broadcastDirection) { myDisplayName = displayName; myListenerClass = listenerClass; diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarListener.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarListener.java index 4fe13658ce21..05b84df4a050 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarListener.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarListener.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.navigationToolbar; import com.intellij.ProjectTopics; @@ -47,7 +47,7 @@ import java.util.List; /** * @author Konstantin Bulenkov */ -public class NavBarListener +public final class NavBarListener implements ProblemListener, FocusListener, FileStatusListener, AnActionListener, FileEditorManagerListener, PsiTreeChangeListener, ModuleRootListener, NavBarModelListener, PropertyChangeListener, KeyListener, WindowFocusListener, LafManagerListener { @@ -56,7 +56,7 @@ public class NavBarListener private final NavBarPanel myPanel; private boolean shouldFocusEditor; - static void subscribeTo(NavBarPanel panel) { + static void subscribeTo(@NotNull NavBarPanel panel) { if (panel.getClientProperty(LISTENER) != null) { unsubscribeFrom(panel); } @@ -68,7 +68,7 @@ public class NavBarListener FileStatusManager.getInstance(project).addFileStatusListener(listener); PsiManager.getInstance(project).addPsiTreeChangeListener(listener); - final MessageBusConnection connection = project.getMessageBus().connect(); + MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(AnActionListener.TOPIC, listener); connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener); connection.subscribe(NavBarModelListener.NAV_BAR, listener); @@ -78,29 +78,31 @@ public class NavBarListener panel.addKeyListener(listener); if (panel.isInFloatingMode()) { - final Window window = SwingUtilities.windowForComponent(panel); + Window window = SwingUtilities.windowForComponent(panel); if (window != null) { window.addWindowFocusListener(listener); } - } else { - LafManager.getInstance().addLafManagerListener(listener); + } + else { + connection.subscribe(LafManagerListener.TOPIC, listener); } } - static void unsubscribeFrom(NavBarPanel panel) { - final NavBarListener listener = (NavBarListener)panel.getClientProperty(LISTENER); + static void unsubscribeFrom(@NotNull NavBarPanel panel) { + NavBarListener listener = (NavBarListener)panel.getClientProperty(LISTENER); panel.putClientProperty(LISTENER, null); - if (listener != null) { - final Project project = panel.getProject(); - KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener); - FileStatusManager.getInstance(project).removeFileStatusListener(listener); - PsiManager.getInstance(project).removePsiTreeChangeListener(listener); - final MessageBusConnection connection = (MessageBusConnection)panel.getClientProperty(BUS); - panel.putClientProperty(BUS, null); - if (connection != null) { - connection.disconnect(); - } - LafManager.getInstance().removeLafManagerListener(listener); + if (listener == null) { + return; + } + + Project project = panel.getProject(); + KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener); + FileStatusManager.getInstance(project).removeFileStatusListener(listener); + PsiManager.getInstance(project).removePsiTreeChangeListener(listener); + MessageBusConnection connection = (MessageBusConnection)panel.getClientProperty(BUS); + panel.putClientProperty(BUS, null); + if (connection != null) { + connection.disconnect(); } } diff --git a/platform/platform-api/src/com/intellij/ide/ui/LafManager.java b/platform/platform-api/src/com/intellij/ide/ui/LafManager.java index d0249a52a92a..5ec7783ad48f 100644 --- a/platform/platform-api/src/com/intellij/ide/ui/LafManager.java +++ b/platform/platform-api/src/com/intellij/ide/ui/LafManager.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.ui; import com.intellij.openapi.Disposable; @@ -22,9 +8,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; -/** - * @author anna - */ public abstract class LafManager { public static LafManager getInstance() { return ApplicationManager.getApplication().getComponent(LafManager.class); @@ -42,9 +25,21 @@ public abstract class LafManager { public abstract void repaintUI(); + /** + * @deprecated Use {@link LafManagerListener#TOPIC} + */ + @Deprecated public abstract void addLafManagerListener(@NotNull LafManagerListener listener); + /** + * @deprecated Use {@link LafManagerListener#TOPIC} + */ + @Deprecated public abstract void addLafManagerListener(@NotNull LafManagerListener listener, @NotNull Disposable disposable); + /** + * @deprecated Use {@link LafManagerListener#TOPIC} + */ + @Deprecated public abstract void removeLafManagerListener(@NotNull LafManagerListener listener); } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/ide/ui/LafManagerListener.java b/platform/platform-api/src/com/intellij/ide/ui/LafManagerListener.java index 7d1a2281758f..0cd8a0771727 100644 --- a/platform/platform-api/src/com/intellij/ide/ui/LafManagerListener.java +++ b/platform/platform-api/src/com/intellij/ide/ui/LafManagerListener.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.ui; +import com.intellij.util.messages.Topic; import org.jetbrains.annotations.NotNull; import java.util.EventListener; @@ -26,6 +13,8 @@ import java.util.EventListener; * * @author Vladimir Kondratyev */ -public interface LafManagerListener extends EventListener{ +public interface LafManagerListener extends EventListener { + Topic TOPIC = new Topic<>(LafManagerListener.class); + void lookAndFeelChanged(@NotNull LafManager source); } diff --git a/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java b/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java index 319088ff1de4..0e0cebec4095 100644 --- a/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java +++ b/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.impl; import com.intellij.execution.ui.ConsoleView; @@ -102,7 +88,7 @@ public class ConsoleViewUtil { @Override public void setColorScheme(@NotNull EditorColorsScheme scheme) {} } - + @NotNull public static DelegateColorScheme updateConsoleColorScheme(@NotNull EditorColorsScheme scheme) { return new DelegateColorScheme(scheme) { @@ -161,13 +147,14 @@ public class ConsoleViewUtil { private static class ColorCache { static { - LafManager.getInstance().addLafManagerListener(new LafManagerListener() { + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, new LafManagerListener() { @Override public void lookAndFeelChanged(@NotNull LafManager source) { mergedTextAttributes.clear(); } }); } + static final Map> textAttributeKeys = ContainerUtil.newConcurrentMap(); static final Map mergedTextAttributes = ConcurrentFactoryMap.createMap(contentKey-> { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeLookAndFeel.java b/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeLookAndFeel.java index 95909289e72b..70a1b8cb146d 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeLookAndFeel.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/QuickChangeLookAndFeel.java @@ -5,11 +5,14 @@ import com.intellij.icons.AllIcons; import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.LafManagerListener; import com.intellij.ide.ui.laf.darcula.DarculaInstaller; +import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.registry.Registry; import com.intellij.util.ui.StartupUiUtil; @@ -49,8 +52,8 @@ public class QuickChangeLookAndFeel extends QuickSwitchSchemeAction { // a twist not to updateUI twice: here and in DarculaInstaller // double updateUI shall be avoided and causes NPE in some components (HelpView) Ref updated = Ref.create(false); - LafManagerListener listener = (s) -> updated.set(true); - lafMan.addLafManagerListener(listener); + Disposable disposable = Disposer.newDisposable(); + ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(LafManagerListener.TOPIC, source -> updated.set(true)); try { if (StartupUiUtil.isUnderDarcula()) { DarculaInstaller.install(); @@ -60,7 +63,7 @@ public class QuickChangeLookAndFeel extends QuickSwitchSchemeAction { } } finally { - lafMan.removeLafManagerListener(listener); + Disposer.dispose(disposable); if (!updated.get()) { lafMan.updateUI(); } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java index 3e65f01c83bb..5cec976d03b2 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java @@ -5,7 +5,6 @@ import com.intellij.icons.AllIcons; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.InstalledPluginsState; import com.intellij.ide.plugins.PluginManagerCore; -import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.LafManagerListener; import com.intellij.openapi.application.*; import com.intellij.openapi.application.impl.ApplicationInfoImpl; @@ -37,7 +36,7 @@ import java.util.zip.ZipFile; /** * @author Alexander Lobas */ -public class PluginLogo { +public final class PluginLogo { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.plugins.newui.PluginLogo"); private static final String CACHE_DIR = "imageCache"; @@ -50,11 +49,17 @@ public class PluginLogo { private static PluginLogoIconProvider Default; private static List> myPrepareToLoad; - private static LafManagerListener myLafListener; + private static boolean lafListenerAdded; private static void initLafListener() { - if (myLafListener == null && !GraphicsEnvironment.isHeadless()) { - LafManager.getInstance().addLafManagerListener(myLafListener = _0 -> { + if (!lafListenerAdded) { + lafListenerAdded = true; + + if (GraphicsEnvironment.isHeadless()) { + return; + } + + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, source -> { Default = null; HiDPIPluginLogoIcon.clearCache(); }); diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java index 2ee696ac441e..b303fb5f943b 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/LafManagerImpl.java @@ -154,11 +154,11 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC @Override public void addLafManagerListener(@NotNull LafManagerListener listener, @NotNull Disposable disposable) { - myEventDispatcher.addListener(listener, disposable); + ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(LafManagerListener.TOPIC, listener); } @Override - public void removeLafManagerListener(@NotNull final LafManagerListener listener) { + public void removeLafManagerListener(@NotNull LafManagerListener listener) { myEventDispatcher.removeListener(listener); } @@ -426,6 +426,9 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC ActionToolbarImpl.updateAllToolbarsImmediately(); } + /** + * @deprecated Use {@link AppUIUtil#updateForDarcula(boolean)} + */ @Deprecated @ApiStatus.ScheduledForRemoval public static void updateForDarcula(boolean isDarcula) { @@ -442,14 +445,6 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC return null; } - @Nullable - private static Icon getAquaMenuInvertedIcon() { - if (SystemInfo.isMac && UIUtil.isUnderIntelliJLaF()) { - return AllIcons.Mac.Tree_white_right_arrow; - } - return null; - } - /** * Updates LAF of all windows. The method also updates font of components * as it's configured in {@code UISettings}. @@ -484,6 +479,7 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC updateUI(frame); } + ApplicationManager.getApplication().getMessageBus().syncPublisher(LafManagerListener.TOPIC).lookAndFeelChanged(this); myEventDispatcher.getMulticaster().lookAndFeelChanged(this); } @@ -609,17 +605,18 @@ public final class LafManagerImpl extends LafManager implements PersistentStateC defaults.put("hidpi.scaleFactor", JBUIScale.scale(1f)); } - private static void fixMenuIssues(UIDefaults uiDefaults) { + private static void fixMenuIssues(@NotNull UIDefaults uiDefaults) { if (SystemInfo.isMac && UIUtil.isUnderIntelliJLaF()) { // update ui for popup menu to get round corners uiDefaults.put("PopupMenuUI", MacPopupMenuUI.class.getCanonicalName()); - uiDefaults.put("Menu.invertedArrowIcon", getAquaMenuInvertedIcon()); + uiDefaults.put("Menu.invertedArrowIcon", AllIcons.Mac.Tree_white_right_arrow); uiDefaults.put("Menu.disabledArrowIcon", getAquaMenuDisabledIcon()); } if (UIUtil.isUnderWin10LookAndFeel()) { uiDefaults.put("Menu.arrowIcon", new Win10MenuArrowIcon()); - } else if ((SystemInfo.isLinux || SystemInfo.isWindows) && (UIUtil.isUnderIntelliJLaF() || StartupUiUtil.isUnderDarcula())) { + } + else if ((SystemInfo.isLinux || SystemInfo.isWindows) && (UIUtil.isUnderIntelliJLaF() || StartupUiUtil.isUnderDarcula())) { uiDefaults.put("Menu.arrowIcon", new DefaultMenuArrowIcon(AllIcons.General.ArrowRight)); } diff --git a/platform/platform-impl/src/com/intellij/internal/GrayFilterConfig.java b/platform/platform-impl/src/com/intellij/internal/GrayFilterConfig.java index b6a48e6686f8..124a514edf1f 100644 --- a/platform/platform-impl/src/com/intellij/internal/GrayFilterConfig.java +++ b/platform/platform-impl/src/com/intellij/internal/GrayFilterConfig.java @@ -1,10 +1,11 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.internal; -import com.intellij.ide.ui.LafManager; +import com.intellij.ide.ui.LafManagerListener; import com.intellij.ide.ui.UISettings; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.IconLoader; @@ -34,6 +35,8 @@ public class GrayFilterConfig extends AnAction implements DumbAware { private final Object[][] data = new Object[3][2]; + private boolean lafListenerAdded; + private void setData() { data[0][0] = BRIGHTNESS; data[1][0] = CONTRAST; @@ -46,10 +49,15 @@ public class GrayFilterConfig extends AnAction implements DumbAware { @Override public void actionPerformed(@NotNull AnActionEvent e) { Window activeFrame = IdeFrameImpl.getActiveFrame(); - if (activeFrame == null) return; + if (activeFrame == null) { + return; + } setData(); - LafManager.getInstance().addLafManagerListener(source -> setData()); + if (!lafListenerAdded) { + lafListenerAdded = true; + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, source -> setData()); + } JTable table = new JTable(data, new String[] {"Property", "Value"}) { @Override diff --git a/platform/platform-impl/src/com/intellij/internal/TextGrayFilterConfig.java b/platform/platform-impl/src/com/intellij/internal/TextGrayFilterConfig.java index 83877cb8cb4d..52cebad4391b 100644 --- a/platform/platform-impl/src/com/intellij/internal/TextGrayFilterConfig.java +++ b/platform/platform-impl/src/com/intellij/internal/TextGrayFilterConfig.java @@ -1,9 +1,9 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.internal; import com.intellij.util.ui.UIUtil; -public class TextGrayFilterConfig extends GrayFilterConfig { +public final class TextGrayFilterConfig extends GrayFilterConfig { @Override protected UIUtil.GrayFilter getGrayFilter() { return (UIUtil.GrayFilter)UIUtil.getTextGrayFilter(); diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/impl/ShadowPainter.java b/platform/platform-impl/src/com/intellij/openapi/ui/impl/ShadowPainter.java index afc597d64ad0..81ce4c827efb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/impl/ShadowPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/impl/ShadowPainter.java @@ -1,7 +1,8 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.ui.impl; -import com.intellij.ide.ui.LafManager; +import com.intellij.ide.ui.LafManagerListener; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.ui.JreHiDpiUtil; import com.intellij.ui.scale.JBUIScale; import com.intellij.ui.scale.ScaleContext; @@ -20,7 +21,7 @@ import java.awt.image.BufferedImage; /** * @author Konstantin Bulenkov */ -public class ShadowPainter extends ScaleContextSupport { +public final class ShadowPainter extends ScaleContextSupport { private final Icon myTop; private final Icon myTopRight; private final Icon myRight; @@ -49,7 +50,7 @@ public class ShadowPainter extends ScaleContextSupport { myTopLeft = topLeft; updateIcons(null); - LafManager.getInstance().addLafManagerListener(source -> updateIcons(null)); + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, source -> updateIcons(null)); } public ShadowPainter(Icon top, Icon topRight, Icon right, Icon bottomRight, Icon bottom, Icon bottomLeft, Icon left, Icon topLeft, @Nullable Color borderColor) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index f2945ecb2dea..92e1d05f0b54 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java @@ -2,7 +2,6 @@ package com.intellij.openapi.wm.impl; import com.intellij.diagnostic.IdeMessagePanel; -import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.LafManagerListener; import com.intellij.ide.ui.UISettings; import com.intellij.idea.SplashManager; @@ -83,7 +82,6 @@ public final class IdeFrameImpl extends JFrame implements IdeFrameEx, Accessible private IdeRootPane myRootPane; private BalloonLayout myBalloonLayout; private IdeFrameDecorator myFrameDecorator; - private final LafManagerListener myLafListener; private final ComponentListener resizedListener; private volatile Image selfie; @@ -97,7 +95,6 @@ public final class IdeFrameImpl extends JFrame implements IdeFrameEx, Accessible myRootPane = new IdeRootPane(this); setRootPane(myRootPane); setBackground(UIUtil.getPanelBackground()); - LafManager.getInstance().addLafManagerListener(myLafListener = src -> setBackground(UIUtil.getPanelBackground())); resizedListener = new ComponentAdapter() { @Override @@ -205,6 +202,8 @@ public final class IdeFrameImpl extends JFrame implements IdeFrameEx, Accessible return; } + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, source -> setBackground(UIUtil.getPanelBackground())); + rootPane.init(this); // to show window thumbnail under Macs @@ -553,7 +552,6 @@ public final class IdeFrameImpl extends JFrame implements IdeFrameEx, Accessible Disposer.dispose(myFrameDecorator); myFrameDecorator = null; } - if (myLafListener != null) LafManager.getInstance().removeLafManagerListener(myLafListener); super.dispose(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowIcon.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowIcon.java index 531d34035dbf..5dd96c0d9451 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowIcon.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowIcon.java @@ -1,7 +1,8 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.wm.impl; -import com.intellij.ide.ui.LafManager; +import com.intellij.ide.ui.LafManagerListener; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.ColorUtil; @@ -12,23 +13,23 @@ import com.intellij.ui.scale.ScaleContext; import com.intellij.util.IconUtil; import com.intellij.util.ui.ImageUtil; import com.intellij.util.ui.StartupUiUtil; -import com.intellij.util.ui.UIUtil; +import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; import java.awt.image.RGBImageFilter; import java.util.Arrays; -import java.util.HashMap; import java.util.Map; /** * @author Konstantin Bulenkov */ -public class ToolWindowIcon implements RetrievableIcon, MenuBarIconProvider { - private static final Map ourCache = new HashMap<>(); +public final class ToolWindowIcon implements RetrievableIcon, MenuBarIconProvider { + private static final Map ourCache = new THashMap<>(); + static { - LafManager.getInstance().addLafManagerListener(x -> ourCache.clear()); + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, source -> ourCache.clear()); } @NotNull @@ -94,7 +95,7 @@ public class ToolWindowIcon implements RetrievableIcon, MenuBarIconProvider { ScaleContext ctx = ScaleContext.create((Graphics2D)g); Image rawImage = ImageUtil.filter(IconUtil.toImage(myIcon, ctx), filter); Image hidpiImage = ImageUtil.ensureHiDPI(rawImage, ctx); - UIUtil.drawImage(g, hidpiImage, x, y, null); + StartupUiUtil.drawImage(g, hidpiImage, x, y, null); } private static int getBaseGray() { diff --git a/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java b/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java index 3e258616cc47..308b3390a34d 100644 --- a/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java +++ b/platform/platform-impl/src/com/intellij/ui/javafx/JavaFxHtmlPanel.java @@ -36,7 +36,6 @@ public class JavaFxHtmlPanel implements Disposable { private final JPanel myPanelWrapper; @NotNull private final List myInitActions = new ArrayList<>(); - private final JavaFXLafManagerListener myLafManagerListener; @Nullable protected JFXPanel myPanel; @Nullable protected WebView myWebView; @@ -84,8 +83,7 @@ public class JavaFxHtmlPanel implements Disposable { })); }))); - myLafManagerListener = new JavaFXLafManagerListener(); - LafManager.getInstance().addLafManagerListener(myLafManagerListener); + ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(LafManagerListener.TOPIC, new JavaFXLafManagerListener()); runInPlatformWhenAvailable(() -> updateLaf(StartupUiUtil.isUnderDarcula())); } @@ -175,10 +173,7 @@ public class JavaFxHtmlPanel implements Disposable { @Override public void dispose() { - runInPlatformWhenAvailable( - () -> getWebViewGuaranteed().getEngine().load(null) - ); - LafManager.getInstance().removeLafManagerListener(myLafManagerListener); + runInPlatformWhenAvailable(() -> getWebViewGuaranteed().getEngine().load(null)); } diff --git a/plugins/markdown/src/org/intellij/plugins/markdown/settings/MarkdownApplicationSettings.java b/plugins/markdown/src/org/intellij/plugins/markdown/settings/MarkdownApplicationSettings.java index d35e5027712f..de0deeb81e71 100644 --- a/plugins/markdown/src/org/intellij/plugins/markdown/settings/MarkdownApplicationSettings.java +++ b/plugins/markdown/src/org/intellij/plugins/markdown/settings/MarkdownApplicationSettings.java @@ -1,7 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.plugins.markdown.settings; -import com.intellij.ide.ui.LafManager; +import com.intellij.ide.ui.LafManagerListener; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ServiceManager; @@ -9,28 +9,24 @@ import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.util.messages.Topic; import com.intellij.util.ui.StartupUiUtil; -import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Attribute; import com.intellij.util.xmlb.annotations.Property; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static org.intellij.plugins.markdown.settings.MarkdownCssSettings.DARCULA; -import static org.intellij.plugins.markdown.settings.MarkdownCssSettings.DEFAULT; - @State( name = "MarkdownApplicationSettings", storages = @Storage("markdown.xml") ) -public class MarkdownApplicationSettings implements PersistentStateComponent, - MarkdownCssSettings.Holder, - MarkdownPreviewSettings.Holder { +public final class MarkdownApplicationSettings implements PersistentStateComponent, + MarkdownCssSettings.Holder, + MarkdownPreviewSettings.Holder { - private final State myState = new State(); + private State myState = new State(); public MarkdownApplicationSettings() { - final MarkdownLAFListener lafListener = new MarkdownLAFListener(); - LafManager.getInstance().addLafManagerListener(lafListener); + MarkdownLAFListener lafListener = new MarkdownLAFListener(); + ApplicationManager.getApplication().getMessageBus().connect().subscribe(LafManagerListener.TOPIC, lafListener); // Let's init proper CSS scheme ApplicationManager.getApplication().invokeLater(() -> lafListener.updateCssSettingsForced(StartupUiUtil.isUnderDarcula())); } @@ -48,7 +44,7 @@ public class MarkdownApplicationSettings implements PersistentStateComponent { +public final class Palette implements PersistentStateComponent { private static final Logger LOG = Logger.getInstance(Palette.class); - private final MyLafManagerListener myLafManagerListener; private final Map myClass2Properties; private final Map myClassName2Item; /*All groups in the palette*/ @@ -102,9 +100,8 @@ public final class Palette implements Disposable, PersistentStateComponent(); myClassName2Item = new HashMap<>(); myGroups = new ArrayList<>(); @@ -112,10 +109,8 @@ public final class Palette implements Disposable, PersistentStateComponent