mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
FlatBorder: moved scaling from getter methods to paintBorder() and getBorderInsets()
This commit is contained in:
@@ -73,16 +73,16 @@ public class FlatBorder
|
||||
FlatUIUtils.setRenderingHints( g2 );
|
||||
|
||||
boolean isCellEditor = isTableCellEditor( c );
|
||||
float focusWidth = isCellEditor ? 0 : getFocusWidth( c );
|
||||
float borderWidth = getBorderWidth( c );
|
||||
float arc = isCellEditor ? 0 : getArc( c );
|
||||
float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) );
|
||||
float borderWidth = scale( (float) getBorderWidth( c ) );
|
||||
float arc = isCellEditor ? 0 : scale( (float) getArc( c ) );
|
||||
|
||||
if( isFocused( c ) ) {
|
||||
float innerFocusWidth = !(c instanceof JScrollPane) ? this.innerFocusWidth : 0;
|
||||
|
||||
g2.setColor( getFocusColor( c ) );
|
||||
FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth,
|
||||
getLineWidth( c ) + scale( innerFocusWidth ), arc );
|
||||
scale( (float) getLineWidth( c ) ) + scale( innerFocusWidth ), arc );
|
||||
}
|
||||
|
||||
g2.setPaint( getBorderColor( c ) );
|
||||
@@ -153,7 +153,8 @@ public class FlatBorder
|
||||
@Override
|
||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||
boolean isCellEditor = isTableCellEditor( c );
|
||||
float ow = (isCellEditor ? 0 : getFocusWidth( c )) + getLineWidth( c );
|
||||
float focusWidth = isCellEditor ? 0 : scale( (float) getFocusWidth( c ) );
|
||||
float ow = focusWidth + scale( (float) getLineWidth( c ) );
|
||||
|
||||
insets = super.getBorderInsets( c, insets );
|
||||
insets.top = Math.round( scale( (float) insets.top ) + ow );
|
||||
@@ -163,19 +164,33 @@ public class FlatBorder
|
||||
return insets;
|
||||
}
|
||||
|
||||
protected float getFocusWidth( Component c ) {
|
||||
return scale( (float) focusWidth );
|
||||
/**
|
||||
* Returns the (unscaled) thickness of the outer focus border.
|
||||
*/
|
||||
protected int getFocusWidth( Component c ) {
|
||||
return focusWidth;
|
||||
}
|
||||
|
||||
protected float getLineWidth( Component c ) {
|
||||
return scale( 1f );
|
||||
/**
|
||||
* Returns the (unscaled) line thickness used to compute the border insets.
|
||||
* This may be different to {@link #getBorderWidth}.
|
||||
*/
|
||||
protected int getLineWidth( Component c ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected float getBorderWidth( Component c ) {
|
||||
/**
|
||||
* Returns the (unscaled) line thickness used to paint the border.
|
||||
* This may be different to {@link #getLineWidth}.
|
||||
*/
|
||||
protected int getBorderWidth( Component c ) {
|
||||
return getLineWidth( c );
|
||||
}
|
||||
|
||||
protected float getArc( Component c ) {
|
||||
/**
|
||||
* Returns the (unscaled) arc diameter of the border.
|
||||
*/
|
||||
protected int getArc( Component c ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.GradientPaint;
|
||||
@@ -124,21 +123,21 @@ public class FlatButtonBorder
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getFocusWidth( Component c ) {
|
||||
protected int getFocusWidth( Component c ) {
|
||||
return FlatToggleButtonUI.isTabButton( c ) ? 0 : super.getFocusWidth( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getBorderWidth( Component c ) {
|
||||
return FlatButtonUI.isDefaultButton( c ) ? scale( (float) defaultBorderWidth ) : super.getBorderWidth( c );
|
||||
protected int getBorderWidth( Component c ) {
|
||||
return FlatButtonUI.isDefaultButton( c ) ? defaultBorderWidth : super.getBorderWidth( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getArc( Component c ) {
|
||||
protected int getArc( Component c ) {
|
||||
switch( FlatButtonUI.getButtonType( c ) ) {
|
||||
case FlatButtonUI.TYPE_SQUARE: return 0;
|
||||
case FlatButtonUI.TYPE_ROUND_RECT: return Float.MAX_VALUE;
|
||||
default: return scale( (float) arc );
|
||||
case FlatButtonUI.TYPE_ROUND_RECT: return Short.MAX_VALUE;
|
||||
default: return arc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Component;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
@@ -33,7 +32,7 @@ public class FlatRoundBorder
|
||||
protected final int arc = UIManager.getInt( "Component.arc" );
|
||||
|
||||
@Override
|
||||
protected float getArc( Component c ) {
|
||||
return scale( (float) arc );
|
||||
protected int getArc( Component c ) {
|
||||
return arc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Component;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
/**
|
||||
* Border for various text components (e.g. {@link javax.swing.JTextField}).
|
||||
*
|
||||
* @uiDefault Component.arc int
|
||||
* @uiDefault TextComponent.arc int
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
@@ -33,7 +32,7 @@ public class FlatTextBorder
|
||||
protected final int arc = UIManager.getInt( "TextComponent.arc" );
|
||||
|
||||
@Override
|
||||
protected float getArc( Component c ) {
|
||||
return scale( (float) arc );
|
||||
protected int getArc( Component c ) {
|
||||
return arc;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user