diff --git a/CHANGELOG.md b/CHANGELOG.md index e2c292d8..ec20e3eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ FlatLaf Change Log ## 1.0-rc3-SNAPSHOT +#### New features and improvements + +- Extras: + - UI Inspector: Use HTML in tooltip. Display color value in same format as + used in FlatLaf properties files. Added color preview. + #### Fixed bugs - Label and ToolTip: Fixed font sizes for ``, ``, ``, `` diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java index 35f03d46..2685702d 100644 --- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java @@ -55,7 +55,6 @@ import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import javax.swing.plaf.UIResource; import javax.swing.text.JTextComponent; -import com.formdev.flatlaf.ui.FlatToolTipUI; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.UIScale; @@ -365,12 +364,7 @@ public class FlatInspector } if( tip == null ) { - tip = new JToolTip() { - @Override - public void updateUI() { - setUI( FlatToolTipUI.createUI( this ) ); - } - }; + tip = new JToolTip(); rootPane.getLayeredPane().add( tip, TOOLTIP_LAYER ); } else tip.setVisible( true ); @@ -397,15 +391,18 @@ public class FlatInspector } private static String buildToolTipText( Component c, int parentLevel ) { + StringBuilder buf = new StringBuilder( 1500 ); + buf.append( "" ); + String name = c.getClass().getName(); name = name.substring( name.lastIndexOf( '.' ) + 1 ); - - String text = - "Class: " + name + " (" + c.getClass().getPackage().getName() + ")\n" + - "Size: " + c.getWidth() + ',' + c.getHeight() + " @ " + c.getX() + ',' + c.getY() + '\n'; + appendRow( buf, "Class", name + " (" + c.getClass().getPackage().getName() + ")" ); + appendRow( buf, "Size", c.getWidth() + ", " + c.getHeight() + "   @ " + c.getX() + ", " + c.getY() ); if( c instanceof Container ) - text += "Insets: " + toString( ((Container)c).getInsets() ) + '\n'; + appendRow( buf, "Insets", toString( ((Container)c).getInsets() ) ); Insets margin = null; if( c instanceof AbstractButton ) @@ -418,28 +415,28 @@ public class FlatInspector margin = ((JToolBar) c).getMargin(); if( margin != null ) - text += "Margin: " + toString( margin ) + '\n'; + appendRow( buf, "Margin", toString( margin ) ); Dimension prefSize = c.getPreferredSize(); Dimension minSize = c.getMinimumSize(); Dimension maxSize = c.getMaximumSize(); - text += "Pref size: " + prefSize.width + ',' + prefSize.height + '\n' + - "Min size: " + minSize.width + ',' + minSize.height + '\n' + - "Max size: " + maxSize.width + ',' + maxSize.height + '\n'; + appendRow( buf, "Pref size", prefSize.width + ", " + prefSize.height ); + appendRow( buf, "Min size", minSize.width + ", " + minSize.height ); + appendRow( buf, "Max size", maxSize.width + ", " + maxSize.height ); if( c instanceof JComponent ) - text += "Border: " + toString( ((JComponent)c).getBorder() ) + '\n'; + appendRow( buf, "Border", toString( ((JComponent)c).getBorder() ) ); - text += "Background: " + toString( c.getBackground() ) + '\n' + - "Foreground: " + toString( c.getForeground() ) + '\n' + - "Font: " + toString( c.getFont() ) + '\n'; + appendRow( buf, "Background", toString( c.getBackground() ) ); + appendRow( buf, "Foreground", toString( c.getForeground() ) ); + appendRow( buf, "Font", toString( c.getFont() ) ); if( c instanceof JComponent ) { try { Field f = JComponent.class.getDeclaredField( "ui" ); f.setAccessible( true ); Object ui = f.get( c ); - text += "UI: " + (ui != null ? ui.getClass().getName() : "null") + '\n'; + appendRow( buf, "UI", (ui != null ? ui.getClass().getName() : "null") ); } catch( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex ) { // ignore } @@ -448,34 +445,46 @@ public class FlatInspector if( c instanceof Container ) { LayoutManager layout = ((Container)c).getLayout(); if( layout != null ) - text += "Layout: " + layout.getClass().getName() + '\n'; + appendRow( buf, "Layout", layout.getClass().getName() ); } - text += "Enabled: " + c.isEnabled() + '\n'; - text += "Opaque: " + c.isOpaque() + (c instanceof JComponent && - FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") + '\n'; + appendRow( buf, "Enabled", String.valueOf( c.isEnabled() ) ); + appendRow( buf, "Opaque", String.valueOf( c.isOpaque() ) + + (c instanceof JComponent && FlatUIUtils.hasOpaqueBeenExplicitlySet( (JComponent) c ) ? " EXPLICIT" : "") ); if( c instanceof AbstractButton ) - text += "ContentAreaFilled: " + ((AbstractButton)c).isContentAreaFilled() + '\n'; - text += "Focusable: " + c.isFocusable() + '\n'; - text += "Left-to-right: " + c.getComponentOrientation().isLeftToRight() + '\n'; - text += "Parent: " + (c.getParent() != null ? c.getParent().getClass().getName() : "null"); + appendRow( buf, "ContentAreaFilled", String.valueOf( ((AbstractButton)c).isContentAreaFilled() ) ); + appendRow( buf, "Focusable", String.valueOf( c.isFocusable() ) ); + appendRow( buf, "Left-to-right", String.valueOf( c.getComponentOrientation().isLeftToRight() ) ); + appendRow( buf, "Parent", (c.getParent() != null ? c.getParent().getClass().getName() : "null") ); + + buf.append( "" ); + buf.append( "
" ); + if( parentLevel > 0 ) + buf.append( "
Parent level: " + parentLevel ); if( parentLevel > 0 ) - text += "\n\nParent level: " + parentLevel; - - if( parentLevel > 0 ) - text += "\n(press Ctrl/Shift to increase/decrease level)"; + buf.append( "
(press Ctrl/Shift to increase/decrease level)" ); else - text += "\n\n(press Ctrl key to inspect parent)"; + buf.append( "
(press Ctrl key to inspect parent)" ); - return text; + buf.append( "
" ); + + return buf.toString(); + } + + private static void appendRow( StringBuilder buf, String key, String value ) { + buf.append( "" ) + .append( key ) + .append( ":" ) + .append( value ) + .append( "" ); } private static String toString( Insets insets ) { if( insets == null ) return "null"; - return insets.top + "," + insets.left + ',' + insets.bottom + ',' + insets.right + return insets.top + ", " + insets.left + ", " + insets.bottom + ", " + insets.right + (insets instanceof UIResource ? " UI" : ""); } @@ -483,10 +492,29 @@ public class FlatInspector if( c == null ) return "null"; - String s = Long.toString( c.getRGB() & 0xffffffffl, 16 ); + StringBuilder buf = new StringBuilder( 150 ); + + buf.append( "" ); // is similar to , but uses same font size as body + buf.append( (c.getAlpha() != 255) + ? String.format( "#%06x%02x", c.getRGB() & 0xffffff, (c.getRGB() >> 24) & 0xff ) + : String.format( "#%06x", c.getRGB() & 0xffffff ) ); + buf.append( "" ); + if( c instanceof UIResource ) - s += " UI"; - return s; + buf.append( " UI" ); + + // color preview + buf.append( "   " ) + .append( "" ) + .append( "                 " ) + .append( "" ); + + if( c.getAlpha() != 255 ) + buf.append( " " ).append( Math.round( c.getAlpha() / 2.55f ) ).append( '%' ); + + return buf.toString(); } private static String toString( Font f ) {