Browse Source

Changed how button arcs work.

Added hand cursor to spinner/comboBox.
Fixed an issue where clicking on the volume icon would move the slider.
pull/15/head
weisj 5 years ago
parent
commit
3597b183c4
  1. 18
      src/main/java/com/weis/darklaf/defaults/DarkDefaults.java
  2. 23
      src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java
  3. 68
      src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java
  4. 2
      src/main/java/com/weis/darklaf/ui/combobox/DarkComboBoxUI.java
  5. 6
      src/main/java/com/weis/darklaf/ui/slider/DarkSliderUI.java
  6. 2
      src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java
  7. 2
      src/main/java/com/weis/darklaf/ui/tabframe/DarkPanelPopupUI.java
  8. 2
      src/main/java/com/weis/darklaf/ui/text/DarkPasswordFieldUI.java
  9. 2
      src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java
  10. 2
      src/main/resources/com/weis/darklaf/properties/ui/button.properties
  11. 4
      src/main/resources/com/weis/darklaf/properties/ui/colorChooser.properties
  12. 2
      src/test/java/UIDemo.java

18
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;
}
}

23
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();
}

68
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")

2
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();
}
}

6
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();
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);
}

2
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;
}

2
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);

2
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;

2
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;

2
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

4
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]

2
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) {{

Loading…
Cancel
Save