UI defaults inspector: show color functions in value tooltips

This commit is contained in:
Karl Tauber
2021-02-06 01:31:34 +01:00
parent 575b8e3f7f
commit a38cf284dd
3 changed files with 34 additions and 24 deletions

View File

@@ -128,6 +128,21 @@ public class ColorFunctions
? hsla[hslIndex] > 65
: hsla[hslIndex] < 35;
}
@Override
public String toString() {
String name;
switch( hslIndex ) {
case 0: name = "spin"; break;
case 1: name = increase ? "saturate" : "desaturate"; break;
case 2: name = increase ? "lighten" : "darken"; break;
case 3: name = increase ? "fadein" : "fadeout"; break;
default: throw new IllegalArgumentException();
}
return String.format( "%s(%.0f%%%s%s)", name, amount,
(relative ? " relative" : ""),
(autoInverse ? " autoInverse" : "") );
}
}
//---- class HSLIncreaseDecrease ------------------------------------------
@@ -148,5 +163,10 @@ public class ColorFunctions
public void apply( float[] hsla ) {
hsla[3] = clamp( amount );
}
@Override
public String toString() {
return String.format( "fade(%.0f%%)", amount );
}
}
}

View File

@@ -59,4 +59,17 @@ public class DerivedColor
public ColorFunction[] getFunctions() {
return functions;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append( super.toString() );
for( ColorFunction function : functions ) {
buf.append( '\n' );
buf.append( function.toString() );
}
return buf.toString();
}
}

View File

@@ -67,8 +67,6 @@ import com.formdev.flatlaf.testing.FlatTestLaf;
import com.formdev.flatlaf.ui.FlatLineBorder;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.ColorFunctions.ColorFunction;
import com.formdev.flatlaf.util.ColorFunctions.Fade;
import com.formdev.flatlaf.util.ColorFunctions.HSLIncreaseDecrease;
import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo;
@@ -409,7 +407,7 @@ public class UIDefaultsDump
DerivedColor derivedColor = (DerivedColor) color;
for( ColorFunction function : derivedColor.getFunctions() ) {
out.print( " " );
dumpColorFunction( out, function );
out.print( function.toString() );
}
}
}
@@ -421,27 +419,6 @@ public class UIDefaultsDump
: String.format( "#%06x", color.getRGB() & 0xffffff );
}
private void dumpColorFunction( PrintWriter out, ColorFunction function ) {
if( function instanceof HSLIncreaseDecrease ) {
HSLIncreaseDecrease func = (HSLIncreaseDecrease) function;
String name;
switch( func.hslIndex ) {
case 0: name = "spin"; break;
case 1: name = func.increase ? "saturate" : "desaturate"; break;
case 2: name = func.increase ? "lighten" : "darken"; break;
case 3: name = func.increase ? "fadein" : "fadeout"; break;
default: throw new IllegalArgumentException();
}
out.printf( "%s(%.0f%%%s%s)", name, func.amount,
(func.relative ? " relative" : ""),
(func.autoInverse ? " autoInverse" : "") );
} else if( function instanceof Fade ) {
Fade func = (Fade) function;
out.printf( "fade(%.0f%%)", func.amount );
} else
throw new IllegalArgumentException( "unknown color function: " + function );
}
private void dumpFont( PrintWriter out, Font font ) {
String strStyle = font.isBold()
? font.isItalic() ? "bolditalic" : "bold"