mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
21 changed files with 734 additions and 389 deletions
@ -0,0 +1,33 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.theme.Theme; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public interface DefaultsInitTask { |
||||
|
||||
void run(final Theme currentTheme, final Map<Object, Object> defaults); |
||||
} |
@ -0,0 +1,114 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.DarkLaf; |
||||
import com.github.weisj.darklaf.PropertyLoader; |
||||
import com.github.weisj.darklaf.theme.FontMapper; |
||||
import com.github.weisj.darklaf.theme.FontSizeRule; |
||||
import com.github.weisj.darklaf.theme.Theme; |
||||
import com.github.weisj.darklaf.util.SystemInfo; |
||||
|
||||
import javax.swing.plaf.FontUIResource; |
||||
import javax.swing.plaf.UIResource; |
||||
import java.awt.*; |
||||
import java.awt.font.TextAttribute; |
||||
import java.text.AttributedCharacterIterator; |
||||
import java.util.Collections; |
||||
import java.util.Map; |
||||
import java.util.Properties; |
||||
|
||||
public class FontDefaultsInitTask implements DefaultsInitTask { |
||||
|
||||
private static final String FONT_PROPERTY_PATH = "properties/"; |
||||
private static final String FONT_SIZE_DEFAULTS_NAME = "font_sizes"; |
||||
private static final String FONT_DEFAULTS_NAME = "font_sizes"; |
||||
|
||||
private static final String MAC_OS_CATALINA_FONT_NAME = ".AppleSystemUIFont"; |
||||
private static final String MAC_OS_FONT_NAME = ".SF NS Text"; |
||||
|
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
loadFontProperties(defaults); |
||||
if (SystemInfo.isMac) { |
||||
patchMacOSFonts(defaults); |
||||
} |
||||
applyFontRule(currentTheme, defaults); |
||||
} |
||||
|
||||
private void loadFontProperties(final Map<Object, Object> defaults) { |
||||
Properties fontSizeProps = PropertyLoader.loadProperties(DarkLaf.class, |
||||
FONT_SIZE_DEFAULTS_NAME, |
||||
FONT_PROPERTY_PATH); |
||||
PropertyLoader.putProperties(fontSizeProps, defaults); |
||||
Properties fontProps = PropertyLoader.loadProperties(DarkLaf.class, |
||||
FONT_DEFAULTS_NAME, |
||||
FONT_PROPERTY_PATH); |
||||
PropertyLoader.putProperties(fontProps, defaults); |
||||
} |
||||
|
||||
private void patchMacOSFonts(final Map<Object, Object> defaults) { |
||||
for (Map.Entry<Object, Object> entry : defaults.entrySet()) { |
||||
if (entry.getValue() instanceof Font) { |
||||
Font font = (Font) entry.getValue(); |
||||
entry.setValue(macOSFontFromFont(font)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private Font macOSFontFromFont(final Font font) { |
||||
Map<AttributedCharacterIterator.Attribute, Integer> attributes |
||||
= Collections.singletonMap(TextAttribute.KERNING, TextAttribute.KERNING_ON); |
||||
String fontName = SystemInfo.isMacOSCatalina ? MAC_OS_CATALINA_FONT_NAME : MAC_OS_FONT_NAME; |
||||
Font macFont = new Font(fontName, font.getStyle(), font.getSize()).deriveFont(attributes); |
||||
if (font instanceof UIResource) { |
||||
macFont = new FontUIResource(macFont); |
||||
} |
||||
return macFont == null ? font : macFont; |
||||
} |
||||
|
||||
private void applyFontRule(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
FontSizeRule rule = currentTheme.getFontSizeRule(); |
||||
if (rule == null || rule == FontSizeRule.DEFAULT) return; |
||||
for (Map.Entry<Object, Object> entry : defaults.entrySet()) { |
||||
if (entry != null && entry.getValue() instanceof Font) { |
||||
entry.setValue(fontWithRule((Font) entry.getValue(), rule, defaults)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private Font fontWithRule(final Font font, final FontSizeRule rule, final Map<Object, Object> defaults) { |
||||
Font withRule = getFontMapper(rule).map(font, defaults); |
||||
if (font instanceof UIResource |
||||
&& !(withRule instanceof UIResource)) { |
||||
withRule = new FontUIResource(withRule); |
||||
} |
||||
return withRule; |
||||
} |
||||
|
||||
private FontMapper getFontMapper(final FontSizeRule rule) { |
||||
if (rule == null) return (font, defaults) -> font; |
||||
return rule.getFontMapper(); |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.theme.Theme; |
||||
|
||||
import javax.swing.*; |
||||
import java.util.Map; |
||||
|
||||
public class IdeaDefaultsInitTask implements DefaultsInitTask { |
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
initIdeaDefaults(defaults); |
||||
} |
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"}) |
||||
private void initIdeaDefaults(final Map<Object, Object> defaults) { |
||||
defaults.put("Table.ancestorInputMap", new UIDefaults.LazyInputMap( |
||||
new Object[]{ |
||||
"ctrl C", "copy", |
||||
"meta C", "copy", |
||||
"ctrl V", "paste", |
||||
"meta V", "paste", |
||||
"ctrl X", "cut", |
||||
"meta X", "cut", |
||||
"COPY", "copy", |
||||
"PASTE", "paste", |
||||
"CUT", "cut", |
||||
"control INSERT", "copy", |
||||
"shift INSERT", "paste", |
||||
"shift DELETE", "cut", |
||||
"RIGHT", "selectNextColumn", |
||||
"KP_RIGHT", "selectNextColumn", |
||||
"LEFT", "selectPreviousColumn", |
||||
"KP_LEFT", "selectPreviousColumn", |
||||
"DOWN", "selectNextRow", |
||||
"KP_DOWN", "selectNextRow", |
||||
"UP", "selectPreviousRow", |
||||
"KP_UP", "selectPreviousRow", |
||||
"shift RIGHT", "selectNextColumnExtendSelection", |
||||
"shift KP_RIGHT", "selectNextColumnExtendSelection", |
||||
"shift LEFT", "selectPreviousColumnExtendSelection", |
||||
"shift KP_LEFT", "selectPreviousColumnExtendSelection", |
||||
"shift DOWN", "selectNextRowExtendSelection", |
||||
"shift KP_DOWN", "selectNextRowExtendSelection", |
||||
"shift UP", "selectPreviousRowExtendSelection", |
||||
"shift KP_UP", "selectPreviousRowExtendSelection", |
||||
"PAGE_UP", "scrollUpChangeSelection", |
||||
"PAGE_DOWN", "scrollDownChangeSelection", |
||||
"HOME", "selectFirstColumn", |
||||
"END", "selectLastColumn", |
||||
"shift PAGE_UP", "scrollUpExtendSelection", |
||||
"shift PAGE_DOWN", "scrollDownExtendSelection", |
||||
"shift HOME", "selectFirstColumnExtendSelection", |
||||
"shift END", "selectLastColumnExtendSelection", |
||||
"ctrl PAGE_UP", "scrollLeftChangeSelection", |
||||
"ctrl PAGE_DOWN", "scrollRightChangeSelection", |
||||
"ctrl HOME", "selectFirstRow", |
||||
"ctrl END", "selectLastRow", |
||||
"ctrl shift PAGE_UP", "scrollRightExtendSelection", |
||||
"ctrl shift PAGE_DOWN", "scrollLeftExtendSelection", |
||||
"ctrl shift HOME", "selectFirstRowExtendSelection", |
||||
"ctrl shift END", "selectLastRowExtendSelection", |
||||
"TAB", "selectNextColumnCell", |
||||
"shift TAB", "selectPreviousColumnCell", |
||||
"ENTER", "selectNextRowCell", |
||||
"shift ENTER", "selectPreviousRowCell", |
||||
"ctrl A", "selectAll", |
||||
"meta A", "selectAll", |
||||
"ESCAPE", "cancel", |
||||
"F2", "startEditing" |
||||
})); |
||||
} |
||||
} |
@ -0,0 +1,108 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.theme.Theme; |
||||
import com.github.weisj.darklaf.util.SystemInfo; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.plaf.metal.MetalLookAndFeel; |
||||
import javax.swing.text.DefaultEditorKit; |
||||
import java.awt.event.InputEvent; |
||||
import java.awt.event.KeyEvent; |
||||
import java.util.Map; |
||||
|
||||
public class InputDefaultsInitTask implements DefaultsInitTask { |
||||
|
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
initInputMapDefaults(defaults); |
||||
patchComboBox(new MetalLookAndFeel().getDefaults(), defaults); |
||||
} |
||||
|
||||
private void initInputMapDefaults(final Map<Object, Object> defaults) { |
||||
// Make ENTER work in JTrees
|
||||
final InputMap treeInputMap = (InputMap) defaults.get("Tree.focusInputMap"); |
||||
if (treeInputMap != null) { |
||||
// it's really possible. For example, GTK+ doesn't have such map
|
||||
treeInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "toggle"); |
||||
} |
||||
// Cut/Copy/Paste in JTextAreas
|
||||
final InputMap textAreaInputMap = (InputMap) defaults.get("TextArea.focusInputMap"); |
||||
if (textAreaInputMap != null) { |
||||
// It really can be null, for example when LAF isn't properly initialized
|
||||
// (Alloy license problem)
|
||||
installCutCopyPasteShortcuts(textAreaInputMap, false); |
||||
} |
||||
// Cut/Copy/Paste in JTextFields
|
||||
final InputMap textFieldInputMap = (InputMap) defaults.get("TextField.focusInputMap"); |
||||
if (textFieldInputMap != null) { |
||||
// It really can be null, for example when LAF isn't properly initialized
|
||||
// (Alloy license problem)
|
||||
installCutCopyPasteShortcuts(textFieldInputMap, false); |
||||
} |
||||
// Cut/Copy/Paste in JPasswordField
|
||||
final InputMap passwordFieldInputMap = (InputMap) defaults.get("PasswordField.focusInputMap"); |
||||
if (passwordFieldInputMap != null) { |
||||
// It really can be null, for example when LAF isn't properly initialized
|
||||
// (Alloy license problem)
|
||||
installCutCopyPasteShortcuts(passwordFieldInputMap, false); |
||||
} |
||||
// Cut/Copy/Paste in JTables
|
||||
final InputMap tableInputMap = (InputMap) defaults.get("Table.ancestorInputMap"); |
||||
if (tableInputMap != null) { |
||||
// It really can be null, for example when LAF isn't properly initialized
|
||||
// (Alloy license problem)
|
||||
installCutCopyPasteShortcuts(tableInputMap, true); |
||||
} |
||||
final InputMap buttonInputMap = (InputMap) defaults.get("Button.focusInputMap"); |
||||
if (buttonInputMap != null && !SystemInfo.isMac) { |
||||
buttonInputMap.put(KeyStroke.getKeyStroke("ENTER"), "pressed"); |
||||
buttonInputMap.put(KeyStroke.getKeyStroke("released ENTER"), "released"); |
||||
} |
||||
} |
||||
|
||||
private void installCutCopyPasteShortcuts(final InputMap inputMap, |
||||
final boolean useSimpleActionKeys) { |
||||
final String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction; |
||||
final String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction; |
||||
final String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction; |
||||
final int mask = SystemInfo.isMac ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK; |
||||
// Ctrl+Ins, Shift+Ins, Shift+Del
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_DOWN_MASK), copyActionKey); |
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_DOWN_MASK), pasteActionKey); |
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK), cutActionKey); |
||||
// Ctrl+C, Ctrl+V, Ctrl+X
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, mask), copyActionKey); |
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, mask), pasteActionKey); |
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, mask), DefaultEditorKit.cutAction); |
||||
} |
||||
|
||||
private static void patchComboBox(final UIDefaults metalDefaults, final Map<Object, Object> defaults) { |
||||
defaults.remove("ComboBox.ancestorInputMap"); |
||||
defaults.remove("ComboBox.actionMap"); |
||||
defaults.put("ComboBox.ancestorInputMap", metalDefaults.get("ComboBox.ancestorInputMap")); |
||||
defaults.put("ComboBox.actionMap", metalDefaults.get("ComboBox.actionMap")); |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.platform.Decorations; |
||||
import com.github.weisj.darklaf.theme.Theme; |
||||
import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI; |
||||
import com.github.weisj.darklaf.util.SystemInfo; |
||||
|
||||
import javax.swing.*; |
||||
import java.util.Map; |
||||
|
||||
public class PlatformDefaultsInitTask implements DefaultsInitTask { |
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
String key = DarkPopupMenuUI.KEY_DEFAULT_LIGHTWEIGHT_POPUPS; |
||||
if (SystemInfo.isWindows10 && Decorations.isCustomDecorationSupported()) { |
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(Boolean.TRUE.equals(defaults.get(key + ".windows"))); |
||||
} else { |
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(Boolean.TRUE.equals(defaults.get(key))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.DarkLaf; |
||||
import com.github.weisj.darklaf.PropertyLoader; |
||||
import com.github.weisj.darklaf.theme.Theme; |
||||
|
||||
import java.util.Map; |
||||
import java.util.Properties; |
||||
|
||||
public class SystemDefaultsInitTask implements DefaultsInitTask { |
||||
|
||||
private static final String OVERWRITES_PATH = "properties/"; |
||||
private static final String OVERWRITES_NAME = "overwrites"; |
||||
|
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
loadSystemOverwrites(defaults); |
||||
} |
||||
|
||||
private void loadSystemOverwrites(final Map<Object, Object> defaults) { |
||||
Properties overwrites = PropertyLoader.loadProperties(DarkLaf.class, OVERWRITES_NAME, OVERWRITES_PATH); |
||||
overwrites.values().removeIf(v -> System.getProperty(DarkLaf.SYSTEM_PROPERTY_PREFIX + v.toString()) == null); |
||||
overwrites.entrySet().forEach( |
||||
e -> e.setValue(System.getProperty(DarkLaf.SYSTEM_PROPERTY_PREFIX + e.getValue().toString()))); |
||||
PropertyLoader.putProperties(overwrites, defaults); |
||||
} |
||||
} |
@ -0,0 +1,99 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.platform.Decorations; |
||||
import com.github.weisj.darklaf.theme.Theme; |
||||
import com.github.weisj.darklaf.util.SystemInfo; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.text.html.HTMLEditorKit; |
||||
import javax.swing.text.html.StyleSheet; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Properties; |
||||
|
||||
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 final DefaultsInitTask userPreferenceInitTask = new UserPreferenceInitTask(); |
||||
|
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
if (!(defaults instanceof UIDefaults)) return; |
||||
loadThemeDefaults(currentTheme, (UIDefaults) defaults); |
||||
} |
||||
|
||||
private void loadThemeDefaults(final Theme currentTheme, final UIDefaults defaults) { |
||||
Properties uiProps = new Properties(); |
||||
currentTheme.loadDefaults(uiProps, defaults); |
||||
|
||||
/* |
||||
* User preferences need to be applied here so changes are applied to all |
||||
* components that use the property. |
||||
*/ |
||||
userPreferenceInitTask.run(currentTheme, uiProps); |
||||
|
||||
currentTheme.loadGlobals(uiProps, defaults); |
||||
installGlobals(uiProps, defaults); |
||||
currentTheme.loadUIProperties(uiProps, defaults); |
||||
currentTheme.loadIconProperties(uiProps, defaults); |
||||
Decorations.loadDecorationProperties(uiProps, defaults); |
||||
currentTheme.loadPlatformProperties(uiProps, defaults); |
||||
adjustPlatformSpecifics(uiProps); |
||||
defaults.putAll(uiProps); |
||||
|
||||
StyleSheet styleSheet = currentTheme.loadStyleSheet(); |
||||
new HTMLEditorKit().setStyleSheet(styleSheet); |
||||
} |
||||
|
||||
private void installGlobals(final Properties uiProps, final Map<Object, Object> defaults) { |
||||
final HashMap<String, Object> globalSettings = new HashMap<>(); |
||||
for (final Object key : uiProps.keySet()) { |
||||
if (key instanceof String && ((String) key).startsWith(GLOBAL_PREFIX)) { |
||||
globalSettings.put(((String) key).substring(GLOBAL_PREFIX.length()), uiProps.get(key)); |
||||
} |
||||
} |
||||
|
||||
for (final Object key : defaults.keySet()) { |
||||
if (key instanceof String && ((String) key).contains(".")) { |
||||
final String s = (String) key; |
||||
final String globalKey = s.substring(s.lastIndexOf('.') + 1); |
||||
if (globalSettings.containsKey(globalKey)) { |
||||
defaults.put(key, globalSettings.get(globalKey)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected void adjustPlatformSpecifics(final Properties uiProps) { |
||||
boolean useScreenMenuBar = Boolean.getBoolean(MAC_OS_MENU_BAR_KEY); |
||||
// If user wants to use Apple menu bar, then we need to keep the default
|
||||
// component for MenuBarUI and MenuUI
|
||||
if (SystemInfo.isMac && useScreenMenuBar) { |
||||
uiProps.remove("MenuBarUI"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.LafManager; |
||||
import com.github.weisj.darklaf.theme.Theme; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public class UserPreferenceInitTask implements DefaultsInitTask { |
||||
|
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
for (DefaultsInitTask task : LafManager.getUserInitTasks()) { |
||||
if (task != null) task.run(currentTheme, defaults); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
/* |
||||
* 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 com.github.weisj.darklaf.components.border.DarkBorders; |
||||
import com.github.weisj.darklaf.theme.Theme; |
||||
import com.github.weisj.darklaf.util.DarkUIUtil; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public class UtilityDefaultsInitTask implements DefaultsInitTask { |
||||
@Override |
||||
public void run(final Theme currentTheme, final Map<Object, Object> defaults) { |
||||
setupUtils(defaults); |
||||
} |
||||
|
||||
private void setupUtils(final Map<Object, Object> defaults) { |
||||
DarkUIUtil.setDropOpacity(getOpacity(defaults, "dropOpacity")); |
||||
DarkUIUtil.setGlowOpacity(getOpacity(defaults, "glowOpacity")); |
||||
DarkUIUtil.setShadowOpacity(getOpacity(defaults, "shadowOpacity")); |
||||
DarkBorders.update(defaults); |
||||
} |
||||
|
||||
private float getOpacity(final Map<Object, Object> defaults, final String key) { |
||||
Object obj = defaults.get(key); |
||||
int val = (obj instanceof Integer) ? (int) obj : 100; |
||||
return val / 100f; |
||||
} |
||||
} |
Loading…
Reference in new issue