Skip to content

Commit

Permalink
Merge pull request #214 into master
Browse files Browse the repository at this point in the history
Slider redesign
  • Loading branch information
DevCharly committed Dec 4, 2020
2 parents e07ae90 + 56bfdc8 commit dd2f73e
Show file tree
Hide file tree
Showing 25 changed files with 901 additions and 251 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FlatLaf Change Log

#### New features and improvements

- Slider: New design and improved customizing. (PR #214)
- JIDE Common Layer: Support `RangeSlider`. (PR #209)
- IntelliJ Themes:
- Added "Gradianto Nature Green" theme.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ private void applyCheckBoxColors( UIDefaults defaults ) {
}
}

/** Rename UI default keys (key --> value). */
private static Map<String, String> uiKeyMapping = new HashMap<>();
/** Copy UI default keys (value --> key). */
private static Map<String, String> uiKeyCopying = new HashMap<>();
private static Map<String, String> uiKeyInverseMapping = new HashMap<>();
private static Map<String, String> checkboxKeyMapping = new HashMap<>();
Expand Down Expand Up @@ -529,6 +531,9 @@ private void applyCheckBoxColors( UIDefaults defaults ) {

// Slider
uiKeyMapping.put( "Slider.trackWidth", "" ); // ignore (used in Material Theme UI Lite)
uiKeyCopying.put( "Slider.trackValueColor", "ProgressBar.foreground" );
uiKeyCopying.put( "Slider.thumbColor", "ProgressBar.foreground" );
uiKeyCopying.put( "Slider.trackColor", "ProgressBar.background" );

// TitlePane
uiKeyCopying.put( "TitlePane.inactiveBackground", "TitlePane.background" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,17 @@ private static Object parseColorFunctions( String value, Function<String, String
case "darken": return parseColorHSLIncreaseDecrease( 2, false, params, resolver, reportError );
case "saturate": return parseColorHSLIncreaseDecrease( 1, true, params, resolver, reportError );
case "desaturate": return parseColorHSLIncreaseDecrease( 1, false, params, resolver, reportError );
case "fadein": return parseColorHSLIncreaseDecrease( 3, true, params, resolver, reportError );
case "fadeout": return parseColorHSLIncreaseDecrease( 3, false, params, resolver, reportError );
case "fade": return parseColorFade( params, resolver, reportError );
case "spin": return parseColorSpin( params, resolver, reportError );
}

throw new IllegalArgumentException( "unknown color function '" + value + "'" );
}

/**
* Syntax: rgb(red,green,blue) or rgba(red,green,blue,alpha) or rgba(color,alpha)
* Syntax: rgb(red,green,blue) or rgba(red,green,blue,alpha)
* - red: an integer 0-255 or a percentage 0-100%
* - green: an integer 0-255 or a percentage 0-100%
* - blue: an integer 0-255 or a percentage 0-100%
Expand All @@ -603,6 +607,8 @@ private static ColorUIResource parseColorRgbOrRgba( boolean hasAlpha, List<Strin
{
if( hasAlpha && params.size() == 2 ) {
// syntax rgba(color,alpha), which allows adding alpha to any color
// NOTE: this syntax is deprecated
// use fade(color,alpha) instead
String colorStr = params.get( 0 );
int alpha = parseInteger( params.get( 1 ), 0, 255, true );

Expand Down Expand Up @@ -639,7 +645,8 @@ private static ColorUIResource parseColorHslOrHsla( boolean hasAlpha, List<Strin

/**
* Syntax: lighten(color,amount[,options]) or darken(color,amount[,options]) or
* saturate(color,amount[,options]) or desaturate(color,amount[,options])
* saturate(color,amount[,options]) or desaturate(color,amount[,options]) or
* fadein(color,amount[,options]) or fadeout(color,amount[,options])
* - color: a color (e.g. #f00) or a color function
* - amount: percentage 0-100%
* - options: [relative] [autoInverse] [noAutoInverse] [lazy] [derived]
Expand Down Expand Up @@ -679,6 +686,59 @@ private static Object parseColorHSLIncreaseDecrease( int hslIndex, boolean incre
};
}

// parse base color, apply function and create derived color
return parseFunctionBaseColor( colorStr, function, derived, resolver, reportError );
}

/**
* Syntax: fade(color,amount[,options])
* - color: a color (e.g. #f00) or a color function
* - amount: percentage 0-100%
* - options: [derived]
*/
private static Object parseColorFade( List<String> params, Function<String, String> resolver, boolean reportError ) {
String colorStr = params.get( 0 );
int amount = parsePercentage( params.get( 1 ) );
boolean derived = false;

if( params.size() > 2 ) {
String options = params.get( 2 );
derived = options.contains( "derived" );
}

// create function
ColorFunction function = new ColorFunctions.Fade( amount );

// parse base color, apply function and create derived color
return parseFunctionBaseColor( colorStr, function, derived, resolver, reportError );
}

/**
* Syntax: spin(color,angle[,options])
* - color: a color (e.g. #f00) or a color function
* - angle: number of degrees to rotate
* - options: [derived]
*/
private static Object parseColorSpin( List<String> params, Function<String, String> resolver, boolean reportError ) {
String colorStr = params.get( 0 );
int amount = parseInteger( params.get( 1 ), true );
boolean derived = false;

if( params.size() > 2 ) {
String options = params.get( 2 );
derived = options.contains( "derived" );
}

// create function
ColorFunction function = new ColorFunctions.HSLIncreaseDecrease( 0, true, amount, false, false );

// parse base color, apply function and create derived color
return parseFunctionBaseColor( colorStr, function, derived, resolver, reportError );
}

private static Object parseFunctionBaseColor( String colorStr, ColorFunction function,
boolean derived, Function<String, String> resolver, boolean reportError )
{
// parse base color
String resolvedColorStr = resolver.apply( colorStr );
ColorUIResource baseColor = (ColorUIResource) parseColorOrFunction( resolvedColorStr, resolver, reportError );
Expand Down
Loading

0 comments on commit dd2f73e

Please sign in to comment.