From 98f2b950ba1f93055c237b9ffd2eb45ba1e59e9c Mon Sep 17 00:00:00 2001 From: weisj Date: Sun, 29 Sep 2019 20:34:47 +0200 Subject: [PATCH] Updated ColorChooser. Fixed decorations for tooltips. --- .../colorchooser/DarkColorChooserPanel.java | 15 +- .../ui/colorchooser/DarkColorChooserUI.java | 7 +- .../DarkSwatchesChooserPanel.java | 142 +++- .../ui/colorchooser/MainSwatchPanel.java | 633 ++++++++++++++++++ .../ui/colorchooser/RecentSwatchPanel.java | 40 ++ .../darklaf/ui/colorchooser/SwatchPanel.java | 171 +++++ .../darklaf/ui/rootpane/DarkTitlePane.java | 48 +- .../com/weis/darklaf/util/DarkUIUtil.java | 5 + .../weis/darklaf/util/WindowsFrameUtil.java | 15 +- .../com/weis/darklaf/darcula.properties | 7 +- src/test/java/ColorChooserDemo.java | 3 +- src/test/java/GenerateColors.java | 33 + 12 files changed, 1093 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/weis/darklaf/ui/colorchooser/MainSwatchPanel.java create mode 100644 src/main/java/com/weis/darklaf/ui/colorchooser/RecentSwatchPanel.java create mode 100644 src/main/java/com/weis/darklaf/ui/colorchooser/SwatchPanel.java create mode 100644 src/test/java/GenerateColors.java diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java index c3b3f9bc..373a1ca3 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java +++ b/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.AncestorListener; import java.awt.*; +import java.awt.event.KeyEvent; public class DarkColorChooserPanel extends AbstractColorChooserPanel implements ColorListener { @@ -72,12 +73,10 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements @Override public void ancestorRemoved(final AncestorEvent event) { - } @Override public void ancestorMoved(final AncestorEvent event) { - } }); @@ -96,7 +95,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements setLayout(new BorderLayout()); 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(Box.createVerticalStrut(10), BorderLayout.SOUTH); updateValueFields(); @@ -254,17 +253,17 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements @Override public String getDisplayName() { - return "Test"; + return "Color Wheel"; } @Override public int getMnemonic() { - return 0; + return KeyEvent.VK_W; } @Override public int getDisplayedMnemonicIndex() { - return 0; + return 6; } @Override @@ -284,8 +283,8 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements } currentColor = color; hexFormatter.setTransparencyEnabled(b); - applyColorToHEX(getColorFromModel()); colorWheelPanel.setColorTransparencySelectionEnabled(b); + applyColorToHEX(getColorFromModel()); firePropertyChange(TRANSPARENCY_ENABLED_PROPERTY, oldValue, b); } @@ -312,7 +311,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements isChanging = true; if (color != null && !color.equals(currentColor)) { var newColor = !isColorTransparencySelectionEnabled() - ? new Color(color.getRed(), color.getBlue(), color.getGreen()) : color; + ? new Color(color.getRed(), color.getGreen(), color.getBlue()) : color; var model = getColorSelectionModel(); if (model != null) { model.setSelectedColor(newColor); diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java index c075a237..afd24198 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java +++ b/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 @Contract("_ -> new") public static ComponentUI createUI(final JComponent c) { @@ -50,7 +46,8 @@ public class DarkColorChooserUI extends BasicColorChooserUI { new DarkColorChooserPanel(new DarkColorModel(), new DarkColorModelHSL(), // new DarkColorModelHSB(), - new DarkColorModelCMYK())}; + new DarkColorModelCMYK()), + new DarkSwatchesChooserPanel(),}; } @Override diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java index c2a26b61..eae54e97 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java +++ b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java @@ -1,9 +1,34 @@ package com.weis.darklaf.ui.colorchooser; +import javax.accessibility.AccessibleContext; import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.LineBorder; 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 { + + + private SwatchPanel swatchPanel; + private RecentSwatchPanel recentSwatchPanel; + private MouseListener mainSwatchListener; + private MouseListener recentSwatchListener; + private KeyListener mainSwatchKeyListener; + private KeyListener recentSwatchKeyListener; + + public DarkSwatchesChooserPanel() { + setInheritsPopupMenu(true); + } + @Override public void updateChooser() { @@ -11,12 +36,124 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel { @Override 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() { - 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 @@ -28,4 +165,5 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel { public Icon getLargeDisplayIcon() { return null; } + } diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/MainSwatchPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/MainSwatchPanel.java new file mode 100644 index 00000000..0d838bfe --- /dev/null +++ b/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, + }; + } +} diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/RecentSwatchPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/RecentSwatchPanel.java new file mode 100644 index 00000000..706df39d --- /dev/null +++ b/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(); + } +} diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/SwatchPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/SwatchPanel.java new file mode 100644 index 00000000..b91dc255 --- /dev/null +++ b/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 + } +} diff --git a/src/main/java/com/weis/darklaf/ui/rootpane/DarkTitlePane.java b/src/main/java/com/weis/darklaf/ui/rootpane/DarkTitlePane.java index cb990a39..e14c87d5 100644 --- a/src/main/java/com/weis/darklaf/ui/rootpane/DarkTitlePane.java +++ b/src/main/java/com/weis/darklaf/ui/rootpane/DarkTitlePane.java @@ -16,6 +16,7 @@ package com.weis.darklaf.ui.rootpane; * limitations under the License. */ +import com.sun.jna.Structure; import com.weis.darklaf.ui.button.DarkButtonUI; import com.weis.darklaf.util.GraphicsUtil; import com.weis.darklaf.util.WindowsFrameUtil; @@ -172,12 +173,35 @@ public class DarkTitlePane extends JComponent { public void addNotify() { super.addNotify(); - uninstallListeners(); window = SwingUtilities.getWindowAncestor(this); 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) { 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 getFieldOrder() { + return List.of("cxLeftWidth", "cxRightWidth", "cyTopHeight", "cyBottomHeight"); + } + } + + @NotNull private Rectangle getMaximizedBounds() { Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration()); diff --git a/src/main/java/com/weis/darklaf/util/DarkUIUtil.java b/src/main/java/com/weis/darklaf/util/DarkUIUtil.java index 6f0b56ea..d51f41d7 100644 --- a/src/main/java/com/weis/darklaf/util/DarkUIUtil.java +++ b/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); } + public static boolean isTooltipShowing(final JComponent component) { + AbstractAction hideTipAction = (AbstractAction) component.getActionMap().get("hideTip"); + return hideTipAction.isEnabled(); + } + public enum Outline { error { @Override diff --git a/src/main/java/com/weis/darklaf/util/WindowsFrameUtil.java b/src/main/java/com/weis/darklaf/util/WindowsFrameUtil.java index a4b33c50..b44e56cb 100644 --- a/src/main/java/com/weis/darklaf/util/WindowsFrameUtil.java +++ b/src/main/java/com/weis/darklaf/util/WindowsFrameUtil.java @@ -15,19 +15,20 @@ import java.awt.*; public final class WindowsFrameUtil { - public static final WinDef.LRESULT PASS_TO_SUPER = new WinDef.LRESULT(-1); - 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) { + public static void enableTitleBar(final Window window, final boolean enabled, final boolean resizable) { if (window == null) return; final HWND hwnd = getHWND(window); int style = User32.INSTANCE.GetWindowLong(hwnd, User32dll.GWL_STYLE); if (enabled) { - style |= 0xc00000; + style |= User32.WS_CAPTION; + } else { + style = User32.WS_THICKFRAME; + } + if (!resizable) { + style &= ~User32.WS_SIZEBOX; } else { - style = 0x00040000; + style |= User32.WS_SIZEBOX; } //ResizeMode="CanResizeWithGrip" AllowsTransparency="True" User32.INSTANCE.SetWindowLong(hwnd, User32dll.GWL_STYLE, style); diff --git a/src/main/resources/com/weis/darklaf/darcula.properties b/src/main/resources/com/weis/darklaf/darcula.properties index 3061ffee..ea168339 100644 --- a/src/main/resources/com/weis/darklaf/darcula.properties +++ b/src/main/resources/com/weis/darklaf/darcula.properties @@ -429,10 +429,15 @@ InternalFrameTitlePane.darcula.hovered.buttonColor = A8A8A8 #ColorChooser ColorChooserUI = com.weis.darklaf.ui.colorchooser.DarkColorChooserUI +ColorChooser.pipetteEnabled = true ColorChooser.previewBorderColor = 646464 ColorChooser.sliderBorderColor = 646464 ColorChooser.sliderKnobColor = 993300 ColorChooser.showPreviewPanelText = false ColorChooser.colorWheelDropBackgroundColor = FFFFFF ColorChooser.colorWheelDropBorderColor = 646464 -ColorChooser.pipetteBorderColor = 646464 \ No newline at end of file +ColorChooser.pipetteBorderColor = 646464 +ColorChooser.swatchesRecentSwatchSize = 15,15 +ColorChooser.swatchesSwatchSize = 15,15 +ColorChooser.swatchBorderColor = 333638 +ColorChooser.swatchGridColor = 4F5152 \ No newline at end of file diff --git a/src/test/java/ColorChooserDemo.java b/src/test/java/ColorChooserDemo.java index e61b7611..7f4d130c 100644 --- a/src/test/java/ColorChooserDemo.java +++ b/src/test/java/ColorChooserDemo.java @@ -8,7 +8,8 @@ public final class ColorChooserDemo { public static void main(final String[] args) { SwingUtilities.invokeLater(() -> { 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); }); } } diff --git a/src/test/java/GenerateColors.java b/src/test/java/GenerateColors.java new file mode 100644 index 00000000..88e9aaf9 --- /dev/null +++ b/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}); + } +}