From d3ada57a50189a8ccc11591d22897ce61f8fbced Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 25 Sep 2019 11:17:17 +0200 Subject: [PATCH] UI inspector: show EmptyBorder insets --- .../com/formdev/flatlaf/FlatInspector.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java index 4198fc70..fa7d9def 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatInspector.java @@ -36,6 +36,7 @@ import javax.swing.JToolBar; import javax.swing.JToolTip; import javax.swing.SwingUtilities; import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import javax.swing.plaf.UIResource; import javax.swing.text.JTextComponent; @@ -186,10 +187,8 @@ public class FlatInspector "Class: " + c.getClass().getSimpleName() + " (" + c.getClass().getPackage().getName() + ")\n" + "Size: " + c.getWidth() + ',' + c.getHeight() + " @ " + c.getX() + ',' + c.getY() + '\n'; - if( c instanceof Container ) { - Insets i = ((Container)c).getInsets(); - text += "Insets: " + i.top + ',' + i.left + ',' + i.bottom + ',' + i.right + '\n'; - } + if( c instanceof Container ) + text += "Insets: " + toString( ((Container)c).getInsets() ) + '\n'; Insets margin = null; if( c instanceof AbstractButton ) @@ -202,7 +201,7 @@ public class FlatInspector margin = ((JToolBar) c).getMargin(); if( margin != null ) - text += "Margin: " + margin.top + ',' + margin.left + ',' + margin.bottom + ',' + margin.right + '\n'; + text += "Margin: " + toString( margin ) + '\n'; Dimension prefSize = c.getPreferredSize(); Dimension minSize = c.getMinimumSize(); @@ -211,10 +210,8 @@ public class FlatInspector "Min size: " + minSize.width + ',' + minSize.height + '\n' + "Max size: " + maxSize.width + ',' + maxSize.height + '\n'; - if( c instanceof JComponent ) { - Border border = ((JComponent)c).getBorder(); - text += "Border: " + (border != null ? border.getClass().getName() : "null") + '\n'; - } + if( c instanceof JComponent ) + text += "Border: " + toString( ((JComponent)c).getBorder() ) + '\n'; text += "Background: " + toString( c.getBackground() ) + '\n' + "Foreground: " + toString( c.getForeground() ) + '\n' + @@ -236,6 +233,13 @@ public class FlatInspector return text; } + private static String toString( Insets insets ) { + if( insets == null ) + return "null"; + + return insets.top + "," + insets.left + ',' + insets.bottom + ',' + insets.right; + } + private static String toString( Color c ) { if( c == null ) return "null"; @@ -253,4 +257,19 @@ public class FlatInspector return f.getFamily() + " " + f.getSize() + " " + f.getStyle() + (f instanceof UIResource ? " UI" : ""); } + + private static String toString( Border b ) { + if( b == null ) + return "null"; + + String s = b.getClass().getName(); + + if( b instanceof EmptyBorder ) + s += '(' + toString( ((EmptyBorder)b).getBorderInsets() ) + ')'; + + if( b instanceof UIResource ) + s += " UI"; + + return s; + } }