Browse Source

Fixed shadow painting.

Made square buttons have zero arc.
Removed unnecessary background painting for password fields.
Removed author tags where not needed anymore.
pull/170/head
weisj 5 years ago
parent
commit
ce6e62066a
  1. 16
      core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java
  2. 15
      core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java
  3. 2
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java
  4. 14
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java
  5. 1
      core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarBorder.java
  6. 1
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  7. 1
      core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java
  8. 35
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java
  9. 1
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  10. 1
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/checkbox/DarkCheckBoxUI.java
  11. 1
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonUI.java
  12. 1
      core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarBorder.java
  13. 6
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties
  14. 3
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties
  15. 1
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

16
core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java

@ -27,6 +27,7 @@ package com.github.weisj.darklaf.graphics;
import java.awt.*; import java.awt.*;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D; import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import javax.swing.*; import javax.swing.*;
@ -117,10 +118,17 @@ public class PaintUtil {
private static void doPaint(final Graphics2D g, final float width, final float height, final float arc, private static void doPaint(final Graphics2D g, final float width, final float height, final float arc,
final float bw, final boolean inside) { final float bw, final boolean inside) {
GraphicsContext context = GraphicsUtil.setupStrokePainting(g); GraphicsContext context = GraphicsUtil.setupStrokePainting(g);
float outerArc = inside ? arc : arc + bw; Shape outerRect;
float innerArc = inside ? arc - bw : arc; Shape innerRect;
Shape outerRect = new RoundRectangle2D.Float(0, 0, width, height, outerArc, outerArc); if (Scale.equalWithError(arc, 0)) {
Shape innerRect = new RoundRectangle2D.Float(bw, bw, width - 2 * bw, height - 2 * bw, innerArc, innerArc); outerRect = new Rectangle2D.Float(0, 0, width, height);
innerRect = new Rectangle2D.Float(bw, bw, width - 2 * bw, height - 2 * bw);
} else {
float outerArc = inside ? arc : arc + bw;
float innerArc = inside ? arc - bw : arc;
outerRect = new RoundRectangle2D.Float(0, 0, width, height, outerArc, outerArc);
innerRect = new RoundRectangle2D.Float(bw, bw, width - 2 * bw, height - 2 * bw, innerArc, innerArc);
}
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD); Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
path.append(outerRect, false); path.append(outerRect, false);
path.append(innerRect, false); path.append(innerRect, false);

15
core/src/main/java/com/github/weisj/darklaf/task/FontDefaultsInitTask.java

@ -60,7 +60,12 @@ public class FontDefaultsInitTask implements DefaultsInitTask {
TextAttribute.KERNING_ON); TextAttribute.KERNING_ON);
private static final Map<AttributedCharacterIterator.Attribute, Integer> DISABLE_KERNING = Collections.singletonMap(TextAttribute.KERNING, private static final Map<AttributedCharacterIterator.Attribute, Integer> DISABLE_KERNING = Collections.singletonMap(TextAttribute.KERNING,
null); null);
/*
* On Catalina the are issues with font kerning and .AppleSystemUIFont.
* For now Helvetica Neue is used instead.
*/
private static final String MAC_OS_CATALINA_FONT_NAME = ".AppleSystemUIFont"; private static final String MAC_OS_CATALINA_FONT_NAME = ".AppleSystemUIFont";
private static final String MAC_OS_CATALINA_FONT_NAME_FALLBACK = "Helvetica Neue";
private static final String WINDOWS_10_FONT_NAME = "Segoe UI"; private static final String WINDOWS_10_FONT_NAME = "Segoe UI";
private static final String MAC_OS_FONT_NAME = ".SF NS Text"; private static final String MAC_OS_FONT_NAME = ".SF NS Text";
@ -74,16 +79,18 @@ public class FontDefaultsInitTask implements DefaultsInitTask {
patchOSFonts(defaults, this::mapWindowsFont); patchOSFonts(defaults, this::mapWindowsFont);
} }
if (SystemInfo.isMacOSCatalina) {
defaults.put(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
if (systemKerningEnabled()) { if (systemKerningEnabled()) {
List<String> kerningFontsList = PropertyUtil.getList(defaults, KERNING_LIST, String.class); List<String> kerningFontsList = PropertyUtil.getList(defaults, KERNING_LIST, String.class);
if (!kerningFontsList.isEmpty()) { if (!kerningFontsList.isEmpty()) {
Set<String> kerningFonts = new HashSet<>(kerningFontsList); Set<String> kerningFonts = new HashSet<>(kerningFontsList);
boolean enabledAll = ALL_FONTS.equals(kerningFontsList.get(0)); boolean enabledAll = ALL_FONTS.equals(kerningFontsList.get(0));
setupKerningPerFont(defaults, key -> { setupKerningPerFont(defaults, key -> enabledAll || kerningFonts.contains(key));
if (enabledAll) return true;
return kerningFonts.contains(key);
});
} }
} }

2
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java

@ -38,7 +38,6 @@ import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkButtonBorder implements Border, UIResource { public class DarkButtonBorder implements Border, UIResource {
@ -89,7 +88,6 @@ public class DarkButtonBorder implements Border, UIResource {
} }
public static boolean showDropShadow(final JComponent c) { public static boolean showDropShadow(final JComponent c) {
if (ButtonConstants.isRound(c)) return false;
return showDropShadow(getCornerFlag(c)); return showDropShadow(getCornerFlag(c));
} }

14
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -51,7 +51,6 @@ import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkButtonUI extends BasicButtonUI implements ButtonConstants { public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
@ -198,9 +197,9 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
g.setColor(shadowColor); g.setColor(shadowColor);
Composite comp = g.getComposite(); Composite comp = g.getComposite();
g.setComposite(PaintUtil.getShadowComposite()); g.setComposite(PaintUtil.getShadowComposite());
int sh = Math.max(shadow, 2 * effectiveArc); int stroke = (int) PaintUtil.getStrokeWidth(g);
paintBackgroundRect(g, effectiveArc, bgRect.x, bgRect.y + bgRect.height + shadow - sh, paintBackgroundRect(g, effectiveArc, bgRect.x, bgRect.y + shadow + stroke,
bgRect.width, sh, false); bgRect.width, bgRect.height);
g.setComposite(comp); g.setComposite(comp);
} }
@ -209,16 +208,15 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
} }
private void paintBackgroundRect(final Graphics2D g2, final int effectiveArc, final Rectangle bgRect) { private void paintBackgroundRect(final Graphics2D g2, final int effectiveArc, final Rectangle bgRect) {
paintBackgroundRect(g2, effectiveArc, bgRect.x, bgRect.y, bgRect.width, bgRect.height, true); paintBackgroundRect(g2, effectiveArc, bgRect.x, bgRect.y, bgRect.width, bgRect.height);
} }
private void paintBackgroundRect(final Graphics2D g2, final int effectiveArc, private void paintBackgroundRect(final Graphics2D g2, final int effectiveArc,
final int x, final int y, final int width, final int height, final int x, final int y, final int width, final int height) {
final boolean respectBorder) {
if (effectiveArc == 0) { if (effectiveArc == 0) {
g2.fillRect(x, y, width, height); g2.fillRect(x, y, width, height);
} else { } else {
PaintUtil.fillRoundRect(g2, x, y, width, height, effectiveArc, respectBorder); PaintUtil.fillRoundRect(g2, x, y, width, height, effectiveArc, true);
} }
} }

