mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Button: paint focused border
This commit is contained in:
@@ -45,6 +45,12 @@ public class FlatButtonBorder
|
||||
float lineWidth = getLineWidth();
|
||||
float arc = UIScale.scale( 6f ); //TODO
|
||||
|
||||
if( c.hasFocus() ) {
|
||||
g2.setColor( UIManager.getColor( FlatButtonUI.isDefaultButton( c )
|
||||
? "Button.default.focusColor" : "Component.focusColor" ) );
|
||||
FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
||||
}
|
||||
|
||||
g2.setPaint( getBorderColor( c ) );
|
||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
||||
} finally {
|
||||
@@ -55,6 +61,9 @@ public class FlatButtonBorder
|
||||
private Paint getBorderColor( Component c ) {
|
||||
if( c.isEnabled() ) {
|
||||
boolean def = FlatButtonUI.isDefaultButton( c );
|
||||
if( c.hasFocus() )
|
||||
return UIManager.getColor( def ? "Button.default.focusedBorderColor" : "Button.focusedBorderColor" );
|
||||
|
||||
Color startColor = UIManager.getColor( def ? "Button.default.startBorderColor" : "Button.startBorderColor" );
|
||||
Color endColor = UIManager.getColor( def ? "Button.default.endBorderColor" : "Button.endBorderColor" );
|
||||
return (startColor.equals( endColor ) )
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.awt.RenderingHints;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import javax.swing.JComponent;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
* Utility methods for UI delegates.
|
||||
@@ -96,4 +97,41 @@ public class FlatUIUtils
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints an outline border.
|
||||
*/
|
||||
public static void paintOutlineBorder( Graphics2D g, int x, int y, int width, int height,
|
||||
float focusWidth, float lineWidth, float arc )
|
||||
{
|
||||
float x1 = x;
|
||||
float y1 = y;
|
||||
float x2 = x1 + width;
|
||||
float y2 = y1 + height;
|
||||
|
||||
float outerArc = arc > 0 ? arc + focusWidth - UIScale.scale( 2f ) : focusWidth;
|
||||
Path2D outerRect = createOutlinePath( x1, y1, x2, y2, outerArc );
|
||||
|
||||
float ow = focusWidth + lineWidth;
|
||||
Path2D innerRect = createOutlinePath( x1 + ow, y1 + ow, x2 - ow, y2 - ow, outerArc - ow );
|
||||
|
||||
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
||||
path.append( outerRect, false );
|
||||
path.append( innerRect, false );
|
||||
g.fill( path );
|
||||
}
|
||||
|
||||
private static Path2D createOutlinePath( float x1, float y1, float x2, float y2, float arc ) {
|
||||
Path2D rect = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
||||
rect.moveTo( x2 - arc, y1 );
|
||||
rect.quadTo( x2, y1, x2, y1 + arc );
|
||||
rect.lineTo( x2, y2 - arc );
|
||||
rect.quadTo( x2, y2, x2 - arc, y2 );
|
||||
rect.lineTo( x1 + arc, y2 );
|
||||
rect.quadTo( x1, y2, x1, y2 - arc );
|
||||
rect.lineTo( x1, y1 + arc );
|
||||
rect.quadTo( x1, y1, x1 + arc, y1 );
|
||||
rect.closePath();
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,19 @@ Button.disabledText=777777
|
||||
Button.startBorderColor=5e6060
|
||||
Button.endBorderColor=5e6060
|
||||
Button.disabledBorderColor=5e6060
|
||||
Button.focusedBorderColor=466d94
|
||||
|
||||
Button.default.background=365880
|
||||
Button.default.foreground=bbbbbb
|
||||
Button.default.startBorderColor=4c708c
|
||||
Button.default.endBorderColor=4c708c
|
||||
Button.default.focusedBorderColor=537699
|
||||
Button.default.focusColor=43688c
|
||||
|
||||
|
||||
#---- Component ----
|
||||
|
||||
Component.focusColor=3d6185
|
||||
|
||||
|
||||
#---- Label ----
|
||||
|
||||
@@ -50,11 +50,19 @@ Button.disabledText=999999
|
||||
Button.startBorderColor=bfbfbf
|
||||
Button.endBorderColor=b3b3b3
|
||||
Button.disabledBorderColor=cfcfcf
|
||||
Button.focusedBorderColor=87afda
|
||||
|
||||
Button.default.background=4A86C7
|
||||
Button.default.foreground=f0f0f0
|
||||
Button.default.startBorderColor=4779ba
|
||||
Button.default.endBorderColor=3167ad
|
||||
Button.default.focusedBorderColor=a8cef6
|
||||
Button.default.focusColor=97c3f3
|
||||
|
||||
|
||||
#---- Component ----
|
||||
|
||||
Component.focusColor=97c3f3
|
||||
|
||||
|
||||
#---- Label ----
|
||||
|
||||
@@ -28,11 +28,19 @@ Button.disabledText=000088
|
||||
Button.startBorderColor=ff0000
|
||||
Button.endBorderColor=0000ff
|
||||
Button.disabledBorderColor=000088
|
||||
Button.focusedBorderColor=466d94
|
||||
|
||||
Button.default.background=dddddd
|
||||
Button.default.foreground=880000
|
||||
Button.default.startBorderColor=ff0000
|
||||
Button.default.endBorderColor=ff0000
|
||||
Button.default.focusedBorderColor=537699
|
||||
Button.default.focusColor=ff0000
|
||||
|
||||
|
||||
#---- Component ----
|
||||
|
||||
Component.focusColor=97c3f3
|
||||
|
||||
|
||||
#---- Label ----
|
||||
|
||||
Reference in New Issue
Block a user