mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 15:00:54 +03:00
UI defaults inspector: indicate when a LaF UI value was overridden with UIManager.put(key,value)
This commit is contained in:
@@ -34,6 +34,7 @@ import javax.swing.table.AbstractTableModel;
|
|||||||
import javax.swing.table.DefaultTableCellRenderer;
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
import com.formdev.flatlaf.icons.FlatAbstractIcon;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
import com.formdev.flatlaf.util.HSLColor;
|
import com.formdev.flatlaf.util.HSLColor;
|
||||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||||
@@ -199,6 +200,7 @@ public class FlatUIDefaultsInspector
|
|||||||
|
|
||||||
private Item[] getUIDefaultsItems() {
|
private Item[] getUIDefaultsItems() {
|
||||||
UIDefaults defaults = UIManager.getDefaults();
|
UIDefaults defaults = UIManager.getDefaults();
|
||||||
|
UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
|
||||||
|
|
||||||
ArrayList<Item> items = new ArrayList<>( defaults.size() );
|
ArrayList<Item> items = new ArrayList<>( defaults.size() );
|
||||||
Enumeration<Object> e = defaults.keys();
|
Enumeration<Object> e = defaults.keys();
|
||||||
@@ -214,7 +216,7 @@ public class FlatUIDefaultsInspector
|
|||||||
if( value instanceof Class )
|
if( value instanceof Class )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
items.add( new Item( String.valueOf( key ), value ) );
|
items.add( new Item( String.valueOf( key ), value, lafDefaults.get( key ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return items.toArray( new Item[items.size()] );
|
return items.toArray( new Item[items.size()] );
|
||||||
@@ -417,29 +419,34 @@ public class FlatUIDefaultsInspector
|
|||||||
private static class Item {
|
private static class Item {
|
||||||
final String key;
|
final String key;
|
||||||
final Object value;
|
final Object value;
|
||||||
|
final Object lafValue;
|
||||||
|
|
||||||
private String valueStr;
|
private String valueStr;
|
||||||
|
|
||||||
Item( String key, Object value ) {
|
Item( String key, Object value, Object lafValue ) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.lafValue = lafValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getValueAsString() {
|
String getValueAsString() {
|
||||||
if( valueStr != null )
|
if( valueStr == null )
|
||||||
return valueStr;
|
valueStr = valueAsString( value );
|
||||||
|
return valueStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String valueAsString( Object value ) {
|
||||||
if( value instanceof Color ) {
|
if( value instanceof Color ) {
|
||||||
Color color = (Color) value;
|
Color color = (Color) value;
|
||||||
HSLColor hslColor = new HSLColor( color );
|
HSLColor hslColor = new HSLColor( color );
|
||||||
if( color.getAlpha() == 255 ) {
|
if( color.getAlpha() == 255 ) {
|
||||||
valueStr = String.format( "%s rgb(%d, %d, %d) hsl(%d, %d, %d)",
|
return String.format( "%s rgb(%d, %d, %d) hsl(%d, %d, %d)",
|
||||||
color2hex( color ),
|
color2hex( color ),
|
||||||
color.getRed(), color.getGreen(), color.getBlue(),
|
color.getRed(), color.getGreen(), color.getBlue(),
|
||||||
(int) hslColor.getHue(), (int) hslColor.getSaturation(),
|
(int) hslColor.getHue(), (int) hslColor.getSaturation(),
|
||||||
(int) hslColor.getLuminance() );
|
(int) hslColor.getLuminance() );
|
||||||
} else {
|
} else {
|
||||||
valueStr = String.format( "%s rgba(%d, %d, %d, %d) hsla(%d, %d, %d, %d)",
|
return String.format( "%s rgba(%d, %d, %d, %d) hsla(%d, %d, %d, %d)",
|
||||||
color2hex( color ),
|
color2hex( color ),
|
||||||
color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha(),
|
color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha(),
|
||||||
(int) hslColor.getHue(), (int) hslColor.getSaturation(),
|
(int) hslColor.getHue(), (int) hslColor.getSaturation(),
|
||||||
@@ -447,33 +454,32 @@ public class FlatUIDefaultsInspector
|
|||||||
}
|
}
|
||||||
} else if( value instanceof Insets ) {
|
} else if( value instanceof Insets ) {
|
||||||
Insets insets = (Insets) value;
|
Insets insets = (Insets) value;
|
||||||
valueStr = insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right;
|
return insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right;
|
||||||
} else if( value instanceof Dimension ) {
|
} else if( value instanceof Dimension ) {
|
||||||
Dimension dim = (Dimension) value;
|
Dimension dim = (Dimension) value;
|
||||||
valueStr = dim.width + "," + dim.height;
|
return dim.width + "," + dim.height;
|
||||||
} else if( value instanceof Font ) {
|
} else if( value instanceof Font ) {
|
||||||
Font font = (Font) value;
|
Font font = (Font) value;
|
||||||
valueStr = font.getFamily() + " " + font.getSize();
|
String s = font.getFamily() + " " + font.getSize();
|
||||||
if( font.isBold() )
|
if( font.isBold() )
|
||||||
valueStr += " bold";
|
s += " bold";
|
||||||
if( font.isItalic() )
|
if( font.isItalic() )
|
||||||
valueStr += " italic";
|
s += " italic";
|
||||||
|
return s;
|
||||||
} else if( value instanceof Icon ) {
|
} else if( value instanceof Icon ) {
|
||||||
Icon icon = (Icon) value;
|
Icon icon = (Icon) value;
|
||||||
valueStr = icon.getIconWidth() + "x" + icon.getIconHeight() + " " + icon.getClass().getName();
|
return icon.getIconWidth() + "x" + icon.getIconHeight() + " " + icon.getClass().getName();
|
||||||
} else if( value instanceof ActionMap ) {
|
} else if( value instanceof ActionMap ) {
|
||||||
ActionMap actionMap = (ActionMap) value;
|
ActionMap actionMap = (ActionMap) value;
|
||||||
valueStr = "ActionMap (" + actionMap.size() + ")";
|
return "ActionMap (" + actionMap.size() + ")";
|
||||||
} else if( value instanceof InputMap ) {
|
} else if( value instanceof InputMap ) {
|
||||||
InputMap inputMap = (InputMap) value;
|
InputMap inputMap = (InputMap) value;
|
||||||
valueStr = "InputMap (" + inputMap.size() + ")";
|
return "InputMap (" + inputMap.size() + ")";
|
||||||
} else
|
} else
|
||||||
valueStr = String.valueOf( value );
|
return String.valueOf( value );
|
||||||
|
|
||||||
return valueStr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String color2hex( Color color ) {
|
private static String color2hex( Color color ) {
|
||||||
int rgb = color.getRGB();
|
int rgb = color.getRGB();
|
||||||
boolean hasAlpha = color.getAlpha() != 255;
|
boolean hasAlpha = color.getAlpha() != 255;
|
||||||
|
|
||||||
@@ -623,6 +629,8 @@ public class FlatUIDefaultsInspector
|
|||||||
extends Renderer
|
extends Renderer
|
||||||
{
|
{
|
||||||
private String key;
|
private String key;
|
||||||
|
private boolean isOverridden;
|
||||||
|
private Icon overriddenIcon;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent( JTable table, Object value,
|
public Component getTableCellRendererComponent( JTable table, Object value,
|
||||||
@@ -630,7 +638,16 @@ public class FlatUIDefaultsInspector
|
|||||||
{
|
{
|
||||||
key = (String) value;
|
key = (String) value;
|
||||||
init( table, key, isSelected, row );
|
init( table, key, isSelected, row );
|
||||||
setToolTipText( key );
|
|
||||||
|
Item item = (Item) table.getValueAt( row, 1 );
|
||||||
|
isOverridden = (item.lafValue != item.value);
|
||||||
|
|
||||||
|
// set tooltip
|
||||||
|
String toolTipText = key;
|
||||||
|
if( isOverridden )
|
||||||
|
toolTipText += " \n\nLaF UI default value was overridden with UIManager.put(key,value).";
|
||||||
|
setToolTipText( toolTipText );
|
||||||
|
|
||||||
return super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
|
return super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,6 +682,23 @@ public class FlatUIDefaultsInspector
|
|||||||
FlatUIUtils.drawString( this, g, clippedText, x, y );
|
FlatUIUtils.drawString( this, g, clippedText, x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( isOverridden ) {
|
||||||
|
if( overriddenIcon == null ) {
|
||||||
|
overriddenIcon = new FlatAbstractIcon( 16, 16, null ) {
|
||||||
|
@Override
|
||||||
|
protected void paintIcon( Component c, Graphics2D g2 ) {
|
||||||
|
g2.setColor( FlatUIUtils.getUIColor( "Actions.Red", Color.red ) );
|
||||||
|
g2.setStroke( new BasicStroke( 2f ) );
|
||||||
|
g2.draw( FlatUIUtils.createPath( false, 3,10, 8,5, 13,10 ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
overriddenIcon.paintIcon( this, g,
|
||||||
|
getWidth() - overriddenIcon.getIconWidth(),
|
||||||
|
(getHeight() - overriddenIcon.getIconHeight()) / 2 );
|
||||||
|
}
|
||||||
|
|
||||||
paintSeparator( g );
|
paintSeparator( g );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -706,7 +740,14 @@ public class FlatUIDefaultsInspector
|
|||||||
setIcon( new SafeIcon( icon ) );
|
setIcon( new SafeIcon( icon ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
setToolTipText( String.valueOf( item.value ) );
|
// set tooltip
|
||||||
|
String toolTipText = String.valueOf( item.value );
|
||||||
|
if( item.value != item.lafValue ) {
|
||||||
|
toolTipText += " \n\nLaF UI default value was overridden with UIManager.put(key,value):\n "
|
||||||
|
+ Item.valueAsString( item.lafValue ) + "\n " + String.valueOf( item.lafValue );
|
||||||
|
}
|
||||||
|
setToolTipText( toolTipText );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user