Browse Source

Updated ColorChooser.

Fixed decorations for tooltips.
pull/1/head
weisj 5 years ago
parent
commit
98f2b950ba
  1. 15
      src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java
  2. 7
      src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java
  3. 142
      src/main/java/com/weis/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java
  4. 633
      src/main/java/com/weis/darklaf/ui/colorchooser/MainSwatchPanel.java
  5. 40
      src/main/java/com/weis/darklaf/ui/colorchooser/RecentSwatchPanel.java
  6. 171
      src/main/java/com/weis/darklaf/ui/colorchooser/SwatchPanel.java
  7. 48
      src/main/java/com/weis/darklaf/ui/rootpane/DarkTitlePane.java
  8. 5
      src/main/java/com/weis/darklaf/util/DarkUIUtil.java
  9. 15
      src/main/java/com/weis/darklaf/util/WindowsFrameUtil.java
  10. 7
      src/main/resources/com/weis/darklaf/darcula.properties
  11. 3
      src/test/java/ColorChooserDemo.java
  12. 33
      src/test/java/GenerateColors.java

15
src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java

@ -11,6 +11,7 @@ import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener; import javax.swing.event.AncestorListener;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyEvent;
public class DarkColorChooserPanel extends AbstractColorChooserPanel implements ColorListener { public class DarkColorChooserPanel extends AbstractColorChooserPanel implements ColorListener {
@ -72,12 +73,10 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
@Override @Override
public void ancestorRemoved(final AncestorEvent event) { public void ancestorRemoved(final AncestorEvent event) {
} }
@Override @Override
public void ancestorMoved(final AncestorEvent event) { public void ancestorMoved(final AncestorEvent event) {
} }
}); });
@ -96,7 +95,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
add(buildTopPanel(true), BorderLayout.NORTH); add(buildTopPanel(UIManager.getBoolean("ColorChooser.pipetteEnabled")), BorderLayout.NORTH);
add(colorWheelPanel, BorderLayout.CENTER); add(colorWheelPanel, BorderLayout.CENTER);
add(Box.createVerticalStrut(10), BorderLayout.SOUTH); add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
updateValueFields(); updateValueFields();
@ -254,17 +253,17 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return "Test"; return "Color Wheel";
} }
@Override @Override
public int getMnemonic() { public int getMnemonic() {
return 0; return KeyEvent.VK_W;
} }
@Override @Override
public int getDisplayedMnemonicIndex() { public int getDisplayedMnemonicIndex() {
return 0; return 6;
} }
@Override @Override
@ -284,8 +283,8 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
} }
currentColor = color; currentColor = color;
hexFormatter.setTransparencyEnabled(b); hexFormatter.setTransparencyEnabled(b);
applyColorToHEX(getColorFromModel());
colorWheelPanel.setColorTransparencySelectionEnabled(b); colorWheelPanel.setColorTransparencySelectionEnabled(b);
applyColorToHEX(getColorFromModel());
firePropertyChange(TRANSPARENCY_ENABLED_PROPERTY, firePropertyChange(TRANSPARENCY_ENABLED_PROPERTY,
oldValue, b); oldValue, b);
} }
@ -312,7 +311,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
isChanging = true; isChanging = true;
if (color != null && !color.equals(currentColor)) { if (color != null && !color.equals(currentColor)) {
var newColor = !isColorTransparencySelectionEnabled() var newColor = !isColorTransparencySelectionEnabled()
? new Color(color.getRed(), color.getBlue(), color.getGreen()) : color; ? new Color(color.getRed(), color.getGreen(), color.getBlue()) : color;
var model = getColorSelectionModel(); var model = getColorSelectionModel();
if (model != null) { if (model != null) {
model.setSelectedColor(newColor); model.setSelectedColor(newColor);

7
src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java

@ -34,10 +34,6 @@ public class DarkColorChooserUI extends BasicColorChooserUI {
} }
}; };
public DarkColorChooserUI() {
var c = new Color(25, 60, 2);
}
@NotNull @NotNull
@Contract("_ -> new") @Contract("_ -> new")
public static ComponentUI createUI(final JComponent c) { public static ComponentUI createUI(final JComponent c) {
@ -50,7 +46,8 @@ public class DarkColorChooserUI extends BasicColorChooserUI {
new DarkColorChooserPanel(new DarkColorModel(), new DarkColorChooserPanel(new DarkColorModel(),
new DarkColorModelHSL(), new DarkColorModelHSL(),
// new DarkColorModelHSB(), // new DarkColorModelHSB(),
new DarkColorModelCMYK())}; new DarkColorModelCMYK()),
new DarkSwatchesChooserPanel(),};
} }
@Override @Override

142
src/main/java/com/weis/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java

