mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
FlatButtonBorder now extends FlatBorder
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.*;
|
import static com.formdev.flatlaf.util.UIScale.*;
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -44,20 +45,25 @@ public class FlatBorder
|
|||||||
|
|
||||||
float focusWidth = getFocusWidth();
|
float focusWidth = getFocusWidth();
|
||||||
float lineWidth = getLineWidth();
|
float lineWidth = getLineWidth();
|
||||||
|
float arc = getArc();
|
||||||
|
|
||||||
if( isFocused( c ) ) {
|
if( isFocused( c ) ) {
|
||||||
g2.setColor( UIManager.getColor( "Component.focusColor" ) );
|
g2.setColor( getFocusColor( c ) );
|
||||||
FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth, lineWidth, 0 );
|
FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
||||||
}
|
}
|
||||||
|
|
||||||
g2.setPaint( getBorderColor( c ) );
|
g2.setPaint( getBorderColor( c ) );
|
||||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, lineWidth, 0 );
|
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paint getBorderColor( Component c ) {
|
protected Color getFocusColor( Component c ) {
|
||||||
|
return UIManager.getColor( "Component.focusColor" );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Paint getBorderColor( Component c ) {
|
||||||
boolean editable = !(c instanceof JTextComponent) || ((JTextComponent)c).isEditable();
|
boolean editable = !(c instanceof JTextComponent) || ((JTextComponent)c).isEditable();
|
||||||
return UIManager.getColor( c.isEnabled() && editable
|
return UIManager.getColor( c.isEnabled() && editable
|
||||||
? (isFocused( c )
|
? (isFocused( c )
|
||||||
@@ -66,7 +72,7 @@ public class FlatBorder
|
|||||||
: "Component.disabledBorderColor" );
|
: "Component.disabledBorderColor" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFocused( Component c ) {
|
protected boolean isFocused( Component c ) {
|
||||||
if( c instanceof JScrollPane ) {
|
if( c instanceof JScrollPane ) {
|
||||||
JViewport viewport = ((JScrollPane)c).getViewport();
|
JViewport viewport = ((JScrollPane)c).getViewport();
|
||||||
Component view = (viewport != null) ? viewport.getView() : null;
|
Component view = (viewport != null) ? viewport.getView() : null;
|
||||||
@@ -94,4 +100,8 @@ public class FlatBorder
|
|||||||
protected float getLineWidth() {
|
protected float getLineWidth() {
|
||||||
return FlatUIUtils.getLineWidth();
|
return FlatUIUtils.getLineWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected float getArc() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,12 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.*;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.GradientPaint;
|
import java.awt.GradientPaint;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import java.awt.Paint;
|
import java.awt.Paint;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.basic.BasicBorders;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Border for {@link javax.swing.JButton}.
|
* Border for {@link javax.swing.JButton}.
|
||||||
@@ -33,35 +29,23 @@ import javax.swing.plaf.basic.BasicBorders;
|
|||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatButtonBorder
|
public class FlatButtonBorder
|
||||||
extends BasicBorders.MarginBorder
|
extends FlatBorder
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
||||||
if( !FlatButtonUI.isContentAreaFilled( c ) )
|
if( FlatButtonUI.isContentAreaFilled( c ) )
|
||||||
return;
|
super.paintBorder( c, g, x, y, width, height );
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D) g.create();
|
|
||||||
try {
|
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
|
||||||
|
|
||||||
float focusWidth = getFocusWidth();
|
|
||||||
float lineWidth = getLineWidth();
|
|
||||||
float arc = FlatUIUtils.getButtonArc();
|
|
||||||
|
|
||||||
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 ) );
|
@Override
|
||||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, lineWidth, arc );
|
protected Color getFocusColor( Component c ) {
|
||||||
} finally {
|
return UIManager.getColor( FlatButtonUI.isDefaultButton( c )
|
||||||
g2.dispose();
|
? "Button.default.focusColor"
|
||||||
}
|
: "Component.focusColor" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paint getBorderColor( Component c ) {
|
@Override
|
||||||
|
protected Paint getBorderColor( Component c ) {
|
||||||
if( c.isEnabled() ) {
|
if( c.isEnabled() ) {
|
||||||
boolean def = FlatButtonUI.isDefaultButton( c );
|
boolean def = FlatButtonUI.isDefaultButton( c );
|
||||||
if( c.hasFocus() )
|
if( c.hasFocus() )
|
||||||
@@ -78,22 +62,7 @@ public class FlatButtonBorder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
protected float getArc() {
|
||||||
float ow = getFocusWidth() + getLineWidth();
|
return FlatUIUtils.getButtonArc();
|
||||||
|
|
||||||
insets = super.getBorderInsets( c, insets );
|
|
||||||
insets.top = Math.round( scale( (float) insets.top ) + ow );
|
|
||||||
insets.left = Math.round( scale( (float) insets.left ) + ow );
|
|
||||||
insets.bottom = Math.round( scale( (float) insets.bottom ) + ow );
|
|
||||||
insets.right = Math.round( scale( (float) insets.right ) + ow );
|
|
||||||
return insets;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected float getFocusWidth() {
|
|
||||||
return FlatUIUtils.getFocusWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected float getLineWidth() {
|
|
||||||
return FlatUIUtils.getLineWidth();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class FlatButtonUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isContentAreaFilled( Component c ) {
|
static boolean isContentAreaFilled( Component c ) {
|
||||||
return c instanceof AbstractButton && ((AbstractButton)c).isContentAreaFilled();
|
return !(c instanceof AbstractButton) || ((AbstractButton)c).isContentAreaFilled();
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isDefaultButton( Component c ) {
|
static boolean isDefaultButton( Component c ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user