diff --git a/core/src/main/java/com/github/weisj/darklaf/components/color/SmallColorChooser.java b/core/src/main/java/com/github/weisj/darklaf/components/color/SmallColorChooser.java index 7e33d953..0e0699fe 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/color/SmallColorChooser.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/color/SmallColorChooser.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.function.Consumer; import javax.swing.*; +import javax.swing.border.Border; import com.github.weisj.darklaf.color.DarkColorModel; import com.github.weisj.darklaf.color.DarkColorModelHSB; @@ -34,6 +35,7 @@ import com.github.weisj.darklaf.color.DarkColorModelHSL; import com.github.weisj.darklaf.color.DarkColorModelRGB; import com.github.weisj.darklaf.components.DefaultColorPipette; import com.github.weisj.darklaf.components.border.DarkBorders; +import com.github.weisj.darklaf.components.border.MarginBorderWrapper; import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.listener.UpdateDocumentListener; import com.github.weisj.darklaf.ui.button.DarkButtonUI; @@ -167,7 +169,8 @@ public class SmallColorChooser extends JPanel { JPanel hexFieldHolder = new JPanel(new GridBagLayout()); hexFieldHolder.setOpaque(false); Box hexBox = Box.createHorizontalBox(); - hexBox.add(new JLabel("#")); + JLabel label = new JLabel("#"); + hexBox.add(label); hexBox.add(createHexField()); hexFieldHolder.add(hexBox); @@ -206,6 +209,7 @@ public class SmallColorChooser extends JPanel { protected JComponent createHexField() { hexField = new JFormattedTextField(); hexField.setColumns(6); + hexField.setMargin(new Insets(2, 2, 2, 2)); hexField.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); hexFormatter = ColorValueFormatter.init(null, 0, true, hexField); hexFormatter.setModel(getDarkColorModel()); @@ -296,13 +300,16 @@ public class SmallColorChooser extends JPanel { return getPreferredSize(); } - @SuppressWarnings("SuspiciousNameCombination") @Override public Dimension getPreferredSize() { - Dimension size = hexField.getPreferredSize(); - size.width = size.height - 2 * UIManager.getInt("TextField.borderThickness"); - size.height = size.width; - return size; + Dimension dim = hexField.getPreferredSize(); + Border border = MarginBorderWrapper.getBorder(hexField); + Insets ins = border != null ? border.getBorderInsets(hexField) : null; + int size = dim.height; + if (ins != null) size -= ins.top + ins.bottom; + dim.width = size; + dim.height = size; + return dim; } }; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java index 347fc7c5..be5d0429 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java @@ -23,6 +23,7 @@ package com.github.weisj.darklaf.ui.colorchooser; import java.awt.*; import java.beans.PropertyChangeListener; +import java.util.List; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; @@ -35,6 +36,7 @@ import com.github.weisj.darklaf.color.DarkColorModelCMYK; import com.github.weisj.darklaf.color.DarkColorModelHSB; import com.github.weisj.darklaf.color.DarkColorModelHSL; import com.github.weisj.darklaf.color.DarkColorModelRGB; +import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.listener.AncestorAdapter; import com.github.weisj.darklaf.util.PropertyKey; @@ -67,6 +69,10 @@ public class DarkColorChooserUI extends BasicColorChooserUI { ((Dialog) win).setResizable(false); chooser.removeAncestorListener(ancestorListener); } + List imageList = win.getIconImages(); + if (imageList == null || imageList.isEmpty()) { + win.setIconImage(IconLoader.createFrameIcon(UIManager.getIcon("ColorChooser.icon"), win)); + } } }; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java index 65bfe292..528045d4 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java @@ -90,7 +90,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { } private boolean isOverEye(final Point p) { - return !passwordEmpty() && DarkTextFieldUI.isOver(getRightIconCoord(), getShowIcon(editor), p); + return !passwordEmpty() && DarkTextFieldUI.isOver(getRightIconPos(), getShowIcon(editor), p); } protected boolean passwordEmpty() { diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java index ff97de52..6bcdbbc5 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java @@ -25,6 +25,7 @@ import java.awt.*; import javax.swing.*; import javax.swing.border.Border; +import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.UIResource; import javax.swing.text.JTextComponent; @@ -47,8 +48,6 @@ public class DarkTextBorder implements Border, UIResource { protected final Color inactiveBorderColor; protected final Color inactiveFocusBorderColor; - protected Insets padding; - protected final int borderSize; protected final int arc; protected final int searchArc; @@ -69,8 +68,6 @@ public class DarkTextBorder implements Border, UIResource { focusArc = UIManager.getInt("TextField.focusArc"); searchArc = UIManager.getInt("TextField.searchArc"); searchFocusArc = UIManager.getInt("TextField.searchFocusArc"); - padding = UIManager.getInsets("TextField.insets"); - if (padding == null) padding = new Insets(0, 0, 0, 0); } protected static boolean hasError(final Component c) { @@ -147,7 +144,7 @@ public class DarkTextBorder implements Border, UIResource { @Override public Insets getBorderInsets(final Component c) { - return DarkUIUtil.addInsets(new Insets(borderSize, borderSize, borderSize, borderSize), padding); + return new InsetsUIResource(borderSize, borderSize, borderSize, borderSize); } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java index b479a7c7..25f15983 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java @@ -63,7 +63,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh protected Color inactiveBackground; private long lastSearchEvent; - protected Insets padding; + private int buttonPad; private final PopupMenuListener searchPopupListener = new PopupMenuAdapter() { @Override @@ -118,9 +118,8 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh protected Dimension addIconSizes(final Dimension dim) { JTextComponent comp = getComponent(); - boolean ltr = comp.getComponentOrientation().isLeftToRight(); - int leftPad = ltr ? padding.left : padding.right; - int rightPad = ltr ? padding.right : padding.left; + int leftPad = buttonPad; + int rightPad = buttonPad; if (doPaintLeftIcon(comp)) { Icon left = getLeftIcon(comp); dim.width += left.getIconWidth() + leftPad; @@ -157,12 +156,12 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh protected void adjustTextRect(final JTextComponent c, final Rectangle r) { boolean ltr = c.getComponentOrientation().isLeftToRight(); if (doPaintLeftIcon(c)) { - int w = getLeftIcon(c).getIconWidth() + padding.left; + int w = getLeftIcon(c).getIconWidth() + buttonPad; if (ltr) r.x += w; r.width -= w; } if (doPaintRightIcon(c)) { - int w = getRightIcon(c).getIconWidth() + padding.right; + int w = getRightIcon(c).getIconWidth() + buttonPad; if (!ltr) r.x += w; r.width -= w; } @@ -192,10 +191,10 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh protected ClickAction getActionUnder(final Point p) { JTextComponent c = getComponent(); if (!c.isEnabled()) return ClickAction.NONE; - if (isOver(getRightIconCoord(), getRightIcon(c), p) && doPaintRightIcon(c)) { + if (isOver(getRightIconPos(), getRightIcon(c), p) && doPaintRightIcon(c)) { return ClickAction.RIGHT_ACTION; } - if (isOver(getLeftIconCoord(), getLeftIcon(c), p) && doPaintLeftIcon(c)) { + if (isOver(getLeftIconPos(), getLeftIcon(c), p) && doPaintLeftIcon(c)) { return ClickAction.LEFT_ACTION; } return ClickAction.NONE; @@ -240,35 +239,43 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh } protected void paintRightIcon(final Graphics g) { - Point p = getRightIconCoord(); + Point p = getRightIconPos(); getRightIcon(editor).paintIcon(null, g, p.x, p.y); } protected void paintLeftIcon(final Graphics g) { - Point p = getLeftIconCoord(); + Point p = getLeftIconPos(); getLeftIcon(editor).paintIcon(null, g, p.x, p.y); } - protected Point getLeftIconCoord() { + protected Point getLeftIconPos() { Rectangle r = getDrawingRect(getComponent()); - int w = getLeftIcon(getComponent()).getIconWidth(); - int left = getBorderInsets(getComponent()).left + padding.left; - return DarkUIUtil.adjustForOrientation(new Point(r.x + left, r.y + (r.height - w) / 2), w, editor); + int iconSize = getLeftIcon(getComponent()).getIconWidth(); + int y = getIconY(r, iconSize); + return DarkUIUtil.adjustForOrientation(new Point(r.x + buttonPad, y), iconSize, editor); } - protected Point getRightIconCoord() { + private int getIconY(final Rectangle r, final int iconSize) { + int contentHeight = r.height; + Insets margin = editor.getMargin(); + if (margin != null) contentHeight -= margin.top + margin.bottom; + int y = r.y + (contentHeight - iconSize) / 2; + if (margin != null) y += margin.top; + return y; + } + + protected Point getRightIconPos() { Rectangle r = getDrawingRect(getComponent()); - int w = getRightIcon(getComponent()).getIconWidth(); - int right = getBorderInsets(getComponent()).right + padding.right; - return DarkUIUtil.adjustForOrientation(new Point(r.x + r.width - w - right, r.y + (r.height - w) / 2), w, - editor); + int iconSize = getRightIcon(getComponent()).getIconWidth(); + int y = getIconY(r, iconSize); + return DarkUIUtil.adjustForOrientation(new Point(r.x + r.width - iconSize - buttonPad, y), iconSize, editor); } protected void showSearchPopup() { if (lastSearchEvent == 0 || (System.currentTimeMillis() - lastSearchEvent) > 250) { JPopupMenu menu = getSearchPopup(getComponent()); if (menu != null) { - menu.show(getComponent(), getLeftIconCoord().x, getComponent().getHeight()); + menu.show(getComponent(), getLeftIconPos().x, getComponent().getHeight()); } } } @@ -291,8 +298,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh searchWithHistoryDisabled = UIManager.getIcon("TextField.search.searchWithHistory.disabled.icon"); search = UIManager.getIcon("TextField.search.search.icon"); searchDisabled = UIManager.getIcon("TextField.search.search.disabled.icon"); - padding = UIManager.getInsets("TextField.insets"); - if (padding == null) padding = new Insets(0, 0, 0, 0); + buttonPad = UIManager.getInt("TextField.iconPad"); } @Override diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java index a6b9502e..be80f94d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java @@ -112,10 +112,18 @@ public abstract class DarkTextUI extends BasicTextUI disabledColor = UIManager.getColor(getPropertyPrefix() + ".disabledBackground"); inactiveColor = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground"); + installMargins(); installBorder(); installPopupMenu(); } + protected void installMargins() { + Insets margin = editor.getMargin(); + if (margin == null || margin instanceof UIResource) { + editor.setMargin(UIManager.getInsets(getPropertyPrefix() + ".margins")); + } + } + public static boolean isBorderlessTextField(final JTextComponent textComponent) { if (textComponent == null) return false; String className = textComponent.getClass().getName(); @@ -365,15 +373,11 @@ public abstract class DarkTextUI extends BasicTextUI if (b == null) { return new Insets(0, 0, 0, 0); } - if (b instanceof DarkTextBorder) { - int bs = ((DarkTextBorder) b).getBorderSize(); - return new Insets(bs, bs, bs, bs); - } return b.getBorderInsets(c); } public Rectangle getDrawingRect(final JTextComponent c) { - return DarkUIUtil.applyInsets(new Rectangle(0, 0, c.getWidth(), c.getHeight()), getBorderInsets(c)); + return DarkUIUtil.applyInsets(new Rectangle(c.getWidth(), c.getHeight()), getBorderInsets(c)); } protected void installDarkKeyBoardActions() { diff --git a/core/src/main/resources/com/github/weisj/darklaf/icons/menu/colorChooser.svg b/core/src/main/resources/com/github/weisj/darklaf/icons/menu/colorChooser.svg new file mode 100644 index 00000000..9763bc02 --- /dev/null +++ b/core/src/main/resources/com/github/weisj/darklaf/icons/menu/colorChooser.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/icons/menu.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/icons/menu.properties index 47d7f110..e34b8499 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/icons/menu.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/icons/menu.properties @@ -50,3 +50,4 @@ Icons.themeSettings.color = %menuIconEnabled Icons.Help.color = %menuIconEnabled Icons.HelpHighlight.color = %questionIconColor Icons.HelpDisabled.color = %menuIconDisabled +Icons.colorChooser.color = %menuIconEnabled diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties index 425686f7..37cd0eb5 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/button.properties @@ -50,8 +50,8 @@ Button.borderThickness = %borderThickness Button.shadowHeight = %shadowHeight Button.borderInsets = 5,14,5,14 -Button.thinBorderInsets = 2,6,2,6 -Button.squareThinBorderInsets = 2,2,2,2 +Button.thinBorderInsets = 3,6,3,6 +Button.squareThinBorderInsets = 3,3,3,3 Button.squareBorderInsets = 5,5,5,5 Button.borderlessRectangularInsets = 0,0,0,0 diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/colorChooser.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/colorChooser.properties index fe66e627..a4379304 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/colorChooser.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/colorChooser.properties @@ -46,5 +46,6 @@ ColorChooser.innerIndicatorRadius = 3 ColorChooser.background = %background #Icons +ColorChooser.icon = menu/colorChooser.svg ColorChooser.pipette.icon = misc/pipette.svg[themed] ColorChooser.pipetteRollover.icon = misc/pipetteRollover.svg[themed] diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties index fd606a43..bd264c5d 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/text.properties @@ -28,10 +28,6 @@ TextComponent.roundedSelection = true TextComponent.selectionBackground = %textCompSelectionBackground TextComponent.selectionForeground = %textCompSelectionForeground -EditorPaneUI = com.github.weisj.darklaf.ui.text.DarkEditorPaneUI -TextPaneUI = com.github.weisj.darklaf.ui.text.DarkTextPaneUI -TextAreaUI = com.github.weisj.darklaf.ui.text.DarkTextAreaUI - TextFieldUI = com.github.weisj.darklaf.ui.text.DarkTextFieldUI TextField.border = com.github.weisj.darklaf.ui.text.DarkTextBorder TextField.border.enabled = %widgetBorder @@ -49,14 +45,16 @@ TextField.selectionBackground = %textCompSelectionBackground TextField.selectionForeground = %textCompSelectionForeground TextField.keepSelectionOnFocusLost = true TextField.extendSelection = false +TextField.iconPad = 2 +TextField.margins = 4,4,4,4 TextField.arc = 0 TextField.focusArc = %arcSecondaryFocus TextField.searchArc = %arc TextField.searchFocusArc = %arcFocus TextField.borderThickness = %borderThickness -TextField.insets = 4,4,4,4 +TextPaneUI = com.github.weisj.darklaf.ui.text.DarkTextPaneUI TextPane.selectionBackground = %textCompSelectionBackground TextPane.selectionForeground = %textCompSelectionForeground TextPane.background = %textBackground @@ -65,8 +63,9 @@ TextPane.disabledBackground = %textBackgroundInactive TextPane.inactiveBackground = %textBackgroundInactive TextPane.border = com.github.weisj.darklaf.ui.text.DarkPlainTextBorder TextPane.extendSelection = true +TextPane.margins = 4,4,4,4 - +EditorPaneUI = com.github.weisj.darklaf.ui.text.DarkEditorPaneUI EditorPane.selectionBackground = %textCompSelectionBackground EditorPane.selectionForeground = %textCompSelectionForeground EditorPane.inactiveForeground = %textForegroundInactive @@ -75,8 +74,9 @@ EditorPane.disabledBackground = %textBackgroundInactive EditorPane.inactiveBackground = %textBackgroundInactive EditorPane.border = com.github.weisj.darklaf.ui.text.DarkPlainTextBorder EditorPane.extendSelection = true +EditorPane.margins = 4,4,4,4 - +TextAreaUI = com.github.weisj.darklaf.ui.text.DarkTextAreaUI TextArea.selectionBackground = %textCompSelectionBackground TextArea.selectionForeground = %textCompSelectionForeground TextArea.background = %textBackground @@ -84,6 +84,7 @@ TextArea.disabledBackground = %textBackgroundInactive TextArea.inactiveBackground = %textBackgroundInactive TextArea.border = com.github.weisj.darklaf.ui.text.DarkPlainTextBorder TextArea.extendSelection = false +TextArea.margins = 4,4,4,4 FormattedTextFieldUI = com.github.weisj.darklaf.ui.text.DarkFormattedTextFieldUI FormattedTextField.border = com.github.weisj.darklaf.ui.text.DarkTextBorder @@ -94,7 +95,7 @@ FormattedTextField.extendSelection = false FormattedTextField.selectionBackground = %textCompSelectionBackground FormattedTextField.selectionForeground = %textCompSelectionForeground - +FormattedTextField.margins = 4,4,4,4 PasswordFieldUI = com.github.weisj.darklaf.ui.text.DarkPasswordFieldUI PasswordField.background = %textBackground @@ -104,6 +105,7 @@ PasswordField.selectionBackground = %textCompSelectionBackground PasswordField.selectionForeground = %textCompSelectionForeground PasswordField.border = com.github.weisj.darklaf.ui.text.DarkTextBorder PasswordField.extendSelection = false +PasswordField.margins = 4,4,4,4 #Icons PasswordField.show.icon = misc/eye.svg[themed] diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java b/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java index 8a1d3dd2..6a3f36ac 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java @@ -189,7 +189,7 @@ public final class PropertyLoader { } Object returnVal = new LoadError(); - if (key.endsWith("Insets") || key.endsWith(".insets")) { + if (key.endsWith("Insets") || key.endsWith(".insets") || key.endsWith(".margins")) { returnVal = parseInsets(value, accumulator, currentDefaults, iconLoader); } else if (!skipObjects && (key.endsWith("Border") || key.endsWith(".border") || key.endsWith("Renderer"))) { return maybeWrap((UIDefaults.LazyValue) def -> parseObject(value), isFallback);