diff --git a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java index 44240afd..38c79ca0 100644 --- a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java +++ b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java @@ -60,34 +60,21 @@ public abstract class DarkColorModel { @Override public abstract String toString(); - public abstract char[] getLabelDescriptorsBefore(); + public abstract String[] getLabelDescriptorsBefore(); public String[] getFullLabelDescriptorsBefore() { return labels; } - public char[] getLabelDescriptorsAfter() { - return new char[]{Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE}; + public String[] getLabelDescriptorsAfter() { + return new String[]{"", "", "", ""}; } public String[] getFullLabelDescriptorsAfter() { - char[] after = getLabelDescriptorsAfter(); - String[] fullAfter = new String[after.length]; - for (int i = 0; i < fullAfter.length; i++) { - if (after[i] != Character.MIN_VALUE) { - fullAfter[i] = String.valueOf(after[i]); - } else { - fullAfter[i] = ""; - } - } - return fullAfter; + return getLabelDescriptorsAfter(); } - public int[] getValuesFromColor(final Color color) { - return new int[]{color.getRed(), color.getGreen(), color.getBlue()}; - } + public abstract int[] getValuesFromColor(final Color color); - public Color getColorFromValues(final int[] values) { - return new Color(values[0], values[1], values[2]); - } + public abstract Color getColorFromValues(final int[] values); } diff --git a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java index cb473154..31a5e93a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java +++ b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java @@ -62,13 +62,13 @@ public class DarkColorModelCMYK extends DarkColorModel { } @Override - public char[] getLabelDescriptorsBefore() { - return new char[]{'C', 'M', 'Y', 'K'}; + public String[] getLabelDescriptorsBefore() { + return new String[]{"C", "M", "Y", "K"}; } @Override - public char[] getLabelDescriptorsAfter() { - return new char[]{'%', '%', '%', '%'}; + public String[] getLabelDescriptorsAfter() { + return new String[]{"%", "%", "%", "%"}; } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java index 920918cc..6cd73314 100644 --- a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java +++ b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java @@ -62,13 +62,13 @@ public class DarkColorModelHSB extends DarkColorModel { } @Override - public char[] getLabelDescriptorsBefore() { - return new char[]{'H', 'S', 'B'}; + public String[] getLabelDescriptorsBefore() { + return new String[]{"H", "S", "B"}; } @Override - public char[] getLabelDescriptorsAfter() { - return new char[]{'\u00B0', '%', '%'}; + public String[] getLabelDescriptorsAfter() { + return new String[]{"\u00B0", "%", "%"}; } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java index 43f7e5b3..eafa53e7 100644 --- a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java +++ b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java @@ -62,13 +62,13 @@ public class DarkColorModelHSL extends DarkColorModel { } @Override - public char[] getLabelDescriptorsBefore() { - return new char[]{'H', 'S', 'L'}; + public String[] getLabelDescriptorsBefore() { + return new String[]{"H", "S", "L"}; } @Override - public char[] getLabelDescriptorsAfter() { - return new char[]{'\u00B0', '%', '%'}; + public String[] getLabelDescriptorsAfter() { + return new String[]{"\u00B0", "%", "%"}; } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelRGB.java b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelRGB.java index 3bd4246d..4fd3ed8b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelRGB.java +++ b/core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelRGB.java @@ -53,12 +53,12 @@ public class DarkColorModelRGB extends DarkColorModel { return "RGB"; } - public char[] getLabelDescriptorsBefore() { - return new char[]{'R', 'G', 'B'}; + public String[] getLabelDescriptorsBefore() { + return new String[]{"R", "G", "B"}; } - public char[] getLabelDescriptorsAfter() { - return new char[]{Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE}; + public String[] getLabelDescriptorsAfter() { + return new String[]{"", "", "", ""}; } public int[] getValuesFromColor(final Color color) { diff --git a/core/src/main/java/com/github/weisj/darklaf/components/ColoredRadioButton.java b/core/src/main/java/com/github/weisj/darklaf/components/ColoredRadioButton.java index 8a433523..5ed919fd 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/ColoredRadioButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/ColoredRadioButton.java @@ -189,7 +189,7 @@ public class ColoredRadioButton extends JRadioButton { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); theme.loadDefaults(props, defaults); Color accentCol = color == DEFAULT_FILLED ? (Color) props.get("widgetFillDefault") : color; - Color focusCol = color == DEFAULT_FILLED ? accentCol : focusColor; + Color focusCol = focusColor == DEFAULT_FILLED ? accentCol : focusColor; adjustment.applyColors(LafManager.getTheme(), props, accentCol, null); PropertyLoader.putProperties(PropertyLoader.loadProperties(DarkLaf.class, "radioButton", "properties/ui/"), @@ -204,12 +204,15 @@ public class ColoredRadioButton extends JRadioButton { for (String prop : COLOR_PROPERTIES) { propertyMap.put(prop, accentCol); } - for (String prop : FOCUS_COLOR_PROPERTIES) { - propertyMap.put(prop, focusCol); + if (focusColor != DEFAULT_FILLED) { + for (String prop : FOCUS_COLOR_PROPERTIES) { + propertyMap.put(prop, focusCol); + } } for (String prop : FOREGROUND_PROPERTIES) { Color fg = ForegroundColorGenerationTask.makeAdjustedForeground((Color) props.get(prop), - accentCol, MIN_FG_CONTRAST); + accentCol, + MIN_FG_CONTRAST); propertyMap.put(prop, fg); } diff --git a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java index c5ac34e7..7a45c750 100644 --- a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java +++ b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java @@ -165,7 +165,7 @@ public class ThemeSettingsPanel extends JPanel { Color currentAccentColor = LafManager.getTheme().getAccentColorRule().getAccentColor(); Color currentSelectionColor = LafManager.getTheme().getAccentColorRule().getSelectionColor(); - JComponent selectionBox = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + JComponent selectionBox = Box.createHorizontalBox(); JLabel selectionColorLabel = new JLabel(resourceBundle.getString("label_selection_color")); selectionColorLabel.setLabelFor(selectionBox); @@ -200,7 +200,7 @@ public class ThemeSettingsPanel extends JPanel { customSelection = addCustomButton(bgSelection, selectionBox, currentSelectionColor, defaultSelectionColor, resourceBundle.getString("color_custom")); - JComponent accentBox = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + JComponent accentBox = Box.createHorizontalBox(); JLabel accentColorLabel = new JLabel(resourceBundle.getString("label_accent_color")); accentColorLabel.setLabelFor(accentBox); diff --git a/core/src/main/java/com/github/weisj/darklaf/task/ForegroundColorGenerationTask.java b/core/src/main/java/com/github/weisj/darklaf/task/ForegroundColorGenerationTask.java index 70328cf9..04f8f7d6 100644 --- a/core/src/main/java/com/github/weisj/darklaf/task/ForegroundColorGenerationTask.java +++ b/core/src/main/java/com/github/weisj/darklaf/task/ForegroundColorGenerationTask.java @@ -31,10 +31,10 @@ import java.util.Properties; import javax.swing.plaf.ColorUIResource; import com.github.weisj.darklaf.color.DarkColorModelHSB; +import com.github.weisj.darklaf.color.DarkColorModelHSL; import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.theme.info.AccentColorRule; import com.github.weisj.darklaf.uiresource.DarkColorUIResource; -import com.github.weisj.darklaf.util.ColorUtil; import com.github.weisj.darklaf.util.Pair; public class ForegroundColorGenerationTask extends ColorAdjustmentTask { @@ -70,10 +70,10 @@ public class ForegroundColorGenerationTask extends ColorAdjustmentTask { MIN_FOREGROUND_DIFFERENCE))); } - public static ColorUIResource makeForeground(final Color c, final double minimumBrightnessDifference) { - double[] hsbBG = DarkColorModelHSB.RGBtoHSBValues(c.getRed(), c.getGreen(), c.getBlue()); - double[] hsbFG = new double[]{hsbBG[0], 0, 1 - hsbBG[2]}; - return makeAdjustedForeground(hsbFG, hsbBG, Bias.BACKGROUND, minimumBrightnessDifference); + public static ColorUIResource makeForeground(final Color bg, final double minimumBrightnessDifference) { + double[] hsbBG = DarkColorModelHSB.RGBtoHSBValues(bg.getRed(), bg.getGreen(), bg.getBlue()); + Color fg = DarkColorModelHSB.getColorFromHSBValues(hsbBG[0], 0, 1 - hsbBG[2]); + return makeAdjustedForeground(fg, bg, Bias.BACKGROUND, minimumBrightnessDifference); } public static ColorUIResource makeAdjustedForeground(final Color fg, final Color bg, @@ -83,28 +83,47 @@ public class ForegroundColorGenerationTask extends ColorAdjustmentTask { public static ColorUIResource makeAdjustedForeground(final Color fg, final Color bg, final Bias bias, final double minimumBrightnessDifference) { - double[] hsbBG = DarkColorModelHSB.RGBtoHSBValues(bg.getRed(), bg.getGreen(), bg.getBlue()); - double[] hsbFG = DarkColorModelHSB.RGBtoHSBValues(fg.getRed(), fg.getGreen(), fg.getBlue()); - return makeAdjustedForeground(hsbFG, hsbBG, bias, minimumBrightnessDifference); - } - - private static ColorUIResource makeAdjustedForeground(final double[] hsbFG, final double[] hsbBG, final Bias bias, - final double minimumBrightnessDifference) { - double bgBrightness = hsbBG[2]; - double fgBrightness = hsbFG[2]; + final double[] hslFG = DarkColorModelHSL.RGBtoHSLValues(fg.getRed(), fg.getGreen(), fg.getBlue()); + final double[] hslBG = DarkColorModelHSL.RGBtoHSLValues(bg.getRed(), bg.getGreen(), bg.getBlue()); + double bgBrightness = hslBG[2]; + double fgBrightness = hslFG[2]; Bias b = bias != null ? bias : Bias.BACKGROUND; + if (b == Bias.BACKGROUND) { - Color c = DarkColorModelHSB.getColorFromHSBValues(hsbBG[0], hsbBG[1], hsbBG[2]); - double bgBright = (1 - hsbBG[1]) * ColorUtil.getPerceivedBrightness(c); - b = bgBright <= 127.5f ? Bias.WHITE : Bias.BLACK; + double bgBright = getLuminance(bg); + b = bgBright <= 0.552 ? Bias.WHITE : Bias.BLACK; } - double difference = Math.abs(fgBrightness - bgBrightness); - if (difference < minimumBrightnessDifference) { - fgBrightness += b.direction * (Math.abs(minimumBrightnessDifference - difference)); - } - return new DarkColorUIResource(DarkColorModelHSB.getColorFromHSBValues(hsbFG[0], hsbFG[1], fgBrightness)); + double bright1 = fgBrightness > bgBrightness && (fgBrightness - bgBrightness) >= minimumBrightnessDifference + ? hslFG[2] + : Math.min(bgBrightness + minimumBrightnessDifference, 1); + double bright2 = fgBrightness < bgBrightness && (bgBrightness - fgBrightness) >= minimumBrightnessDifference + ? hslFG[2] + : Math.max(bgBrightness - minimumBrightnessDifference, 0); + + double brightness = b == Bias.WHITE ? bright1 : bright2; + return new DarkColorUIResource(DarkColorModelHSL.getColorFromHSLValues(hslFG[0], hslFG[1], brightness)); + } + + private static double getLuminance(final Color c) { + return getLuminance(c.getRed(), c.getGreen(), c.getBlue()); + } + + private static double getLuminance(final int red, final int green, final int blue) { + double r = red / 255.0; + double g = green / 255.0; + double b = blue / 255.0; + double R = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4); + double G = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4); + double B = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4); + return 0.2126 * R + 0.7152 * G + 0.0722 * B; + } + + private static double calculateContrast(final double fgBrightness, final double bgBrightness) { + double bright = Math.max(fgBrightness, bgBrightness); + double dark = Math.min(fgBrightness, bgBrightness); + return (bright + 0.05) / (dark + 0.05); } public enum Bias { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java index 79a224df..9cca95f0 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java @@ -233,7 +233,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements } private void updateDescriptors() { - char[] desc = getDarkColorModel().getLabelDescriptorsBefore(); + String[] desc = getDarkColorModel().getLabelDescriptorsBefore(); String[] descAfter = getDarkColorModel().getFullLabelDescriptorsAfter(); for (int i = 0; i < descriptors.length; i++) { if (i < desc.length) {