Browse Source

Made decorations creation process more flexible and independent of the platform specific implementation.

Signed-off-by: weisj <weisj@arcor.de>
pull/48/head
weisj 5 years ago
parent
commit
1dbc8ff662
  1. 36
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 27
      core/src/main/java/com/github/weisj/darklaf/LafManager.java
  3. 49
      core/src/main/java/com/github/weisj/darklaf/decorations/DefaultDecorationsProvider.java
  4. 57
      core/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorations.java
  5. 53
      core/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java
  6. 2
      core/src/main/java/com/github/weisj/darklaf/decorations/windows/CloseButtonUI.java
  7. 40
      core/src/main/java/com/github/weisj/darklaf/decorations/windows/DarkTitlePaneWindows.java
  8. 2
      core/src/main/java/com/github/weisj/darklaf/decorations/windows/TitlePaneIcon.java
  9. 48
      core/src/main/java/com/github/weisj/darklaf/decorations/windows/WindowsDecorationsProvider.java
  10. 2
      core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java
  11. 32
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/CustomTitlePane.java
  12. 19
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  13. 18
      windows/src/main/cpp/JNIDecorations.cpp
  14. 8
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java

36
core/src/main/java/com/github/weisj/darklaf/DarkLaf.java

@ -24,11 +24,11 @@
package com.github.weisj.darklaf;
import com.github.weisj.darklaf.components.border.DarkBorders;
import com.github.weisj.darklaf.platform.windows.JNIDecorations;
import com.github.weisj.darklaf.decorations.JNIDecorations;
import com.github.weisj.darklaf.platform.SystemInfo;
import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI;
import com.github.weisj.darklaf.util.PropertyLoader;
import com.github.weisj.darklaf.platform.SystemInfo;
import sun.awt.AppContext;
import javax.swing.*;
@ -55,7 +55,6 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
private static final Logger LOGGER = Logger.getLogger(DarkLaf.class.getName());
private static final String NAME = "Darklaf";
private static boolean decorationsEnabled = true;
private final BasicLookAndFeel base;
/**
@ -77,22 +76,6 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
}
public static boolean isDecorationsEnabled() {
return LafManager.getTheme().useCustomDecorations() && decorationsEnabled;
}
public static void setDecorationsEnabled(final boolean decorationsEnabled) {
if (DarkLaf.decorationsEnabled != decorationsEnabled) {
DarkLaf.decorationsEnabled = decorationsEnabled;
if (decorationsEnabled) {
boolean update = JNIDecorations.updateLibrary();
if (update) {
LafManager.updateLaf();
}
}
}
}
@Override
public UIDefaults getDefaults() {
try {
@ -104,10 +87,9 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
initInputMapDefaults(defaults);
loadThemeDefaults(defaults);
initIdeaDefaults(defaults);
patchComboBox(metalDefaults, defaults);
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
patchComboBox(metalDefaults, defaults);
setupDecorations();
return defaults;
} catch (final Exception e) {
@ -116,6 +98,12 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
return super.getDefaults();
}
private void setupDecorations() {
JNIDecorations.updateLibrary();
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
}
protected void adjustPlatformSpecifics(final Properties uiProps) {
boolean useScreenMenuBar = Boolean.getBoolean("apple.laf.useScreenMenuBar");
// If user wants to use Apple menu bar, then we need to keep the default
@ -184,7 +172,6 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
StyleSheet styleSheet = currentTheme.loadStyleSheet();
new HTMLEditorKit().setStyleSheet(styleSheet);
setDecorationsEnabled(currentTheme.useCustomDecorations());
}
@SuppressWarnings({"HardCodedStringLiteral"})
@ -388,7 +375,8 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
@Override
public boolean getSupportsWindowDecorations() {
return LafManager.getTheme().useCustomDecorations()
return LafManager.isDecorationsEnabled()
&& LafManager.getTheme().useCustomDecorations()
&& JNIDecorations.isCustomDecorationSupported();
}

27
core/src/main/java/com/github/weisj/darklaf/LafManager.java

@ -44,6 +44,7 @@ public final class LafManager {
private static Theme theme;
private static boolean logEnabled = false;
private static boolean decorationsOverwrite = true;
static {
/*
@ -76,6 +77,32 @@ public final class LafManager {
LafManager.logEnabled = logEnabled;
}
/**
* Returns whther custom decorations should be used.
* If this returns true decorations still might not be used if the theme or platform don't support them.
*
* @return true if decorations should be used.
*/
public static boolean isDecorationsEnabled() {
return decorationsOverwrite;
}
/**
* Set globally whether decorations are enabled. By default this is true.
* Decorations are used if this value is set to true and the current platform and theme support
* custom decorations.
*
* @param enabled true if decorations should be used if available.
*/
public static void setDecorationsEnabled(final boolean enabled) {
if (decorationsOverwrite != enabled) {
decorationsOverwrite = enabled;
if (!decorationsOverwrite) {
updateLaf();
}
}
}
/**
* Get the current theme. This method will never return null even if the LaF isn#t currently installed.
*

49
core/src/main/java/com/github/weisj/darklaf/decorations/DefaultDecorationsProvider.java

@ -0,0 +1,49 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.decorations;
import com.github.weisj.darklaf.ui.rootpane.CustomTitlePane;
import javax.swing.*;
public class DefaultDecorationsProvider implements JNIDecorationsProvider {
@Override
public CustomTitlePane createTitlePane(final JRootPane rootPane) {
return new CustomTitlePane() {
@Override
public void uninstall() {
}
};
}
@Override
public boolean isCustomDecorationSupported() {
return false;
}
@Override
public boolean updateLibrary() {
return false;
}
}

57
core/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorations.java

@ -0,0 +1,57 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.decorations;
import com.github.weisj.darklaf.decorations.windows.WindowsDecorationsProvider;
import com.github.weisj.darklaf.platform.SystemInfo;
import com.github.weisj.darklaf.ui.rootpane.CustomTitlePane;
import javax.swing.*;
public final class JNIDecorations {
private static JNIDecorationsProvider decorationsProvider;
static {
//Extend for different platforms.
if (SystemInfo.isWindows) {
decorationsProvider = new WindowsDecorationsProvider();
} else {
decorationsProvider = new DefaultDecorationsProvider();
}
}
public static CustomTitlePane createTitlePane(final JRootPane rootPane) {
return decorationsProvider.createTitlePane(rootPane);
}
public static boolean isCustomDecorationSupported() {
return decorationsProvider.isCustomDecorationSupported();
}
public static boolean updateLibrary() {
return decorationsProvider.updateLibrary();
}
}

53
core/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java

@ -0,0 +1,53 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.decorations;
import com.github.weisj.darklaf.ui.rootpane.CustomTitlePane;
import javax.swing.*;
public interface JNIDecorationsProvider {
/**
* Create the custom title pane.
*
* @param rootPane The root pane to create the title pane for.
* @return the custom title pane.
*/
CustomTitlePane createTitlePane(final JRootPane rootPane);
/**
* Returns whether custom decorations are supported.
*
* @return true if decorations are supported.
*/
boolean isCustomDecorationSupported();
/**
* Load the decorations library if necessary.
*
* @return true if successful and library wasn't already loaded.
*/
boolean updateLibrary();
}