@ -1,9 +1,34 @@
package com.weis.darklaf.ui.colorchooser; package com.weis.darklaf.ui.colorchooser;
import javax.accessibility.AccessibleContext;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.colorchooser.AbstractColorChooserPanel; import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.colorchooser.ColorSelectionModel;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;
public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel { public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
private SwatchPanel swatchPanel;
private RecentSwatchPanel recentSwatchPanel;
private MouseListener mainSwatchListener;
private MouseListener recentSwatchListener;
private KeyListener mainSwatchKeyListener;
private KeyListener recentSwatchKeyListener;
public DarkSwatchesChooserPanel() {
setInheritsPopupMenu(true);
}
@Override @Override
public void updateChooser() { public void updateChooser() {
@ -11,12 +36,124 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
@Override @Override
protected void buildChooser() { protected void buildChooser() {
String recentStr = UIManager.getString("ColorChooser.swatchesRecentText", getLocale());
JPanel superHolder = new JPanel();
superHolder.setLayout(new BoxLayout(superHolder, BoxLayout.Y_AXIS));
swatchPanel = new MainSwatchPanel();
swatchPanel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, getDisplayName());
swatchPanel.setInheritsPopupMenu(true);
recentSwatchPanel = new RecentSwatchPanel();
recentSwatchPanel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, recentStr);
mainSwatchKeyListener = new MainSwatchKeyListener();
mainSwatchListener = new MainSwatchListener();
swatchPanel.addMouseListener(mainSwatchListener);
swatchPanel.addKeyListener(mainSwatchKeyListener);
recentSwatchListener = new RecentSwatchListener();
recentSwatchKeyListener = new RecentSwatchKeyListener();
recentSwatchPanel.addMouseListener(recentSwatchListener);
recentSwatchPanel.addKeyListener(recentSwatchKeyListener);
JPanel mainHolder = new JPanel(new FlowLayout(FlowLayout.CENTER));
Border border = new LineBorder(UIManager.getColor("ColorChooser.swatchBorderColor"));
swatchPanel.setBorder(border);
mainHolder.add(swatchPanel);
superHolder.add(mainHolder);
recentSwatchPanel.setInheritsPopupMenu(true);
JPanel recentHolder = new JPanel(new FlowLayout(FlowLayout.CENTER));
recentSwatchPanel.setBorder(border);
recentHolder.setInheritsPopupMenu(true);
recentHolder.add(recentSwatchPanel);
JLabel l = new JLabel(recentStr);
l.setLabelFor(recentSwatchPanel);
var labelHolder = new JPanel(new FlowLayout(FlowLayout.LEFT));
labelHolder.add(l);
superHolder.add(labelHolder);
superHolder.add(recentHolder);
superHolder.setInheritsPopupMenu(true);
add(superHolder);
}
protected void setSelectedColor(final Color color) {
ColorSelectionModel model = getColorSelectionModel();
if (model != null) {
model.setSelectedColor(color);
}
}
public void uninstallChooserPanel(final JColorChooser enclosingChooser) {
super.uninstallChooserPanel(enclosingChooser);
swatchPanel.removeMouseListener(mainSwatchListener);
swatchPanel.removeKeyListener(mainSwatchKeyListener);
recentSwatchPanel.removeMouseListener(recentSwatchListener);
recentSwatchPanel.removeKeyListener(recentSwatchKeyListener);
swatchPanel = null;
recentSwatchPanel = null;
mainSwatchListener = null;
mainSwatchKeyListener = null;
recentSwatchListener = null;
recentSwatchKeyListener = null;
removeAll(); // strip out all the sub-components
} }
@Override
public String getDisplayName() { public String getDisplayName() {
return null; return UIManager.getString("ColorChooser.swatchesNameText", getLocale());
}
public void installChooserPanel(final JColorChooser enclosingChooser) {
super.installChooserPanel(enclosingChooser);
}
protected class RecentSwatchKeyListener extends KeyAdapter {
public void keyPressed(final KeyEvent e) {
if (KeyEvent.VK_SPACE == e.getKeyCode()) {
Color color = recentSwatchPanel.getSelectedColor();
setSelectedColor(color);
}
}
}
protected class MainSwatchKeyListener extends KeyAdapter {
public void keyPressed(final KeyEvent e) {
if (KeyEvent.VK_SPACE == e.getKeyCode()) {
Color color = swatchPanel.getSelectedColor();
setSelectedColor(color);
recentSwatchPanel.setMostRecentColor(color);
}
}
}
protected class RecentSwatchListener extends MouseAdapter implements Serializable {
public void mousePressed(final MouseEvent e) {
if (isEnabled()) {
Color color = recentSwatchPanel.getColorForLocation(e.getX(), e.getY());
recentSwatchPanel.setSelectedColorFromLocation(e.getX(), e.getY());
setSelectedColor(color);
recentSwatchPanel.requestFocusInWindow();
}
}
}
protected class MainSwatchListener extends MouseAdapter implements Serializable {
public void mousePressed(final MouseEvent e) {
if (isEnabled()) {
Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
setSelectedColor(color);
swatchPanel.setSelectedColorFromLocation(e.getX(), e.getY());
recentSwatchPanel.setMostRecentColor(color);
swatchPanel.requestFocusInWindow();
}
}
} }
@Override @Override
@ -28,4 +165,5 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
public Icon getLargeDisplayIcon() { public Icon getLargeDisplayIcon() {
return null; return null;
} }
} }

