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 borderSize;
protected int arc; protected int arc;
protected int minimumArc;
protected int searchArc; protected int searchArc;
protected int focusArc;
protected int searchFocusArc;
protected Insets padding; protected Insets padding;
protected Icon showIcon; protected Icon showIcon;
@ -62,8 +63,9 @@ public class DarkTextBorder implements Border, UIResource {
inactiveBorderColor = UIManager.getColor("TextField.border.disabled"); inactiveBorderColor = UIManager.getColor("TextField.border.disabled");
borderSize = UIManager.getInt("TextField.borderThickness"); borderSize = UIManager.getInt("TextField.borderThickness");
arc = UIManager.getInt("TextField.arc"); arc = UIManager.getInt("TextField.arc");
focusArc = UIManager.getInt("TextField.focusArc");
searchArc = UIManager.getInt("TextField.searchArc"); searchArc = UIManager.getInt("TextField.searchArc");
minimumArc = UIManager.getInt("TextField.minimumArc"); searchFocusArc = UIManager.getInt("TextField.searchFocusArc");
padding = UIManager.getInsets("TextField.insets"); padding = UIManager.getInsets("TextField.insets");
showIcon = UIManager.getIcon("PasswordField.show.icon"); showIcon = UIManager.getIcon("PasswordField.show.icon");
} }
@ -80,19 +82,11 @@ public class DarkTextBorder implements Border, UIResource {
} }
protected int getArcSize(final Component c) { protected int getArcSize(final Component c) {
boolean alt = DarkTextFieldUI.chooseAlternativeArc(c); return DarkTextFieldUI.isSearchField(c) ? searchArc : arc;
if (!alt && !DarkTextFieldUI.isSearchField(c)) {
return 0;
}
return DarkTextFieldUI.isSearchField(c) ? (alt ? arc : searchArc) : (alt ? searchArc : arc);
} }
protected int getFocusArcSize(final Component c) { protected int getFocusArcSize(final Component c) {
boolean alt = DarkTextFieldUI.chooseAlternativeArc(c); return DarkTextFieldUI.isSearchField(c) ? searchFocusArc : focusArc;
if (!alt && !DarkTextFieldUI.isSearchField(c)) {
return minimumArc;
}
return DarkTextFieldUI.isSearchField(c) ? (alt ? arc : searchArc) : (alt ? searchArc : arc);
} }
public int getBorderSize() { public int getBorderSize() {
@ -110,36 +104,15 @@ public class DarkTextBorder implements Border, UIResource {
GraphicsContext config = GraphicsUtil.setupStrokePainting(g); GraphicsContext config = GraphicsUtil.setupStrokePainting(g);
int arcSize = getArcSize(c); int arcSize = getArcSize(c);
int focusArcSize = getFocusArcSize(c); int focusArcSize = getFocusArcSize(c);
if (!DarkTextFieldUI.isSearchField(c)) { if (hasError(c)) {
if (hasError(c)) { DarkUIUtil.paintOutlineBorder(g, width, height, focusArcSize, borderSize,
DarkUIUtil.paintOutlineBorder(g, width, height, focusArcSize, borderSize, c.hasFocus(), DarkUIUtil.Outline.error);
c.hasFocus(), DarkUIUtil.Outline.error); } else if (c.hasFocus()) {
} else if (c.hasFocus()) { DarkUIUtil.paintFocusBorder(g, width, height, focusArcSize, borderSize);
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);
}
} }
g.setColor(getBorderColor(c));
DarkUIUtil.paintLineBorder(g, borderSize, borderSize, width - 2 * borderSize,
height - 2 * borderSize, arcSize);
g.translate(-x, -y); g.translate(-x, -y);
config.restore(); 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); 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) { public static boolean isOver(final Point p, final Icon icon, final Point e) {
return new Rectangle(p.x, p.y, return new Rectangle(p.x, p.y,
icon.getIconWidth(), icon.getIconHeight()).contains(e); icon.getIconWidth(), icon.getIconHeight()).contains(e);
@ -206,12 +201,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
@Override @Override
protected int getArcSize(final JComponent c) { protected int getArcSize(final JComponent c) {
boolean alt = chooseAlternativeArc(c); return DarkTextFieldUI.isSearchField(c) ? searchArcSize : arcSize;
if (!alt && !isSearchField(c)) {
return 0;
}
return DarkTextFieldUI.isSearchField(c) ? (alt ? arcSize : searchArcSize)
: (alt ? searchArcSize : arcSize);
} }
private void paintClearIcon(final Graphics2D g) { 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.plaf.basic.BasicTextUI;
import javax.swing.text.*; import javax.swing.text.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.HashSet; import java.util.HashSet;
@ -52,6 +50,17 @@ import java.util.Set;
public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeListener { public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeListener {
protected JTextComponent editor; 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 @Override
protected Caret createCaret() { protected Caret createCaret() {
@ -87,12 +96,15 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
editor.addPropertyChangeListener(this); editor.addPropertyChangeListener(this);
editor.addFocusListener(focusListener);
} }
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
editor.removePropertyChangeListener(this); editor.removePropertyChangeListener(this);
editor.removeFocusListener(focusListener);
focusListener = null;
} }
@Override @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.background = %textBackground
TextField.selectionBackground = %textSelectionBackground TextField.selectionBackground = %textSelectionBackground
TextField.selectionForeground = %textSelectionForeground TextField.selectionForeground = %textSelectionForeground
TextField.insets = 4,4,4,4
TextField.arc = %arcSecondary TextField.arc = %arc
TextField.minimumArc = %arcSecondary TextField.focusArc = %arcFocus
TextField.searchArc = %arc TextField.searchArc = %arc
TextField.searchFocusArc = %arcFocus TextField.searchFocusArc = %arcFocus
TextField.focusArc = %arcSecondaryFocus
TextField.borderThickness = %borderThickness TextField.borderThickness = %borderThickness
TextField.insets = 2,2,2,2
TextPane.selectionBackground = %textSelectionBackground TextPane.selectionBackground = %textSelectionBackground
TextPane.selectionForeground = %textSelectionForeground TextPane.selectionForeground = %textSelectionForeground

Loading…
Cancel
Save