Browse Source

ComboBox and Spinner now have smaller insets.

ComboBox and Spinner now use the correct icons on intellij_mac.
TextFields now correctly paint their background in a table.

Signed-off-by: weisj <weisj@arcor.de>
pull/42/head
weisj 5 years ago
parent
commit
4a3041ace8
  1. 44
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java
  2. 3
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java
  3. 22
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java
  4. 6
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java
  5. 14
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  6. 4
      core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java
  7. 5
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/comboBox.properties
  8. 3
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/spinner.properties
  9. 3
      core/src/main/resources/com/github/weisj/darklaf/theme/intellij/intellij_mac.properties

44
core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java

@ -47,8 +47,6 @@ import java.beans.PropertyChangeListener;
*/
public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyChangeListener {
private static final int BUTTON_PAD = 7;
private final MouseListener mouseListener = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
@ -69,7 +67,6 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
private Insets boxPadding;
private Insets cellPadding;
public static ComponentUI createUI(final JComponent c) {
return new DarkComboBoxUI();
}
@ -163,11 +160,14 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
}
protected JButton createArrowButton() {
int buttonPad = UIManager.getInt("ComboBox.buttonPad");
JButton button = ArrowButton.createUpDownArrow(comboBox,
UIManager.getIcon("ComboBox.arrow.icon"),
new ComboIcon(comboBox,
UIManager.getIcon("ComboBox.arrowEditable.icon"),
UIManager.getIcon("ComboBox.arrow.icon")),
UIManager.getIcon("ComboBox.arrowInactive.icon"),
SwingConstants.SOUTH, true, false,
new Insets(0, BUTTON_PAD, 0, BUTTON_PAD));
new Insets(0, buttonPad, 0, buttonPad));
button.setBorder(BorderFactory.createEmptyBorder());
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
return button;
@ -325,7 +325,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
Area rect;
Area iconRect;
if (!isTableCellEditor && !isTreeCellEditor) {
rect = new Area(new RoundRectangle2D.Double(bSize, bSize, width - 2 * bSize,
rect = new Area(new RoundRectangle2D.Double(bSize - 1, bSize, width - 2 * bSize + 2,
height - 2 * bSize, arc, arc));
iconRect = new Area(new Rectangle(off, 0, width, height));
} else {
@ -430,4 +430,36 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
comboBox.repaint();
}
}
private static class ComboIcon implements Icon {
private final JComboBox<?> box;
private final Icon editableIcon;
private final Icon icon;
private ComboIcon(final JComboBox<?> box, final Icon editableIcon, final Icon icon) {
this.box = box;
this.editableIcon = editableIcon;
this.icon = icon;
}
private Icon getIcon() {
return box.isEditable() ? editableIcon : icon;
}
@Override
public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
getIcon().paintIcon(c, g, x, y);
}
@Override
public int getIconWidth() {
return getIcon().getIconWidth();
}
@Override
public int getIconHeight() {
return getIcon().getIconHeight();
}
}
}

3
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java

@ -121,7 +121,8 @@ public class DarkSpinnerBorder implements Border, UIResource {
if (DarkSpinnerUI.isTableCellEditor(c) || DarkSpinnerUI.isTreeCellEditor(c)) {
return new InsetsUIResource(cellInsets.top, insets.left, insets.bottom, insets.right);
}
return new InsetsUIResource(insets.top, insets.left, insets.bottom, insets.right);
return new InsetsUIResource(insets.top + borderSize, insets.left + borderSize,
insets.bottom + borderSize, insets.right + borderSize);
}
@Override

22
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java

