Browse Source

Improve visibility of selected indicator for ColoredRadioButton.

pull/189/head
weisj 4 years ago
parent
commit
66b28435fa
  1. 25
      core/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java
  2. 8
      core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java
  3. 8
      core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java
  4. 8
      core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java
  5. 8
      core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelRGB.java
  6. 7
      core/src/main/java/com/github/weisj/darklaf/components/ColoredRadioButton.java
  7. 4
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java
  8. 61
      core/src/main/java/com/github/weisj/darklaf/task/ForegroundColorGenerationTask.java
  9. 2
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java

25
core/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java

@ -60,34 +60,21 @@ public abstract class DarkColorModel {
@Override @Override
public abstract String toString(); public abstract String toString();
public abstract char[] getLabelDescriptorsBefore(); public abstract String[] getLabelDescriptorsBefore();
public String[] getFullLabelDescriptorsBefore() { public String[] getFullLabelDescriptorsBefore() {
return labels; return labels;
} }
public char[] getLabelDescriptorsAfter() { public String[] getLabelDescriptorsAfter() {
return new char[]{Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE}; return new String[]{"", "", "", ""};
} }
public String[] getFullLabelDescriptorsAfter() { public String[] getFullLabelDescriptorsAfter() {
char[] after = getLabelDescriptorsAfter(); return 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;
} }
public int[] getValuesFromColor(final Color color) { public abstract int[] getValuesFromColor(final Color color);
return new int[]{color.getRed(), color.getGreen(), color.getBlue()};
}
public Color getColorFromValues(final int[] values) { public abstract Color getColorFromValues(final int[] values);
return new Color(values[0], values[1], values[2]);
}
} }

8
core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java

@ -62,13 +62,13 @@ public class DarkColorModelCMYK extends DarkColorModel {
} }
@Override @Override
public char[] getLabelDescriptorsBefore() { public String[] getLabelDescriptorsBefore() {
return new char[]{'C', 'M', 'Y', 'K'}; return new String[]{"C", "M", "Y", "K"};
} }
@Override @Override
public char[] getLabelDescriptorsAfter() { public String[] getLabelDescriptorsAfter() {
return new char[]{'%', '%', '%', '%'}; return new String[]{"%", "%", "%", "%"};
} }
@Override @Override

8
core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java

@ -62,13 +62,13 @@ public class DarkColorModelHSB extends DarkColorModel {
} }
@Override @Override
public char[] getLabelDescriptorsBefore() { public String[] getLabelDescriptorsBefore() {
return new char[]{'H', 'S', 'B'}; return new String[]{"H", "S", "B"};
} }
@Override @Override
public char[] getLabelDescriptorsAfter() { public String[] getLabelDescriptorsAfter() {
return new char[]{'\u00B0', '%', '%'}; return new String[]{"\u00B0", "%", "%"};
} }
@Override @Override

8
core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java

@ -62,13 +62,13 @@ public class DarkColorModelHSL extends DarkColorModel {
} }
@Override @Override
public char[] getLabelDescriptorsBefore() { public String[] getLabelDescriptorsBefore() {
return new char[]{'H', 'S', 'L'}; return new String[]{"H", "S", "L"};
} }
@Override @Override
public char[] getLabelDescriptorsAfter() { public String[] getLabelDescriptorsAfter() {
return new char[]{'\u00B0', '%', '%'}; return new String[]{"\u00B0", "%", "%"};
} }
@Override @Override

8
core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelRGB.java