1
core/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarBorder.java

@ -27,7 +27,6 @@ package com.github.weisj.darklaf.ui.progressbar;
import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.BorderUIResource;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkProgressBarBorder extends BorderUIResource.EmptyBorderUIResource { public class DarkProgressBarBorder extends BorderUIResource.EmptyBorderUIResource {

1
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java

@ -40,7 +40,6 @@ import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener { public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener {

1
core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java

@ -35,7 +35,6 @@ import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.util.ColorUtil; import com.github.weisj.darklaf.util.ColorUtil;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkScrollBarUI extends BasicScrollBarUI implements ScrollBarConstants { public class DarkScrollBarUI extends BasicScrollBarUI implements ScrollBarConstants {

35
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java

@ -25,23 +25,19 @@
package com.github.weisj.darklaf.ui.text; package com.github.weisj.darklaf.ui.text;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.util.Arrays; import java.util.Arrays;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.icons.EmptyIcon;
import com.github.weisj.darklaf.ui.text.bridge.DarkPasswordFieldUIBridge; import com.github.weisj.darklaf.ui.text.bridge.DarkPasswordFieldUIBridge;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge {
@ -51,7 +47,6 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge {
protected Icon show; protected Icon show;
protected Icon showPressed; protected Icon showPressed;
protected int borderSize; protected int borderSize;
protected int arc;
private char echo_dot = '*'; private char echo_dot = '*';
private boolean showTriggered = false; private boolean showTriggered = false;
@ -62,38 +57,10 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge {
@Override @Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
borderSize = UIManager.getInt("PasswordField.borderThickness");
arc = UIManager.getInt("PasswordField.arc");
show = UIManager.getIcon("PasswordField.show.icon"); show = UIManager.getIcon("PasswordField.show.icon");
showPressed = UIManager.getIcon("PasswordField.showPressed.icon"); showPressed = UIManager.getIcon("PasswordField.showPressed.icon");
} }
protected void paintBackground(final Graphics graphics) {
Graphics2D g = (Graphics2D) graphics;
JTextComponent c = getComponent();
Container parent = c.getParent();
if (parent != null) {
g.setColor(parent.getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
Border border = c.getBorder();
GraphicsContext config = new GraphicsContext(g);
if (border instanceof DarkTextBorder) {
if (c.isEnabled() && c.isEditable()) {
g.setColor(c.getBackground());
}
int width = c.getWidth();
int height = c.getHeight();
int w = borderSize;
PaintUtil.fillRoundRect(g, w, w, width - 2 * w, height - 2 * w, arc);
} else {
super.paintBackground(g);
}
config.restore();
}
@Override @Override
protected boolean doPaintLeftIcon(final JTextComponent c) { protected boolean doPaintLeftIcon(final JTextComponent c) {
return false; return false;

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

@ -44,7 +44,6 @@ import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyChangeListener, MouseClickListener { public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyChangeListener, MouseClickListener {

1
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/checkbox/DarkCheckBoxUI.java

@ -33,7 +33,6 @@ import javax.swing.plaf.ComponentUI;
import com.github.weisj.darklaf.ui.togglebutton.radiobutton.DarkRadioButtonUI; import com.github.weisj.darklaf.ui.togglebutton.radiobutton.DarkRadioButtonUI;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkCheckBoxUI extends DarkRadioButtonUI { public class DarkCheckBoxUI extends DarkRadioButtonUI {

1
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonUI.java

@ -48,7 +48,6 @@ import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonFocusNavigationActio
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyChangeListener, ToggleButtonConstants { public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyChangeListener, ToggleButtonConstants {

1
core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarBorder.java

@ -31,7 +31,6 @@ import javax.swing.border.AbstractBorder;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkToolBarBorder extends AbstractBorder implements UIResource, SwingConstants { public class DarkToolBarBorder extends AbstractBorder implements UIResource, SwingConstants {

6
core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties

@ -42,10 +42,10 @@ Button.activeFillColorRollOver = %hoverHighlight
Button.activeFillColorClick = %clickHighlight Button.activeFillColorClick = %clickHighlight
Button.arc = %arc Button.arc = %arc
Button.squareArc = %arcSecondary Button.squareArc = 0
Button.focusArc = %arcFocus Button.focusArc = %arcFocus
Button.squareFocusArc = %arcSecondaryFocus Button.squareFocusArc = 0
Button.minimumArc = %arcSecondary Button.minimumArc = 0
Button.borderThickness = %borderThickness Button.borderThickness = %borderThickness
Button.shadowHeight = %shadowHeight Button.shadowHeight = %shadowHeight

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

@ -104,9 +104,6 @@ PasswordField.selectionForeground = %textCompSelectionForeground
PasswordField.border = com.github.weisj.darklaf.ui.text.DarkTextBorder PasswordField.border = com.github.weisj.darklaf.ui.text.DarkTextBorder
PasswordField.extendSelection = false PasswordField.extendSelection = false
PasswordField.arc = %arcSecondary
PasswordField.borderThickness = %borderThickness
#Icons #Icons
PasswordField.show.icon = misc/eye.svg[themed] PasswordField.show.icon = misc/eye.svg[themed]
PasswordField.showPressed.icon = misc/eyeHovered.svg[themed] PasswordField.showPressed.icon = misc/eyeHovered.svg[themed]

1
windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

@ -46,7 +46,6 @@ import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.Scale; import com.github.weisj.darklaf.util.Scale;
/** /**
* @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
public class WindowsTitlePane extends CustomTitlePane { public class WindowsTitlePane extends CustomTitlePane {

Loading…
Cancel
Save