From 3597b183c414e2cfd0de93283a3eff109d8fd27c Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 15 Oct 2019 22:28:44 +0200 Subject: [PATCH] Changed how button arcs work. Added hand cursor to spinner/comboBox. Fixed an issue where clicking on the volume icon would move the slider. --- .../weis/darklaf/defaults/DarkDefaults.java | 18 +++++ .../darklaf/ui/button/DarkButtonBorder.java | 23 ++++++- .../weis/darklaf/ui/button/DarkButtonUI.java | 68 ++++++++++--------- .../darklaf/ui/combobox/DarkComboBoxUI.java | 2 +- .../weis/darklaf/ui/slider/DarkSliderUI.java | 8 ++- .../darklaf/ui/spinner/DarkSpinnerUI.java | 2 + .../darklaf/ui/tabframe/DarkPanelPopupUI.java | 2 +- .../darklaf/ui/text/DarkPasswordFieldUI.java | 2 +- .../weis/darklaf/ui/text/DarkTextFieldUI.java | 2 +- .../darklaf/properties/ui/button.properties | 2 + .../properties/ui/colorChooser.properties | 4 +- src/test/java/UIDemo.java | 2 +- 12 files changed, 90 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/weis/darklaf/defaults/DarkDefaults.java b/src/main/java/com/weis/darklaf/defaults/DarkDefaults.java index 5efcd839..7e514690 100644 --- a/src/main/java/com/weis/darklaf/defaults/DarkDefaults.java +++ b/src/main/java/com/weis/darklaf/defaults/DarkDefaults.java @@ -39,6 +39,8 @@ public class DarkDefaults { protected int SpinnerBorderSize = -1; protected int TabFrameTabHeight = -1; protected int TaskPaneArc = -1; + protected int ButtonSquareArc = -1; + protected int ButtonMinimumArc = -1; public static DarkDefaults get() { if (instance == null) { @@ -64,6 +66,8 @@ public class DarkDefaults { SpinnerBorderSize = -1; TabFrameTabHeight = -1; TaskPaneArc = -1; + ButtonSquareArc = -1; + ButtonMinimumArc = -1; } public int getButtonArc() { @@ -135,4 +139,18 @@ public class DarkDefaults { } return TaskPaneArc; } + + public int getButtonSquareArc() { + if (ButtonSquareArc < 0) { + ButtonSquareArc = UIManager.getInt("Button.squareArc"); + } + return ButtonSquareArc; + } + + public int getButtonMinimumArc() { + if (ButtonMinimumArc < 0) { + ButtonMinimumArc = UIManager.getInt("Button.minimumArc"); + } + return ButtonMinimumArc; + } } diff --git a/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java b/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java index b6ee3e68..9f1e91da 100644 --- a/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java +++ b/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java @@ -76,12 +76,25 @@ public class DarkButtonBorder implements Border, UIResource { } public static int getArc(final Component c) { - return DarkButtonUI.isSquare(c) && !DarkButtonUI.isForceRoundCorner(c) ? 0 : getArcSize(); + if (DarkButtonUI.isNoArc(c)) return 0; + boolean square = DarkButtonUI.isSquare(c); + boolean alt = DarkButtonUI.chooseAlternativeArc(c); + return square ? alt ? getArcSize() + : getSquareArcSize() + : alt ? getSquareArcSize() : getArcSize(); + } + + public static int getSquareArcSize() { + return DarkDefaults.get().getButtonSquareArc(); } public static int getFocusArc(final Component c) { - return DarkButtonUI.isSquare(c) && !DarkButtonUI.isForceRoundCorner(c) ? getSquareFocusArcSize() - : getFocusArcSize(); + if (DarkButtonUI.isNoArc(c)) return getMinimumArc(); + boolean square = DarkButtonUI.isSquare(c); + boolean alt = DarkButtonUI.chooseAlternativeArc(c); + return square ? alt ? getFocusArcSize() + : getSquareFocusArcSize() + : alt ? getSquareFocusArcSize() : getFocusArcSize(); } private void paintShadow(@NotNull final Graphics2D g2, final int width, final int height, final int arc) { @@ -126,6 +139,10 @@ public class DarkButtonBorder implements Border, UIResource { return DarkDefaults.get().getButtonArc(); } + public static int getMinimumArc() { + return DarkDefaults.get().getButtonMinimumArc(); + } + public static int getSquareFocusArcSize() { return DarkDefaults.get().getButtonSquareFocusArc(); } diff --git a/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java b/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java index 76742f2a..06d488f7 100644 --- a/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java +++ b/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java @@ -51,7 +51,6 @@ public class DarkButtonUI extends BasicButtonUI { protected static final Rectangle viewRect = new Rectangle(); protected static final Rectangle textRect = new Rectangle(); protected static final Rectangle iconRect = new Rectangle(); - protected int arcSize; protected int borderSize; protected int shadowHeight; protected AbstractButton button; @@ -71,7 +70,6 @@ public class DarkButtonUI extends BasicButtonUI { @Override protected void installDefaults(final AbstractButton b) { super.installDefaults(b); - arcSize = DarkButtonBorder.getArcSize(); borderSize = DarkButtonBorder.getBorderSize(); shadowHeight = DarkButtonBorder.getShadowSize(); } @@ -121,32 +119,10 @@ public class DarkButtonUI extends BasicButtonUI { return fg; } - protected void paintButton(final Graphics g, @NotNull final JComponent c) { - Graphics2D g2 = (Graphics2D) g; - if (shouldDrawBackground(c)) { - int arc = getArcSize(c); - if (isShadowVariant(c)) { - var b = (AbstractButton) c; - if (b.isEnabled() && b.getModel().isRollover()) { - GraphicsUtil.setupAAPainting(g2); - g.setColor(getShadowColor(b)); - if (isFullShadow(c)) { - g.fillRect(0, 0, c.getWidth(), c.getHeight()); - } else { - DarkUIUtil.paintRoundRect((Graphics2D) g, 0, 0, c.getWidth(), c.getHeight(), arc); - } - } - } else { - g2.setColor(getBackgroundColor(c)); - if (isSquare(c) && !isForceRoundCorner(c)) { - g2.fillRect(borderSize, borderSize, c.getWidth() - 2 * borderSize, - c.getHeight() - 2 * borderSize - shadowHeight); - } else { - DarkUIUtil.paintRoundRect((Graphics2D) g, borderSize, borderSize, c.getWidth() - 2 * borderSize, - c.getHeight() - 2 * borderSize - shadowHeight, arc); - } - } - } + @Contract("null -> false") + public static boolean isNoArc(final Component c) { + return c instanceof JButton + && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.noArc")); } protected String layout(@NotNull final AbstractButton b, final JComponent c, final FontMetrics fm, @@ -195,8 +171,32 @@ public class DarkButtonUI extends BasicButtonUI { return c.isEnabled() && border != null && button.isContentAreaFilled(); } - protected int getArcSize(final JComponent c) { - return isSquare(c) && !isForceRoundCorner(c) ? 0 : arcSize; + protected void paintButton(final Graphics g, @NotNull final JComponent c) { + Graphics2D g2 = (Graphics2D) g; + if (shouldDrawBackground(c)) { + int arc = getArcSize(c); + if (isShadowVariant(c)) { + var b = (AbstractButton) c; + if (b.isEnabled() && b.getModel().isRollover()) { + GraphicsUtil.setupAAPainting(g2); + g.setColor(getShadowColor(b)); + if (isFullShadow(c)) { + g.fillRect(0, 0, c.getWidth(), c.getHeight()); + } else { + DarkUIUtil.paintRoundRect((Graphics2D) g, 0, 0, c.getWidth(), c.getHeight(), arc); + } + } + } else { + g2.setColor(getBackgroundColor(c)); + if (isSquare(c) && !chooseAlternativeArc(c)) { + g2.fillRect(borderSize, borderSize, c.getWidth() - 2 * borderSize, + c.getHeight() - 2 * borderSize - shadowHeight); + } else { + DarkUIUtil.paintRoundRect((Graphics2D) g, borderSize, borderSize, c.getWidth() - 2 * borderSize, + c.getHeight() - 2 * borderSize - shadowHeight, arc); + } + } + } } @Contract("null -> false") @@ -221,6 +221,10 @@ public class DarkButtonUI extends BasicButtonUI { && "fullShadow".equals(((JButton) c).getClientProperty("JButton.variant")); } + protected int getArcSize(final JComponent c) { + return DarkButtonBorder.getArc(c); + } + protected Color getBackgroundColor(@NotNull final JComponent c) { var defaultButton = (c instanceof JButton && (((JButton) c).isDefaultButton())); var rollOver = (c instanceof JButton && (((JButton) c).isRolloverEnabled() @@ -255,9 +259,9 @@ public class DarkButtonUI extends BasicButtonUI { } @Contract("null -> false") - public static boolean isForceRoundCorner(final Component c) { + public static boolean chooseAlternativeArc(final Component c) { return c instanceof JButton - && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.forceRoundCorner")); + && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.alternativeArc")); } @Contract("null -> false") diff --git a/src/main/java/com/weis/darklaf/ui/combobox/DarkComboBoxUI.java b/src/main/java/com/weis/darklaf/ui/combobox/DarkComboBoxUI.java index 41c94ac8..27ece676 100644 --- a/src/main/java/com/weis/darklaf/ui/combobox/DarkComboBoxUI.java +++ b/src/main/java/com/weis/darklaf/ui/combobox/DarkComboBoxUI.java @@ -146,6 +146,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border { JButton button = ArrowButton.createUpDownArrow(comboBox, SwingConstants.SOUTH, true, false, new Insets(0, BUTTON_PAD, 0, BUTTON_PAD)); button.setBorder(BorderFactory.createEmptyBorder()); + button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); return button; } @@ -390,5 +391,4 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border { public void resetPopup() { ((DarkComboPopup) popup).reset(); } - } diff --git a/src/main/java/com/weis/darklaf/ui/slider/DarkSliderUI.java b/src/main/java/com/weis/darklaf/ui/slider/DarkSliderUI.java index b86cb1a7..3309613e 100644 --- a/src/main/java/com/weis/darklaf/ui/slider/DarkSliderUI.java +++ b/src/main/java/com/weis/darklaf/ui/slider/DarkSliderUI.java @@ -97,7 +97,11 @@ public class DarkSliderUI extends BasicSliderUI { @Override protected void calculateGeometry() { super.calculateGeometry(); - calculateIconRect(); + if (showVolumeIcon(slider)) { + calculateIconRect(); + } else { + iconRect.setBounds(-1, -1, 0, 0); + } } @Override @@ -264,7 +268,6 @@ public class DarkSliderUI extends BasicSliderUI { int value = slider.getValue() - slider.getMinimum(); double percentage = value / (double) range; boolean enabled = slider.isEnabled(); - String prefix = slider.isEnabled() ? "enabled_" : "disabled_"; if (Math.abs(percentage) < 1E-6) { return enabled ? DarkIcons.get().getSliderVolumeLevel0() : DarkIcons.get().getSliderVolumeLevel0Inactive(); @@ -534,6 +537,7 @@ public class DarkSliderUI extends BasicSliderUI { int pos = isHorizontal() ? evt.getX() : evt.getY(); int loc = getLocationForValue(getSnappedValue(evt)); offset = (loc < 0) ? 0 : pos - loc; + if (iconRect.contains(evt.getPoint())) return; super.mousePressed(evt); } diff --git a/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java b/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java index 15b07c9e..2d8d2892 100644 --- a/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java +++ b/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java @@ -132,6 +132,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe prevButton = createArrow(SwingConstants.SOUTH); prevButton.setName("Spinner.previousButton"); prevButton.setBorder(new EmptyBorder(1, 1, 1, 1)); + prevButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); installPreviousButtonListeners(prevButton); return prevButton; } @@ -141,6 +142,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe JButton nextButton = createArrow(SwingConstants.NORTH); nextButton.setName("Spinner.nextButton"); nextButton.setBorder(new EmptyBorder(1, 1, 1, 1)); + nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); installNextButtonListeners(nextButton); return nextButton; } diff --git a/src/main/java/com/weis/darklaf/ui/tabframe/DarkPanelPopupUI.java b/src/main/java/com/weis/darklaf/ui/tabframe/DarkPanelPopupUI.java index 811328bf..4feb91d9 100644 --- a/src/main/java/com/weis/darklaf/ui/tabframe/DarkPanelPopupUI.java +++ b/src/main/java/com/weis/darklaf/ui/tabframe/DarkPanelPopupUI.java @@ -356,7 +356,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe super(icon); this.ui = ui; putClientProperty("JButton.buttonType", "square"); - putClientProperty("JButton.forceRoundCorner", Boolean.TRUE); + putClientProperty("JButton.alternativeArc", Boolean.TRUE); putClientProperty("JButton.variant", "shadow"); setRolloverEnabled(true); setFocus(false); diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkPasswordFieldUI.java b/src/main/java/com/weis/darklaf/ui/text/DarkPasswordFieldUI.java index acfbab35..5e6e5473 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkPasswordFieldUI.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkPasswordFieldUI.java @@ -99,7 +99,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { return new DarkPasswordFieldUI(); } - private void updateCursor(final Point p) { + protected void updateCursor(final Point p) { boolean insideTextArea = DarkTextFieldUI.getDrawingRect(getComponent()).contains(p) && p.x >= DarkTextFieldUI.getTextRect(getComponent()).x && p.x < getShowIconCoord().x; diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java b/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java index 29bf734f..ee397076 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java @@ -145,7 +145,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh icon.getIconWidth(), icon.getIconHeight()).contains(e); } - private void updateCursor(final Point p) { + protected void updateCursor(final Point p) { var action = getActionUnder(p); boolean oldClear = clearHovered; clearHovered = action == ClickAction.CLEAR; diff --git a/src/main/resources/com/weis/darklaf/properties/ui/button.properties b/src/main/resources/com/weis/darklaf/properties/ui/button.properties index 4134c13e..aebfa81d 100644 --- a/src/main/resources/com/weis/darklaf/properties/ui/button.properties +++ b/src/main/resources/com/weis/darklaf/properties/ui/button.properties @@ -39,8 +39,10 @@ Button.activeFillColorRollOver = %hoverHighlight Button.activeFillColorClick = %clickHighlight Button.arc = %arc +Button.squareArc = %arcSecondary Button.focusArc = %arcFocus Button.squareFocusArc = %arcSecondaryFocus +Button.minimumArc = %arcSecondary Button.borderThickness = %borderThickness Button.shadowHeight = 3 diff --git a/src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties b/src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties index cbf92ce9..25057251 100644 --- a/src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties +++ b/src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties @@ -36,9 +36,7 @@ ColorChooser.swatchBorderColor = %borderSecondary ColorChooser.swatchGridColor = %gridLine ColorChooser.sliderShadow = %shadow ColorChooser.errorDelay = 600 - -#Todo -ColorChooser.swatchesDefaultRecentColor = +ColorChooser.swatchesDefaultRecentColor = %background #Icons ColorChooser.pipette.icon = misc/pipette.svg[aware] ColorChooser.pipetteRollover.icon = misc/pipette_rollover.svg[aware] diff --git a/src/test/java/UIDemo.java b/src/test/java/UIDemo.java index ed61dd6a..f37ce478 100644 --- a/src/test/java/UIDemo.java +++ b/src/test/java/UIDemo.java @@ -89,7 +89,7 @@ public final class UIDemo { setRolloverEnabled(true); putClientProperty("JButton.buttonType", "square"); putClientProperty("JButton.thin", Boolean.TRUE); - putClientProperty("JButton.forceRoundCorner", Boolean.TRUE); + putClientProperty("JButton.alternativeArc", Boolean.TRUE); putClientProperty("JButton.variant", "shadow"); }}); add(new JButton(folderIcon) {{