mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
FlatUIUtils: renamed and documented component painting methods
This commit is contained in:
@@ -79,12 +79,12 @@ public class FlatBorder
|
|||||||
|
|
||||||
if( isFocused( c ) ) {
|
if( isFocused( c ) ) {
|
||||||
g2.setColor( getFocusColor( c ) );
|
g2.setColor( getFocusColor( c ) );
|
||||||
FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth,
|
FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth,
|
||||||
getLineWidth() + scale( (float) innerFocusWidth ), arc );
|
getLineWidth() + scale( (float) innerFocusWidth ), arc );
|
||||||
}
|
}
|
||||||
|
|
||||||
g2.setPaint( getBorderColor( c ) );
|
g2.setPaint( getBorderColor( c ) );
|
||||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, borderWidth, arc );
|
FlatUIUtils.paintComponentBorder( g2, x, y, width, height, focusWidth, borderWidth, arc );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ public class FlatButtonUI
|
|||||||
g2.setPaint( new GradientPaint( 0, 0, startBg, 0, c.getHeight(), endBg ) );
|
g2.setPaint( new GradientPaint( 0, 0, startBg, 0, c.getHeight(), endBg ) );
|
||||||
else
|
else
|
||||||
FlatUIUtils.setColor( g2, background, def ? defaultBackground : c.getBackground() );
|
FlatUIUtils.setColor( g2, background, def ? defaultBackground : c.getBackground() );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ public class FlatComboBoxUI
|
|||||||
g2.setColor( enabled
|
g2.setColor( enabled
|
||||||
? (editableBackground != null && comboBox.isEditable() ? editableBackground : c.getBackground())
|
? (editableBackground != null && comboBox.isEditable() ? editableBackground : c.getBackground())
|
||||||
: getDisabledBackground( comboBox ) );
|
: getDisabledBackground( comboBox ) );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
// paint arrow button background
|
// paint arrow button background
|
||||||
if( enabled ) {
|
if( enabled ) {
|
||||||
@@ -326,7 +326,7 @@ public class FlatComboBoxUI
|
|||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
else
|
else
|
||||||
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
g2.setClip( oldClip );
|
g2.setClip( oldClip );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class FlatLineBorder
|
|||||||
try {
|
try {
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
g2.setColor( lineColor );
|
g2.setColor( lineColor );
|
||||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, 0f, scale( 1f ), 0f );
|
FlatUIUtils.paintComponentBorder( g2, x, y, width, height, 0f, scale( 1f ), 0f );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ public class FlatSpinnerUI
|
|||||||
g2.setColor( enabled
|
g2.setColor( enabled
|
||||||
? c.getBackground()
|
? c.getBackground()
|
||||||
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground) );
|
: (isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground) );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
// paint arrow buttons background
|
// paint arrow buttons background
|
||||||
if( enabled ) {
|
if( enabled ) {
|
||||||
@@ -277,7 +277,7 @@ public class FlatSpinnerUI
|
|||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
else
|
else
|
||||||
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
g2.setClip( oldClip );
|
g2.setClip( oldClip );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ public class FlatTextFieldUI
|
|||||||
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
|
: (isIntelliJTheme && (!c.isEnabled() || !c.isEditable())
|
||||||
? FlatUIUtils.getParentBackground( c )
|
? FlatUIUtils.getParentBackground( c )
|
||||||
: background) );
|
: background) );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, 0 );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, 0 );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,9 +125,39 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a round rectangle.
|
* Paints an outer border, which is usually a focus border.
|
||||||
|
* <p>
|
||||||
|
* The outside bounds of the painted border are {@code x,y,width,height}.
|
||||||
|
* The line width of the painted border is {@code focusWidth + lineWidth}.
|
||||||
|
* The given arc diameter refers to the inner rectangle ({@code x,y,width,height} minus {@code focusWidth}).
|
||||||
|
*
|
||||||
|
* @see #paintComponentBorder
|
||||||
|
* @see #paintComponentBackground
|
||||||
*/
|
*/
|
||||||
public static void drawRoundRectangle( Graphics2D g, int x, int y, int width, int height,
|
public static void paintComponentOuterBorder( Graphics2D g, int x, int y, int width, int height,
|
||||||
|
float focusWidth, float lineWidth, float arc )
|
||||||
|
{
|
||||||
|
float outerRadius = (arc > 0) ? arc + focusWidth - UIScale.scale( 2f ) : focusWidth;
|
||||||
|
float ow = focusWidth + lineWidth;
|
||||||
|
float innerRadius = outerRadius - ow;
|
||||||
|
|
||||||
|
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
||||||
|
path.append( createRoundRectanglePath( x, y, width, height, outerRadius, outerRadius, outerRadius, outerRadius ), false );
|
||||||
|
path.append( createRoundRectanglePath( x + ow, y + ow, width - (ow * 2), height - (ow * 2), innerRadius, innerRadius, innerRadius, innerRadius ), false );
|
||||||
|
g.fill( path );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the border of a component as round rectangle.
|
||||||
|
* <p>
|
||||||
|
* The outside bounds of the painted border are
|
||||||
|
* {@code x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)}.
|
||||||
|
* The given arc diameter refers to the painted rectangle (and not to {@code x,y,width,height}).
|
||||||
|
*
|
||||||
|
* @see #paintComponentOuterBorder
|
||||||
|
* @see #paintComponentBackground
|
||||||
|
*/
|
||||||
|
public static void paintComponentBorder( Graphics2D g, int x, int y, int width, int height,
|
||||||
float focusWidth, float lineWidth, float arc )
|
float focusWidth, float lineWidth, float arc )
|
||||||
{
|
{
|
||||||
float arc2 = arc > lineWidth ? arc - lineWidth : 0f;
|
float arc2 = arc > lineWidth ? arc - lineWidth : 0f;
|
||||||
@@ -146,9 +176,16 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills a round rectangle.
|
* Fills the background of a component with a round rectangle.
|
||||||
|
* <p>
|
||||||
|
* The bounds of the painted round rectangle are
|
||||||
|
* {@code x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)}.
|
||||||
|
* The given arc diameter refers to the painted rectangle (and not to {@code x,y,width,height}).
|
||||||
|
*
|
||||||
|
* @see #paintComponentOuterBorder
|
||||||
|
* @see #paintComponentBorder
|
||||||
*/
|
*/
|
||||||
public static void fillRoundRectangle( Graphics2D g, int x, int y, int width, int height,
|
public static void paintComponentBackground( Graphics2D g, int x, int y, int width, int height,
|
||||||
float focusWidth, float arc )
|
float focusWidth, float arc )
|
||||||
{
|
{
|
||||||
g.fill( new RoundRectangle2D.Float(
|
g.fill( new RoundRectangle2D.Float(
|
||||||
@@ -189,25 +226,6 @@ public class FlatUIUtils
|
|||||||
return null;
|
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 outerArc = (arc > 0) ? arc + focusWidth - UIScale.scale( 2f ) : focusWidth;
|
|
||||||
float ow = focusWidth + lineWidth;
|
|
||||||
|
|
||||||
Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
|
|
||||||
path.append( createOutlinePath( x, y, width, height, outerArc ), false );
|
|
||||||
path.append( createOutlinePath( x + ow, y + ow, width - (ow * 2), height - (ow * 2), outerArc - ow ), false );
|
|
||||||
g.fill( path );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Shape createOutlinePath( float x, float y, float width, float height, float arc ) {
|
|
||||||
return createRoundRectanglePath( x, y, width, height, arc, arc, arc, arc );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius or each corner.
|
* Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius or each corner.
|
||||||
*/
|
*/
|
||||||
@@ -222,7 +240,7 @@ public class FlatUIUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a filled rounded rectangle shape and allows specifying the radius or each corner.
|
* Creates a filled rounded rectangle shape and allows specifying the radius of each corner.
|
||||||
*/
|
*/
|
||||||
public static Shape createRoundRectanglePath( float x, float y, float width, float height,
|
public static Shape createRoundRectanglePath( float x, float y, float width, float height,
|
||||||
float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight )
|
float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight )
|
||||||
@@ -256,10 +274,16 @@ public class FlatUIUtils
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a closed path for the given points.
|
||||||
|
*/
|
||||||
public static Path2D createPath( double... points ) {
|
public static Path2D createPath( double... points ) {
|
||||||
return createPath( true, points );
|
return createPath( true, points );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a open or closed path for the given points.
|
||||||
|
*/
|
||||||
public static Path2D createPath( boolean close, double... points ) {
|
public static Path2D createPath( boolean close, double... points ) {
|
||||||
Path2D path = new Path2D.Float();
|
Path2D path = new Path2D.Float();
|
||||||
path.moveTo( points[0], points[1] );
|
path.moveTo( points[0], points[1] );
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ public class FlatDatePickerUI
|
|||||||
|
|
||||||
// paint background
|
// paint background
|
||||||
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
g2.setColor( enabled ? c.getBackground() : disabledBackground );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
|
|
||||||
// paint arrow button background
|
// paint arrow button background
|
||||||
if( enabled ) {
|
if( enabled ) {
|
||||||
@@ -247,7 +247,7 @@ public class FlatDatePickerUI
|
|||||||
g2.clipRect( arrowX, 0, width - arrowX, height );
|
g2.clipRect( arrowX, 0, width - arrowX, height );
|
||||||
else
|
else
|
||||||
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
g2.clipRect( 0, 0, arrowX + arrowWidth, height );
|
||||||
FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc );
|
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
|
||||||
g2.setClip( oldClip );
|
g2.setClip( oldClip );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user