Class FlatUIUtils
- java.lang.Object
-
- com.formdev.flatlaf.ui.FlatUIUtils
-
public class FlatUIUtils extends java.lang.Object
Utility methods for UI delegates.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FlatUIUtils.NonUIResourceBorder
static class
FlatUIUtils.RepaintFocusListener
-
Field Summary
Fields Modifier and Type Field Description static double
CLOSE_PATH
static double
CURVE_TO
private static javax.swing.UIDefaults
lightAWTPeerDefaults
static double
MOVE_TO
static double
QUAD_TO
static double
ROUNDED
private static java.util.WeakHashMap<javax.swing.LookAndFeel,java.util.IdentityHashMap<java.lang.Object,javax.swing.plaf.ComponentUI>>
sharedUIinstances
private static boolean
useSharedUIs
-
Constructor Summary
Constructors Constructor Description FlatUIUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.Dimension
addInsets(java.awt.Dimension dim, java.awt.Insets insets)
static java.awt.Insets
addInsets(java.awt.Insets insets1, java.awt.Insets insets2)
static java.awt.Rectangle
addInsets(java.awt.Rectangle r, java.awt.Insets insets)
private static java.lang.String
buildSubKey(java.lang.String key, java.lang.String subKey)
InsertssubKey
at last dot inkey
.static boolean
canUseSharedUI(javax.swing.JComponent c)
Returns whether the component UI for the given component can be shared with other components.static java.awt.Shape
createArrowShape(int direction, boolean chevron, float w, float h)
Creates a chevron or triangle arrow shape for the given direction and size.static java.awt.Shape
createComponentRectangle(float x, float y, float w, float h, float arc)
Creates a (rounded) rectangle used to paint components (border, background, etc.).static java.awt.geom.Path2D
createPath(boolean close, double... points)
Creates an open or closed path for the given points.static java.awt.geom.Path2D
createPath(double... points)
Creates a closed path for the given points.static java.awt.geom.Path2D
createRectangle(float x, float y, float width, float height, float lineWidth)
Creates a not-filled rectangle shape with the given line width.static java.awt.geom.Path2D
createRoundRectangle(float x, float y, float width, float height, float lineWidth, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight)
Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius of each corner.static java.awt.Shape
createRoundRectanglePath(float x, float y, float width, float height, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight)
Creates a filled rounded rectangle shape and allows specifying the radius of each corner.static java.awt.Shape
createRoundTrianglePath(float x1, float y1, float x2, float y2, float x3, float y3, float arc)
Creates a rounded triangle shape for the given points and arc radius.static javax.swing.plaf.ComponentUI
createSharedUI(java.lang.Object key, java.util.function.Supplier<javax.swing.plaf.ComponentUI> newInstanceSupplier)
Creates a shared component UI for the given key and the current Laf.static java.awt.Color
deriveColor(java.awt.Color color, java.awt.Color baseColor)
private static double
distance(double x1, double y1, double x2, double y2)
Calculates the distance between two points.static void
drawShapePure(java.awt.Graphics2D g, java.awt.Shape shape)
Draws the given shape with disabled stroke normalization.static void
drawString(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int x, int y)
Draws the given string at the specified location.static void
drawStringUnderlineCharAt(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int underlinedIndex, int x, int y)
Draws the given string at the specified location underlining the specified character.private static java.awt.Container
findOpaqueParent(java.awt.Container c)
Find the first parent that is opaque.static boolean
getBoolean(javax.swing.JComponent c, java.lang.String systemPropertyKey, java.lang.String clientPropertyKey, java.lang.String uiKey, boolean defaultValue)
static float
getBorderArc(javax.swing.JComponent c)
Returns the scaled arc diameter of the border for the given component.static int
getBorderFocusAndLineWidth(javax.swing.JComponent c)
Returns the scaled thickness of the border.static float
getBorderFocusWidth(javax.swing.JComponent c)
Returns the scaled thickness of the outer focus border for the given component.static float
getBorderLineWidth(javax.swing.JComponent c)
Returns the scaled line thickness used to compute the border insets.static FlatBorder
getOutsideFlatBorder(javax.swing.JComponent c)
static java.awt.Color
getParentBackground(javax.swing.JComponent c)
Gets the background color of the first opaque parent.static boolean
getSubUIBoolean(java.lang.String key, java.lang.String subKey, boolean defaultValue)
static java.awt.Color
getSubUIColor(java.lang.String key, java.lang.String subKey)
static java.awt.Dimension
getSubUIDimension(java.lang.String key, java.lang.String subKey)
static java.awt.Font
getSubUIFont(java.lang.String key, java.lang.String subKey)
static javax.swing.Icon
getSubUIIcon(java.lang.String key, java.lang.String subKey)
static java.awt.Insets
getSubUIInsets(java.lang.String key, java.lang.String subKey)
static int
getSubUIInt(java.lang.String key, java.lang.String subKey, int defaultValue)
static boolean
getUIBoolean(java.lang.String key, boolean defaultValue)
static java.awt.Color
getUIColor(java.lang.String key, int defaultColorRGB)
static java.awt.Color
getUIColor(java.lang.String key, java.awt.Color defaultColor)
static java.awt.Color
getUIColor(java.lang.String key, java.lang.String defaultKey)
static <T extends java.lang.Enum<T>>
TgetUIEnum(java.lang.String key, java.lang.Class<T> enumType, T defaultValue)
static float
getUIFloat(java.lang.String key, float defaultValue)
static int
getUIInt(java.lang.String key, int defaultValue)
static boolean
hasOpaqueBeenExplicitlySet(javax.swing.JComponent c)
static boolean
hasRoundBorder(javax.swing.JComponent c)
(package private) static boolean
isAWTPeer(java.awt.Component c)
static boolean
isCellEditor(java.awt.Component c)
static boolean
isChevron(java.lang.String arrowType)
static boolean
isFullScreen(java.awt.Component c)
Returns whether the given component is in a window that is in full-screen mode.(package private) static boolean
isInActiveWindow(java.awt.Component c, java.awt.Window activeWindow)
static boolean
isInsetsEmpty(java.awt.Insets insets)
static boolean
isPermanentFocusOwner(java.awt.Component c)
Returns whether the given component is the permanent focus owner and is in the active window or in a popup window owned by the active window.static java.lang.Boolean
isRoundRect(java.awt.Component c)
static boolean
isUseSharedUIs()
Returns whether shared UI delegates are used.private static double
lerp(double v1, double v2, double t)
Calculates linear interpolation between two values.static int
minimumHeight(javax.swing.JComponent c, int minimumHeight)
static int
minimumWidth(javax.swing.JComponent c, int minimumWidth)
(package private) static boolean
needsLightAWTPeer(javax.swing.JComponent c)
Checks whether component is used as peer for AWT (on macOS) and whether a dark FlatLaf theme is active, which requires special handling because AWT always uses light colors.static java.awt.Color
nonUIResource(java.awt.Color c)
static java.awt.Font
nonUIResource(java.awt.Font font)
static javax.swing.border.Border
nonUIResource(javax.swing.border.Border border)
static void
paintArrow(java.awt.Graphics2D g, int x, int y, int width, int height, int direction, boolean chevron, int arrowSize, float arrowThickness, float xOffset, float yOffset)
Paints a chevron or triangle arrow in the center of the given rectangle.static void
paintComponentBackground(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float arc)
Fills the background of a component with a rounded rectangle.(package private) static void
paintFilledRectangle(java.awt.Graphics g, java.awt.Color color, float x, float y, float w, float h)
static void
paintGrip(java.awt.Graphics g, int x, int y, int width, int height, boolean horizontal, int dotCount, int dotSize, int gap, boolean centerPrecise)
static void
paintOutline(java.awt.Graphics2D g, float x, float y, float w, float h, float lineWidth, float arc)
Paints an outline at the given bounds using the given line width.static void
paintOutline(java.awt.Graphics2D g, float x, float y, float w, float h, float lineWidth, float arc, float innerArc)
Paints an outline at the given bounds using the given line width.static void
paintOutlinedComponent(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float focusWidthFraction, float focusInnerWidth, float borderWidth, float arc, java.awt.Paint focusColor, java.awt.Paint borderColor, java.awt.Paint background)
Paints an outlined component with rounded corners, consisting of following parts: an (optional) outer border, which is usually a focus indicator an (optional) component border the (optional) component background(package private) static void
paintOutlinedComponent(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float focusWidthFraction, float focusInnerWidth, float borderWidth, float arc, java.awt.Paint focusColor, java.awt.Paint borderColor, java.awt.Paint background, boolean scrollPane)
private static void
paintOutlinedComponentImpl(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float focusWidthFraction, float focusInnerWidth, float borderWidth, float arc, java.awt.Paint focusColor, java.awt.Paint borderColor, java.awt.Paint background, boolean scrollPane, double scaleFactor)
static void
paintParentBackground(java.awt.Graphics g, javax.swing.JComponent c)
Fill background with parent's background color because the visible component is smaller than its bounds (for the focus decoration).private static void
paintRoundedSelectionImpl(java.awt.Graphics2D g, int x, int y, int width, int height, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight)
static void
paintSelection(java.awt.Graphics2D g, int x, int y, int width, int height, java.awt.Insets insets, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight, int flags)
Paints a selection.static void
resetRenderingHints(java.awt.Graphics g, java.lang.Object[] oldRenderingHints)
Resets rendering hints previously set withsetRenderingHints(java.awt.Graphics)
.(package private) static void
runWithLightAWTPeerUIDefaults(java.lang.Runnable runnable)
static void
runWithoutRenderingHints(java.awt.Graphics g, java.lang.Object[] oldRenderingHints, java.lang.Runnable runnable)
Temporary resets rendering hints set withsetRenderingHints(java.awt.Graphics)
and runs the given runnable.static void
setInsets(java.awt.Insets dest, java.awt.Insets src)
static java.lang.Object[]
setRenderingHints(java.awt.Graphics g)
Sets rendering hints used for painting.static boolean
setUseSharedUIs(boolean useSharedUIs)
Specifies whether shared UI delegates are used.static java.awt.Rectangle
subtractInsets(java.awt.Rectangle r, java.awt.Insets insets)
(package private) static javax.swing.border.Border
unwrapNonUIResourceBorder(javax.swing.border.Border border)
-
-
-
Field Detail
-
useSharedUIs
private static boolean useSharedUIs
-
sharedUIinstances
private static final java.util.WeakHashMap<javax.swing.LookAndFeel,java.util.IdentityHashMap<java.lang.Object,javax.swing.plaf.ComponentUI>> sharedUIinstances
-
lightAWTPeerDefaults
private static javax.swing.UIDefaults lightAWTPeerDefaults
-
MOVE_TO
public static final double MOVE_TO
- Since:
- 3
- See Also:
- Constant Field Values
-
QUAD_TO
public static final double QUAD_TO
- Since:
- 3
- See Also:
- Constant Field Values
-
CURVE_TO
public static final double CURVE_TO
- Since:
- 3
- See Also:
- Constant Field Values
-
ROUNDED
public static final double ROUNDED
- Since:
- 3
- See Also:
- Constant Field Values
-
CLOSE_PATH
public static final double CLOSE_PATH
- Since:
- 3
- See Also:
- Constant Field Values
-
-
Method Detail
-
addInsets
public static java.awt.Rectangle addInsets(java.awt.Rectangle r, java.awt.Insets insets)
-
subtractInsets
public static java.awt.Rectangle subtractInsets(java.awt.Rectangle r, java.awt.Insets insets)
-
addInsets
public static java.awt.Dimension addInsets(java.awt.Dimension dim, java.awt.Insets insets)
-
addInsets
public static java.awt.Insets addInsets(java.awt.Insets insets1, java.awt.Insets insets2)
-
setInsets
public static void setInsets(java.awt.Insets dest, java.awt.Insets src)
-
isInsetsEmpty
public static boolean isInsetsEmpty(java.awt.Insets insets)
- Since:
- 3.5
-
getUIColor
public static java.awt.Color getUIColor(java.lang.String key, int defaultColorRGB)
-
getUIColor
public static java.awt.Color getUIColor(java.lang.String key, java.awt.Color defaultColor)
-
getUIColor
public static java.awt.Color getUIColor(java.lang.String key, java.lang.String defaultKey)
-
getUIBoolean
public static boolean getUIBoolean(java.lang.String key, boolean defaultValue)
- Since:
- 1.1
-
getUIInt
public static int getUIInt(java.lang.String key, int defaultValue)
-
getUIFloat
public static float getUIFloat(java.lang.String key, float defaultValue)
-
getUIEnum
public static <T extends java.lang.Enum<T>> T getUIEnum(java.lang.String key, java.lang.Class<T> enumType, T defaultValue)
- Since:
- 2
-
getSubUIColor
public static java.awt.Color getSubUIColor(java.lang.String key, java.lang.String subKey)
- Since:
- 3.2
-
getSubUIBoolean
public static boolean getSubUIBoolean(java.lang.String key, java.lang.String subKey, boolean defaultValue)
- Since:
- 3.2
-
getSubUIInt
public static int getSubUIInt(java.lang.String key, java.lang.String subKey, int defaultValue)
- Since:
- 3.2
-
getSubUIInsets
public static java.awt.Insets getSubUIInsets(java.lang.String key, java.lang.String subKey)
- Since:
- 3.2
-
getSubUIDimension
public static java.awt.Dimension getSubUIDimension(java.lang.String key, java.lang.String subKey)
- Since:
- 3.2
-
getSubUIIcon
public static javax.swing.Icon getSubUIIcon(java.lang.String key, java.lang.String subKey)
- Since:
- 3.2
-
getSubUIFont
public static java.awt.Font getSubUIFont(java.lang.String key, java.lang.String subKey)
- Since:
- 3.2
-
buildSubKey
private static java.lang.String buildSubKey(java.lang.String key, java.lang.String subKey)
InsertssubKey
at last dot inkey
.E.g.
buildSubKey( "TitlePane.font", "small" )
returns"TitlePane.small.font"
.
-
getBoolean
public static boolean getBoolean(javax.swing.JComponent c, java.lang.String systemPropertyKey, java.lang.String clientPropertyKey, java.lang.String uiKey, boolean defaultValue)
- Since:
- 1.1.2
-
isChevron
public static boolean isChevron(java.lang.String arrowType)
-
nonUIResource
public static java.awt.Color nonUIResource(java.awt.Color c)
-
nonUIResource
public static java.awt.Font nonUIResource(java.awt.Font font)
-
nonUIResource
public static javax.swing.border.Border nonUIResource(javax.swing.border.Border border)
- Since:
- 2
-
unwrapNonUIResourceBorder
static javax.swing.border.Border unwrapNonUIResourceBorder(javax.swing.border.Border border)
-
minimumWidth
public static int minimumWidth(javax.swing.JComponent c, int minimumWidth)
-
minimumHeight
public static int minimumHeight(javax.swing.JComponent c, int minimumHeight)
-
isCellEditor
public static boolean isCellEditor(java.awt.Component c)
-
isPermanentFocusOwner
public static boolean isPermanentFocusOwner(java.awt.Component c)
Returns whether the given component is the permanent focus owner and is in the active window or in a popup window owned by the active window. Used to paint focus indicators.
-
isInActiveWindow
static boolean isInActiveWindow(java.awt.Component c, java.awt.Window activeWindow)
-
isAWTPeer
static boolean isAWTPeer(java.awt.Component c)
-
needsLightAWTPeer
static boolean needsLightAWTPeer(javax.swing.JComponent c)
Checks whether component is used as peer for AWT (on macOS) and whether a dark FlatLaf theme is active, which requires special handling because AWT always uses light colors.
-
runWithLightAWTPeerUIDefaults
static void runWithLightAWTPeerUIDefaults(java.lang.Runnable runnable)
-
isFullScreen
public static boolean isFullScreen(java.awt.Component c)
Returns whether the given component is in a window that is in full-screen mode.
-
isRoundRect
public static java.lang.Boolean isRoundRect(java.awt.Component c)
-
getBorderFocusWidth
public static float getBorderFocusWidth(javax.swing.JComponent c)
Returns the scaled thickness of the outer focus border for the given component.
-
getBorderLineWidth
public static float getBorderLineWidth(javax.swing.JComponent c)
Returns the scaled line thickness used to compute the border insets.- Since:
- 2
-
getBorderFocusAndLineWidth
public static int getBorderFocusAndLineWidth(javax.swing.JComponent c)
Returns the scaled thickness of the border. This includes the outer focus border and the actual component border.- Since:
- 2
-
getBorderArc
public static float getBorderArc(javax.swing.JComponent c)
Returns the scaled arc diameter of the border for the given component.
-
hasRoundBorder
public static boolean hasRoundBorder(javax.swing.JComponent c)
-
getOutsideFlatBorder
public static FlatBorder getOutsideFlatBorder(javax.swing.JComponent c)
-
setRenderingHints
public static java.lang.Object[] setRenderingHints(java.awt.Graphics g)
Sets rendering hints used for painting.
-
resetRenderingHints
public static void resetRenderingHints(java.awt.Graphics g, java.lang.Object[] oldRenderingHints)
Resets rendering hints previously set withsetRenderingHints(java.awt.Graphics)
.
-
runWithoutRenderingHints
public static void runWithoutRenderingHints(java.awt.Graphics g, java.lang.Object[] oldRenderingHints, java.lang.Runnable runnable)
Temporary resets rendering hints set withsetRenderingHints(java.awt.Graphics)
and runs the given runnable.This is intended for painting text while rendering hints are set.
If text antialiasing is disabled (in OS system settings or via
-Dawt.useSystemAAFontSettings=off
), but general antialiasing is enabled, then text is still painted using some kind of "grayscale" antialiasing, which may make the text look bold (depends on font and font size). To avoid this, temporary disable general antialiasing. This does not affect text rendering if text antialiasing is enabled (usually the default).
-
deriveColor
public static java.awt.Color deriveColor(java.awt.Color color, java.awt.Color baseColor)
-
paintComponentBackground
public static void paintComponentBackground(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float arc)
Fills the background of a component with a rounded rectangle.The bounds of the painted rounded rectangle are
x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)
. The given arc diameter refers to the painted rectangle (and not tox,y,width,height
).
-
paintOutlinedComponent
public static void paintOutlinedComponent(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float focusWidthFraction, float focusInnerWidth, float borderWidth, float arc, java.awt.Paint focusColor, java.awt.Paint borderColor, java.awt.Paint background)
Paints an outlined component with rounded corners, consisting of following parts:- an (optional) outer border, which is usually a focus indicator
- an (optional) component border
- the (optional) component background
Each part is painted only if the corresponding part color is not
null
. The parts are painted in this order:- background
- focus border
- border
Background: The bounds of the filled rounded rectangle are
[x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)]
. The focus border and the border may paint over the background.Focus border: The outside bounds of the painted focus border are
[x, y, width, height]
. The thickness of the painted focus border is(focusWidth * focusWidthFraction) + focusInnerWidth
. The border may paint over the focus border iffocusInnerWidth > 0
.Border: The outside bounds of the painted border are
[x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)]
. The thickness of the painted border isborderWidth
.- Parameters:
g
- the graphics context used for paintingx
- the x coordinate of the componenty
- the y coordinate of the componentwidth
- the width of the componentheight
- the height of the componentfocusWidth
- the width of the focus border, or0
focusWidthFraction
- specified how much of the focus border is painted (in range 0 - 1); can be used for animation; the painted thickness of the focus border is(focusWidth * focusWidthFraction) + focusInnerWidth
focusInnerWidth
- the inner width of the focus border, or0
; if a border is painted thenfocusInnerWidth
needs to be larger thanborderWidth
to be not hidden by the borderborderWidth
- the width of the border, or0
arc
- the arc diameter used for the outside shape of the component border; the other needed arc diameters are computed from this arc diameterfocusColor
- the color of the focus border, ornull
borderColor
- the color of the border, ornull
background
- the background color of the component, ornull
- Since:
- 2
-
paintOutlinedComponent
static void paintOutlinedComponent(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float focusWidthFraction, float focusInnerWidth, float borderWidth, float arc, java.awt.Paint focusColor, java.awt.Paint borderColor, java.awt.Paint background, boolean scrollPane)
-
paintOutlinedComponentImpl
private static void paintOutlinedComponentImpl(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float focusWidthFraction, float focusInnerWidth, float borderWidth, float arc, java.awt.Paint focusColor, java.awt.Paint borderColor, java.awt.Paint background, boolean scrollPane, double scaleFactor)
-
paintOutline
public static void paintOutline(java.awt.Graphics2D g, float x, float y, float w, float h, float lineWidth, float arc)
Paints an outline at the given bounds using the given line width. Depending on the given arc, a rectangle, rounded rectangle or circle (if w == h) is painted.- Parameters:
g
- the graphics context used for paintingx
- the x coordinate of the outliney
- the y coordinate of the outlinew
- the width of the outlineh
- the height of the outlinelineWidth
- the width of the outlinearc
- the arc diameter used for the outside shape of the outline- Since:
- 2
-
paintOutline
public static void paintOutline(java.awt.Graphics2D g, float x, float y, float w, float h, float lineWidth, float arc, float innerArc)
Paints an outline at the given bounds using the given line width. Depending on the given arc, a rectangle, rounded rectangle or circle (if w == h) is painted.- Parameters:
g
- the graphics context used for paintingx
- the x coordinate of the outliney
- the y coordinate of the outlinew
- the width of the outlineh
- the height of the outlinelineWidth
- the width of the outlinearc
- the arc diameter used for the outside shape of the outlineinnerArc
- the arc diameter used for the inside shape of the outline- Since:
- 2
-
createComponentRectangle
public static java.awt.Shape createComponentRectangle(float x, float y, float w, float h, float arc)
Creates a (rounded) rectangle used to paint components (border, background, etc.). The given arc diameter is limited to min(width,height).
-
paintFilledRectangle
static void paintFilledRectangle(java.awt.Graphics g, java.awt.Color color, float x, float y, float w, float h)
-
paintSelection
public static void paintSelection(java.awt.Graphics2D g, int x, int y, int width, int height, java.awt.Insets insets, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight, int flags)
Paints a selection.The bounds of the painted selection (rounded) rectangle are
x + insets.left, y + insets.top, width - insets.left - insets.right, height - insets.top - insets.bottom
. The given arc radius refers to the painted rectangle (and not tox,y,width,height
).- Since:
- 3
-
paintRoundedSelectionImpl
private static void paintRoundedSelectionImpl(java.awt.Graphics2D g, int x, int y, int width, int height, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight)
-
paintGrip
public static void paintGrip(java.awt.Graphics g, int x, int y, int width, int height, boolean horizontal, int dotCount, int dotSize, int gap, boolean centerPrecise)
-
paintParentBackground
public static void paintParentBackground(java.awt.Graphics g, javax.swing.JComponent c)
Fill background with parent's background color because the visible component is smaller than its bounds (for the focus decoration).
-
getParentBackground
public static java.awt.Color getParentBackground(javax.swing.JComponent c)
Gets the background color of the first opaque parent.
-
findOpaqueParent
private static java.awt.Container findOpaqueParent(java.awt.Container c)
Find the first parent that is opaque.
-
createRectangle
public static java.awt.geom.Path2D createRectangle(float x, float y, float width, float height, float lineWidth)
Creates a not-filled rectangle shape with the given line width.
-
createRoundRectangle
public static java.awt.geom.Path2D createRoundRectangle(float x, float y, float width, float height, float lineWidth, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight)
Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius of each corner.
-
createRoundRectanglePath
public static java.awt.Shape createRoundRectanglePath(float x, float y, float width, float height, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight)
Creates a filled rounded rectangle shape and allows specifying the radius of each corner.
-
createRoundTrianglePath
public static java.awt.Shape createRoundTrianglePath(float x1, float y1, float x2, float y2, float x3, float y3, float arc)
Creates a rounded triangle shape for the given points and arc radius.- Since:
- 3
-
paintArrow
public static void paintArrow(java.awt.Graphics2D g, int x, int y, int width, int height, int direction, boolean chevron, int arrowSize, float arrowThickness, float xOffset, float yOffset)
Paints a chevron or triangle arrow in the center of the given rectangle.- Parameters:
g
- the graphics context used for paintingx
- the x coordinate of the rectangley
- the y coordinate of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangledirection
- the arrow direction (SwingConstants.NORTH
,SwingConstants.SOUTH
SwingConstants.WEST
orSwingConstants.EAST
)chevron
-true
for chevron arrow,false
for triangle arrowarrowSize
- the width of the painted arrow (for vertical direction) (will be scaled)arrowThickness
- the thickness of the painted chevron arrow (will be scaled)xOffset
- an offset added to the x coordinate of the arrow to paint it out-of-center. Usually zero. (will be scaled)yOffset
- an offset added to the y coordinate of the arrow to paint it out-of-center. Usually zero. (will be scaled)- Since:
- 3
-
createArrowShape
public static java.awt.Shape createArrowShape(int direction, boolean chevron, float w, float h)
Creates a chevron or triangle arrow shape for the given direction and size.The chevron shape is an open path that can be painted with
Graphics2D.draw(Shape)
. The triangle shape is a close path that can be painted withGraphics2D.fill(Shape)
.- Parameters:
direction
- the arrow direction (SwingConstants.NORTH
,SwingConstants.SOUTH
SwingConstants.WEST
orSwingConstants.EAST
)chevron
-true
for chevron arrow,false
for triangle arroww
- the width of the returned shapeh
- the height of the returned shape- Since:
- 1.1
-
createPath
public static java.awt.geom.Path2D createPath(double... points)
Creates a closed path for the given points.
-
createPath
public static java.awt.geom.Path2D createPath(boolean close, double... points)
Creates an open or closed path for the given points.
-
lerp
private static double lerp(double v1, double v2, double t)
Calculates linear interpolation between two values. https://en.wikipedia.org/wiki/Linear_interpolation#Programming_language_support
-
distance
private static double distance(double x1, double y1, double x2, double y2)
Calculates the distance between two points.
-
drawShapePure
public static void drawShapePure(java.awt.Graphics2D g, java.awt.Shape shape)
Draws the given shape with disabled stroke normalization. The x/y coordinates of the shape are translated by a half pixel.- Since:
- 2.1
-
drawString
public static void drawString(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int x, int y)
Draws the given string at the specified location. The provided component is used to query text properties and anti-aliasing hints.Use this method instead of
Graphics.drawString(String, int, int)
for correct anti-aliasing.Replacement for
SwingUtilities2.drawString()
. UsesHiDPIUtils.drawStringWithYCorrection(JComponent, Graphics2D, String, int, int)
.
-
drawStringUnderlineCharAt
public static void drawStringUnderlineCharAt(javax.swing.JComponent c, java.awt.Graphics g, java.lang.String text, int underlinedIndex, int x, int y)
Draws the given string at the specified location underlining the specified character. The provided component is used to query text properties and anti-aliasing hints.Replacement for
SwingUtilities2.drawStringUnderlineCharAt()
. UsesHiDPIUtils.drawStringUnderlineCharAtWithYCorrection(JComponent, Graphics2D, String, int, int, int)
.
-
hasOpaqueBeenExplicitlySet
public static boolean hasOpaqueBeenExplicitlySet(javax.swing.JComponent c)
-
isUseSharedUIs
public static boolean isUseSharedUIs()
Returns whether shared UI delegates are used.- Since:
- 1.6
-
setUseSharedUIs
public static boolean setUseSharedUIs(boolean useSharedUIs)
Specifies whether shared UI delegates are used. This does not change already existing UI delegates.- Since:
- 1.6
-
createSharedUI
public static javax.swing.plaf.ComponentUI createSharedUI(java.lang.Object key, java.util.function.Supplier<javax.swing.plaf.ComponentUI> newInstanceSupplier)
Creates a shared component UI for the given key and the current Laf. Each Laf instance has its own shared component UI instance.This is for GUI builders that support Laf switching and may use multiple Laf instances at the same time.
-
canUseSharedUI
public static boolean canUseSharedUI(javax.swing.JComponent c)
Returns whether the component UI for the given component can be shared with other components. This is only possible if it does not have styles.
-
-