UIDefaultsDump: dump HSL color values

This commit is contained in:
Karl Tauber
2021-08-06 10:45:57 +02:00
parent 0544a605c3
commit bfb1642284
6 changed files with 1612 additions and 1587 deletions

View File

@@ -70,6 +70,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.ColorFunctions.ColorFunction;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.HSLColor;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo;
@@ -84,6 +85,7 @@ public class UIDefaultsDump
private final UIDefaults defaults;
private final Properties derivedColorKeys;
private final boolean isIntelliJTheme;
private final boolean dumpHSL;
private String lastPrefix;
private JComponent dummyComponent;
@@ -349,6 +351,7 @@ public class UIDefaultsDump
derivedColorKeys = loadDerivedColorKeys();
isIntelliJTheme = (lookAndFeel instanceof IntelliJTheme.ThemeLaf);
dumpHSL = lookAndFeel instanceof FlatLaf;
}
private void dump( PrintWriter out, Predicate<String> keyFilter ) {
@@ -457,16 +460,16 @@ public class UIDefaultsDump
if( resolvedColor != color && resolvedColor.getRGB() != color.getRGB() ) {
if( !isIntelliJTheme ) {
System.err.println( "Key '" + key + "': derived colors not equal" );
System.err.println( " Default color: " + dumpColorHex( color ) );
System.err.println( " Resolved color: " + dumpColorHex( resolvedColor ) );
System.err.println( " Default color: " + dumpColorHexAndHSL( color ) );
System.err.println( " Resolved color: " + dumpColorHexAndHSL( resolvedColor ) );
}
out.printf( "%s / ",
dumpColorHex( resolvedColor ) );
dumpColorHexAndHSL( resolvedColor ) );
}
out.printf( "%s %s",
dumpColorHex( color ),
dumpColorHexAndHSL( color ),
dumpClass( color ) );
if( color instanceof DerivedColor ) {
@@ -479,6 +482,13 @@ public class UIDefaultsDump
}
}
private String dumpColorHexAndHSL( Color color ) {
String hex = dumpColorHex( color );
return dumpHSL
? hex + " " + dumpColorHSL( color )
: hex;
}
private String dumpColorHex( Color color ) {
boolean hasAlpha = (color.getAlpha() != 255);
return hasAlpha
@@ -486,6 +496,21 @@ public class UIDefaultsDump
: String.format( "#%06x", color.getRGB() & 0xffffff );
}
private String dumpColorHSL( Color color ) {
HSLColor hslColor = new HSLColor( color );
int hue = Math.round( hslColor.getHue() );
int saturation = Math.round( hslColor.getSaturation() );
int luminance = Math.round( hslColor.getLuminance() );
if( color.getAlpha() == 255 ) {
return String.format( "HSL %3d %3d %3d",
hue, saturation, luminance );
} else {
int alpha = Math.round( hslColor.getAlpha() * 100 );
return String.format( "HSLA %3d %3d %3d %2d",
hue, saturation, luminance, alpha );
}
}
private void dumpFont( PrintWriter out, Font font ) {
String strStyle = font.isBold()
? font.isItalic() ? "bolditalic" : "bold"