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 9aeb24de..37b46c33 100644 --- a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -55,7 +55,8 @@ public class DarkLaf extends BasicLookAndFeel { new FontDefaultsInitTask(), new UtilityDefaultsInitTask(), new SystemDefaultsInitTask(), - new PlatformDefaultsInitTask() + new PlatformDefaultsInitTask(), + new UserInitTask(), }; /* * The base look and feel. This may vary to handle different platform support. diff --git a/core/src/main/java/com/github/weisj/darklaf/LafManager.java b/core/src/main/java/com/github/weisj/darklaf/LafManager.java index 42201dbd..3d4b86fc 100644 --- a/core/src/main/java/com/github/weisj/darklaf/LafManager.java +++ b/core/src/main/java/com/github/weisj/darklaf/LafManager.java @@ -27,7 +27,9 @@ package com.github.weisj.darklaf; import java.awt.*; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.logging.Level; import java.util.logging.LogManager; @@ -38,6 +40,7 @@ import javax.swing.*; import com.github.weisj.darklaf.platform.DecorationsHandler; import com.github.weisj.darklaf.platform.ThemePreferencesHandler; import com.github.weisj.darklaf.task.DefaultsAdjustmentTask; +import com.github.weisj.darklaf.task.DefaultsInitTask; import com.github.weisj.darklaf.theme.*; import com.github.weisj.darklaf.theme.event.ThemePreferenceChangeEvent; import com.github.weisj.darklaf.theme.event.ThemePreferenceListener; @@ -56,7 +59,8 @@ public final class LafManager { private static Theme theme; private static boolean logEnabled = false; private static final List registeredThemes = new ArrayList<>(); - private static final Collection uiDefaultsTasks = new HashSet<>(); + private static final Collection uiDefaultsTasks = new ArrayList<>(); + private static final Collection uiInitTasks = new ArrayList<>(); static { enableLogging(true); @@ -392,14 +396,47 @@ public final class LafManager { } /** - * Get a view of all currently registered init tasks. Modification will also mutate the collection itself. + * Get a view of all currently registered defaults init tasks. Modification will also mutate the collection itself. * * @return collection of init tasks. */ - public static Collection getUserAdjustmentTasks() { + public static Collection getUserDefaultsAdjustmentTasks() { return uiDefaultsTasks; } + /** + * Register a task to modify the laf defaults. + * + * @param task the defaults init task. + */ + public static void registerInitTask(final DefaultsInitTask task) { + uiInitTasks.add(task); + } + + /** + * Remove a registered task to modify the laf defaults. + * + * @param task the defaults init task. + */ + public static void removeInitTask(final DefaultsInitTask task) { + uiInitTasks.remove(task); + } + + /** + * Get a view of all currently registered ui init tasks. Modification will also mutate the collection itself. + * + * @return collection of init tasks. + */ + public static Collection getUserInitTasks() { + return uiInitTasks; + } + + /** + * Get the closest match of a registered theme for the given theme. + * + * @param theme the theme to match to. + * @return the closes match. NonNull. + */ public static Theme getClosestMatchForTheme(final Theme theme) { if (theme == null) return themeForPreferredStyle(null); for (Theme registered : getRegisteredThemes()) { diff --git a/core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java b/core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java index 6afb0a9d..d9603a0b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java +++ b/core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java @@ -40,8 +40,7 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask { private static final String GLOBAL_PREFIX = "global."; private static final String MAC_OS_MENU_BAR_KEY = "apple.laf.useScreenMenuBar"; - private static final String[] UI_PROPERTIES = new String[]{ - "borders", "button", "checkBox", "colorChooser", + private static final String[] UI_PROPERTIES = new String[]{"borders", "button", "checkBox", "colorChooser", "comboBox", "fileChooser", "tristate", "internalFrame", "label", "list", "menu", "menuBar", "menuItem", "numberingPane", "optionPane", "panel", @@ -49,13 +48,10 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask { "scrollBar", "scrollPane", "separator", "slider", "spinner", "splitPane", "statusBar", "tabbedPane", "tabFrame", "table", "taskPane", "text", - "toggleButton", "toolBar", "toolTip", "tree", "misc" - }; - private static final String[] ICON_PROPERTIES = new String[]{ - "checkBox", "radioButton", "dialog", "files", "frame", - "indicator", "menu", "misc", "navigation" - }; - private final DefaultsAdjustmentTask userPreferenceAdjustment = new UserPreferenceAdjustmentTask(); + "toggleButton", "toolBar", "toolTip", "tree", "misc"}; + private static final String[] ICON_PROPERTIES = new String[]{"checkBox", "radioButton", "dialog", "files", "frame", + "indicator", "menu", "misc", "navigation"}; + private final DefaultsAdjustmentTask userPreferenceAdjustment = new UserDefaultsAdjustmentTask(); private final DefaultsAdjustmentTask accentColorAdjustment = new AccentColorAdjustmentTask(); private final DefaultsAdjustmentTask foregroundGeneration = new ForegroundColorGenerationTask(); diff --git a/core/src/main/java/com/github/weisj/darklaf/task/UserDefaultsAdjustmentTask.java b/core/src/main/java/com/github/weisj/darklaf/task/UserDefaultsAdjustmentTask.java new file mode 100644 index 00000000..7d214729 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/task/UserDefaultsAdjustmentTask.java @@ -0,0 +1,37 @@ +/* + * 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.task; + +import java.util.Collection; + +import com.github.weisj.darklaf.LafManager; + +public class UserDefaultsAdjustmentTask extends UserPreferenceAdjustmentTask { + + @Override + protected Collection getTasks() { + return LafManager.getUserDefaultsAdjustmentTasks(); + } +} diff --git a/core/src/main/java/com/github/weisj/darklaf/task/UserInitTask.java b/core/src/main/java/com/github/weisj/darklaf/task/UserInitTask.java new file mode 100644 index 00000000..1c98fd62 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/task/UserInitTask.java @@ -0,0 +1,40 @@ +/* + * 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.task; + +import javax.swing.*; + +import com.github.weisj.darklaf.LafManager; +import com.github.weisj.darklaf.theme.Theme; + +public class UserInitTask implements DefaultsInitTask { + + @Override + public void run(final Theme currentTheme, final UIDefaults defaults) { + for (DefaultsInitTask task : LafManager.getUserInitTasks()) { + task.run(currentTheme, defaults); + } + } +} diff --git a/core/src/main/java/com/github/weisj/darklaf/task/UserPreferenceAdjustmentTask.java b/core/src/main/java/com/github/weisj/darklaf/task/UserPreferenceAdjustmentTask.java index c9bfe825..ba467b19 100644 --- a/core/src/main/java/com/github/weisj/darklaf/task/UserPreferenceAdjustmentTask.java +++ b/core/src/main/java/com/github/weisj/darklaf/task/UserPreferenceAdjustmentTask.java @@ -24,17 +24,19 @@ */ package com.github.weisj.darklaf.task; +import java.util.Collection; import java.util.Properties; -import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.theme.Theme; -public class UserPreferenceAdjustmentTask implements DefaultsAdjustmentTask { +public abstract class UserPreferenceAdjustmentTask implements DefaultsAdjustmentTask { @Override public void run(final Theme currentTheme, final Properties properties) { - for (DefaultsAdjustmentTask task : LafManager.getUserAdjustmentTasks()) { + for (DefaultsAdjustmentTask task : getTasks()) { if (task != null) task.run(currentTheme, properties); } } + + protected abstract Collection getTasks(); }