@ -53,12 +53,12 @@ public class DarkColorModelRGB extends DarkColorModel {
return "RGB"; return "RGB";
} }
public char[] getLabelDescriptorsBefore() { public String[] getLabelDescriptorsBefore() {
return new char[]{'R', 'G', 'B'}; return new String[]{"R", "G", "B"};
} }
public char[] getLabelDescriptorsAfter() { public String[] getLabelDescriptorsAfter() {
return new char[]{Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE}; return new String[]{"", "", "", ""};
} }
public int[] getValuesFromColor(final Color color) { public int[] getValuesFromColor(final Color color) {

7
core/src/main/java/com/github/weisj/darklaf/components/ColoredRadioButton.java

@ -189,7 +189,7 @@ public class ColoredRadioButton extends JRadioButton {
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); UIDefaults defaults = UIManager.getLookAndFeelDefaults();
theme.loadDefaults(props, defaults); theme.loadDefaults(props, defaults);
Color accentCol = color == DEFAULT_FILLED ? (Color) props.get("widgetFillDefault") : color; 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); adjustment.applyColors(LafManager.getTheme(), props, accentCol, null);
PropertyLoader.putProperties(PropertyLoader.loadProperties(DarkLaf.class, "radioButton", PropertyLoader.putProperties(PropertyLoader.loadProperties(DarkLaf.class, "radioButton",
"properties/ui/"), "properties/ui/"),
@ -204,12 +204,15 @@ public class ColoredRadioButton extends JRadioButton {
for (String prop : COLOR_PROPERTIES) { for (String prop : COLOR_PROPERTIES) {
propertyMap.put(prop, accentCol); propertyMap.put(prop, accentCol);
} }
if (focusColor != DEFAULT_FILLED) {
for (String prop : FOCUS_COLOR_PROPERTIES) { for (String prop : FOCUS_COLOR_PROPERTIES) {
propertyMap.put(prop, focusCol); propertyMap.put(prop, focusCol);
} }
}
for (String prop : FOREGROUND_PROPERTIES) { for (String prop : FOREGROUND_PROPERTIES) {
Color fg = ForegroundColorGenerationTask.makeAdjustedForeground((Color) props.get(prop), Color fg = ForegroundColorGenerationTask.makeAdjustedForeground((Color) props.get(prop),
accentCol, MIN_FG_CONTRAST); accentCol,
MIN_FG_CONTRAST);
propertyMap.put(prop, fg); propertyMap.put(prop, fg);
} }

4
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 currentAccentColor = LafManager.getTheme().getAccentColorRule().getAccentColor();
Color currentSelectionColor = LafManager.getTheme().getAccentColorRule().getSelectionColor(); 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")); JLabel selectionColorLabel = new JLabel(resourceBundle.getString("label_selection_color"));
selectionColorLabel.setLabelFor(selectionBox); selectionColorLabel.setLabelFor(selectionBox);
@ -200,7 +200,7 @@ public class ThemeSettingsPanel extends JPanel {
customSelection = addCustomButton(bgSelection, selectionBox, currentSelectionColor, defaultSelectionColor, customSelection = addCustomButton(bgSelection, selectionBox, currentSelectionColor, defaultSelectionColor,
resourceBundle.getString("color_custom")); 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")); JLabel accentColorLabel = new JLabel(resourceBundle.getString("label_accent_color"));
accentColorLabel.setLabelFor(accentBox); accentColorLabel.setLabelFor(accentBox);

61
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 javax.swing.plaf.ColorUIResource;
import com.github.weisj.darklaf.color.DarkColorModelHSB; 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.Theme;
import com.github.weisj.darklaf.theme.info.AccentColorRule; import com.github.weisj.darklaf.theme.info.AccentColorRule;
import com.github.weisj.darklaf.uiresource.DarkColorUIResource; import com.github.weisj.darklaf.uiresource.DarkColorUIResource;
import com.github.weisj.darklaf.util.ColorUtil;
import com.github.weisj.darklaf.util.Pair; import com.github.weisj.darklaf.util.Pair;
public class ForegroundColorGenerationTask extends ColorAdjustmentTask { public class ForegroundColorGenerationTask extends ColorAdjustmentTask {
@ -70,10 +70,10 @@ public class ForegroundColorGenerationTask extends ColorAdjustmentTask {
MIN_FOREGROUND_DIFFERENCE))); MIN_FOREGROUND_DIFFERENCE)));
} }
public static ColorUIResource makeForeground(final Color c, final double minimumBrightnessDifference) { public static ColorUIResource makeForeground(final Color bg, final double minimumBrightnessDifference) {
double[] hsbBG = DarkColorModelHSB.RGBtoHSBValues(c.getRed(), c.getGreen(), c.getBlue()); double[] hsbBG = DarkColorModelHSB.RGBtoHSBValues(bg.getRed(), bg.getGreen(), bg.getBlue());
double[] hsbFG = new double[]{hsbBG[0], 0, 1 - hsbBG[2]}; Color fg = DarkColorModelHSB.getColorFromHSBValues(hsbBG[0], 0, 1 - hsbBG[2]);
return makeAdjustedForeground(hsbFG, hsbBG, Bias.BACKGROUND, minimumBrightnessDifference); return makeAdjustedForeground(fg, bg, Bias.BACKGROUND, minimumBrightnessDifference);
} }
public static ColorUIResource makeAdjustedForeground(final Color fg, final Color bg, 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, public static ColorUIResource makeAdjustedForeground(final Color fg, final Color bg, final Bias bias,
final double minimumBrightnessDifference) { final double minimumBrightnessDifference) {
double[] hsbBG = DarkColorModelHSB.RGBtoHSBValues(bg.getRed(), bg.getGreen(), bg.getBlue()); final double[] hslFG = DarkColorModelHSL.RGBtoHSLValues(fg.getRed(), fg.getGreen(), fg.getBlue());
double[] hsbFG = DarkColorModelHSB.RGBtoHSBValues(fg.getRed(), fg.getGreen(), fg.getBlue()); final double[] hslBG = DarkColorModelHSL.RGBtoHSLValues(bg.getRed(), bg.getGreen(), bg.getBlue());
return makeAdjustedForeground(hsbFG, hsbBG, bias, minimumBrightnessDifference); double bgBrightness = hslBG[2];
} double fgBrightness = hslFG[2];
private static ColorUIResource makeAdjustedForeground(final double[] hsbFG, final double[] hsbBG, final Bias bias,
final double minimumBrightnessDifference) {
double bgBrightness = hsbBG[2];
double fgBrightness = hsbFG[2];
Bias b = bias != null ? bias : Bias.BACKGROUND; Bias b = bias != null ? bias : Bias.BACKGROUND;
if (b == Bias.BACKGROUND) { if (b == Bias.BACKGROUND) {
Color c = DarkColorModelHSB.getColorFromHSBValues(hsbBG[0], hsbBG[1], hsbBG[2]); double bgBright = getLuminance(bg);
double bgBright = (1 - hsbBG[1]) * ColorUtil.getPerceivedBrightness(c); b = bgBright <= 0.552 ? Bias.WHITE : Bias.BLACK;
b = bgBright <= 127.5f ? Bias.WHITE : Bias.BLACK;
} }
double difference = Math.abs(fgBrightness - bgBrightness); double bright1 = fgBrightness > bgBrightness && (fgBrightness - bgBrightness) >= minimumBrightnessDifference
if (difference < minimumBrightnessDifference) { ? hslFG[2]
fgBrightness += b.direction * (Math.abs(minimumBrightnessDifference - difference)); : 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());
} }
return new DarkColorUIResource(DarkColorModelHSB.getColorFromHSBValues(hsbFG[0], hsbFG[1], fgBrightness));
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 { public enum Bias {

2
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() { private void updateDescriptors() {
char[] desc = getDarkColorModel().getLabelDescriptorsBefore(); String[] desc = getDarkColorModel().getLabelDescriptorsBefore();
String[] descAfter = getDarkColorModel().getFullLabelDescriptorsAfter(); String[] descAfter = getDarkColorModel().getFullLabelDescriptorsAfter();
for (int i = 0; i < descriptors.length; i++) { for (int i = 0; i < descriptors.length; i++) {
if (i < desc.length) { if (i < desc.length) {

Loading…
Cancel
Save