Browse Source

Add option to synthesise a LookAndFeel class that automatically installs a theme for better interoperability with the LookAndFeelInfo class.

Load available themes as Service.
pull/198/head
weisj 4 years ago
parent
commit
9edb1f5026
  1. 7
      annotations-processor/build.gradle.kts
  2. 86
      annotations-processor/src/main/java/com/github/weisj/darklaf/annotations/processor/SynthesisesLafProcessor.java
  3. 1
      annotations-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  4. 3
      annotations/build.gradle.kts
  5. 36
      annotations/src/main/java/com/github/weisj/darklaf/annotations/SynthesiseLaf.java
  6. 1
      core/build.gradle.kts
  7. 42
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  8. 2
      core/src/main/java/com/github/weisj/darklaf/DarkLafInfo.java
  9. 36
      core/src/main/java/com/github/weisj/darklaf/LafManager.java
  10. 43
      core/src/main/java/com/github/weisj/darklaf/synthesised/ThemedDarkLaf.java
  11. 56
      core/src/main/java/com/github/weisj/darklaf/synthesised/ThemedDarklafInfo.java
  12. 20
      core/src/test/java/ui/ComponentDemo.java
  13. 2
      dependencies-bom/build.gradle.kts
  14. 1
      gradle.properties
  15. 2
      settings.gradle.kts
  16. 6
      theme/build.gradle.kts
  17. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/DarculaTheme.java
  18. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/HighContrastDarkTheme.java
  19. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/HighContrastLightTheme.java
  20. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java
  21. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/OneDarkTheme.java
  22. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/SolarizedDarkTheme.java
  23. 4
      theme/src/main/java/com/github/weisj/darklaf/theme/SolarizedLightTheme.java
  24. 113
      theme/src/main/java/com/github/weisj/darklaf/theme/laf/DelegatingThemedLaf.java
  25. 56
      theme/src/main/java/com/github/weisj/darklaf/theme/laf/ReflectiveDelegatingThemedLaf.java
  26. 36
      theme/src/main/java/com/github/weisj/darklaf/theme/laf/ThemedLookAndFeel.java

7
annotations-processor/build.gradle.kts

@ -0,0 +1,7 @@
plugins {
`java-library`
}
dependencies {
api(project(":darklaf-annotations"))
}

86
annotations-processor/src/main/java/com/github/weisj/darklaf/annotations/processor/SynthesisesLafProcessor.java

