mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
22 changed files with 714 additions and 123 deletions
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public enum ContrastRule { |
||||
HIGH_CONTRAST, |
||||
STANDARD |
||||
} |
@ -0,0 +1,91 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public class DefaultThemeProvider implements ThemeProvider { |
||||
|
||||
private final Theme lightTheme; |
||||
private final Theme darkTheme; |
||||
private final Theme lightHighContrastTheme; |
||||
private final Theme darkHighContrastTheme; |
||||
|
||||
public DefaultThemeProvider() { |
||||
this(new IntelliJTheme(), new DarculaTheme(), |
||||
new HighContrastLightTheme(), new HighContrastDarkTheme()); |
||||
} |
||||
|
||||
public DefaultThemeProvider(final Theme lightTheme, |
||||
final Theme darkTheme, |
||||
final Theme lightHighContrastTheme, |
||||
final Theme darkHighContrastTheme) { |
||||
/* |
||||
* Ensure the given themes actually serve the purpose they are intended for. |
||||
*/ |
||||
if (Theme.isDark(lightTheme)) { |
||||
throw new UnsupportedThemeException("Given light theme " + lightTheme |
||||
+ "is declared as dark"); |
||||
} |
||||
if (Theme.isDark(lightHighContrastTheme)) { |
||||
throw new UnsupportedThemeException("Given light high-contrast theme " + lightHighContrastTheme |
||||
+ " is declared as dark"); |
||||
} |
||||
if (!Theme.isDark(darkTheme)) { |
||||
throw new UnsupportedThemeException("Given dark theme " + darkTheme |
||||
+ "is not declared as dark"); |
||||
} |
||||
if (!Theme.isDark(darkHighContrastTheme)) { |
||||
throw new UnsupportedThemeException("Given dark high-contrast theme " + darkTheme |
||||
+ "is not declared as dark"); |
||||
} |
||||
/* |
||||
* A high contrast theme may serve as a standard theme, but a standard theme should never be used |
||||
* for high contrast themes. |
||||
*/ |
||||
if (!Theme.isHighContrast(lightHighContrastTheme)) { |
||||
throw new UnsupportedThemeException("Given light high-contrast theme " + lightHighContrastTheme |
||||
+ " is not declared as high-contrast"); |
||||
} |
||||
if (!Theme.isHighContrast(darkHighContrastTheme)) { |
||||
throw new UnsupportedThemeException("Given dark high-contrast theme " + darkHighContrastTheme |
||||
+ " is not declared as high-contrast"); |
||||
} |
||||
this.lightTheme = lightTheme; |
||||
this.darkTheme = darkTheme; |
||||
this.lightHighContrastTheme = lightHighContrastTheme; |
||||
this.darkHighContrastTheme = darkHighContrastTheme; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Theme getTheme(final PreferredThemeStyle themeStyle) { |
||||
if (themeStyle == null) return lightTheme; |
||||
boolean dark = themeStyle.getStyleRule() == StyleRule.DARK; |
||||
boolean highContrast = themeStyle.getContrastRule() == ContrastRule.HIGH_CONTRAST; |
||||
Theme theme = dark ? highContrast ? darkHighContrastTheme : darkTheme |
||||
: highContrast ? lightHighContrastTheme : lightTheme; |
||||
// Apply the font size.
|
||||
theme.setFontSizeRule(themeStyle.getFontSizeRule()); |
||||
return theme; |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public interface FontMapper { |
||||
|
||||
Font map(final Font font, final UIDefaults defaults); |
||||
} |
@ -0,0 +1,51 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public enum FontSizeRule { |
||||
DEFAULT("default"), |
||||
TINY("tiny"), |
||||
SMALLER("smaller"), |
||||
SMALL("small"), |
||||
MEDIUM("medium"), |
||||
LARGE("large"), |
||||
LARGER("larger"), |
||||
HUGE("huge"); |
||||
|
||||
private final String propertyKey; |
||||
private final PropertyFontMapper fontMapper; |
||||
|
||||
FontSizeRule(final String propertyKey) { |
||||
this.propertyKey = propertyKey; |
||||
fontMapper = new PropertyFontMapper(getPropertyKey()); |
||||
} |
||||
|
||||
public String getPropertyKey() { |
||||
return "fontSize." + propertyKey; |
||||
} |
||||
|
||||
public FontMapper getFontMapper() { |
||||
return fontMapper; |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public class PreferredThemeStyle { |
||||
|
||||
private final ContrastRule contrastRule; |
||||
private final StyleRule styleRule; |
||||
private final FontSizeRule fontSizeRule; |
||||
|
||||
public PreferredThemeStyle(final ContrastRule contrastRule, |
||||
final StyleRule styleRule, |
||||
final FontSizeRule fontSizeRule) { |
||||
if (contrastRule == null) throw new IllegalArgumentException("null is not a valid contrast rule"); |
||||
if (styleRule == null) throw new IllegalArgumentException("null is not a valid style rule"); |
||||
if (fontSizeRule == null) throw new IllegalArgumentException("null is not a valid font size rule"); |
||||
this.contrastRule = contrastRule; |
||||
this.styleRule = styleRule; |
||||
this.fontSizeRule = fontSizeRule; |
||||
} |
||||
|
||||
public ContrastRule getContrastRule() { |
||||
return contrastRule; |
||||
} |
||||
|
||||
public StyleRule getStyleRule() { |
||||
return styleRule; |
||||
} |
||||
|
||||
public FontSizeRule getFontSizeRule() { |
||||
return fontSizeRule; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public enum PresetIconRule { |
||||
NONE, |
||||
DARK, |
||||
LIGHT |
||||
} |
@ -0,0 +1,71 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import com.github.weisj.darklaf.LafManager; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.util.logging.Logger; |
||||
|
||||
public class PropertyFontMapper implements FontMapper { |
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(PropertyFontMapper.class.getName()); |
||||
|
||||
private Theme lastTheme = null; |
||||
private int adjustment; |
||||
private String propertyKey; |
||||
|
||||
public PropertyFontMapper(final String propertyKey) { |
||||
this.propertyKey = propertyKey; |
||||
} |
||||
|
||||
@Override |
||||
public Font map(final Font font, final UIDefaults defaults) { |
||||
adjustment = getSize(defaults); |
||||
// No need to create a new font.
|
||||
if (adjustment == 0) return font; |
||||
if (adjustment < font.getSize2D()) { |
||||
if (adjustment != Integer.MIN_VALUE) { |
||||
LOGGER.warning("Font " + font + " would be invisible after applying " |
||||
+ "an adjustment of " + adjustment + ". Aborting!"); |
||||
} |
||||
return font; |
||||
} |
||||
return font.deriveFont(font.getSize2D() + adjustment); |
||||
} |
||||
|
||||
private int getSize(final UIDefaults defaults) { |
||||
// Use cached value if already queried.
|
||||
if (lastTheme == LafManager.getTheme()) return adjustment; |
||||
lastTheme = LafManager.getTheme(); |
||||
Object obj = defaults.get(propertyKey); |
||||
if (!(obj instanceof Integer)) { |
||||
LOGGER.warning("Font size property '" + propertyKey + "' not specified. Mapper will do nothing"); |
||||
return Integer.MIN_VALUE; |
||||
} else { |
||||
return (int) obj; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public enum StyleRule { |
||||
DARK, |
||||
LIGHT |
||||
} |
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
public interface ThemeProvider { |
||||
|
||||
Theme getTheme(final PreferredThemeStyle themeStyle); |
||||
} |
@ -0,0 +1,35 @@
|
||||
# suppress inspection "UnusedProperty" for whole file |
||||
# |
||||
# 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. |
||||
# |
||||
# The default font size to use. |
||||
fontSize.default = 12 |
||||
|
||||
# The following values are all relative to the default font size (or those specified on 'font.properties') |
||||
fontSize.tiny = -6 |
||||
fontSize.smaller = -4 |
||||
fontSize.small = -2 |
||||
fontSize.medium = 0 |
||||
fontSize.large = 4 |
||||
fontSize.larger = 8 |
||||
fontSize.huge = 12 |
Loading…
Reference in new issue