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 bacb5acd5..5a456f22b 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 @@ -554,12 +554,16 @@ else if( c instanceof JToolBar ) appendRow( buf, "Left-to-right", String.valueOf( c.getComponentOrientation().isLeftToRight() ) ); appendRow( buf, "Parent", (c.getParent() != null ? toString( c.getParent().getClass(), classHierarchy ) : "null") ); - if( c instanceof JComponent ) { + if( c instanceof JComponent ) { Object style = ((JComponent)c).getClientProperty( FlatClientProperties.STYLE ); if( style != null ) appendRow( buf, "FlatLaf Style", style.toString() ); } + if( c instanceof FlatInspectorInfoProvider ) { + ((FlatInspectorInfoProvider) c).appendInspectorInfo( buf, classHierarchy ); + } + // append parent level buf.append( "" ); if( parentLevel > 0 ) @@ -582,7 +586,7 @@ else if( c instanceof JToolBar ) return buf.toString(); } - private static void appendRow( StringBuilder buf, String key, String value ) { + public static void appendRow( StringBuilder buf, String key, String value ) { buf.append( "" ) .append( key ) .append( ":" ) @@ -590,7 +594,7 @@ private static void appendRow( StringBuilder buf, String key, String value ) { .append( "" ); } - private static String toString( Class cls, boolean classHierarchy ) { + public static String toString( Class cls, boolean classHierarchy ) { StringBuilder buf = new StringBuilder( 100 ); int level = 0; @@ -623,7 +627,7 @@ private static String toString( Class cls, boolean classHierarchy ) { return buf.toString(); } - private static String toString( Insets insets ) { + public static String toString( Insets insets ) { if( insets == null ) return "null"; @@ -631,7 +635,7 @@ private static String toString( Insets insets ) { + (insets instanceof UIResource ? " UI" : ""); } - private static String toString( Color c ) { + public static String toString( Color c ) { if( c == null ) return "null"; @@ -660,7 +664,7 @@ private static String toString( Color c ) { return buf.toString(); } - private static String toString( Font f ) { + public static String toString( Font f ) { if( f == null ) return "null"; @@ -668,7 +672,7 @@ private static String toString( Font f ) { + (f instanceof UIResource ? " UI" : ""); } - private static String toString( Border b, boolean classHierarchy ) { + public static String toString( Border b, boolean classHierarchy ) { if( b == null ) return "null"; diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspectorInfoProvider.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspectorInfoProvider.java new file mode 100644 index 000000000..0b09c59e7 --- /dev/null +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspectorInfoProvider.java @@ -0,0 +1,52 @@ +/* + * Copyright 2026 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.extras; + +/** + * Implement this interface in a {@link java.awt.Component} to let {@link FlatInspector} + * show additional, component-specific information in its debug tooltip. + *

+ * {@link #appendInspectorInfo(StringBuilder,boolean)} is invoked while + * {@code FlatInspector} is building the HTML tooltip content for the inspected component. + * The rows are appended after the built-in "FlatLaf Style" row and before the footer + * that shows the parent inspection level and key bindings hint. + */ +public interface FlatInspectorInfoProvider +{ + /** + * Appends additional HTML table rows with component-specific debug information. + *

+ * Use {@link FlatInspector#appendRow(StringBuilder, String, String)} to append rows, + * and the {@code FlatInspector.toString(...)} helpers (for {@link Class}, + * {@link java.awt.Insets}, {@link java.awt.Color}, {@link java.awt.Font}, + * {@link javax.swing.border.Border}) to format values the same way the rest of the + * tooltip does, e.g.: + *

+	 * FlatInspector.appendRow( buf, "Model",
+	 *     FlatInspector.toString( model.getClass(), showClassHierarchy ) );
+	 * 
+ * Values are inserted as-is (not HTML-escaped), so avoid passing raw user text that + * may contain {@code <}, {@code >} or {@code &} unless it is already safe to embed + * as HTML. + * + * @param buf the buffer used to build the tooltip HTML + * @param showClassHierarchy whether the user has toggled display of the full class + * hierarchy (Alt key); pass this through to + * {@code FlatInspector.toString(Class, boolean)} calls for consistency + */ + void appendInspectorInfo( StringBuilder buf, boolean showClassHierarchy ); +}