mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
12 changed files with 1093 additions and 26 deletions
@ -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, |
||||
}; |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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
|
||||
} |
||||
} |
@ -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…
Reference in new issue