mirror of https://github.com/weisJ/darklaf.git
weisj
4 years ago
26 changed files with 558 additions and 19 deletions
@ -0,0 +1,7 @@
|
||||
plugins { |
||||
`java-library` |
||||
} |
||||
|
||||
dependencies { |
||||
api(project(":darklaf-annotations")) |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -0,0 +1 @@
|
||||
com.github.weisj.darklaf.annotations.processor.SynthesisesLafProcessor |
@ -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"; |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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…
Reference in new issue