mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
UI defaults inspector: use short format for hex colors if possible; use uppercase hex
This commit is contained in:
@@ -428,14 +428,14 @@ public class FlatUIDefaultsInspector
|
|||||||
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( "#%06x rgb(%d, %d, %d) hsl(%d, %d, %d)",
|
valueStr = String.format( "%s rgb(%d, %d, %d) hsl(%d, %d, %d)",
|
||||||
color.getRGB() & 0xffffff,
|
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( "#%06x%02x rgba(%d, %d, %d, %d) hsla(%d, %d, %d, %d)",
|
valueStr = String.format( "%s rgba(%d, %d, %d, %d) hsla(%d, %d, %d, %d)",
|
||||||
color.getRGB() & 0xffffff, color.getAlpha(),
|
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(),
|
||||||
(int) hslColor.getLuminance(), (int) (hslColor.getAlpha() * 100) );
|
(int) hslColor.getLuminance(), (int) (hslColor.getAlpha() * 100) );
|
||||||
@@ -467,6 +467,23 @@ public class FlatUIDefaultsInspector
|
|||||||
|
|
||||||
return valueStr;
|
return valueStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String color2hex( Color color ) {
|
||||||
|
int rgb = color.getRGB();
|
||||||
|
boolean hasAlpha = color.getAlpha() != 255;
|
||||||
|
|
||||||
|
boolean useShortFormat =
|
||||||
|
(rgb & 0xf0000000) == (rgb & 0xf000000) << 4 &&
|
||||||
|
(rgb & 0xf00000) == (rgb & 0xf0000) << 4 &&
|
||||||
|
(rgb & 0xf000) == (rgb & 0xf00) << 4 &&
|
||||||
|
(rgb & 0xf0) == (rgb & 0xf) << 4;
|
||||||
|
|
||||||
|
if( useShortFormat ) {
|
||||||
|
int srgb = ((rgb & 0xf0000) >> 8) | ((rgb & 0xf00) >> 4) | (rgb & 0xf);
|
||||||
|
return String.format( hasAlpha ? "#%03X%X" : "#%03X", srgb, (rgb >> 24) & 0xf );
|
||||||
|
} else
|
||||||
|
return String.format( hasAlpha ? "#%06X%02X" : "#%06X", rgb & 0xffffff, (rgb >> 24) & 0xff );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class ItemsTableModel ----------------------------------------------
|
//---- class ItemsTableModel ----------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user