From bb5c2eea10d9d290f69a8d305360a7af8cb551a0 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 28 Sep 2021 11:12:17 +0200 Subject: [PATCH] Accent color: - added `Component.accentColor` - dark themes: changed threshold for contrast() from 39% down to 25% for better readability of text - Demo: added "Default" accent color and changed "Blue" to lighter color (issue #233) --- .../resources/com/formdev/flatlaf/FlatDarkLaf.properties | 5 +++-- .../resources/com/formdev/flatlaf/FlatLightLaf.properties | 1 + .../src/main/java/com/formdev/flatlaf/demo/DemoFrame.java | 6 +++++- .../com/formdev/flatlaf/demo/FlatDarkLaf.properties | 6 ++++-- .../com/formdev/flatlaf/demo/FlatLightLaf.properties | 4 +++- flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt | 1 + flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt | 1 + .../com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt | 1 + 8 files changed, 19 insertions(+), 6 deletions(-) diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index 16742af2..8b44d38e 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -35,7 +35,7 @@ @background = #3c3f41 @foreground = #bbb @selectionBackground = @accentSelectionBackground -@selectionForeground = contrast(@selectionBackground,@background,@foreground,39%) +@selectionForeground = contrast(@selectionBackground,@background,@foreground,25%) @selectionInactiveBackground = spin(saturate(shade(@selectionBackground,70%),20%),-15) @selectionInactiveForeground = @foreground @disabledText = #888 @@ -164,6 +164,7 @@ Component.disabledBorderColor = $Component.borderColor Component.focusedBorderColor = lighten($Component.focusColor,5%) Component.focusColor = @accentFocusColor Component.linkColor = @accentLinkColor +Component.accentColor = if(@accentColor, @accentColor, @accentBaseColor) Component.grayFilter = -20,-70,100 Component.error.borderColor = desaturate($Component.error.focusedBorderColor,25%) @@ -242,7 +243,7 @@ PopupMenu.borderColor = #5e5e5e ProgressBar.background = #555 ProgressBar.foreground = @accentSliderColor ProgressBar.selectionBackground = @foreground -ProgressBar.selectionForeground = contrast($ProgressBar.foreground,@background,@foreground,39%) +ProgressBar.selectionForeground = contrast($ProgressBar.foreground,@background,@foreground,25%) #---- RootPane ---- diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index 525bb525..ebc57e6b 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -171,6 +171,7 @@ Component.disabledBorderColor = lighten($Component.borderColor,4%) Component.focusedBorderColor = shade($Component.focusColor,10%) Component.focusColor = @accentFocusColor Component.linkColor = @accentLinkColor +Component.accentColor = if(@accentColor, @accentColor, @accentBaseColor) Component.grayFilter = 25,-25,100 Component.error.borderColor = lighten(desaturate($Component.error.focusedBorderColor,20%),25%) diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java index 22391701..be913508 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java @@ -336,9 +336,12 @@ class DemoFrame // flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties and // flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties private static String[] accentColorKeys = { - "Demo.accent.blue", "Demo.accent.purple", "Demo.accent.red", + "Demo.accent.default", "Demo.accent.blue", "Demo.accent.purple", "Demo.accent.red", "Demo.accent.orange", "Demo.accent.yellow", "Demo.accent.green", }; + private static String[] accentColorNames = { + "Default", "Blue", "Purple", "Red", "Orange", "Yellow", "Green", + }; private final JToggleButton[] accentColorButtons = new JToggleButton[accentColorKeys.length]; private JLabel accentColorLabel; @@ -351,6 +354,7 @@ class DemoFrame ButtonGroup group = new ButtonGroup(); for( int i = 0; i < accentColorButtons.length; i++ ) { accentColorButtons[i] = new JToggleButton( new AccentColorIcon( accentColorKeys[i] ) ); + accentColorButtons[i].setToolTipText( accentColorNames[i] ); accentColorButtons[i].addActionListener( this::accentColorChanged ); toolBar.add( accentColorButtons[i] ); group.add( accentColorButtons[i] ); diff --git a/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties b/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties index e87ea1e1..16132ad6 100644 --- a/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties +++ b/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatDarkLaf.properties @@ -16,9 +16,11 @@ #---- Demo.accent ---- -Demo.accent.blue = #4B6EAF +# accent colors from https://github.com/89netraM/SystemColors/blob/master/src/net/asberg/macos/AccentColor.java +Demo.accent.default = #4B6EAF +Demo.accent.blue = #0A84FF Demo.accent.purple = #BF5AF2 -Demo.accent.red = #e81123 +Demo.accent.red = #FF453A Demo.accent.orange = #FF9F0A Demo.accent.yellow = #FFCC00 Demo.accent.green = #32D74B diff --git a/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties b/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties index da420470..d004fb63 100644 --- a/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties +++ b/flatlaf-demo/src/main/resources/com/formdev/flatlaf/demo/FlatLightLaf.properties @@ -16,7 +16,9 @@ #---- Demo.accent ---- -Demo.accent.blue = #2675BF +# accent colors from https://github.com/89netraM/SystemColors/blob/master/src/net/asberg/macos/AccentColor.java +Demo.accent.default = #2675BF +Demo.accent.blue = #007AFF Demo.accent.purple = #BF5AF2 Demo.accent.red = #FF3B30 Demo.accent.orange = #FF9500 diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt index 84f7ac67..81391cd4 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -216,6 +216,7 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI #---- Component ---- +Component.accentColor #4b6eaf HSL 219 40 49 javax.swing.plaf.ColorUIResource [UI] Component.arc 5 Component.arrowType chevron Component.borderColor #646464 HSL 0 0 39 javax.swing.plaf.ColorUIResource [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt index b4a7720e..b2546a32 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -220,6 +220,7 @@ ComboBoxUI com.formdev.flatlaf.ui.FlatComboBoxUI #---- Component ---- +Component.accentColor #2675bf HSL 209 67 45 javax.swing.plaf.ColorUIResource [UI] Component.arc 5 Component.arrowType chevron Component.borderColor #c4c4c4 HSL 0 0 77 javax.swing.plaf.ColorUIResource [UI] diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index c50e3328..c68d78ed 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -172,6 +172,7 @@ ComboBox.selectionBackground ComboBox.selectionForeground ComboBox.timeFactor ComboBoxUI +Component.accentColor Component.arc Component.arrowType Component.borderColor