mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Fix NPE in FlatUIDefaultsInspector when color is null
This commit is contained in:
@@ -777,6 +777,9 @@ public class FlatUIDefaultsInspector
|
|||||||
|
|
||||||
@SuppressWarnings( "FormatString" ) // Error Prone
|
@SuppressWarnings( "FormatString" ) // Error Prone
|
||||||
private static String color2hex( Color color ) {
|
private static String color2hex( Color color ) {
|
||||||
|
|
||||||
|
if ( color == null ) return "#none";
|
||||||
|
|
||||||
int rgb = color.getRGB();
|
int rgb = color.getRGB();
|
||||||
boolean hasAlpha = color.getAlpha() != 255;
|
boolean hasAlpha = color.getAlpha() != 255;
|
||||||
|
|
||||||
@@ -1019,7 +1022,7 @@ public class FlatUIDefaultsInspector
|
|||||||
init( table, item.key, isSelected, row );
|
init( table, item.key, isSelected, row );
|
||||||
|
|
||||||
// reset background, foreground and icon
|
// reset background, foreground and icon
|
||||||
if( !(item.value instanceof Color) ) {
|
if( !isTargetClass() ) {
|
||||||
setBackground( null );
|
setBackground( null );
|
||||||
setForeground( null );
|
setForeground( null );
|
||||||
}
|
}
|
||||||
@@ -1033,12 +1036,19 @@ public class FlatUIDefaultsInspector
|
|||||||
|
|
||||||
if( item.value instanceof Color ) {
|
if( item.value instanceof Color ) {
|
||||||
Color color = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value;
|
Color color = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value;
|
||||||
boolean isDark = new HSLColor( color ).getLuminance() < 70 && color.getAlpha() >= 128;
|
|
||||||
valueColor = color;
|
valueColor = color;
|
||||||
setForeground( isDark ? Color.white : Color.black );
|
setForeground( fgColor( color ) );
|
||||||
} else if( item.value instanceof Icon ) {
|
} else if( item.value instanceof Icon ) {
|
||||||
Icon icon = (Icon) item.value;
|
Icon icon = (Icon) item.value;
|
||||||
setIcon( new SafeIcon( icon ) );
|
setIcon( new SafeIcon( icon ) );
|
||||||
|
} else if ( item.value instanceof FlatLineBorder ) {
|
||||||
|
Color lineColor = ((FlatLineBorder)item.value).getLineColor();
|
||||||
|
valueColor = lineColor == null
|
||||||
|
? (isSelected ? table.getSelectionBackground() : table.getBackground())
|
||||||
|
: lineColor;
|
||||||
|
setForeground( lineColor == null
|
||||||
|
? (isSelected ? table.getSelectionForeground() : table.getForeground())
|
||||||
|
: fgColor( lineColor ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set tooltip
|
// set tooltip
|
||||||
@@ -1054,9 +1064,18 @@ public class FlatUIDefaultsInspector
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTargetClass() {
|
||||||
|
return item.value instanceof Color || item.value instanceof FlatLineBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color fgColor( Color color ) {
|
||||||
|
boolean isDark = new HSLColor( color ).getLuminance() < 70 && color.getAlpha() >= 128;
|
||||||
|
return isDark ? Color.white : Color.black;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent( Graphics g ) {
|
protected void paintComponent( Graphics g ) {
|
||||||
if( item.value instanceof Color ) {
|
if( isTargetClass() ) {
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
Color background = valueColor;
|
Color background = valueColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user