@ -0,0 +1,86 @@
/*
* 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.annotations.processor;
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.ElementFilter;
import javax.tools.JavaFileObject;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
@SupportedAnnotationTypes("com.github.weisj.darklaf.annotations.SynthesiseLaf")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class SynthesisesLafProcessor extends AbstractProcessor {
private static final String IDENT = " ";
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
Collection<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(SynthesiseLaf.class);
List<TypeElement> types = ElementFilter.typesIn(annotatedElements);
String packageName = "com.github.weisj.darklaf.theme.laf";
String baseClassName = "ReflectiveDelegatingThemedLaf";
for (TypeElement typeElement : types) {
String themeName = typeElement.getSimpleName().toString();
String themePath = typeElement.getQualifiedName().toString();
String synthesisedClassName = themeName + "DarklafLookAndFeel";
String synthesisedName = packageName + "." + synthesisedClassName;
String baseLaf = typeElement.getAnnotation(SynthesiseLaf.class).baseLaf();
StringBuilder builder = new StringBuilder();
builder.append("package ").append(packageName).append(";\n\n")
.append("import ").append(themePath).append(";\n\n")
.append("public class ").append(synthesisedClassName).append(" extends ").append(baseClassName)
.append(" {\n\n")
.append(IDENT)
.append("public ").append(synthesisedClassName).append("() {\n")
.append(IDENT).append(IDENT)
.append("super(new ").append(themeName).append("(), \"").append(baseLaf).append("\");\n")
.append(IDENT)
.append("}\n")
.append("}");
try {
JavaFileObject javaFileObject = processingEnv.getFiler().createSourceFile(synthesisedName);
Writer writer = javaFileObject.openWriter();
writer.write(builder.toString());
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
}

1
annotations-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor

@ -0,0 +1 @@
com.github.weisj.darklaf.annotations.processor.SynthesisesLafProcessor

3
annotations/build.gradle.kts

@ -0,0 +1,3 @@
plugins {
`java-library`
}

36
annotations/src/main/java/com/github/weisj/darklaf/annotations/SynthesiseLaf.java

@ -0,0 +1,36 @@
/*
* 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.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface SynthesiseLaf {
String baseLaf() default "com.github.weisj.darklaf.synthesised.ThemedDarkLaf";
}

1
core/build.gradle.kts

@ -16,6 +16,7 @@ dependencies {
implementation(project(":darklaf-property-loader")) implementation(project(":darklaf-property-loader"))
implementation("org.swinglabs:jxlayer") implementation("org.swinglabs:jxlayer")
compileOnly("org.swinglabs:swingx") compileOnly("org.swinglabs:swingx")
testImplementation("com.formdev:svgSalamander") testImplementation("com.formdev:svgSalamander")
testImplementation("com.miglayout:miglayout-core") testImplementation("com.miglayout:miglayout-core")
testImplementation("com.miglayout:miglayout-swing") testImplementation("com.miglayout:miglayout-swing")

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

@ -24,16 +24,17 @@
*/ */
package com.github.weisj.darklaf; package com.github.weisj.darklaf;
import java.awt.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.plaf.metal.MetalLookAndFeel; import javax.swing.plaf.metal.MetalLookAndFeel;
import com.github.weisj.darklaf.platform.DecorationsHandler; import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.task.*; import com.github.weisj.darklaf.task.*;
import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.theme.laf.ThemedLookAndFeel;
import com.github.weisj.darklaf.ui.DarkPopupFactory; import com.github.weisj.darklaf.ui.DarkPopupFactory;
import com.github.weisj.darklaf.ui.popupmenu.MouseGrabberUtil; import com.github.weisj.darklaf.ui.popupmenu.MouseGrabberUtil;
import com.github.weisj.darklaf.util.LogUtil; import com.github.weisj.darklaf.util.LogUtil;
@ -42,7 +43,7 @@ import com.github.weisj.darklaf.util.SystemInfo;
/** /**
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkLaf extends BasicLookAndFeel { public class DarkLaf extends ThemedLookAndFeel {
public static final String SYSTEM_PROPERTY_PREFIX = "darklaf."; public static final String SYSTEM_PROPERTY_PREFIX = "darklaf.";
public static final String ALLOW_NATIVE_CODE_FLAG = DarkLaf.SYSTEM_PROPERTY_PREFIX + "allowNativeCode"; public static final String ALLOW_NATIVE_CODE_FLAG = DarkLaf.SYSTEM_PROPERTY_PREFIX + "allowNativeCode";
@ -130,7 +131,10 @@ public class DarkLaf extends BasicLookAndFeel {
@Override @Override
public UIDefaults getDefaults() { public UIDefaults getDefaults() {
final UIDefaults defaults = base.getDefaults(); final UIDefaults defaults = base.getDefaults();
final Theme currentTheme = LafManager.getTheme(); final Theme currentTheme = getTheme();
if (isInitialized && !LafManager.getTheme().equals(currentTheme)) {
LafManager.setTheme(currentTheme);
}
for (DefaultsInitTask task : INIT_TASKS) { for (DefaultsInitTask task : INIT_TASKS) {
if (task.onlyDuringInstallation() && !isInitialized) continue; if (task.onlyDuringInstallation() && !isInitialized) continue;
task.run(currentTheme, defaults); task.run(currentTheme, defaults);
@ -138,6 +142,36 @@ public class DarkLaf extends BasicLookAndFeel {
return defaults; return defaults;
} }
@Override
public LayoutStyle getLayoutStyle() {
return base.getLayoutStyle();
}
@Override
public void provideErrorFeedback(final Component component) {
base.provideErrorFeedback(component);
}
@Override
public Icon getDisabledIcon(final JComponent component, final Icon icon) {
return base.getDisabledIcon(component, icon);
}
@Override
public Icon getDisabledSelectedIcon(final JComponent component, final Icon icon) {
return base.getDisabledSelectedIcon(component, icon);
}
@Override
protected void setTheme(final Theme theme) {
// Do nothing.
}
@Override
public Theme getTheme() {
return LafManager.getTheme();
}
@Override @Override
public String getName() { public String getName() {
return "Darklaf"; return "Darklaf";
@ -150,7 +184,7 @@ public class DarkLaf extends BasicLookAndFeel {
@Override @Override
public String getDescription() { public String getDescription() {
return "Dark Look and feel based on Darcula-LAF"; return "A themeable Look and Feel";
} }
@Override @Override

2
core/src/main/java/com/github/weisj/darklaf/DarkLafInfo.java

@ -27,7 +27,7 @@ package com.github.weisj.darklaf;
import javax.swing.*; import javax.swing.*;
/** /**
* {@link javax.swing.UIManager.LookAndFeelInfo} for {@link DarkLaf}. * {@link javax.swing.UIManager.LookAndFeelInfo} for {@link com.github.weisj.darklaf.DarkLaf}.
* *
* @author Jannis Weis * @author Jannis Weis
*/ */

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

