From 26c77b31187e19857fb1418c22345028abd56776 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 15 May 2020 11:32:53 +0200 Subject: [PATCH] Button, ComboBox, TextField and DatePicker UI delegates now get Component.focusWidth and Button.arc/Component.arc/TextComponent.arc from component border --- .../com/formdev/flatlaf/ui/FlatButtonUI.java | 34 ++++--------------- .../formdev/flatlaf/ui/FlatComboBoxUI.java | 13 +++---- .../flatlaf/ui/FlatPasswordFieldUI.java | 14 +++----- .../formdev/flatlaf/ui/FlatScrollPaneUI.java | 2 +- .../com/formdev/flatlaf/ui/FlatSpinnerUI.java | 18 ++++------ .../formdev/flatlaf/ui/FlatTextFieldUI.java | 24 +++++-------- .../flatlaf/ui/FlatToggleButtonUI.java | 7 +--- .../com/formdev/flatlaf/ui/FlatUIUtils.java | 21 ++++++++++++ .../flatlaf/ui/MigLayoutVisualPadding.java | 12 ++++--- .../flatlaf/swingx/ui/FlatDatePickerUI.java | 12 ++----- .../flatlaf/testing/FlatComponentsTest.java | 28 --------------- .../flatlaf/testing/FlatComponentsTest.jfd | 32 ----------------- 12 files changed, 64 insertions(+), 153 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java index a3001f6e..10b9ee82 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java @@ -39,7 +39,6 @@ import javax.swing.JToggleButton; import javax.swing.JToolBar; import javax.swing.LookAndFeel; import javax.swing.UIManager; -import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicButtonListener; @@ -61,8 +60,6 @@ import com.formdev.flatlaf.util.UIScale; * * * - * @uiDefault Component.focusWidth int - * @uiDefault Button.arc int * @uiDefault Button.minimumWidth int * @uiDefault Button.iconTextGap int * @uiDefault Button.startBackground Color optional; if set, a gradient paint is used and Button.background is ignored @@ -92,8 +89,6 @@ import com.formdev.flatlaf.util.UIScale; public class FlatButtonUI extends BasicButtonUI { - protected int focusWidth; - protected int arc; protected int minimumWidth; protected int iconTextGap; @@ -139,8 +134,6 @@ public class FlatButtonUI if( !defaults_initialized ) { String prefix = getPropertyPrefix(); - focusWidth = UIManager.getInt( "Component.focusWidth" ); - arc = UIManager.getInt( "Button.arc" ); minimumWidth = UIManager.getInt( prefix + "minimumWidth" ); iconTextGap = FlatUIUtils.getUIInt( prefix + "iconTextGap", 4 ); @@ -187,7 +180,7 @@ public class FlatButtonUI LookAndFeel.installProperty( b, "opaque", false ); LookAndFeel.installProperty( b, "iconTextGap", scale( iconTextGap ) ); - MigLayoutVisualPadding.install( b, getFocusWidth( b ) ); + MigLayoutVisualPadding.install( b ); } @Override @@ -279,20 +272,9 @@ public class FlatButtonUI try { FlatUIUtils.setRenderingHints( g2 ); - Border border = c.getBorder(); - int buttonType = FlatButtonUI.getButtonType( c ); boolean isToolBarButton = isToolBarButton( c ); - float focusWidth = (border instanceof FlatBorder && !isToolBarButton) ? scale( (float) getFocusWidth( c ) ) : 0; - float arc; - - if( buttonType == TYPE_SQUARE ) - arc = 0; - else if( buttonType == TYPE_ROUND_RECT ) - arc = Float.MAX_VALUE; - else if( border instanceof FlatButtonBorder || isToolBarButton ) - arc = scale( (float) this.arc ); - else - arc = 0; + float focusWidth = isToolBarButton ? 0 : FlatUIUtils.getBorderFocusWidth( c ); + float arc = FlatUIUtils.getBorderArc( c ); boolean def = isDefaultButton( c ); @@ -426,15 +408,11 @@ public class FlatButtonUI if( isIconOnlyButton( c ) ) prefSize.width = Math.max( prefSize.width, prefSize.height ); else if( !isToolBarButton( c ) && c.getBorder() instanceof FlatButtonBorder ) { - int focusWidth = getFocusWidth( c ); - prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) + (focusWidth * 2) ) ); - prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) + (focusWidth * 2) ) ); + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + prefSize.width = Math.max( prefSize.width, scale( FlatUIUtils.minimumWidth( c, minimumWidth ) ) + Math.round( focusWidth * 2 ) ); + prefSize.height = Math.max( prefSize.height, scale( FlatUIUtils.minimumHeight( c, 0 ) ) + Math.round( focusWidth * 2 ) ); } return prefSize; } - - protected int getFocusWidth( JComponent c ) { - return focusWidth; - } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 97204d54..dba17cc0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -76,8 +76,6 @@ import com.formdev.flatlaf.util.UIScale; * * * - * @uiDefault Component.focusWidth int - * @uiDefault Component.arc int * @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.borderColor Color @@ -96,8 +94,6 @@ import com.formdev.flatlaf.util.UIScale; public class FlatComboBoxUI extends BasicComboBoxUI { - protected int focusWidth; - protected int arc; protected String arrowType; protected boolean isIntelliJTheme; protected Color borderColor; @@ -150,8 +146,6 @@ public class FlatComboBoxUI LookAndFeel.installProperty( comboBox, "opaque", false ); - focusWidth = UIManager.getInt( "Component.focusWidth" ); - arc = UIManager.getInt( "Component.arc" ); arrowType = UIManager.getString( "Component.arrowType" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); borderColor = UIManager.getColor( "Component.borderColor" ); @@ -170,7 +164,7 @@ public class FlatComboBoxUI // scale padding = UIScale.scale( padding ); - MigLayoutVisualPadding.install( comboBox, focusWidth ); + MigLayoutVisualPadding.install( comboBox ); } @Override @@ -318,6 +312,9 @@ public class FlatComboBoxUI @Override public void update( Graphics g, JComponent c ) { + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + float arc = FlatUIUtils.getBorderArc( c ); + // fill background if opaque to avoid garbage if user sets opaque to true if( c.isOpaque() && (focusWidth > 0 || arc > 0) ) FlatUIUtils.paintParentBackground( g, c ); @@ -327,8 +324,6 @@ public class FlatComboBoxUI int width = c.getWidth(); int height = c.getHeight(); - float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0; - float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0; int arrowX = arrowButton.getX(); int arrowWidth = arrowButton.getWidth(); boolean enabled = comboBox.isEnabled(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java index adb1d707..5949d19b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java @@ -57,8 +57,6 @@ import com.formdev.flatlaf.FlatClientProperties; * * * - * @uiDefault TextComponent.arc int - * @uiDefault Component.focusWidth int * @uiDefault Component.minimumWidth int * @uiDefault Component.isIntelliJTheme boolean * @uiDefault PasswordField.placeholderForeground Color @@ -70,8 +68,6 @@ import com.formdev.flatlaf.FlatClientProperties; public class FlatPasswordFieldUI extends BasicPasswordFieldUI { - protected int arc; - protected int focusWidth; protected int minimumWidth; protected boolean isIntelliJTheme; protected Color placeholderForeground; @@ -89,8 +85,6 @@ public class FlatPasswordFieldUI super.installDefaults(); String prefix = getPropertyPrefix(); - arc = UIManager.getInt( "TextComponent.arc" ); - focusWidth = UIManager.getInt( "Component.focusWidth" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); @@ -98,7 +92,7 @@ public class FlatPasswordFieldUI LookAndFeel.installProperty( getComponent(), "opaque", false ); - MigLayoutVisualPadding.install( getComponent(), focusWidth ); + MigLayoutVisualPadding.install( getComponent() ); } @Override @@ -160,7 +154,7 @@ public class FlatPasswordFieldUI @Override protected void paintSafely( Graphics g ) { - FlatTextFieldUI.paintBackground( g, getComponent(), focusWidth, arc, isIntelliJTheme ); + FlatTextFieldUI.paintBackground( g, getComponent(), isIntelliJTheme ); FlatTextFieldUI.paintPlaceholder( g, getComponent(), placeholderForeground ); paintCapsLock( g ); super.paintSafely( g ); @@ -194,8 +188,8 @@ public class FlatPasswordFieldUI private Dimension applyMinimumWidth( Dimension size, JComponent c ) { int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth ); - int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0; - size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) ); + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + size.width = Math.max( size.width, scale( minimumWidth ) + Math.round( focusWidth * 2 ) ); return size; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java index 1a118dbb..5c0b72aa 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollPaneUI.java @@ -83,7 +83,7 @@ public class FlatScrollPaneUI int focusWidth = UIManager.getInt( "Component.focusWidth" ); LookAndFeel.installProperty( c, "opaque", focusWidth == 0 ); - MigLayoutVisualPadding.install( scrollpane, focusWidth ); + MigLayoutVisualPadding.install( scrollpane ); } @Override diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java index 8c0e20ee..a67ed692 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java @@ -56,8 +56,6 @@ import javax.swing.plaf.basic.BasicSpinnerUI; * * * - * @uiDefault Component.focusWidth int - * @uiDefault Component.arc int * @uiDefault Component.minimumWidth int * @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.isIntelliJTheme boolean @@ -78,8 +76,6 @@ public class FlatSpinnerUI { private Handler handler; - protected int focusWidth; - protected int arc; protected int minimumWidth; protected String arrowType; protected boolean isIntelliJTheme; @@ -103,8 +99,6 @@ public class FlatSpinnerUI LookAndFeel.installProperty( spinner, "opaque", false ); - focusWidth = UIManager.getInt( "Component.focusWidth" ); - arc = UIManager.getInt( "Component.arc" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" ); arrowType = UIManager.getString( "Component.arrowType" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); @@ -121,7 +115,7 @@ public class FlatSpinnerUI // scale padding = scale( padding ); - MigLayoutVisualPadding.install( spinner, focusWidth ); + MigLayoutVisualPadding.install( spinner ); } @Override @@ -246,8 +240,11 @@ public class FlatSpinnerUI @Override public void update( Graphics g, JComponent c ) { + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + float arc = FlatUIUtils.getBorderArc( c ); + // fill background if opaque to avoid garbage if user sets opaque to true - if( c.isOpaque() && (focusWidth > 0 || arc != 0) ) + if( c.isOpaque() && (focusWidth > 0 || arc > 0) ) FlatUIUtils.paintParentBackground( g, c ); Graphics2D g2 = (Graphics2D) g; @@ -255,8 +252,6 @@ public class FlatSpinnerUI int width = c.getWidth(); int height = c.getHeight(); - float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0; - float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0; Component nextButton = getHandler().nextButton; int arrowX = nextButton.getX(); int arrowWidth = nextButton.getWidth(); @@ -328,8 +323,9 @@ public class FlatSpinnerUI // the arrows width is the same as the inner height so that the arrows area is square int minimumWidth = FlatUIUtils.minimumWidth( spinner, FlatSpinnerUI.this.minimumWidth ); int innerHeight = editorSize.height + padding.top + padding.bottom; + float focusWidth = FlatUIUtils.getBorderFocusWidth( spinner ); return new Dimension( - Math.max( insets.left + insets.right + editorSize.width + padding.left + padding.right + innerHeight, scale( minimumWidth + (focusWidth * 2) ) ), + Math.max( insets.left + insets.right + editorSize.width + padding.left + padding.right + innerHeight, scale( minimumWidth ) + Math.round( focusWidth * 2 ) ), insets.top + insets.bottom + innerHeight ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java index 1f5173b3..03795eae 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java @@ -60,8 +60,6 @@ import com.formdev.flatlaf.FlatClientProperties; * * * - * @uiDefault TextComponent.arc int - * @uiDefault Component.focusWidth int * @uiDefault Component.minimumWidth int * @uiDefault Component.isIntelliJTheme boolean * @uiDefault TextField.placeholderForeground Color @@ -72,8 +70,6 @@ import com.formdev.flatlaf.FlatClientProperties; public class FlatTextFieldUI extends BasicTextFieldUI { - protected int arc; - protected int focusWidth; protected int minimumWidth; protected boolean isIntelliJTheme; protected Color placeholderForeground; @@ -89,15 +85,13 @@ public class FlatTextFieldUI super.installDefaults(); String prefix = getPropertyPrefix(); - arc = UIManager.getInt( "TextComponent.arc" ); - focusWidth = UIManager.getInt( "Component.focusWidth" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); placeholderForeground = UIManager.getColor( prefix + ".placeholderForeground" ); LookAndFeel.installProperty( getComponent(), "opaque", false ); - MigLayoutVisualPadding.install( getComponent(), focusWidth ); + MigLayoutVisualPadding.install( getComponent() ); } @Override @@ -140,7 +134,7 @@ public class FlatTextFieldUI @Override protected void paintSafely( Graphics g ) { - paintBackground( g, getComponent(), focusWidth, arc, isIntelliJTheme ); + paintBackground( g, getComponent(), isIntelliJTheme ); paintPlaceholder( g, getComponent(), placeholderForeground ); super.paintSafely( g ); } @@ -150,7 +144,7 @@ public class FlatTextFieldUI // background is painted elsewhere } - static void paintBackground( Graphics g, JTextComponent c, int focusWidth, int arc, boolean isIntelliJTheme ) { + static void paintBackground( Graphics g, JTextComponent c, boolean isIntelliJTheme ) { Border border = c.getBorder(); // do not paint background if: @@ -161,6 +155,9 @@ public class FlatTextFieldUI if( !c.isOpaque() && !(border instanceof FlatBorder) && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) ) return; + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + float arc = FlatUIUtils.getBorderArc( c ); + // fill background if opaque to avoid garbage if user sets opaque to true if( c.isOpaque() && (focusWidth > 0 || arc > 0) ) FlatUIUtils.paintParentBackground( g, c ); @@ -170,16 +167,13 @@ public class FlatTextFieldUI try { FlatUIUtils.setRenderingHints( g2 ); - float fFocusWidth = (border instanceof FlatBorder) ? scale( (float) focusWidth ) : 0; - float fArc = (border instanceof FlatTextBorder) ? scale( (float) arc ) : 0; - Color background = c.getBackground(); g2.setColor( !(background instanceof UIResource) ? background : (isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) ? FlatUIUtils.getParentBackground( c ) : background) ); - FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, fArc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc ); } finally { g2.dispose(); } @@ -232,8 +226,8 @@ public class FlatTextFieldUI return size; int minimumWidth = FlatUIUtils.minimumWidth( getComponent(), this.minimumWidth ); - int focusWidth = (c.getBorder() instanceof FlatBorder) ? this.focusWidth : 0; - size.width = Math.max( size.width, scale( minimumWidth + (focusWidth * 2) ) ); + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + size.width = Math.max( size.width, scale( minimumWidth ) + Math.round( focusWidth * 2 ) ); return size; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java index c664a7dd..2fb12278 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java @@ -138,7 +138,7 @@ public class FlatToggleButtonUI case BUTTON_TYPE: if( BUTTON_TYPE_TAB.equals( e.getOldValue() ) || BUTTON_TYPE_TAB.equals( e.getNewValue() ) ) { MigLayoutVisualPadding.uninstall( b ); - MigLayoutVisualPadding.install( b, getFocusWidth( b ) ); + MigLayoutVisualPadding.install( b ); b.revalidate(); } @@ -212,9 +212,4 @@ public class FlatToggleButtonUI return super.getForeground( c ); } - - @Override - protected int getFocusWidth( JComponent c ) { - return isTabButton( c ) ? 0 : super.getFocusWidth( c ); - } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java index 15b3a413..91c34d82 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java @@ -39,6 +39,7 @@ import java.util.function.Consumer; import javax.swing.JComponent; import javax.swing.LookAndFeel; import javax.swing.UIManager; +import javax.swing.border.Border; import javax.swing.plaf.UIResource; import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.util.DerivedColor; @@ -142,6 +143,26 @@ public class FlatUIUtils return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == c); } + /** + * Returns the scaled thickness of the outer focus border for the given component. + */ + public static float getBorderFocusWidth( JComponent c ) { + Border border = c.getBorder(); + return (border instanceof FlatBorder) + ? UIScale.scale( (float) ((FlatBorder)border).getFocusWidth( c ) ) + : 0; + } + + /** + * Returns the scaled arc diameter of the border for the given component. + */ + public static float getBorderArc( JComponent c ) { + Border border = c.getBorder(); + return (border instanceof FlatBorder) + ? UIScale.scale( (float) ((FlatBorder)border).getArc( c ) ) + : 0; + } + /** * Sets rendering hints used for painting. */ diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/MigLayoutVisualPadding.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/MigLayoutVisualPadding.java index 3d6c1d47..ddb8c044 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/MigLayoutVisualPadding.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/MigLayoutVisualPadding.java @@ -21,6 +21,7 @@ import java.awt.Insets; import java.beans.PropertyChangeListener; import java.util.function.Function; import javax.swing.JComponent; +import javax.swing.border.Border; /** * Support for MigLayout visual paddings. @@ -69,14 +70,17 @@ public class MigLayoutVisualPadding /** * Convenience method that checks whether component border is a FlatBorder. */ - public static void install( JComponent c, int focusWidth ) { + public static void install( JComponent c ) { if( !migLayoutAvailable ) return; install( c, c2 -> { - return (c2.getBorder() instanceof FlatBorder) - ? new Insets( focusWidth, focusWidth, focusWidth, focusWidth ) - : null; + Border border = c2.getBorder(); + if( border instanceof FlatBorder ) { + int focusWidth = ((FlatBorder)border).getFocusWidth( c2 ); + return new Insets( focusWidth, focusWidth, focusWidth, focusWidth ); + } else + return null; }, "border" ); } diff --git a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java index 5bff5639..27ada24a 100644 --- a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java +++ b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java @@ -46,8 +46,6 @@ import org.jdesktop.swingx.JXPanel; import org.jdesktop.swingx.calendar.DatePickerFormatter.DatePickerFormatterUIResource; import org.jdesktop.swingx.plaf.basic.BasicDatePickerUI; import com.formdev.flatlaf.ui.FlatArrowButton; -import com.formdev.flatlaf.ui.FlatBorder; -import com.formdev.flatlaf.ui.FlatRoundBorder; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.ui.MigLayoutVisualPadding; import com.formdev.flatlaf.util.UIScale; @@ -62,8 +60,6 @@ public class FlatDatePickerUI { protected Insets padding; - protected int focusWidth; - protected int arc; protected String arrowType; protected Color borderColor; protected Color disabledBorderColor; @@ -88,8 +84,6 @@ public class FlatDatePickerUI padding = UIManager.getInsets( "ComboBox.padding" ); - focusWidth = UIManager.getInt( "Component.focusWidth" ); - arc = UIManager.getInt( "Component.arc" ); arrowType = UIManager.getString( "Component.arrowType" ); borderColor = UIManager.getColor( "Component.borderColor" ); disabledBorderColor = UIManager.getColor( "Component.disabledBorderColor" ); @@ -130,7 +124,7 @@ public class FlatDatePickerUI LookAndFeel.installBorder( datePicker, "JXDatePicker.border" ); LookAndFeel.installProperty( datePicker, "opaque", Boolean.TRUE ); - MigLayoutVisualPadding.install( datePicker, focusWidth ); + MigLayoutVisualPadding.install( datePicker ); } @Override @@ -228,8 +222,8 @@ public class FlatDatePickerUI int width = c.getWidth(); int height = c.getHeight(); - float focusWidth = (c.getBorder() instanceof FlatBorder) ? scale( (float) this.focusWidth ) : 0; - float arc = (c.getBorder() instanceof FlatRoundBorder) ? scale( (float) this.arc ) : 0; + float focusWidth = FlatUIUtils.getBorderFocusWidth( c ); + float arc = FlatUIUtils.getBorderArc( c ); int arrowX = popupButton.getX(); int arrowWidth = popupButton.getWidth(); boolean enabled = c.isEnabled(); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java index 2077bfe4..94c25002 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java @@ -83,8 +83,6 @@ public class FlatComponentsTest JButton button15 = new JButton(); JButton button16 = new JButton(); JButton button20 = new JButton(); - JButton button24 = new JButton(); - JButton button25 = new JButton(); JLabel toggleButtonLabel = new JLabel(); JToggleButton toggleButton1 = new JToggleButton(); JToggleButton toggleButton9 = new JToggleButton(); @@ -99,8 +97,6 @@ public class FlatComponentsTest JToggleButton toggleButton13 = new JToggleButton(); JToggleButton toggleButton14 = new JToggleButton(); JToggleButton toggleButton18 = new JToggleButton(); - JToggleButton toggleButton21 = new JToggleButton(); - JToggleButton toggleButton22 = new JToggleButton(); JLabel checkBoxLabel = new JLabel(); JCheckBox checkBox1 = new JCheckBox(); JCheckBox checkBox2 = new JCheckBox(); @@ -375,18 +371,6 @@ public class FlatComponentsTest button20.setBorder(BorderFactory.createEmptyBorder()); add(button20, "cell 6 1"); - //---- button24 ---- - button24.setText("sq"); - button24.setBorder(BorderFactory.createEmptyBorder()); - button24.putClientProperty("JButton.buttonType", "square"); - add(button24, "cell 6 1"); - - //---- button25 ---- - button25.setText("rd"); - button25.setBorder(new EmptyBorder(0, 10, 0, 10)); - button25.putClientProperty("JButton.buttonType", "roundRect"); - add(button25, "cell 6 1"); - //---- toggleButtonLabel ---- toggleButtonLabel.setText("JToggleButton:"); add(toggleButtonLabel, "cell 0 2"); @@ -458,18 +442,6 @@ public class FlatComponentsTest toggleButton18.setBorder(BorderFactory.createEmptyBorder()); add(toggleButton18, "cell 6 2"); - //---- toggleButton21 ---- - toggleButton21.setText("sq"); - toggleButton21.setBorder(BorderFactory.createEmptyBorder()); - toggleButton21.putClientProperty("JButton.buttonType", "square"); - add(toggleButton21, "cell 6 2"); - - //---- toggleButton22 ---- - toggleButton22.setText("rd"); - toggleButton22.setBorder(new EmptyBorder(0, 10, 0, 10)); - toggleButton22.putClientProperty("JButton.buttonType", "roundRect"); - add(toggleButton22, "cell 6 2"); - //---- checkBoxLabel ---- checkBoxLabel.setText("JCheckBox"); add(checkBoxLabel, "cell 0 3"); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd index 4cfda44b..94520f0b 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.jfd @@ -144,22 +144,6 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 6 1" } ) - add( new FormComponent( "javax.swing.JButton" ) { - name: "button24" - "text": "sq" - "border": #EmptyBorder0 - "$client.JButton.buttonType": "square" - }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 6 1" - } ) - add( new FormComponent( "javax.swing.JButton" ) { - name: "button25" - "text": "rd" - "border": &EmptyBorder1 new javax.swing.border.EmptyBorder( 0, 10, 0, 10 ) - "$client.JButton.buttonType": "roundRect" - }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 6 1" - } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "toggleButtonLabel" "text": "JToggleButton:" @@ -259,22 +243,6 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 6 2" } ) - add( new FormComponent( "javax.swing.JToggleButton" ) { - name: "toggleButton21" - "text": "sq" - "border": #EmptyBorder0 - "$client.JButton.buttonType": "square" - }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 6 2" - } ) - add( new FormComponent( "javax.swing.JToggleButton" ) { - name: "toggleButton22" - "text": "rd" - "border": #EmptyBorder1 - "$client.JButton.buttonType": "roundRect" - }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 6 2" - } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "checkBoxLabel" "text": "JCheckBox"