replaced FlatUIUtils.setColor() with deriveColor() for more flexibility

This commit is contained in:
Karl Tauber
2020-05-20 14:24:22 +02:00
parent be529655d6
commit 87b73f26f5
7 changed files with 14 additions and 14 deletions

View File

@@ -111,13 +111,13 @@ public class FlatCheckBoxIcon
paintBorder( g2 ); paintBorder( g2 );
// paint background // paint background
FlatUIUtils.setColor( g2, FlatButtonUI.buttonStateColor( c, g2.setColor( FlatUIUtils.deriveColor( FlatButtonUI.buttonStateColor( c,
selected ? selectedBackground : background, selected ? selectedBackground : background,
disabledBackground, disabledBackground,
focusedBackground, focusedBackground,
selected && selectedHoverBackground != null ? selectedHoverBackground : hoverBackground, selected && selectedHoverBackground != null ? selectedHoverBackground : hoverBackground,
selected && selectedPressedBackground != null ? selectedPressedBackground : pressedBackground ), selected && selectedPressedBackground != null ? selectedPressedBackground : pressedBackground ),
background ); background ) );
paintBackground( g2 ); paintBackground( g2 );
// paint checkmark // paint checkmark

View File

@@ -100,12 +100,12 @@ public class FlatHelpButtonIcon
g2.fill( new Ellipse2D.Float( focusWidth + 0.5f, focusWidth + 0.5f, 21, 21 ) ); g2.fill( new Ellipse2D.Float( focusWidth + 0.5f, focusWidth + 0.5f, 21, 21 ) );
// paint background // paint background
FlatUIUtils.setColor( g2, FlatButtonUI.buttonStateColor( c, g2.setColor( FlatUIUtils.deriveColor( FlatButtonUI.buttonStateColor( c,
background, background,
disabledBackground, disabledBackground,
focusedBackground, focusedBackground,
hoverBackground, hoverBackground,
pressedBackground ), background ); pressedBackground ), background ) );
g2.fill( new Ellipse2D.Float( focusWidth + 1.5f, focusWidth + 1.5f, 19, 19 ) ); g2.fill( new Ellipse2D.Float( focusWidth + 1.5f, focusWidth + 1.5f, 19, 19 ) );
// paint question mark // paint question mark

View File

@@ -53,7 +53,7 @@ public abstract class FlatInternalFrameAbstractIcon
protected void paintBackground( Component c, Graphics2D g ) { protected void paintBackground( Component c, Graphics2D g ) {
Color background = FlatButtonUI.buttonStateColor( c, null, null, null, hoverBackground, pressedBackground ); Color background = FlatButtonUI.buttonStateColor( c, null, null, null, hoverBackground, pressedBackground );
if( background != null ) { if( background != null ) {
FlatUIUtils.setColor( g, background, c.getBackground() ); g.setColor( FlatUIUtils.deriveColor( background, c.getBackground() ) );
g.fillRect( 0, 0, width, height ); g.fillRect( 0, 0, width, height );
} }
} }

View File

@@ -312,7 +312,7 @@ public class FlatButtonUI
if( background == startBg && endBg != null && !startBg.equals( endBg ) ) if( background == startBg && endBg != null && !startBg.equals( endBg ) )
g2.setPaint( new GradientPaint( 0, 0, startBg, 0, height, endBg ) ); g2.setPaint( new GradientPaint( 0, 0, startBg, 0, height, endBg ) );
else else
FlatUIUtils.setColor( g2, background, def ? defaultBackground : c.getBackground() ); g2.setColor( FlatUIUtils.deriveColor( background, def ? defaultBackground : c.getBackground() ) );
FlatUIUtils.paintComponentBackground( g2, x, y, width, height, focusWidth, arc ); FlatUIUtils.paintComponentBackground( g2, x, y, width, height, focusWidth, arc );
} finally { } finally {

View File

@@ -151,7 +151,7 @@ public class FlatMenuUI
if( model.isRollover() && !model.isArmed() && !model.isSelected() && if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() ) model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
{ {
FlatUIUtils.setColor( g, hoverBackground, menuItem.getBackground() ); g.setColor( FlatUIUtils.deriveColor( hoverBackground, menuItem.getBackground() ) );
g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() ); g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
} else } else
super.paintBackground( g, selectionBackground ); super.paintBackground( g, selectionBackground );

View File

@@ -201,7 +201,7 @@ public class FlatSliderUI
} }
if( coloredTrack != null ) { if( coloredTrack != null ) {
FlatUIUtils.setColor( g, FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor), thumbColor ); g.setColor( FlatUIUtils.deriveColor( FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor), thumbColor ) );
((Graphics2D)g).fill( coloredTrack ); ((Graphics2D)g).fill( coloredTrack );
} }
@@ -211,10 +211,10 @@ public class FlatSliderUI
@Override @Override
public void paintThumb( Graphics g ) { public void paintThumb( Graphics g ) {
FlatUIUtils.setColor( g, slider.isEnabled() g.setColor( FlatUIUtils.deriveColor( slider.isEnabled()
? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor)) ? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor))
: disabledForeground, : disabledForeground,
thumbColor ); thumbColor ) );
if( isRoundThumb() ) if( isRoundThumb() )
g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height ); g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height );

View File

@@ -194,10 +194,10 @@ public class FlatUIUtils
MAC_USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE ); MAC_USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE );
} }
public static void setColor( Graphics g, Color color, Color baseColor ) { public static Color deriveColor( Color color, Color baseColor ) {
if( color instanceof DerivedColor ) return (color instanceof DerivedColor)
color = ((DerivedColor)color).derive( baseColor ); ? ((DerivedColor)color).derive( baseColor )
g.setColor( color ); : color;
} }
/** /**