Browse Source

Added option to modify all defaults individually.

pull/142/head
weisj 5 years ago
parent
commit
58570fbd63
  1. 3
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 45
      core/src/main/java/com/github/weisj/darklaf/LafManager.java
  3. 14
      core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java
  4. 37
      core/src/main/java/com/github/weisj/darklaf/task/UserDefaultsAdjustmentTask.java
  5. 40
      core/src/main/java/com/github/weisj/darklaf/task/UserInitTask.java
  6. 8
      core/src/main/java/com/github/weisj/darklaf/task/UserPreferenceAdjustmentTask.java

3
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.

45
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<Theme> registeredThemes = new ArrayList<>();
private static final Collection<DefaultsAdjustmentTask> uiDefaultsTasks = new HashSet<>();
private static final Collection<DefaultsAdjustmentTask> uiDefaultsTasks = new ArrayList<>();
private static final Collection<DefaultsInitTask> 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<DefaultsAdjustmentTask> getUserAdjustmentTasks() {
public static Collection<DefaultsAdjustmentTask> 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<DefaultsInitTask> 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()) {

14
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();

37
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<DefaultsAdjustmentTask> getTasks() {
return LafManager.getUserDefaultsAdjustmentTasks();
}
}

40
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);
}
}
}

8
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<DefaultsAdjustmentTask> getTasks();
}

Loading…
Cancel
Save