mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
Merge PR #1080: Fix NPE in FlatUIDefaultsInspector when color is null
This commit is contained in:
@@ -8,6 +8,10 @@ FlatLaf Change Log
|
||||
- Popup: Fixed scrolling popup painting issue on Windows 10 when a glass pane is
|
||||
visible and frame is maximized. (issue #1071)
|
||||
- ToolBar: Grip disappeared when switching between Look and Feels. (issue #1075)
|
||||
- Extras:
|
||||
- UI defaults inspector: Fixed NPE if color of `FlatLineBorder` is null. Also
|
||||
use `FlatLineBorder` line color as cell background color in "Value" column.
|
||||
(PR #1080)
|
||||
|
||||
|
||||
## 3.7
|
||||
|
||||
@@ -777,6 +777,9 @@ public class FlatUIDefaultsInspector
|
||||
|
||||
@SuppressWarnings( "FormatString" ) // Error Prone
|
||||
private static String color2hex( Color color ) {
|
||||
if( color == null )
|
||||
return "";
|
||||
|
||||
int rgb = color.getRGB();
|
||||
boolean hasAlpha = color.getAlpha() != 255;
|
||||
|
||||
@@ -1018,28 +1021,36 @@ public class FlatUIDefaultsInspector
|
||||
item = (Item) value;
|
||||
init( table, item.key, isSelected, row );
|
||||
|
||||
// reset background, foreground and icon
|
||||
if( !(item.value instanceof Color) ) {
|
||||
// get color of value
|
||||
valueColor = null;
|
||||
if( item.value instanceof Color )
|
||||
valueColor = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value;
|
||||
else if( item.value instanceof FlatLineBorder )
|
||||
valueColor = ((FlatLineBorder)item.value).getLineColor();
|
||||
|
||||
// reset background and foreground
|
||||
if( valueColor == null ) {
|
||||
setBackground( null );
|
||||
setForeground( null );
|
||||
}
|
||||
if( !(item.value instanceof Icon) )
|
||||
setIcon( null );
|
||||
|
||||
// value to string
|
||||
value = item.getValueAsString();
|
||||
|
||||
super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
|
||||
|
||||
if( item.value instanceof Color ) {
|
||||
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;
|
||||
// set foreground, if value has color
|
||||
if( valueColor != null ) {
|
||||
boolean isDark = new HSLColor( valueColor ).getLuminance() < 70 && valueColor.getAlpha() >= 128;
|
||||
setForeground( isDark ? Color.white : Color.black );
|
||||
} else if( item.value instanceof Icon ) {
|
||||
}
|
||||
|
||||
// set icon
|
||||
if( item.value instanceof Icon ) {
|
||||
Icon icon = (Icon) item.value;
|
||||
setIcon( new SafeIcon( icon ) );
|
||||
}
|
||||
} else
|
||||
setIcon( null );
|
||||
|
||||
// set tooltip
|
||||
String toolTipText = (item.value instanceof Object[])
|
||||
@@ -1056,7 +1067,7 @@ public class FlatUIDefaultsInspector
|
||||
|
||||
@Override
|
||||
protected void paintComponent( Graphics g ) {
|
||||
if( item.value instanceof Color ) {
|
||||
if( valueColor != null ) {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
Color background = valueColor;
|
||||
|
||||
Reference in New Issue
Block a user