Browse Source

Shadow in ColorChooser is now controlled by %shadow property.

pull/15/head
weisj 5 years ago
parent
commit
60cd5775ee
  1. 24
      src/main/java/com/weis/darklaf/ui/colorchooser/DarkPreviewPanel.java
  2. 5
      src/main/java/com/weis/darklaf/ui/colorchooser/SlideComponent.java
  3. 8
      src/main/java/com/weis/darklaf/util/ColorUtil.java
  4. 1
      src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties

24
src/main/java/com/weis/darklaf/ui/colorchooser/DarkPreviewPanel.java

@ -69,13 +69,11 @@ public class DarkPreviewPanel extends JPanel {
g.setColor(Color.white);
g.fillRect(offsetX, 0, SQUARE_SIZE, SQUARE_SIZE);
g.setColor(color);
g.fillRect(offsetX + INNER_GAP,
INNER_GAP,
g.fillRect(offsetX + INNER_GAP, INNER_GAP,
SQUARE_SIZE - (INNER_GAP * 2),
SQUARE_SIZE - (INNER_GAP * 2));
g.setColor(Color.white);
g.fillRect(offsetX + INNER_GAP * 2,
INNER_GAP * 2,
g.fillRect(offsetX + INNER_GAP * 2, INNER_GAP * 2,
SQUARE_SIZE - (INNER_GAP * 4),
SQUARE_SIZE - (INNER_GAP * 4));
@ -86,13 +84,11 @@ public class DarkPreviewPanel extends JPanel {
g.setColor(Color.black);
g.fillRect(offsetX, 0, SQUARE_SIZE, SQUARE_SIZE);
g.setColor(color);
g.fillRect(offsetX + INNER_GAP,
INNER_GAP,
g.fillRect(offsetX + INNER_GAP, INNER_GAP,
SQUARE_SIZE - (INNER_GAP * 2),
SQUARE_SIZE - (INNER_GAP * 2));
g.setColor(Color.white);
g.fillRect(offsetX + INNER_GAP * 2,
INNER_GAP * 2,
g.fillRect(offsetX + INNER_GAP * 2, INNER_GAP * 2,
SQUARE_SIZE - (INNER_GAP * 4),
SQUARE_SIZE - (INNER_GAP * 4));
g.translate(-(SQUARE_SIZE + SQUARE_GAP), 0);
@ -101,8 +97,7 @@ public class DarkPreviewPanel extends JPanel {
g.setColor(Color.white);
g.fillRect(offsetX, 0, SQUARE_SIZE, SQUARE_SIZE);
g.setColor(color);
g.fillRect(offsetX + INNER_GAP,
INNER_GAP,
g.fillRect(offsetX + INNER_GAP, INNER_GAP,
SQUARE_SIZE - (INNER_GAP * 2),
SQUARE_SIZE - (INNER_GAP * 2));
g.translate(-(SQUARE_SIZE + SQUARE_GAP), -(SQUARE_SIZE + SQUARE_GAP));
@ -112,13 +107,11 @@ public class DarkPreviewPanel extends JPanel {
g.setColor(Color.white);
g.fillRect(offsetX, 0, SQUARE_SIZE, SQUARE_SIZE);
g.setColor(color);
g.fillRect(offsetX + INNER_GAP,
INNER_GAP,
g.fillRect(offsetX + INNER_GAP, INNER_GAP,
SQUARE_SIZE - (INNER_GAP * 2),
SQUARE_SIZE - (INNER_GAP * 2));
g.setColor(Color.black);
g.fillRect(offsetX + INNER_GAP * 2,
INNER_GAP * 2,
g.fillRect(offsetX + INNER_GAP * 2, INNER_GAP * 2,
SQUARE_SIZE - (INNER_GAP * 4),
SQUARE_SIZE - (INNER_GAP * 4));
g.translate(-((SQUARE_SIZE + SQUARE_GAP) * 2), 0);
@ -127,8 +120,7 @@ public class DarkPreviewPanel extends JPanel {
g.setColor(Color.black);
g.fillRect(offsetX, 0, SQUARE_SIZE, SQUARE_SIZE);
g.setColor(color);
g.fillRect(offsetX + INNER_GAP,
INNER_GAP,
g.fillRect(offsetX + INNER_GAP, INNER_GAP,
SQUARE_SIZE - (INNER_GAP * 2),
SQUARE_SIZE - (INNER_GAP * 2));
g.translate(-((SQUARE_SIZE + SQUARE_GAP) * 2), -(SQUARE_SIZE + SQUARE_GAP));

5
src/main/java/com/weis/darklaf/ui/colorchooser/SlideComponent.java

@ -1,6 +1,7 @@
package com.weis.darklaf.ui.colorchooser;
import com.weis.darklaf.components.alignment.Alignment;
import com.weis.darklaf.util.ColorUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@ -166,7 +167,7 @@ class SlideComponent extends JComponent {
arrowShadow.addPoint(x + 7, y + 7);
arrowShadow.addPoint(x - 5, y + 13);
g2d.setColor(new Color(0, 0, 0, 70));
g2d.setColor(ColorUtil.toAlpha(UIManager.getColor("ColorChooser.sliderShadow"), 0.5));
g2d.fill(arrowShadow);
Polygon arrowHead = new Polygon();
@ -184,7 +185,7 @@ class SlideComponent extends JComponent {
arrowShadow.addPoint(x + 13, y - 5);
arrowShadow.addPoint(x + 7, y + 7);
g2d.setColor(new Color(0, 0, 0, 70));
g2d.setColor(ColorUtil.toAlpha(UIManager.getColor("ColorChooser.sliderShadow"), 0.5));
g2d.fill(arrowShadow);
Polygon arrowHead = new Polygon();

8
src/main/java/com/weis/darklaf/util/ColorUtil.java

@ -28,7 +28,13 @@ public final class ColorUtil {
@Contract("_, _ -> new")
public static Color toAlpha(final Color color, final int a) {
Color c = color != null ? color : Color.black;
return new Color(c.getRed(), c.getGreen(), c.getBlue(), a);
return new Color(c.getRed(), c.getGreen(), c.getBlue(), Math.min(Math.max(0, a), 255));
}
@NotNull
@Contract("_, _ -> new")
public static Color toAlpha(final Color color, final double alpha) {
return toAlpha(color, (int) (alpha * 255));
}
public static Color fromHex(final String str, final Color defaultValue) {

1
src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties

@ -12,6 +12,7 @@ ColorChooser.swatchesRecentSwatchSize = 15,15
ColorChooser.swatchesSwatchSize = 15,15
ColorChooser.swatchBorderColor = %borderSecondary
ColorChooser.swatchGridColor = %gridLine
ColorChooser.sliderShadow = %shadow
#Icons
ColorChooser.pipette.icon = misc/pipette.svg[aware]

Loading…
Cancel
Save