633
src/main/java/com/weis/darklaf/ui/colorchooser/MainSwatchPanel.java

@ -0,0 +1,633 @@
package com.weis.darklaf.ui.colorchooser;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
class MainSwatchPanel extends SwatchPanel {
protected void initValues() {
swatchSize = UIManager.getDimension("ColorChooser.swatchesSwatchSize", getLocale());
numSwatches = new Dimension(30, 20);
gap = new Dimension(1, 1);
}
protected void initColors() {
int[] rawValues = initRawValues();
int numColors = rawValues.length / 3;
colors = new Color[numColors];
for (int i = 0; i < numColors; i++) {
colors[i] = new Color(rawValues[(i * 3)], rawValues[(i * 3) + 1], rawValues[(i * 3) + 2]);
}
}
@NotNull
@Contract(value = " -> new", pure = true)
private int[] initRawValues() {
return new int[]{
0, 0, 0,
20, 0, 0,
20, 4, 0,
20, 8, 0,
20, 12, 0,
20, 16, 0,
20, 20, 0,
16, 20, 0,
12, 20, 0,
8, 20, 0,
4, 20, 0,
0, 20, 0,
0, 20, 4,
0, 20, 8,
0, 20, 12,
0, 20, 16,
0, 20, 20,
0, 16, 20,
0, 12, 20,
0, 8, 20,
0, 4, 20,
0, 0, 20,
4, 0, 20,
8, 0, 20,
12, 0, 20,
16, 0, 20,
20, 0, 20,
20, 0, 16,
20, 0, 12,
20, 0, 8,
13, 13, 13,
46, 0, 0,
46, 9, 0,
46, 18, 0,
46, 28, 0,
46, 37, 0,
46, 46, 0,
37, 46, 0,
28, 46, 0,
18, 46, 0,
9, 46, 0,
0, 46, 0,
0, 46, 9,
0, 46, 18,
0, 46, 28,
0, 46, 37,
0, 46, 46,
0, 37, 46,
0, 28, 46,
0, 18, 46,
0, 9, 46,
0, 0, 46,
8, 0, 46,
18, 0, 46,
28, 0, 46,
37, 0, 46,
46, 0, 46,
46, 0, 37,
46, 0, 28,
46, 0, 18,
26, 26, 26,
71, 0, 0,
71, 14, 0,
71, 29, 0,
71, 43, 0,
71, 57, 0,
71, 71, 0,
57, 71, 0,
43, 71, 0,
29, 71, 0,
14, 71, 0,
0, 71, 0,
0, 71, 14,
0, 71, 29,
0, 71, 43,
0, 71, 57,
0, 71, 71,
0, 57, 71,
0, 43, 71,
0, 29, 71,
0, 14, 71,
0, 0, 71,
13, 0, 71,
29, 0, 71,
43, 0, 71,
57, 0, 71,
71, 0, 71,
71, 0, 57,
71, 0, 43,
71, 0, 29,
40, 40, 40,
97, 0, 0,
97, 19, 0,
97, 39, 0,
97, 58, 0,
97, 78, 0,
97, 97, 0,
78, 97, 0,
58, 97, 0,
39, 97, 0,
19, 97, 0,
0, 97, 0,
0, 97, 19,
0, 97, 39,
0, 97, 58,
0, 97, 78,
0, 97, 97,
0, 78, 97,
0, 58, 97,
0, 39, 97,
0, 19, 97,
0, 0, 97,
18, 0, 97,
39, 0, 97,
58, 0, 97,
78, 0, 97,
97, 0, 97,
97, 0, 78,
97, 0, 58,
97, 0, 39,
53, 53, 53,
117, 0, 0,
117, 23, 0,
117, 47, 0,
117, 70, 0,
117, 94, 0,
117, 117, 0,
94, 117, 0,
70, 117, 0,
47, 117, 0,
23, 117, 0,
0, 117, 0,
0, 117, 23,
0, 117, 47,
0, 117, 70,
0, 117, 94,
0, 117, 117,
0, 94, 117,
0, 70, 117,
0, 47, 117,
0, 23, 117,
0, 0, 117,
22, 0, 117,
47, 0, 117,
70, 0, 117,
94, 0, 117,
117, 0, 117,
117, 0, 94,
117, 0, 70,
117, 0, 47,
67, 67, 67,
143, 0, 0,
143, 29, 0,
143, 57, 0,
143, 86, 0,
143, 114, 0,
143, 143, 0,
114, 143, 0,
86, 143, 0,
57, 143, 0,
29, 143, 0,
0, 143, 0,
0, 143, 29,
0, 143, 57,
0, 143, 86,
0, 143, 114,
0, 143, 143,
0, 114, 143,
0, 86, 143,
0, 57, 143,
0, 29, 143,
0, 0, 143,
26, 0, 143,
57, 0, 143,
86, 0, 143,
114, 0, 143,
143, 0, 143,
143, 0, 114,
143, 0, 86,
143, 0, 57,
80, 80, 80,
168, 0, 0,
168, 34, 0,
168, 67, 0,
168, 101, 0,
168, 135, 0,
168, 168, 0,
135, 168, 0,
101, 168, 0,
67, 168, 0,
34, 168, 0,
0, 168, 0,
0, 168, 34,
0, 168, 67,
0, 168, 101,
0, 168, 135,
0, 168, 168,
0, 135, 168,
0, 101, 168,
0, 67, 168,
0, 34, 168,
0, 0, 168,
31, 0, 168,
67, 0, 168,
101, 0, 168,
135, 0, 168,
168, 0, 168,
168, 0, 135,
168, 0, 101,
168, 0, 67,
93, 93, 93,
194, 0, 0,
194, 39, 0,
194, 78, 0,
194, 116, 0,
194, 155, 0,
194, 194, 0,
155, 194, 0,
116, 194, 0,
78, 194, 0,
39, 194, 0,
0, 194, 0,
0, 194, 39,
0, 194, 78,
0, 194, 116,
0, 194, 155,
0, 194, 194,
0, 155, 194,
0, 116, 194,
0, 78, 194,
0, 39, 194,
0, 0, 194,
36, 0, 194,
78, 0, 194,
116, 0, 194,
155, 0, 194,
194, 0, 194,
194, 0, 155,
194, 0, 116,
194, 0, 78,
107, 107, 107,
214, 0, 0,
214, 43, 0,
214, 86, 0,
214, 129, 0,
214, 171, 0,
214, 214, 0,
171, 214, 0,
129, 214, 0,
86, 214, 0,
43, 214, 0,
0, 214, 0,
0, 214, 43,
0, 214, 86,
0, 214, 129,
0, 214, 171,
0, 214, 214,
0, 171, 214,
0, 129, 214,
0, 86, 214,
0, 43, 214,
0, 0, 214,
39, 0, 214,
86, 0, 214,
129, 0, 214,
171, 0, 214,
214, 0, 214,
214, 0, 171,
214, 0, 129,
214, 0, 86,
120, 120, 120,
240, 0, 0,
240, 48, 0,
240, 96, 0,
240, 144, 0,
240, 192, 0,
240, 240, 0,
192, 240, 0,
144, 240, 0,
96, 240, 0,
48, 240, 0,
0, 240, 0,
0, 240, 48,
0, 240, 96,
0, 240, 144,
0, 240, 192,
0, 240, 240,
0, 192, 240,
0, 144, 240,
0, 96, 240,
0, 48, 240,
0, 0, 240,
44, 0, 240,
96, 0, 240,
144, 0, 240,
192, 0, 240,
240, 0, 240,
240, 0, 192,
240, 0, 144,
240, 0, 96,
134, 134, 134,
255, 10, 10,
255, 59, 10,
255, 108, 10,
255, 157, 10,
255, 206, 10,
255, 255, 10,
206, 255, 10,
157, 255, 10,
108, 255, 10,
59, 255, 10,
10, 255, 10,
10, 255, 59,
10, 255, 108,
10, 255, 157,
10, 255, 206,
10, 255, 255,
10, 206, 255,
10, 157, 255,
10, 108, 255,
10, 59, 255,
10, 10, 255,
55, 10, 255,
108, 10, 255,
157, 10, 255,
206, 10, 255,
255, 10, 255,
255, 10, 206,
255, 10, 157,
255, 10, 108,
147, 147, 147,
255, 36, 36,
255, 80, 36,
255, 123, 36,
255, 167, 36,
255, 211, 36,
255, 255, 36,
211, 255, 36,
167, 255, 36,
123, 255, 36,
80, 255, 36,
36, 255, 36,
36, 255, 80,
36, 255, 123,
36, 255, 167,
36, 255, 211,
36, 255, 255,
36, 211, 255,
36, 167, 255,
36, 123, 255,
36, 80, 255,
36, 36, 255,
76, 36, 255,
123, 36, 255,
167, 36, 255,
211, 36, 255,
255, 36, 255,
255, 36, 211,
255, 36, 167,
255, 36, 123,
161, 161, 161,
255, 56, 56,
255, 96, 56,
255, 136, 56,
255, 175, 56,
255, 215, 56,
255, 255, 56,
215, 255, 56,
175, 255, 56,
136, 255, 56,
96, 255, 56,
56, 255, 56,
56, 255, 96,
56, 255, 136,
56, 255, 175,
56, 255, 215,
56, 255, 255,
56, 215, 255,
56, 175, 255,
56, 136, 255,
56, 96, 255,
56, 56, 255,
93, 56, 255,
136, 56, 255,
175, 56, 255,
215, 56, 255,
255, 56, 255,
255, 56, 215,
255, 56, 175,
255, 56, 136,
174, 174, 174,
255, 82, 82,
255, 116, 82,
255, 151, 82,
255, 186, 82,
255, 220, 82,
255, 255, 82,
220, 255, 82,
186, 255, 82,
151, 255, 82,
116, 255, 82,
82, 255, 82,
82, 255, 116,
82, 255, 151,
82, 255, 186,
82, 255, 220,
82, 255, 255,
82, 220, 255,
82, 186, 255,
82, 151, 255,
82, 116, 255,
82, 82, 255,
113, 82, 255,
151, 82, 255,
186, 82, 255,
220, 82, 255,
255, 82, 255,
255, 82, 220,
255, 82, 186,
255, 82, 151,
187, 187, 187,
255, 107, 107,
255, 137, 107,
255, 166, 107,
255, 196, 107,
255, 225, 107,
255, 255, 107,
225, 255, 107,
196, 255, 107,
166, 255, 107,
137, 255, 107,
107, 255, 107,
107, 255, 137,
107, 255, 166,
107, 255, 196,
107, 255, 225,
107, 255, 255,
107, 225, 255,
107, 196, 255,
107, 166, 255,
107, 137, 255,
107, 107, 255,
134, 107, 255,
166, 107, 255,
196, 107, 255,
225, 107, 255,
255, 107, 255,
255, 107, 225,
255, 107, 196,
255, 107, 166,
201, 201, 201,
255, 133, 133,
255, 157, 133,
255, 182, 133,
255, 206, 133,
255, 231, 133,
255, 255, 133,
231, 255, 133,
206, 255, 133,
182, 255, 133,
157, 255, 133,
133, 255, 133,
133, 255, 157,
133, 255, 182,
133, 255, 206,
133, 255, 231,
133, 255, 255,
133, 231, 255,
133, 206, 255,
133, 182, 255,
133, 157, 255,
133, 133, 255,
155, 133, 255,
182, 133, 255,
206, 133, 255,
231, 133, 255,
255, 133, 255,
255, 133, 231,
255, 133, 206,
255, 133, 182,
214, 214, 214,
255, 153, 153,
255, 173, 153,
255, 194, 153,
255, 214, 153,
255, 235, 153,
255, 255, 153,
235, 255, 153,
214, 255, 153,
194, 255, 153,
173, 255, 153,
153, 255, 153,
153, 255, 173,
153, 255, 194,
153, 255, 214,
153, 255, 235,
153, 255, 255,
153, 235, 255,
153, 214, 255,
153, 194, 255,
153, 173, 255,
153, 153, 255,
172, 153, 255,
194, 153, 255,
214, 153, 255,
235, 153, 255,
255, 153, 255,
255, 153, 235,
255, 153, 214,
255, 153, 194,
228, 228, 228,
255, 179, 179,
255, 194, 179,
255, 209, 179,
255, 224, 179,
255, 240, 179,
255, 255, 179,
240, 255, 179,
224, 255, 179,
209, 255, 179,
194, 255, 179,
179, 255, 179,
179, 255, 194,
179, 255, 209,
179, 255, 224,
179, 255, 240,
179, 255, 255,
179, 240, 255,
179, 224, 255,
179, 209, 255,
179, 194, 255,
179, 179, 255,
193, 179, 255,
209, 179, 255,
224, 179, 255,
240, 179, 255,
255, 179, 255,
255, 179, 240,
255, 179, 224,
255, 179, 209,
241, 241, 241,
255, 204, 204,
255, 214, 204,
255, 224, 204,
255, 235, 204,
255, 245, 204,
255, 255, 204,
245, 255, 204,
235, 255, 204,
224, 255, 204,
214, 255, 204,
204, 255, 204,
204, 255, 214,
204, 255, 224,
204, 255, 235,
204, 255, 245,
204, 255, 255,
204, 245, 255,
204, 235, 255,
204, 224, 255,
204, 214, 255,
204, 204, 255,
213, 204, 255,
224, 204, 255,
235, 204, 255,
245, 204, 255,
255, 204, 255,
255, 204, 245,
255, 204, 235,
255, 204, 224,
255, 255, 255,
255, 229, 229,
255, 235, 229,
255, 240, 229,
255, 245, 229,
255, 250, 229,
255, 255, 229,
250, 255, 229,
245, 255, 229,
240, 255, 229,
235, 255, 229,
229, 255, 229,
229, 255, 235,
229, 255, 240,
229, 255, 245,
229, 255, 250,
229, 255, 255,
229, 250, 255,
229, 245, 255,
229, 240, 255,
229, 235, 255,
229, 229, 255,
234, 229, 255,
240, 229, 255,
245, 229, 255,
250, 229, 255,
255, 229, 255,
255, 229, 250,
255, 229, 245,
255, 229, 240,
};
}
}

