Browse Source

Add option to change the shared ThemeSettingsPanel.

pull/222/head
weisj 4 years ago
parent
commit
efa446a32d
  1. 17
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java
  2. 6
      utils/src/main/java/com/github/weisj/darklaf/util/LazyValue.java
  3. 40
      utils/src/main/java/com/github/weisj/darklaf/util/MutableLazyValue.java

17
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java

@ -41,6 +41,7 @@ import com.github.weisj.darklaf.theme.info.PreferredThemeStyle;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyValue;
import com.github.weisj.darklaf.util.LogUtil;
import com.github.weisj.darklaf.util.MutableLazyValue;
public class ThemeSettings implements ThemePreferenceListener {
@ -48,7 +49,7 @@ public class ThemeSettings implements ThemePreferenceListener {
private static final LazyValue<ThemeSettings> instance = new LazyValue<>(ThemeSettings::new);
private static final LazyValue<Icon> icon = new LazyValue<>(() -> UIManager.getIcon("ThemeSettings.icon"));
private final LazyValue<ThemeSettingsPanel> settingsPanel;
private final MutableLazyValue<ThemeSettingsPanel> settingsPanel;
private JDialog dialog;
@ -88,7 +89,7 @@ public class ThemeSettings implements ThemePreferenceListener {
LafManager.addThemePreferenceChangeListener(this);
currentConfiguration = new DefaultSettingsConfiguration();
savedConfiguration = new DefaultSettingsConfiguration();
settingsPanel = new LazyValue<>(() -> {
settingsPanel = new MutableLazyValue<>(() -> {
ThemeSettingsPanel panel = new ThemeSettingsPanel();
panel.loadConfiguration(currentConfiguration);
return panel;
@ -147,6 +148,18 @@ public class ThemeSettings implements ThemePreferenceListener {
return settingsPanel.get();
}
/**
* Set the shared {@link ThemeSettingsPanel}.
*
* @param panel the @link ThemeSettingsPanel}.
*/
public void setThemeSettingsPanel(final ThemeSettingsPanel panel) {
if (panel != null) {
settingsPanel.set(panel);
panel.loadConfiguration(currentConfiguration);
}
}
/**
* Returns whether the option to follow the system settings is enabled.
*

6
utils/src/main/java/com/github/weisj/darklaf/util/LazyValue.java

@ -51,6 +51,10 @@ public class LazyValue<T> {
return value;
}
protected void set(final T value) {
this.value = value;
}
public void ifPresent(final Consumer<T> action) {
if (isInitialized() && value != null) {
action.accept(value);
@ -64,7 +68,7 @@ public class LazyValue<T> {
}
public T get() {
if (value == null) value = load();
if (value == null) set(load());
return value;
}
}

40
utils/src/main/java/com/github/weisj/darklaf/util/MutableLazyValue.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.util;
import java.util.function.Supplier;
public class MutableLazyValue<T> extends LazyValue<T> {
public MutableLazyValue(final T value) {
super(value);
}
public MutableLazyValue(final Supplier<T> supplier) {
super(supplier);
}
public void set(final T value) {
super.set(value);
}
}
Loading…
Cancel
Save