@ -35,12 +35,7 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicSpinnerUI;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.*;
import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;
import java.beans.PropertyChangeEvent;
@ -52,7 +47,6 @@ import java.beans.PropertyChangeListener;
*/
public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener {
private static final int BUTTON_PAD = 7;
private final FocusListener focusListener = new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
@ -204,7 +198,8 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
private JButton createArrow(final int direction) {
Insets insets = new Insets(0, BUTTON_PAD, 0, BUTTON_PAD);
int buttonPad = UIManager.getInt("Spinner.buttonPad");
Insets insets = new Insets(0, buttonPad, 0, buttonPad);
JButton button = ArrowButton.createUpDownArrow(spinner,
getArrowIcon(direction),
getArrowInactiveIcon(direction), direction,
@ -244,14 +239,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
int height = c.getHeight();
JComponent editor = spinner.getEditor();
if (editorComponent != null) {
if (!editorComponent.isEnabled()) {
if (compColor == null) {
compColor = editorComponent.getBackground();
editorComponent.setBackground(getBackground(c));
} else {
compColor = null;
}
}
editorComponent.setBackground(getBackground(c));
g.setColor(editorComponent.getBackground());
} else {
((Graphics2D) g).setPaint(getBackground(c));
@ -292,7 +280,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
Rectangle bounds = prevButton.getBounds();
boolean leftToRight = spinner.getComponentOrientation().isLeftToRight();
int off = leftToRight ? bounds.x : bounds.x + bounds.width;
Area rect = new Area(new RoundRectangle2D.Double(bSize, bSize, width - 2 * bSize, height - 2 * bSize,
Area rect = new Area(new RoundRectangle2D.Double(bSize - 1, bSize - 1, width - 2 * bSize + 2, height - 2 * bSize + 1,
arc, arc));
Area iconRect = new Area(new Rectangle(off, 0, width, height));
if (leftToRight) {

6
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java

@ -28,6 +28,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.text.Document;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.ParseException;
@ -54,6 +55,11 @@ public class DarkFormattedTextFieldUI extends DarkTextFieldUI implements Propert
super.installUI(c);
}
@Override
protected void paintBackground(final Graphics graphics) {
super.paintBackground(graphics);
}
@Override
public void propertyChange(final PropertyChangeEvent evt) {
super.propertyChange(evt);

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

@ -97,9 +97,14 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
@Override
protected void paintBackground(final Graphics g) {
Container parent = editor.getParent();
if (editor.isOpaque() && parent != null) {
g.setColor(parent.getBackground());
if (editor.isOpaque()) {
Container parent = editor.getParent();
if (parent != null) {
g.setColor(parent.getBackground());
}
if (DarkTextBorder.isCellEditor(editor) || DarkUIUtil.isInCell(editor)) {
g.setColor(editor.getBackground());
}
g.fillRect(0, 0, editor.getWidth(), editor.getHeight());
}
@ -113,6 +118,9 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
g.fillRect(ins.left, ins.top, editor.getWidth() - ins.left - ins.right,
editor.getHeight() - ins.top - ins.bottom);
}
} else {
g.setColor(editor.getBackground());
g.fillRect(0, 0, editor.getWidth(), editor.getHeight());
}
}

4
core/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java

@ -128,7 +128,9 @@ public final class DarkUIUtil {
public static void fillRoundRect(final Graphics2D g, final float x, final float y,
final float width, final float height, final int arc) {
g.fill(new RoundRectangle2D.Float(x, y, width, height, arc, arc));
Stroke stroke = g.getStroke();
float lw = stroke instanceof BasicStroke ? ((BasicStroke) stroke).getLineWidth() : 1;
g.fill(new RoundRectangle2D.Float(x - lw, y - lw, width + lw, height + lw, arc, arc));
}

5
core/src/main/resources/com/github/weisj/darklaf/properties/ui/comboBox.properties

@ -39,10 +39,11 @@ ComboBox.selectionBackground = %highlightFillFocus
ComboBox.arc = %arc
ComboBox.borderThickness = %borderThickness
ComboBox.selectionForeground = %textSelectionForeground
ComboBox.insets = 4,6,4,6
ComboBox.insets = 2,2,2,2
ComboBox.cellEditorInsets = 2,5,2,5
ComboBox.buttonPad = 4
#Icons
ComboBox.arrow.icon = navigation/arrowDown.svg[themed]
ComboBox.arrowEditable.icon = navigation/arrowDown.svg[themed]
ComboBox.arrowInactive.icon = navigation/arrowDownDisabled.svg[themed]

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

@ -39,7 +39,8 @@ Spinner.arc = %arc
Spinner.borderThickness = %borderThickness
Spinner.cellEditorInsets = 2,5,2,5
Spinner.insets = 7,7,7,7
Spinner.insets = 2,2,2,2
Spinner.buttonPad = 4
Spinner.plus.icon = misc/plus.svg[themed]
Spinner.plusInactive.icon = misc/plus.svg[themed]

3
core/src/main/resources/com/github/weisj/darklaf/theme/intellij/intellij_mac.properties

@ -23,7 +23,8 @@
#
ComboBox.arrowBackgroundStart = 68B2FA
ComboBox.arrowBackgroundEnd = 0E80FF
ComboBox.arrow.icon = navigation/arrowDownSelected.svg[themed]
ComboBox.arrow.icon = navigation/arrowDown.svg[themed]
ComboBox.arrowEditable.icon = navigation/arrowDownSelected.svg[themed]
Spinner.arrowBackgroundStart = 68B2FA
Spinner.arrowBackgroundEnd = 0E80FF

Loading…
Cancel
Save