40
src/main/java/com/weis/darklaf/ui/colorchooser/RecentSwatchPanel.java

@ -0,0 +1,40 @@
package com.weis.darklaf.ui.colorchooser;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
class RecentSwatchPanel extends SwatchPanel {
private Color defaultRecentColor;
protected void initValues() {
swatchSize = UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize", getLocale());
numSwatches = new Dimension(30, 5);
gap = new Dimension(1, 1);
}
protected void initColors() {
defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor", getLocale());
int numColors = numSwatches.width * numSwatches.height;
colors = new Color[numColors];
for (int i = 0; i < numColors; i++) {
colors[i] = defaultRecentColor;
}
}
public void setMostRecentColor(final Color c) {
if (colors[0].equals(c)) return;
System.arraycopy(colors, 0, colors, 1, colors.length - 1);
colors[0] = c;
repaint();
}
@Override
public String getToolTipText(final MouseEvent e) {
Color color = getColorForLocation(e.getX(), e.getY());
if (color == defaultRecentColor) return null;
return color.getRed() + ", " + color.getGreen() + ", " + color.getBlue();
}
}

171
src/main/java/com/weis/darklaf/ui/colorchooser/SwatchPanel.java

@ -0,0 +1,171 @@
package com.weis.darklaf.ui.colorchooser;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
abstract class SwatchPanel extends JPanel {
protected Color[] colors;
protected Dimension swatchSize;
protected Dimension numSwatches;
protected Dimension gap;
private int selRow;
private int selCol;
public SwatchPanel() {
initValues();
initColors();
setToolTipText(""); // register for events
setOpaque(true);
setBackground(UIManager.getColor("ColorChooser.swatchGridColor"));
setFocusable(true);
setInheritsPopupMenu(true);
addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent e) {
repaint();
}
public void focusLost(final FocusEvent e) {
repaint();
}
});
addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent e) {
int typed = e.getKeyCode();
switch (typed) {
case KeyEvent.VK_UP:
if (selRow > 0) {
selRow--;
repaint();
}
break;
case KeyEvent.VK_DOWN:
if (selRow < numSwatches.height - 1) {
selRow++;
repaint();
}
break;
case KeyEvent.VK_LEFT:
if (selCol > 0 && SwatchPanel.this.getComponentOrientation().isLeftToRight()) {
selCol--;
repaint();
} else if (selCol < numSwatches.width - 1
&& !SwatchPanel.this.getComponentOrientation().isLeftToRight()) {
selCol++;
repaint();
}
break;
case KeyEvent.VK_RIGHT:
if (selCol < numSwatches.width - 1
&& SwatchPanel.this.getComponentOrientation().isLeftToRight()) {
selCol++;
repaint();
} else if (selCol > 0 && !SwatchPanel.this.getComponentOrientation().isLeftToRight()) {
selCol--;
repaint();
}
break;
case KeyEvent.VK_HOME:
selCol = 0;
selRow = 0;
repaint();
break;
case KeyEvent.VK_END:
selCol = numSwatches.width - 1;
selRow = numSwatches.height - 1;
repaint();
break;
}
}
});
}
public Color getSelectedColor() {
return getColorForCell(selCol, selRow);
}
protected void initValues() {
}
public void paintComponent(@NotNull final Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
for (int row = 0; row < numSwatches.height; row++) {
int y = row * (swatchSize.height + gap.height);
for (int column = 0; column < numSwatches.width; column++) {
Color c = getColorForCell(column, row);
g.setColor(c);
int x;
if (!this.getComponentOrientation().isLeftToRight()) {
x = (numSwatches.width - column - 1) * (swatchSize.width + gap.width);
} else {
x = column * (swatchSize.width + gap.width);
}
g.fillRect(x, y, swatchSize.width, swatchSize.height);
if (selRow == row && selCol == column && this.isFocusOwner()) {
Color c2 = new Color(c.getRed() < 125 ? 225 : 30,
c.getGreen() < 125 ? 225 : 30,
c.getBlue() < 125 ? 225 : 30);
g.setColor(c2);
g.drawLine(x, y, x + swatchSize.width, y);
g.drawLine(x, y, x, y + swatchSize.height);
g.drawLine(x + swatchSize.width, y, x + swatchSize.width, y + swatchSize.height);
g.drawLine(x, y + swatchSize.height, x + swatchSize.width, y + swatchSize.height);
g.drawLine(x, y, x + swatchSize.width, y + swatchSize.height);
g.drawLine(x, y + swatchSize.height, x + swatchSize.width, y);
}
}
}
}
public Dimension getPreferredSize() {
int x = numSwatches.width * (swatchSize.width + gap.width) - 1;
int y = numSwatches.height * (swatchSize.height + gap.height) - 1;
return new Dimension(x, y);
}
protected void initColors() {
}
public String getToolTipText(final MouseEvent e) {
Color color = getColorForLocation(e.getX(), e.getY());
return color.getRed() + ", " + color.getGreen() + ", " + color.getBlue();
}
public void setSelectedColorFromLocation(final int x, final int y) {
if (!this.getComponentOrientation().isLeftToRight()) {
selCol = numSwatches.width - x / (swatchSize.width + gap.width) - 1;
} else {
selCol = x / (swatchSize.width + gap.width);
}
selRow = y / (swatchSize.height + gap.height);
repaint();
}
public Color getColorForLocation(final int x, final int y) {
int column;
if (!this.getComponentOrientation().isLeftToRight()) {
column = numSwatches.width - x / (swatchSize.width + gap.width) - 1;
} else {
column = x / (swatchSize.width + gap.width);
}
int row = y / (swatchSize.height + gap.height);
return getColorForCell(column, row);
}
private Color getColorForCell(final int column, final int row) {
return colors[(row * numSwatches.width) + column]; // (STEVE) - change data orientation here
}
}

