Browse Source

Fixed focus border not showing when text border is applied to no TextField components.

Adjusted insets of TextFields.

Signed-off-by: weisj <weisj@arcor.de>
pull/44/head
weisj 5 years ago
parent
commit
009628fdb3
  1. 55
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java
  2. 12
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  3. 18
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  4. 7
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties

55
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java

@ -49,8 +49,9 @@ public class DarkTextBorder implements Border, UIResource {
protected int borderSize;
protected int arc;
protected int minimumArc;
protected int searchArc;
protected int focusArc;
protected int searchFocusArc;
protected Insets padding;
protected Icon showIcon;
@ -62,8 +63,9 @@ public class DarkTextBorder implements Border, UIResource {
inactiveBorderColor = UIManager.getColor("TextField.border.disabled");
borderSize = UIManager.getInt("TextField.borderThickness");
arc = UIManager.getInt("TextField.arc");
focusArc = UIManager.getInt("TextField.focusArc");
searchArc = UIManager.getInt("TextField.searchArc");
minimumArc = UIManager.getInt("TextField.minimumArc");
searchFocusArc = UIManager.getInt("TextField.searchFocusArc");
padding = UIManager.getInsets("TextField.insets");
showIcon = UIManager.getIcon("PasswordField.show.icon");
}
@ -80,19 +82,11 @@ public class DarkTextBorder implements Border, UIResource {
}
protected int getArcSize(final Component c) {
boolean alt = DarkTextFieldUI.chooseAlternativeArc(c);
if (!alt && !DarkTextFieldUI.isSearchField(c)) {
return 0;
}
return DarkTextFieldUI.isSearchField(c) ? (alt ? arc : searchArc) : (alt ? searchArc : arc);
return DarkTextFieldUI.isSearchField(c) ? searchArc : arc;
}
protected int getFocusArcSize(final Component c) {
boolean alt = DarkTextFieldUI.chooseAlternativeArc(c);
if (!alt && !DarkTextFieldUI.isSearchField(c)) {
return minimumArc;
}
return DarkTextFieldUI.isSearchField(c) ? (alt ? arc : searchArc) : (alt ? searchArc : arc);
return DarkTextFieldUI.isSearchField(c) ? searchFocusArc : focusArc;
}
public int getBorderSize() {
@ -110,36 +104,15 @@ public class DarkTextBorder implements Border, UIResource {
GraphicsContext config = GraphicsUtil.setupStrokePainting(g);
int arcSize = getArcSize(c);
int focusArcSize = getFocusArcSize(c);
if (!DarkTextFieldUI.isSearchField(c)) {
if (hasError(c)) {
DarkUIUtil.paintOutlineBorder(g, width, height, focusArcSize, borderSize,
c.hasFocus(), DarkUIUtil.Outline.error);
} else if (c.hasFocus()) {
DarkUIUtil.paintFocusBorder(g, width, height, focusArcSize, borderSize);
}
g.setColor(getBorderColor(c));
if (DarkTextFieldUI.chooseAlternativeArc(c)) {
DarkUIUtil.paintLineBorder(g, borderSize, borderSize, width - 2 * borderSize,
height - 2 * borderSize, arcSize);
} else {
DarkUIUtil.paintLineBorder(g, borderSize, borderSize, width - 2 * borderSize,
height - 2 * borderSize, 0);
}
} else if (DarkTextFieldUI.isSearchField(c)) {
g.setColor(getBorderColor(c));
if (((JComponent) c).getClientProperty("JTextField.Search.noBorderRing") != Boolean.TRUE) {
if (hasError(c)) {
DarkUIUtil.paintOutlineBorder(g, width, height, focusArcSize, borderSize,
c.hasFocus(), DarkUIUtil.Outline.error);
} else if (c.hasFocus()) {
DarkUIUtil.paintFocusBorder(g, width, height, arcSize, borderSize);
}
g.setColor(getBorderColor(c));
DarkUIUtil.paintLineBorder(g, borderSize, borderSize, width - 2 * borderSize,
height - 2 * borderSize, arcSize);
}
if (hasError(c)) {
DarkUIUtil.paintOutlineBorder(g, width, height, focusArcSize, borderSize,
c.hasFocus(), DarkUIUtil.Outline.error);
} else if (c.hasFocus()) {
DarkUIUtil.paintFocusBorder(g, width, height, focusArcSize, borderSize);
}
g.setColor(getBorderColor(c));
DarkUIUtil.paintLineBorder(g, borderSize, borderSize, width - 2 * borderSize,
height - 2 * borderSize, arcSize);
g.translate(-x, -y);
config.restore();
}

12
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java

@ -108,11 +108,6 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
return new Rectangle(i.left, i.top, dim.width - i.left - i.right, dim.height - i.top - i.bottom);
}
public static boolean chooseAlternativeArc(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextField.alternativeArc"));
}
public static boolean isOver(final Point p, final Icon icon, final Point e) {
return new Rectangle(p.x, p.y,
icon.getIconWidth(), icon.getIconHeight()).contains(e);
@ -206,12 +201,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
@Override
protected int getArcSize(final JComponent c) {
boolean alt = chooseAlternativeArc(c);
if (!alt && !isSearchField(c)) {
return 0;
}
return DarkTextFieldUI.isSearchField(c) ? (alt ? arcSize : searchArcSize)
: (alt ? searchArcSize : arcSize);
return DarkTextFieldUI.isSearchField(c) ? searchArcSize : arcSize;
}
private void paintClearIcon(final Graphics2D g) {

18
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -38,9 +38,7 @@ import javax.swing.plaf.InputMapUIResource;
import javax.swing.plaf.basic.BasicTextUI;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashSet;
@ -52,6 +50,17 @@ import java.util.Set;
public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeListener {
protected JTextComponent editor;
private FocusListener focusListener = new FocusListener() {
@Override
public void focusGained(final FocusEvent e) {
editor.repaint();
}
@Override
public void focusLost(final FocusEvent e) {
editor.repaint();
}
};
@Override
protected Caret createCaret() {
@ -87,12 +96,15 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
protected void installListeners() {
super.installListeners();
editor.addPropertyChangeListener(this);
editor.addFocusListener(focusListener);
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
editor.removePropertyChangeListener(this);
editor.removeFocusListener(focusListener);
focusListener = null;
}
@Override

7
core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties

@ -40,14 +40,13 @@ TextField.inactiveBackground = %textBackgroundInactive
TextField.background = %textBackground
TextField.selectionBackground = %textSelectionBackground
TextField.selectionForeground = %textSelectionForeground
TextField.insets = 4,4,4,4
TextField.arc = %arcSecondary
TextField.minimumArc = %arcSecondary
TextField.arc = %arc
TextField.focusArc = %arcFocus
TextField.searchArc = %arc
TextField.searchFocusArc = %arcFocus
TextField.focusArc = %arcSecondaryFocus
TextField.borderThickness = %borderThickness
TextField.insets = 2,2,2,2
TextPane.selectionBackground = %textSelectionBackground
TextPane.selectionForeground = %textSelectionForeground

Loading…
Cancel
Save