2
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/CloseButtonUI.java → core/src/main/java/com/github/weisj/darklaf/decorations/windows/CloseButtonUI.java

@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.ui.rootpane;
package com.github.weisj.darklaf.decorations.windows;
import com.github.weisj.darklaf.ui.button.DarkButtonUI;

40
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java → core/src/main/java/com/github/weisj/darklaf/decorations/windows/DarkTitlePaneWindows.java

@ -22,11 +22,12 @@
* SOFTWARE.
*/
package com.github.weisj.darklaf.ui.rootpane;
package com.github.weisj.darklaf.decorations.windows;
import com.github.weisj.darklaf.decorators.AncestorAdapter;
import com.github.weisj.darklaf.icons.ScaledIcon;
import com.github.weisj.darklaf.platform.windows.JNIDecorations;
import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows;
import com.github.weisj.darklaf.ui.rootpane.CustomTitlePane;
import com.github.weisj.darklaf.util.Scale;
import sun.awt.SunToolkit;
@ -36,12 +37,7 @@ import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.plaf.UIResource;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
@ -50,7 +46,7 @@ import java.util.List;
* @author Konstantin Bulenkov
* @author Jannis Weis
*/
public class DarkTitlePane extends JComponent {
public class DarkTitlePaneWindows extends CustomTitlePane {
private static final int PAD = 5;
private static final int BAR_HEIGHT = 28;
private static final int BUTTON_WIDTH = 46;
@ -133,7 +129,7 @@ public class DarkTitlePane extends JComponent {
private Color activeForeground;
private Color border;
public DarkTitlePane(final JRootPane root) {
public DarkTitlePaneWindows(final JRootPane root) {
this.rootPane = root;
rootPane.addContainerListener(rootPaneContainerListener);
rootPane.getLayeredPane().addContainerListener(layeredPaneContainerListener);
@ -192,7 +188,7 @@ public class DarkTitlePane extends JComponent {
protected void uninstallDecorations() {
window = null;
JNIDecorations.uninstallDecorations(windowHandle);
JNIDecorationsWindows.uninstallDecorations(windowHandle);
windowHandle = 0;
rootPane.removeContainerListener(rootPaneContainerListener);
rootPane.getLayeredPane().removeContainerListener(layeredPaneContainerListener);
@ -205,12 +201,12 @@ public class DarkTitlePane extends JComponent {
public void install() {
if (window != null) {
if (window instanceof Dialog || window instanceof Frame) {
windowHandle = JNIDecorations.getHWND(window);
windowHandle = JNIDecorationsWindows.getHWND(window);
JNIDecorations.installDecorations(windowHandle);
JNIDecorationsWindows.installDecorations(windowHandle);
updateResizeBehaviour();
Color color = window.getBackground();
JNIDecorations.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
}
if (window instanceof Frame) {
@ -240,7 +236,7 @@ public class DarkTitlePane extends JComponent {
private WindowListener createWindowListener() {
return new DarkTitlePane.WindowHandler();
return new DarkTitlePaneWindows.WindowHandler();
}
@ -363,15 +359,15 @@ public class DarkTitlePane extends JComponent {
}
private void minimize() {
JNIDecorations.minimize(windowHandle);
JNIDecorationsWindows.minimize(windowHandle);
}
private void maximize() {
JNIDecorations.maximize(windowHandle);
JNIDecorationsWindows.maximize(windowHandle);
}
private void restore() {
JNIDecorations.restore(windowHandle);
JNIDecorationsWindows.restore(windowHandle);
}
private void createActions() {
@ -473,7 +469,7 @@ public class DarkTitlePane extends JComponent {
boolean res = isResizable(window, rootPane);
if (oldResizable != res) {
oldResizable = res;
JNIDecorations.setResizable(windowHandle, res);
JNIDecorationsWindows.setResizable(windowHandle, res);
}
}
@ -716,7 +712,7 @@ public class DarkTitlePane extends JComponent {
right = tmp;
}
JNIDecorations.updateValues(windowHandle, Scale.scaleWidth(left),
JNIDecorationsWindows.updateValues(windowHandle, Scale.scaleWidth(left),
Scale.scaleWidth(right),
Scale.scaleHeight(height));
@ -748,7 +744,7 @@ public class DarkTitlePane extends JComponent {
setState(frame.getExtendedState(), true);
}
if ("resizable".equals(name)) {
JNIDecorations.setResizable(windowHandle, Boolean.TRUE.equals(pce.getNewValue()));
JNIDecorationsWindows.setResizable(windowHandle, Boolean.TRUE.equals(pce.getNewValue()));
getRootPane().repaint();
}
} else if ("title".equals(name)) {
@ -763,7 +759,7 @@ public class DarkTitlePane extends JComponent {
repaint();
} else if ("background".equals(name) && pce.getNewValue() instanceof Color) {
Color color = (Color) pce.getNewValue();
JNIDecorations.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
}
}
}

2
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/TitlePaneIcon.java → core/src/main/java/com/github/weisj/darklaf/decorations/windows/TitlePaneIcon.java

@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.ui.rootpane;
package com.github.weisj.darklaf.decorations.windows;
import javax.swing.*;
import java.awt.*;

48
core/src/main/java/com/github/weisj/darklaf/decorations/windows/WindowsDecorationsProvider.java

@ -0,0 +1,48 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.decorations.windows;
import com.github.weisj.darklaf.decorations.JNIDecorationsProvider;
import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows;
import com.github.weisj.darklaf.ui.rootpane.CustomTitlePane;
import javax.swing.*;
public class WindowsDecorationsProvider implements JNIDecorationsProvider {
@Override
public CustomTitlePane createTitlePane(final JRootPane rootPane) {
return new DarkTitlePaneWindows(rootPane);
}
@Override
public boolean isCustomDecorationSupported() {
return JNIDecorationsWindows.isCustomDecorationSupported();
}
@Override
public boolean updateLibrary() {
return JNIDecorationsWindows.updateLibrary();
}
}

2
core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java

@ -23,8 +23,8 @@
*/
package com.github.weisj.darklaf.ui.internalframe;
import com.github.weisj.darklaf.decorations.windows.TitlePaneIcon;
import com.github.weisj.darklaf.icons.EmptyIcon;
import com.github.weisj.darklaf.ui.rootpane.TitlePaneIcon;
import sun.swing.SwingUtilities2;
import javax.accessibility.AccessibleContext;

32
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/CustomTitlePane.java

@ -0,0 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.ui.rootpane;
import javax.swing.*;
public abstract class CustomTitlePane extends JComponent {
public abstract void uninstall();
}

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

@ -24,7 +24,7 @@
package com.github.weisj.darklaf.ui.rootpane;
import com.github.weisj.darklaf.platform.windows.JNIDecorations;
import com.github.weisj.darklaf.decorations.JNIDecorations;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
@ -42,7 +42,7 @@ import java.beans.PropertyChangeListener;
*/
public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener {
private Window window;
private DarkTitlePane titlePane;
private CustomTitlePane titlePane;
private LayoutManager layoutManager;
private LayoutManager oldLayout;
private JRootPane rootPane;
@ -139,7 +139,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
}
private void installClientDecorations(final JRootPane root) {
DarkTitlePane titlePane = createTitlePane(root);
CustomTitlePane titlePane = JNIDecorations.createTitlePane(root);
setTitlePane(root, titlePane);
updateWindow(root.getParent());
installLayout(root);
@ -154,11 +154,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
}
}
protected DarkTitlePane createTitlePane(final JRootPane root) {
return new DarkTitlePane(root);
}
private void setTitlePane(final JRootPane root, final DarkTitlePane titlePane) {
private void setTitlePane(final JRootPane root, final CustomTitlePane titlePane) {
JLayeredPane layeredPane = root.getLayeredPane();
JComponent oldTitlePane = getTitlePane();
@ -222,8 +218,11 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
if (currWindow != null) {
if (currWindow != window) {
if (!JNIDecorations.isCustomDecorationSupported()) return;
if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) return;
if (!JNIDecorations.isCustomDecorationSupported()
|| rootPane.getWindowDecorationStyle() == JRootPane.NONE) {
uninstallClientDecorations(rootPane);
return;
}
updateClientDecoration();
}
window = currWindow;

18
windows/src/main/cpp/JNIDecorations.cpp

@ -22,7 +22,7 @@
* SOFTWARE.
*/
#include "JNIDecorations.h"
#include "com_github_weisj_darklaf_platform_windows_JNIDecorations.h"
#include "com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows.h"
#include <dwmapi.h>
#include <iostream>
#include <map>
@ -130,7 +130,7 @@ LRESULT CALLBACK WindowWrapper::WindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_setResizable(JNIEnv *env, jclass obj, jlong hwnd, jboolean res)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_setResizable(JNIEnv *env, jclass obj, jlong hwnd, jboolean res)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
auto wrap = wrapper_map[handle];
@ -141,7 +141,7 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_setResizable(JNIEn
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_updateValues(JNIEnv *env, jclass obj, jlong hwnd,
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_updateValues(JNIEnv *env, jclass obj, jlong hwnd,
jint l, jint r, jint h)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
@ -155,7 +155,7 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_updateValues(JNIEn
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_setBackground(JNIEnv *env, jclass obj, jlong hwnd, jint r, jint g, jint b)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_setBackground(JNIEnv *env, jclass obj, jlong hwnd, jint r, jint g, jint b)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
auto wrap = wrapper_map[handle];
@ -166,7 +166,7 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_setBackground(JNIE
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_installDecorations(JNIEnv *env, jclass obj, jlong hwnd)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_installDecorations(JNIEnv *env, jclass obj, jlong hwnd)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
@ -194,7 +194,7 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_installDecorations
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_uninstallDecorations(JNIEnv *env, jclass obj, jlong hwnd)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_uninstallDecorations(JNIEnv *env, jclass obj, jlong hwnd)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
auto wrap = wrapper_map[handle];
@ -209,21 +209,21 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_uninstallDecoratio
//Window functions.
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_minimize(JNIEnv *env, jclass obj, jlong hwnd)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_minimize(JNIEnv *env, jclass obj, jlong hwnd)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
ShowWindow(handle, SW_MINIMIZE);
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_maximize(JNIEnv *env, jclass obj, jlong hwnd)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_maximize(JNIEnv *env, jclass obj, jlong hwnd)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
ShowWindow(handle, SW_MAXIMIZE);
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorations_restore(JNIEnv *env, jclass obj, jlong hwnd)
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_restore(JNIEnv *env, jclass obj, jlong hwnd)
{
HWND handle = reinterpret_cast<HWND>(hwnd);
ShowWindow(handle, SW_RESTORE);

8
windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorations.java → windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java

@ -36,16 +36,12 @@ import java.util.logging.Logger;
/**
* @author Jannis Weis
*/
public class JNIDecorations {
public class JNIDecorationsWindows {
private static final Logger LOGGER = Logger.getLogger(JNIDecorations.class.getName());
private static final Logger LOGGER = Logger.getLogger(JNIDecorationsWindows.class.getName());
private static boolean supported;
private static boolean loaded;
static {
updateLibrary();
}
public static native void updateValues(final long hwnd, final int left, final int right, final int height);
public static native void setResizable(final long hwnd, final boolean resizable);
Loading…
Cancel
Save