From c917e6c11c3fe80bd1b04309d9a36e516ed5f31c Mon Sep 17 00:00:00 2001 From: weisj Date: Thu, 20 Feb 2020 23:17:57 +0100 Subject: [PATCH] Moved custom decorations base classes to own module as not all implementations of custom decorations are JNI based. Signed-off-by: weisj --- core/build.gradle.kts | 1 + .../main/java/com/github/weisj/darklaf/DarkLaf.java | 10 +++++----- .../{JNIDecorations.java => Decorations.java} | 13 +++++++------ .../platform/DefaultDecorationsProvider.java | 8 ++++---- .../github/weisj/darklaf/theme/IntelliJTheme.java | 2 +- .../java/com/github/weisj/darklaf/theme/Theme.java | 2 +- .../weisj/darklaf/ui/button/DarkButtonUI.java | 2 +- .../weisj/darklaf/ui/rootpane/DarkRootPaneUI.java | 8 ++++---- .../github/weisj/darklaf/ui/tree/DarkTreeUI.java | 9 ++------- core/src/test/java/theme/MyCustomTheme.java | 2 +- decorations-base/build.gradle.kts | 3 +++ .../github/weisj}/decorations/CustomTitlePane.java | 2 +- .../weisj/decorations/DecorationsProvider.java | 10 ++++------ settings.gradle.kts | 1 + .../com/github/weisj/darklaf/util}/SystemInfo.java | 2 +- windows/build.gradle.kts | 1 + .../platform/windows/JNIDecorationsWindows.java | 4 ++-- .../windows/WindowsDecorationsProvider.java | 10 +++++----- .../platform/windows/ui/DarkTitlePaneWindows.java | 4 ++-- 19 files changed, 47 insertions(+), 47 deletions(-) rename core/src/main/java/com/github/weisj/darklaf/platform/{JNIDecorations.java => Decorations.java} (86%) create mode 100644 decorations-base/build.gradle.kts rename {native-utils/src/main/java/com/github/weisj/darklaf => decorations-base/src/main/java/com/github/weisj}/decorations/CustomTitlePane.java (96%) rename native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java => decorations-base/src/main/java/com/github/weisj/decorations/DecorationsProvider.java (88%) rename {native-utils/src/main/java/com/github/weisj/darklaf/platform => utils/src/main/java/com/github/weisj/darklaf/util}/SystemInfo.java (99%) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 08f306b9..3b2fc9e5 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -10,6 +10,7 @@ plugins { dependencies { implementation(project(":darklaf-native-utils")) implementation(project(":darklaf-utils")) + implementation(project(":darklaf-decorations-base")) implementation(project(":darklaf-windows")) implementation(project(":darklaf-property-loader")) implementation("org.swinglabs:jxlayer") diff --git a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java index 6d94cac1..c5df960a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -24,10 +24,10 @@ package com.github.weisj.darklaf; import com.github.weisj.darklaf.components.border.DarkBorders; -import com.github.weisj.darklaf.platform.JNIDecorations; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.platform.Decorations; import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI; +import com.github.weisj.darklaf.util.SystemInfo; import sun.awt.AppContext; import javax.swing.*; @@ -118,7 +118,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener } private void setupDecorations() { - JNIDecorations.updateLibrary(); + Decorations.initialize(); JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); } @@ -186,7 +186,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener currentTheme.loadUIProperties(uiProps, defaults); currentTheme.loadIconProperties(uiProps, defaults); currentTheme.loadPlatformProperties(uiProps, defaults); - JNIDecorations.loadDecorationProperties(uiProps, defaults); + Decorations.loadDecorationProperties(uiProps, defaults); adjustPlatformSpecifics(uiProps); defaults.putAll(uiProps); @@ -402,7 +402,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener public boolean getSupportsWindowDecorations() { return LafManager.isDecorationsEnabled() && LafManager.getTheme().useCustomDecorations() - && JNIDecorations.isCustomDecorationSupported(); + && Decorations.isCustomDecorationSupported(); } diff --git a/core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java b/core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java similarity index 86% rename from core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java rename to core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java index 68dad573..55418b34 100644 --- a/core/src/main/java/com/github/weisj/darklaf/platform/JNIDecorations.java +++ b/core/src/main/java/com/github/weisj/darklaf/platform/Decorations.java @@ -23,16 +23,17 @@ */ package com.github.weisj.darklaf.platform; -import com.github.weisj.darklaf.decorations.CustomTitlePane; -import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; import com.github.weisj.darklaf.platform.windows.WindowsDecorationsProvider; +import com.github.weisj.darklaf.util.SystemInfo; +import com.github.weisj.decorations.CustomTitlePane; +import com.github.weisj.decorations.DecorationsProvider; import javax.swing.*; import java.util.Properties; -public final class JNIDecorations { +public final class Decorations { - private static JNIDecorationsProvider decorationsProvider; + private static DecorationsProvider decorationsProvider; static { //Extend for different platforms. @@ -52,8 +53,8 @@ public final class JNIDecorations { return decorationsProvider.isCustomDecorationSupported(); } - public static boolean updateLibrary() { - return decorationsProvider.updateLibrary(); + public static void initialize() { + decorationsProvider.initialize(); } public static void loadDecorationProperties(final Properties uiProps, final UIDefaults defaults) { diff --git a/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java b/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java index 47cef96f..4e6d89fb 100644 --- a/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java +++ b/core/src/main/java/com/github/weisj/darklaf/platform/DefaultDecorationsProvider.java @@ -23,13 +23,13 @@ */ package com.github.weisj.darklaf.platform; -import com.github.weisj.darklaf.decorations.CustomTitlePane; -import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; +import com.github.weisj.decorations.CustomTitlePane; +import com.github.weisj.decorations.DecorationsProvider; import javax.swing.*; import java.util.Properties; -public class DefaultDecorationsProvider implements JNIDecorationsProvider { +public class DefaultDecorationsProvider implements DecorationsProvider { @Override public CustomTitlePane createTitlePane(final JRootPane rootPane) { return new CustomTitlePane() { @@ -45,7 +45,7 @@ public class DefaultDecorationsProvider implements JNIDecorationsProvider { } @Override - public boolean updateLibrary() { + public boolean initialize() { return false; } diff --git a/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java b/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java index 93111892..2f376b3f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java +++ b/core/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java @@ -24,7 +24,7 @@ package com.github.weisj.darklaf.theme; import com.github.weisj.darklaf.PropertyLoader; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.util.SystemInfo; import javax.swing.*; import java.util.Properties; diff --git a/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java b/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java index 18e86c51..3d24a321 100644 --- a/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java +++ b/core/src/main/java/com/github/weisj/darklaf/theme/Theme.java @@ -26,7 +26,7 @@ package com.github.weisj.darklaf.theme; import com.github.weisj.darklaf.DarkLaf; import com.github.weisj.darklaf.DarkMetalTheme; import com.github.weisj.darklaf.PropertyLoader; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.util.SystemInfo; import javax.swing.*; import javax.swing.plaf.metal.MetalLookAndFeel; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java index 5e0626b8..8daefa9d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java @@ -23,10 +23,10 @@ */ package com.github.weisj.darklaf.ui.button; -import com.github.weisj.darklaf.platform.SystemInfo; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; +import com.github.weisj.darklaf.util.SystemInfo; import sun.swing.SwingUtilities2; import javax.swing.*; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java index 6e67f94b..9958dd3f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java @@ -24,8 +24,8 @@ package com.github.weisj.darklaf.ui.rootpane; -import com.github.weisj.darklaf.decorations.CustomTitlePane; -import com.github.weisj.darklaf.platform.JNIDecorations; +import com.github.weisj.darklaf.platform.Decorations; +import com.github.weisj.decorations.CustomTitlePane; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -140,7 +140,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener } private void installClientDecorations(final JRootPane root) { - CustomTitlePane titlePane = JNIDecorations.createTitlePane(root); + CustomTitlePane titlePane = Decorations.createTitlePane(root); setTitlePane(root, titlePane); updateWindow(root.getParent()); installLayout(root); @@ -219,7 +219,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener if (currWindow != null) { if (currWindow != window) { - if (!JNIDecorations.isCustomDecorationSupported() + if (!Decorations.isCustomDecorationSupported() || rootPane.getWindowDecorationStyle() == JRootPane.NONE) { uninstallClientDecorations(rootPane); return; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java index 7c6baa01..809cb148 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java @@ -24,7 +24,7 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.util.DarkUIUtil; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.util.SystemInfo; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -35,12 +35,7 @@ import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Enumeration; diff --git a/core/src/test/java/theme/MyCustomTheme.java b/core/src/test/java/theme/MyCustomTheme.java index 53342410..b56c6885 100644 --- a/core/src/test/java/theme/MyCustomTheme.java +++ b/core/src/test/java/theme/MyCustomTheme.java @@ -24,7 +24,7 @@ package theme; import com.github.weisj.darklaf.theme.Theme; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.util.SystemInfo; import javax.swing.*; import java.util.Properties; diff --git a/decorations-base/build.gradle.kts b/decorations-base/build.gradle.kts new file mode 100644 index 00000000..f6727627 --- /dev/null +++ b/decorations-base/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + `java-library` +} diff --git a/native-utils/src/main/java/com/github/weisj/darklaf/decorations/CustomTitlePane.java b/decorations-base/src/main/java/com/github/weisj/decorations/CustomTitlePane.java similarity index 96% rename from native-utils/src/main/java/com/github/weisj/darklaf/decorations/CustomTitlePane.java rename to decorations-base/src/main/java/com/github/weisj/decorations/CustomTitlePane.java index 8b9101e3..84288866 100644 --- a/native-utils/src/main/java/com/github/weisj/darklaf/decorations/CustomTitlePane.java +++ b/decorations-base/src/main/java/com/github/weisj/decorations/CustomTitlePane.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.decorations; +package com.github.weisj.decorations; import javax.swing.*; diff --git a/native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java b/decorations-base/src/main/java/com/github/weisj/decorations/DecorationsProvider.java similarity index 88% rename from native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java rename to decorations-base/src/main/java/com/github/weisj/decorations/DecorationsProvider.java index 44288d88..6062c56b 100644 --- a/native-utils/src/main/java/com/github/weisj/darklaf/decorations/JNIDecorationsProvider.java +++ b/decorations-base/src/main/java/com/github/weisj/decorations/DecorationsProvider.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.github.weisj.darklaf.decorations; +package com.github.weisj.decorations; import javax.swing.*; import java.util.Properties; -public interface JNIDecorationsProvider { +public interface DecorationsProvider { /** * Create the custom title pane. @@ -44,11 +44,9 @@ public interface JNIDecorationsProvider { boolean isCustomDecorationSupported(); /** - * Load the decorations library if necessary. - * - * @return true if successful and library wasn't already loaded. + * Initialize all necessary resources. */ - boolean updateLibrary(); + void initialize(); /** * Load the necessary properties into the defaults. diff --git a/settings.gradle.kts b/settings.gradle.kts index 51217fd1..ad023099 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,6 +18,7 @@ include( "dependencies-bom", "native-utils", "core", + "decorations-base", "windows", "property-loader", "utils" diff --git a/native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java b/utils/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java similarity index 99% rename from native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java rename to utils/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java index 99351775..87cea63e 100644 --- a/native-utils/src/main/java/com/github/weisj/darklaf/platform/SystemInfo.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/SystemInfo.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.platform; +package com.github.weisj.darklaf.util; import java.util.regex.Pattern; diff --git a/windows/build.gradle.kts b/windows/build.gradle.kts index ed96c1c9..5c43c8f9 100644 --- a/windows/build.gradle.kts +++ b/windows/build.gradle.kts @@ -10,6 +10,7 @@ fun DependencyHandlerScope.javaImplementation(dep: Any) { dependencies { javaImplementation(project(":darklaf-native-utils")) javaImplementation(project(":darklaf-utils")) + javaImplementation(project(":darklaf-decorations-base")) javaImplementation(project(":darklaf-property-loader")) javaImplementation("net.java.dev.jna:jna") } diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java index 05b9b709..13868e8c 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java @@ -24,7 +24,7 @@ package com.github.weisj.darklaf.platform.windows; import com.github.weisj.darklaf.platform.NativeUtil; -import com.github.weisj.darklaf.platform.SystemInfo; +import com.github.weisj.darklaf.util.SystemInfo; import com.sun.jna.Native; import com.sun.jna.Pointer; @@ -63,7 +63,7 @@ public class JNIDecorationsWindows { } /** - * Load the decorations library if necessary. + * Load the decorations-library if necessary. * * @return true if successful and library wasn't already loaded. */ diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java index 49b7f6e3..31df16df 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java @@ -24,15 +24,15 @@ package com.github.weisj.darklaf.platform.windows; import com.github.weisj.darklaf.PropertyLoader; -import com.github.weisj.darklaf.decorations.CustomTitlePane; -import com.github.weisj.darklaf.decorations.JNIDecorationsProvider; import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.platform.windows.ui.DarkTitlePaneWindows; +import com.github.weisj.decorations.CustomTitlePane; +import com.github.weisj.decorations.DecorationsProvider; import javax.swing.*; import java.util.Properties; -public class WindowsDecorationsProvider implements JNIDecorationsProvider { +public class WindowsDecorationsProvider implements DecorationsProvider { @Override public CustomTitlePane createTitlePane(final JRootPane rootPane) { @@ -45,8 +45,8 @@ public class WindowsDecorationsProvider implements JNIDecorationsProvider { } @Override - public boolean updateLibrary() { - return JNIDecorationsWindows.updateLibrary(); + public void initialize() { + JNIDecorationsWindows.updateLibrary(); } @Override diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java index 0318d111..bb484383 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/DarkTitlePaneWindows.java @@ -24,10 +24,10 @@ package com.github.weisj.darklaf.platform.windows.ui; -import com.github.weisj.darklaf.decorations.CustomTitlePane; import com.github.weisj.darklaf.icons.ScaledIcon; import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; import com.github.weisj.darklaf.util.Scale; +import com.github.weisj.decorations.CustomTitlePane; import sun.awt.SunToolkit; import javax.accessibility.AccessibleContext; @@ -57,7 +57,7 @@ public class DarkTitlePaneWindows extends CustomTitlePane { public void componentAdded(final ContainerEvent e) { if (e.getChild() instanceof JMenuBar) { menuBar = getRootPane().getJMenuBar(); - //Otherwise a white bar will appear where the menuBar used to be. + //Otherwise, a white bar will appear where the menuBar used to be. menuBar.setPreferredSize(new Dimension(0, 0)); add(menuBar); }