From f15d0ae50b9ad6126d4c382c12a2123b511449d4 Mon Sep 17 00:00:00 2001 From: weisj Date: Wed, 9 Oct 2019 22:17:35 +0200 Subject: [PATCH] Changed clear icon for search variant. Fixed border opacity for search variant. --- .../weis/darklaf/ui/text/DarkTextBorder.java | 5 ++--- .../weis/darklaf/ui/text/DarkTextFieldUI.java | 17 ++++++++++++----- .../weis/darklaf/properties/ui/text.properties | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java b/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java index 8a5d6f94..9d4c6c75 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java @@ -44,8 +44,7 @@ public class DarkTextBorder implements Border, UIResource { g.setColor(DarkTextFieldUI.getBorderColor(c)); if (((JComponent) c).getClientProperty("JTextField.Search.noBorderRing") != Boolean.TRUE) { if (c.hasFocus()) { - DarkUIUtil.paintOutlineBorder(g, width, height, arcSize, true, - true, DarkUIUtil.Outline.focus); + DarkUIUtil.paintFocusBorder(g, width, height, arcSize, true); } g.setColor(DarkTextFieldUI.getBorderColor(c)); DarkUIUtil.paintLineBorder(g, BORDER_SIZE, BORDER_SIZE, width - 2 * BORDER_SIZE, @@ -62,7 +61,7 @@ public class DarkTextBorder implements Border, UIResource { BORDER_SIZE + PADDING, BORDER_SIZE + PADDING); if (DarkTextFieldUI.isSearchField(c)) { int searchWidth = DarkTextFieldUI.getSearchIcon(c).getIconWidth(); - int clearWidth = DarkTextFieldUI.getClearIcon().getIconWidth(); + int clearWidth = DarkTextFieldUI.getClearIcon(false).getIconWidth(); insets.left += PADDING + searchWidth; insets.right += PADDING + clearWidth; } else if (DarkPasswordFieldUI.hasShowIcon(c)) { 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 2cea77a1..d356ee7d 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java @@ -66,6 +66,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh lastSearchEvent = System.currentTimeMillis(); } }; + private boolean clearHovered; @NotNull @Contract("_ -> new") @@ -81,8 +82,9 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh } @Contract(pure = true) - public static Icon getClearIcon() { - return UIManager.getIcon("TextField.search.clear.icon"); + public static Icon getClearIcon(final boolean clearHovered) { + return clearHovered ? UIManager.getIcon("TextField.search.clearHover.icon") + : UIManager.getIcon("TextField.search.clear.icon"); } public static Color getBorderColor(@NotNull final Component c) { @@ -130,6 +132,11 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh private void updateCursor(final Point p) { var action = getActionUnder(p); + boolean oldClear = clearHovered; + clearHovered = action == ClickAction.CLEAR; + if (oldClear != clearHovered) { + editor.repaint(); + } var drawRect = getDrawingRect(getComponent()); var textRect = getTextRect(getComponent()); int rightBoundary = getComponent().getText().isEmpty() @@ -210,7 +217,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh private void paintClearIcon(final Graphics2D g) { Point p = getClearIconCoord(); - getClearIcon().paintIcon(null, g, p.x, p.y); + getClearIcon(clearHovered).paintIcon(null, g, p.x, p.y); } private void paintSearchIcon(final Graphics2D g) { @@ -220,14 +227,14 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh protected Point getClearIconCoord() { Rectangle r = getDrawingRect(getComponent()); - int w = getClearIcon().getIconWidth(); + int w = getClearIcon(clearHovered).getIconWidth(); return new Point(r.x + r.width - w - DarkTextBorder.PADDING, r.y + (r.height - w) / 2); } private ClickAction getActionUnder(final Point p) { var c = getComponent(); if (isSearchField(c)) { - if (isOver(getClearIconCoord(), getClearIcon(), p)) { + if (isOver(getClearIconCoord(), getClearIcon(clearHovered), p)) { return ClickAction.CLEAR; } if (isOver(getSearchIconCoord(), getSearchIcon(c), p)) { diff --git a/src/main/resources/com/weis/darklaf/properties/ui/text.properties b/src/main/resources/com/weis/darklaf/properties/ui/text.properties index eba357f0..21e6d1f1 100644 --- a/src/main/resources/com/weis/darklaf/properties/ui/text.properties +++ b/src/main/resources/com/weis/darklaf/properties/ui/text.properties @@ -46,4 +46,5 @@ PasswordField.show.icon = navigation/eye.svg[dual] PasswordField.showPressed.icon = navigation/eye.svg[aware] TextField.search.searchWithHistory.icon = navigation/searchWithHistory.svg[aware] TextField.search.search.icon = navigation/search.svg[aware] -TextField.search.clear.icon = navigation/clear.svg[aware](12,12) \ No newline at end of file +TextField.search.clear.icon = navigation/close.svg[aware] +TextField.search.clearHover.icon = navigation/closeHovered.svg[aware] \ No newline at end of file