48
src/main/java/com/weis/darklaf/ui/rootpane/DarkTitlePane.java

@ -16,6 +16,7 @@ package com.weis.darklaf.ui.rootpane;
* limitations under the License. * limitations under the License.
*/ */
import com.sun.jna.Structure;
import com.weis.darklaf.ui.button.DarkButtonUI; import com.weis.darklaf.ui.button.DarkButtonUI;
import com.weis.darklaf.util.GraphicsUtil; import com.weis.darklaf.util.GraphicsUtil;
import com.weis.darklaf.util.WindowsFrameUtil; import com.weis.darklaf.util.WindowsFrameUtil;
@ -172,12 +173,35 @@ public class DarkTitlePane extends JComponent {
public void addNotify() { public void addNotify() {
super.addNotify(); super.addNotify();
uninstallListeners(); uninstallListeners();
window = SwingUtilities.getWindowAncestor(this); window = SwingUtilities.getWindowAncestor(this);
if (window != null) { if (window != null) {
WindowsFrameUtil.enableTitleBar(window, false); if (window instanceof Dialog || window instanceof Frame) {
//rootPane.getWindowDecorationStyle() == JRootPane.FRAME
WindowsFrameUtil.enableTitleBar(window, false, true);
}
// var hwnd = WindowsFrameUtil.getHWND(window);
// NativeLibrary dwm = NativeLibrary.getInstance("dwmapi");
// dwm.getFunction("DwmExtendFrameIntoClientArea").invoke(WinNT.HRESULT.class,
// new Object[]{hwnd, new MARGINS(0, 0, 0, 0)});
// WindowsFrameUtil.User32dll.INSTANCE.SetWindowPos(hwnd, new WinDef.HWND(new Pointer(0)), 0, 0, 0, 0,
// WinUser.SWP_NOZORDER |
// WinUser.SWP_NOOWNERZORDER |
// WinUser.SWP_NOMOVE |
// WinUser.SWP_NOSIZE |
// WinUser.SWP_FRAMECHANGED);
// WindowsFrameUtil.setWindowCallback(window, new WindowsFrameUtil.WindowProc() {
// @Override
// public WinDef.LRESULT callback(final WinDef.HWND hWnd, final int uMsg, final WinDef.WPARAM uParam,
// final WinDef.LPARAM lParam) throws LastErrorException {
// if (uMsg == 0x0083 && uParam.intValue() != 0) {
// return new WinDef.LRESULT(0);
// }
// return parent.callback(hWnd, uMsg, uParam, lParam);
// }
// });
if (window instanceof Frame) { if (window instanceof Frame) {
titleLabel.setText(((Frame) window).getTitle()); titleLabel.setText(((Frame) window).getTitle());
@ -195,6 +219,26 @@ public class DarkTitlePane extends JComponent {
} }
} }
public class MARGINS extends Structure implements Structure.ByReference {
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
public MARGINS(final int a, final int b, final int c, final int d) {
cxLeftWidth = a;
cxRightWidth = b;
cyTopHeight = c;
cyBottomHeight = d;
}
@Override
protected List<String> getFieldOrder() {
return List.of("cxLeftWidth", "cxRightWidth", "cyTopHeight", "cyBottomHeight");
}
}
@NotNull @NotNull
private Rectangle getMaximizedBounds() { private Rectangle getMaximizedBounds() {
Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration()); Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration());

5
src/main/java/com/weis/darklaf/util/DarkUIUtil.java

@ -226,6 +226,11 @@ public final class DarkUIUtil {
return component instanceof Window ? (Window) component : SwingUtilities.getWindowAncestor(component); return component instanceof Window ? (Window) component : SwingUtilities.getWindowAncestor(component);
} }
public static boolean isTooltipShowing(final JComponent component) {
AbstractAction hideTipAction = (AbstractAction) component.getActionMap().get("hideTip");
return hideTipAction.isEnabled();
}
public enum Outline { public enum Outline {
error { error {
@Override @Override

15
src/main/java/com/weis/darklaf/util/WindowsFrameUtil.java

@ -15,19 +15,20 @@ import java.awt.*;
public final class WindowsFrameUtil { public final class WindowsFrameUtil {
public static final WinDef.LRESULT PASS_TO_SUPER = new WinDef.LRESULT(-1); public static void enableTitleBar(final Window window, final boolean enabled, final boolean resizable) {
public static final WinDef.LRESULT PASS_TO_DEFAULT = new WinDef.LRESULT(-2);
private static int prevWndProc;
public static void enableTitleBar(final Window window, final boolean enabled) {
if (window == null) return; if (window == null) return;
final HWND hwnd = getHWND(window); final HWND hwnd = getHWND(window);
int style = User32.INSTANCE.GetWindowLong(hwnd, User32dll.GWL_STYLE); int style = User32.INSTANCE.GetWindowLong(hwnd, User32dll.GWL_STYLE);
if (enabled) { if (enabled) {
style |= 0xc00000; style |= User32.WS_CAPTION;
} else {
style = User32.WS_THICKFRAME;
}
if (!resizable) {
style &= ~User32.WS_SIZEBOX;
} else { } else {
style = 0x00040000; style |= User32.WS_SIZEBOX;
} }
//ResizeMode="CanResizeWithGrip" AllowsTransparency="True" //ResizeMode="CanResizeWithGrip" AllowsTransparency="True"
User32.INSTANCE.SetWindowLong(hwnd, User32dll.GWL_STYLE, style); User32.INSTANCE.SetWindowLong(hwnd, User32dll.GWL_STYLE, style);

7
src/main/resources/com/weis/darklaf/darcula.properties

@ -429,10 +429,15 @@ InternalFrameTitlePane.darcula.hovered.buttonColor = A8A8A8
#ColorChooser #ColorChooser
ColorChooserUI = com.weis.darklaf.ui.colorchooser.DarkColorChooserUI ColorChooserUI = com.weis.darklaf.ui.colorchooser.DarkColorChooserUI
ColorChooser.pipetteEnabled = true
ColorChooser.previewBorderColor = 646464 ColorChooser.previewBorderColor = 646464
ColorChooser.sliderBorderColor = 646464 ColorChooser.sliderBorderColor = 646464
ColorChooser.sliderKnobColor = 993300 ColorChooser.sliderKnobColor = 993300
ColorChooser.showPreviewPanelText = false ColorChooser.showPreviewPanelText = false
ColorChooser.colorWheelDropBackgroundColor = FFFFFF ColorChooser.colorWheelDropBackgroundColor = FFFFFF
ColorChooser.colorWheelDropBorderColor = 646464 ColorChooser.colorWheelDropBorderColor = 646464
ColorChooser.pipetteBorderColor = 646464 ColorChooser.pipetteBorderColor = 646464
ColorChooser.swatchesRecentSwatchSize = 15,15
ColorChooser.swatchesSwatchSize = 15,15
ColorChooser.swatchBorderColor = 333638
ColorChooser.swatchGridColor = 4F5152

3
src/test/java/ColorChooserDemo.java

@ -8,7 +8,8 @@ public final class ColorChooserDemo {
public static void main(final String[] args) { public static void main(final String[] args) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
LafManager.loadLaf(LafManager.Theme.Dark); LafManager.loadLaf(LafManager.Theme.Dark);
JColorChooser.showDialog(null, "Color Chooser with transparency", Color.RED, true); JColorChooser.showDialog(null, "Color Chooser without transparency",
Color.RED, false);
}); });
} }
} }

33
src/test/java/GenerateColors.java

@ -0,0 +1,33 @@
import com.weis.darklaf.color.DarkColorModelHSL;
import java.awt.*;
public class GenerateColors {
public static void main(final String[] args) {
int cols = 30;
int rows = 20;
System.out.println("{");
int r = 255;
int g = 255;
int b = 255;
for (int i = 1; i < rows + 1; i++) {
r = g = b = (int) ((i - 1) * 255.0 / (rows - 1));
System.out.println(r + "," + g + "," + b + ",");
for (int j = 0; j < cols - 1; j++) {
var c = colorFromPos(j, i, rows + 1, cols);
System.out.println(c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ",");
}
}
System.out.println("};");
}
private static Color colorFromPos(final int x, final int y, final int height, final int width) {
int h, s, l;
l = (int) (100 * y / (double) height);
s = 100;
h = (int) (360 * ((double) x / width));
return new DarkColorModelHSL().getColorFromValues(new int[]{h, s, l});
}
}
Loading…
Cancel
Save