Browse Source

Reduce flickering when switching theme on windows.

pull/187/head
weisj 4 years ago
parent
commit
25470e97a3
  1. 4
      core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java
  2. 6
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  3. 2
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java
  4. 2
      platform-base/src/main/java/com/github/weisj/darklaf/platform/decorations/CustomTitlePane.java
  5. 15
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

4
core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java

@ -37,10 +37,10 @@ public class DefaultDecorationsProvider implements DecorationsProvider {
public CustomTitlePane createTitlePane(final JRootPane rootPane, final int decorationStyle, final Window window) { public CustomTitlePane createTitlePane(final JRootPane rootPane, final int decorationStyle, final Window window) {
return new CustomTitlePane() { return new CustomTitlePane() {
@Override @Override
public void install() {} public void uninstall(final boolean removeDecorations) {}
@Override @Override
public void uninstall() {} public void install() {}
}; };
} }

6
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java

@ -33,6 +33,8 @@ import javax.swing.*;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicRootPaneUI; import javax.swing.plaf.basic.BasicRootPaneUI;
import com.github.weisj.darklaf.DarkLaf;
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.platform.DecorationsHandler; import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.platform.decorations.CustomTitlePane; import com.github.weisj.darklaf.platform.decorations.CustomTitlePane;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
@ -122,7 +124,9 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
uninstallBorder(root); uninstallBorder(root);
root.removeHierarchyListener(this); root.removeHierarchyListener(this);
if (titlePane != null) { if (titlePane != null) {
titlePane.uninstall(); boolean removeDecorations = !(UIManager.getLookAndFeel() instanceof DarkLaf)
|| !LafManager.isDecorationsEnabled();
titlePane.uninstall(removeDecorations);
setTitlePane(root, null); setTitlePane(root, null);
} }
uninstallLayout(root); uninstallLayout(root);

2
macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java

@ -138,7 +138,7 @@ public class MacOSTitlePane extends CustomTitlePane {
} }
@Override @Override
public void uninstall() { public void uninstall(final boolean removeDecorations) {
if (titleLabel != null) { if (titleLabel != null) {
remove(titleLabel); remove(titleLabel);
titleLabel = null; titleLabel = null;

2
platform-base/src/main/java/com/github/weisj/darklaf/platform/decorations/CustomTitlePane.java

@ -32,7 +32,7 @@ public abstract class CustomTitlePane extends JComponent {
protected int decorationStyle; protected int decorationStyle;
public abstract void uninstall(); public abstract void uninstall(final boolean removeDecorations);
/** /**
* Do not call directly. * Do not call directly.

15
windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

@ -172,9 +172,10 @@ public class WindowsTitlePane extends CustomTitlePane {
return button; return button;
} }
public void uninstall() { @Override
public void uninstall(final boolean removeDecorations) {
uninstallListeners(); uninstallListeners();
uninstallDecorations(); uninstallDecorations(removeDecorations);
removeAll(); removeAll();
if (menuBar != null) { if (menuBar != null) {
getRootPane().setJMenuBar(menuBar); getRootPane().setJMenuBar(menuBar);
@ -192,9 +193,11 @@ public class WindowsTitlePane extends CustomTitlePane {
} }
} }
protected void uninstallDecorations() { protected void uninstallDecorations(final boolean removeDecorations) {
if (windowHandle != 0) { if (windowHandle != 0) {
JNIDecorationsWindows.uninstallDecorations(windowHandle, decorationStyle != JRootPane.NONE); if (removeDecorations) {
JNIDecorationsWindows.uninstallDecorations(windowHandle, decorationStyle != JRootPane.NONE);
}
windowHandle = 0; windowHandle = 0;
} }
rootPane.removeContainerListener(rootPaneContainerListener); rootPane.removeContainerListener(rootPaneContainerListener);
@ -228,7 +231,7 @@ public class WindowsTitlePane extends CustomTitlePane {
public void setDecorationsStyle(final int style) { public void setDecorationsStyle(final int style) {
super.setDecorationsStyle(style); super.setDecorationsStyle(style);
if (style == JRootPane.NONE && windowHandle != 0) { if (style == JRootPane.NONE && windowHandle != 0) {
uninstall(); uninstall(true);
} else if (windowHandle == 0) { } else if (windowHandle == 0) {
install(); install();
} }
@ -245,7 +248,7 @@ public class WindowsTitlePane extends CustomTitlePane {
Color color = rootPane.getBackground(); Color color = rootPane.getBackground();
JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue()); JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
} else { } else {
uninstall(); uninstall(decorationStyle != JRootPane.NONE);
return false; return false;
} }
} }

Loading…
Cancel
Save