@ -25,9 +25,7 @@
package com.github.weisj.darklaf; package com.github.weisj.darklaf;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -37,6 +35,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.platform.DecorationsHandler; import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.platform.ThemePreferencesHandler; import com.github.weisj.darklaf.platform.ThemePreferencesHandler;
import com.github.weisj.darklaf.settings.ThemeSettings; import com.github.weisj.darklaf.settings.ThemeSettings;
import com.github.weisj.darklaf.synthesised.ThemedDarklafInfo;
import com.github.weisj.darklaf.task.DefaultsAdjustmentTask; import com.github.weisj.darklaf.task.DefaultsAdjustmentTask;
import com.github.weisj.darklaf.task.DefaultsInitTask; import com.github.weisj.darklaf.task.DefaultsInitTask;
import com.github.weisj.darklaf.theme.*; import com.github.weisj.darklaf.theme.*;
@ -63,13 +62,10 @@ public final class LafManager {
static { static {
setLogLevel(Level.WARNING); setLogLevel(Level.WARNING);
registerTheme(new IntelliJTheme(), ServiceLoader.load(Theme.class).forEach(LafManager::registerTheme);
new DarculaTheme(), for (UIManager.LookAndFeelInfo info : getRegisteredThemeInfos()) {
new SolarizedLightTheme(), UIManager.installLookAndFeel(info);
new SolarizedDarkTheme(), }
new OneDarkTheme(),
new HighContrastLightTheme(),
new HighContrastDarkTheme());
} }
/** /**
@ -285,6 +281,26 @@ public final class LafManager {
return themes; return themes;
} }
/**
* Get {@link javax.swing.UIManager.LookAndFeelInfo}s for all currently registered themes.
* These can be directly used to install the specified theme.
* Only themes that are annotated using @SynthesiseLaf and compiled with the corresponding
* annotations processor may contribute to this list.
*
* @return all look and feel infos for currently registered themes as array.
*/
public static UIManager.LookAndFeelInfo[] getRegisteredThemeInfos() {
return Arrays.stream(getRegisteredThemes())
.map(ThemedDarklafInfo::new)
.filter(ThemedDarklafInfo::exists)
.toArray(UIManager.LookAndFeelInfo[]::new);
}
/**
* Get a combobox model for all currently registered themes.
*
* @return the combo box model.
*/
public static ComboBoxModel<Theme> getThemeComboBoxModel() { public static ComboBoxModel<Theme> getThemeComboBoxModel() {
return new DefaultComboBoxModel<>(getRegisteredThemes()); return new DefaultComboBoxModel<>(getRegisteredThemes());
} }

43
core/src/main/java/com/github/weisj/darklaf/synthesised/ThemedDarkLaf.java

@ -0,0 +1,43 @@
/*
* 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.synthesised;
import com.github.weisj.darklaf.DarkLaf;
import com.github.weisj.darklaf.theme.Theme;
public class ThemedDarkLaf extends DarkLaf {
private Theme theme;
@Override
protected void setTheme(final Theme theme) {
this.theme = theme;
}
@Override
public Theme getTheme() {
return theme != null ? theme : super.getTheme();
}
}

56
core/src/main/java/com/github/weisj/darklaf/synthesised/ThemedDarklafInfo.java

@ -0,0 +1,56 @@
/*
* 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.synthesised;
import javax.swing.*;
import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.theme.laf.ReflectiveDelegatingThemedLaf;
public class ThemedDarklafInfo extends UIManager.LookAndFeelInfo {
private final String className;
public ThemedDarklafInfo(final Theme theme) {
super(theme.getName(), "");
String themeName = theme.getClass().getSimpleName();
String packageName = ReflectiveDelegatingThemedLaf.class.getPackage().getName();
className = packageName + "." + themeName + "DarklafLookAndFeel";
}
public boolean exists() {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
@Override
public String getClassName() {
return className;
}
}

20
core/src/test/java/ui/ComponentDemo.java

@ -129,7 +129,7 @@ public interface ComponentDemo {
static JMenu createThemeMenu() { static JMenu createThemeMenu() {
JMenu menu = new JMenu("Theme"); JMenu menu = new JMenu("Theme");
ButtonGroup bg = new ButtonGroup(); ButtonGroup bg = new ButtonGroup();
for (Theme theme : LafManager.getRegisteredThemes()) { for (UIManager.LookAndFeelInfo theme : LafManager.getRegisteredThemeInfos()) {
createThemeItem(menu, bg, theme); createThemeItem(menu, bg, theme);
} }
menu.addMenuListener(new MenuListener() { menu.addMenuListener(new MenuListener() {
@ -157,7 +157,7 @@ public interface ComponentDemo {
String currentThemeName = LafManager.getTheme().getName(); String currentThemeName = LafManager.getTheme().getName();
Enumeration<AbstractButton> enumeration = bg.getElements(); Enumeration<AbstractButton> enumeration = bg.getElements();
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
ThemeMenuItem mi = (ThemeMenuItem) enumeration.nextElement(); JMenuItem mi = (JMenuItem) enumeration.nextElement();
if (Objects.equals(currentThemeName, mi.getName())) return mi; if (Objects.equals(currentThemeName, mi.getName())) return mi;
} }
return null; return null;
@ -169,8 +169,20 @@ public interface ComponentDemo {
return menu; return menu;
} }
static void createThemeItem(final JMenu menu, final ButtonGroup bg, final Theme theme) { static void createThemeItem(final JMenu menu, final ButtonGroup bg, final UIManager.LookAndFeelInfo info) {
final ThemeMenuItem mi = new ThemeMenuItem(theme); // final ThemeMenuItem mi = new ThemeMenuItem(theme);
JMenuItem mi = new JRadioButtonMenuItem(info.getName());
mi.addActionListener(event -> {
try {
UIManager.setLookAndFeel(info.getClassName());
} catch (ClassNotFoundException
| InstantiationException
| IllegalAccessException
| UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
LafManager.updateLaf();
});
menu.add(mi); menu.add(mi);
bg.add(mi); bg.add(mi);
} }

2
dependencies-bom/build.gradle.kts

@ -38,5 +38,7 @@ dependencies {
apiv("com.miglayout:miglayout-swing", "miglayout") apiv("com.miglayout:miglayout-swing", "miglayout")
apiv("org.junit.jupiter:junit-jupiter-api", "junit") apiv("org.junit.jupiter:junit-jupiter-api", "junit")
apiv("org.junit.jupiter:junit-jupiter-engine", "junit") apiv("org.junit.jupiter:junit-jupiter-engine", "junit")
apiv("com.google.auto.service:auto-service-annotations", "auto-service")
apiv("com.google.auto.service:auto-service", "auto-service")
} }
} }

1
gradle.properties

@ -22,3 +22,4 @@ swingx.version = 1.6.1
svgSalamander.version = 1.1.2.1 svgSalamander.version = 1.1.2.1
junit.version = 5.6.2 junit.version = 5.6.2
rsyntaxtextarea.version = 3.1.1 rsyntaxtextarea.version = 3.1.1
auto-service.version = 1.0-rc5

2
settings.gradle.kts

@ -15,6 +15,8 @@ rootProject.name = "darklaf"
include( include(
"dependencies-bom", "dependencies-bom",
"annotations",
"annotations-processor",
"native-utils", "native-utils",
"core", "core",
"theme", "theme",

6
theme/build.gradle.kts

@ -5,4 +5,10 @@ plugins {
dependencies { dependencies {
implementation(project(":darklaf-property-loader")) implementation(project(":darklaf-property-loader"))
implementation(project(":darklaf-utils")) implementation(project(":darklaf-utils"))
compileOnly(project(":darklaf-annotations"))
annotationProcessor(project(":darklaf-annotations-processor"))
compileOnly("com.google.auto.service:auto-service-annotations")
annotationProcessor("com.google.auto.service:auto-service")
} }

4
theme/src/main/java/com/github/weisj/darklaf/theme/DarculaTheme.java

@ -24,12 +24,16 @@
*/ */
package com.github.weisj.darklaf.theme; package com.github.weisj.darklaf.theme;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
/** /**
* @author Jannis Weis * @author Jannis Weis
*/ */
@AutoService(Theme.class)
@SynthesiseLaf
public class DarculaTheme extends Theme { public class DarculaTheme extends Theme {
@Override @Override

4
theme/src/main/java/com/github/weisj/darklaf/theme/HighContrastDarkTheme.java

@ -28,10 +28,14 @@ import java.util.Properties;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.ContrastRule; import com.github.weisj.darklaf.theme.info.ContrastRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
@AutoService(Theme.class)
@SynthesiseLaf
public class HighContrastDarkTheme extends Theme { public class HighContrastDarkTheme extends Theme {
@Override @Override

4
theme/src/main/java/com/github/weisj/darklaf/theme/HighContrastLightTheme.java

@ -28,10 +28,14 @@ import java.util.Properties;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.ContrastRule; import com.github.weisj.darklaf.theme.info.ContrastRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
@AutoService(Theme.class)
@SynthesiseLaf
public class HighContrastLightTheme extends Theme { public class HighContrastLightTheme extends Theme {
@Override @Override

4
theme/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java

@ -28,12 +28,16 @@ import java.util.Properties;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
/** /**
* @author Jannis Weis * @author Jannis Weis
*/ */
@AutoService(Theme.class)
@SynthesiseLaf
public class IntelliJTheme extends Theme { public class IntelliJTheme extends Theme {
@Override @Override

4
theme/src/main/java/com/github/weisj/darklaf/theme/OneDarkTheme.java

@ -28,9 +28,13 @@ import java.util.Properties;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
@AutoService(Theme.class)
@SynthesiseLaf
public class OneDarkTheme extends Theme { public class OneDarkTheme extends Theme {
@Override @Override
protected PresetIconRule getPresetIconRule() { protected PresetIconRule getPresetIconRule() {

4
theme/src/main/java/com/github/weisj/darklaf/theme/SolarizedDarkTheme.java

@ -28,9 +28,13 @@ import java.util.Properties;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
@AutoService(Theme.class)
@SynthesiseLaf
public class SolarizedDarkTheme extends Theme { public class SolarizedDarkTheme extends Theme {
@Override @Override

4
theme/src/main/java/com/github/weisj/darklaf/theme/SolarizedLightTheme.java

@ -28,9 +28,13 @@ import java.util.Properties;
import javax.swing.*; import javax.swing.*;
import com.github.weisj.darklaf.annotations.SynthesiseLaf;
import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.ColorToneRule;
import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.github.weisj.darklaf.theme.info.PresetIconRule;
import com.google.auto.service.AutoService;
@AutoService(Theme.class)
@SynthesiseLaf
public class SolarizedLightTheme extends Theme { public class SolarizedLightTheme extends Theme {
@Override @Override

113
theme/src/main/java/com/github/weisj/darklaf/theme/laf/DelegatingThemedLaf.java

@ -0,0 +1,113 @@
/*
* 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.theme.laf;
import java.awt.*;
import javax.swing.*;
import com.github.weisj.darklaf.theme.Theme;
public class DelegatingThemedLaf extends ThemedLookAndFeel {
private final Theme theme;
private final LookAndFeel lafBase;
public DelegatingThemedLaf(final Theme theme, final ThemedLookAndFeel lafBase) {
this.theme = theme;
this.lafBase = lafBase;
lafBase.setTheme(theme);
}
@Override
public String getName() {
return theme.getName();
}
@Override
public String getID() {
return lafBase.getID() + " - " + getName();
}
@Override
public String getDescription() {
return lafBase.getDescription();
}
@Override
public boolean isNativeLookAndFeel() {
return lafBase.isNativeLookAndFeel();
}
@Override
public boolean isSupportedLookAndFeel() {
return lafBase.isSupportedLookAndFeel();
}
@Override
protected void setTheme(final Theme theme) {
// Do nothing.
}
@Override
public Theme getTheme() {
return theme;
}
@Override
public LayoutStyle getLayoutStyle() {
return lafBase.getLayoutStyle();
}
@Override
public void provideErrorFeedback(final Component component) {
lafBase.provideErrorFeedback(component);
}
@Override
public Icon getDisabledIcon(final JComponent component, final Icon icon) {
return lafBase.getDisabledIcon(component, icon);
}
@Override
public Icon getDisabledSelectedIcon(final JComponent component, final Icon icon) {
return lafBase.getDisabledSelectedIcon(component, icon);
}
@Override
public void initialize() {
lafBase.initialize();
}
@Override
public void uninitialize() {
lafBase.uninitialize();
}
@Override
public UIDefaults getDefaults() {
return lafBase.getDefaults();
}
}

56
theme/src/main/java/com/github/weisj/darklaf/theme/laf/ReflectiveDelegatingThemedLaf.java

@ -0,0 +1,56 @@
/*
* 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.theme.laf;
import java.lang.reflect.InvocationTargetException;
import javax.swing.*;
import com.github.weisj.darklaf.theme.Theme;
public class ReflectiveDelegatingThemedLaf extends DelegatingThemedLaf {
public ReflectiveDelegatingThemedLaf(final Theme theme, final String baseLafClass) {
super(theme, getLaf(baseLafClass));
}
@Override
public UIDefaults getDefaults() {
return super.getDefaults();
}
private static ThemedLookAndFeel getLaf(final String baseLafClass) {
try {
Class<?> base = Class.forName(baseLafClass);
if (!ThemedLookAndFeel.class.isAssignableFrom(base)) {
throw new IllegalArgumentException(base + " is not of type " + ThemedLookAndFeel.class);
}
return (ThemedLookAndFeel) base.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | NoSuchMethodException
| InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}

36
theme/src/main/java/com/github/weisj/darklaf/theme/laf/ThemedLookAndFeel.java

@ -0,0 +1,36 @@
/*
* 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.theme.laf;
import javax.swing.*;
import com.github.weisj.darklaf.theme.Theme;
public abstract class ThemedLookAndFeel extends LookAndFeel {
protected abstract void setTheme(final Theme theme);
public abstract Theme getTheme();
}
Loading…
Cancel
Save