Class FlatUIUtils
- java.lang.Object
-
- com.formdev.flatlaf.ui.FlatUIUtils
-
public class FlatUIUtils extends java.lang.ObjectUtility methods for UI delegates.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFlatUIUtils.RepaintFocusListener
-
Field Summary
Fields Modifier and Type Field Description static booleanMAC_USE_QUARTZ
-
Constructor Summary
Constructors Constructor Description FlatUIUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.DimensionaddInsets(java.awt.Dimension dim, java.awt.Insets insets)static java.awt.InsetsaddInsets(java.awt.Insets insets1, java.awt.Insets insets2)static java.awt.RectangleaddInsets(java.awt.Rectangle r, java.awt.Insets insets)static java.awt.ShapecreateComponentRectangle(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.Path2DcreatePath(boolean close, double... points)Creates a open or closed path for the given points.static java.awt.geom.Path2DcreatePath(double... points)Creates a closed path for the given points.static java.awt.geom.Path2DcreateRectangle(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.Path2DcreateRoundRectangle(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 or each corner.static java.awt.ShapecreateRoundRectanglePath(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 javax.swing.plaf.ComponentUIcreateSharedUI(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.ColorderiveColor(java.awt.Color color, java.awt.Color baseColor)static voiddrawString(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 voiddrawStringUnderlineCharAt(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.static floatgetBorderArc(javax.swing.JComponent c)Returns the scaled arc diameter of the border for the given component.static floatgetBorderFocusWidth(javax.swing.JComponent c)Returns the scaled thickness of the outer focus border for the given component.static FlatBordergetOutsideFlatBorder(javax.swing.JComponent c)static java.awt.ColorgetParentBackground(javax.swing.JComponent c)Gets the background color of the first opaque parent.static java.awt.ColorgetUIColor(java.lang.String key, int defaultColorRGB)static java.awt.ColorgetUIColor(java.lang.String key, java.awt.Color defaultColor)static java.awt.ColorgetUIColor(java.lang.String key, java.lang.String defaultKey)static floatgetUIFloat(java.lang.String key, float defaultValue)static intgetUIInt(java.lang.String key, int defaultValue)static booleanhasOpaqueBeenExplicitlySet(javax.swing.JComponent c)static booleanhasRoundBorder(javax.swing.JComponent c)static booleanisCellEditor(java.awt.Component c)static booleanisChevron(java.lang.String arrowType)static booleanisFullScreen(java.awt.Component c)Returns whether the given component is in a window that is in full-screen mode.static booleanisPermanentFocusOwner(java.awt.Component c)Returns whether the given component is the permanent focus owner and is in the active window.static java.lang.BooleanisRoundRect(java.awt.Component c)static intminimumHeight(javax.swing.JComponent c, int minimumHeight)static intminimumWidth(javax.swing.JComponent c, int minimumWidth)static java.awt.ColornonUIResource(java.awt.Color c)static java.awt.FontnonUIResource(java.awt.Font font)static voidpaintComponentBackground(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float arc)Fills the background of a component with a round rectangle.static voidpaintComponentBorder(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc)Draws the border of a component as round rectangle.static voidpaintComponentOuterBorder(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc)Paints an outer border, which is usually a focus border.static voidpaintGrip(java.awt.Graphics g, int x, int y, int width, int height, boolean horizontal, int dotCount, int dotSize, int gap, boolean centerPrecise)static voidpaintParentBackground(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).static voidresetRenderingHints(java.awt.Graphics g, java.lang.Object[] oldRenderingHints)Resets rendering hints previously set withsetRenderingHints(java.awt.Graphics).static voidrunWithoutRenderingHints(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 voidsetInsets(java.awt.Insets dest, java.awt.Insets src)static java.lang.Object[]setRenderingHints(java.awt.Graphics g)Sets rendering hints used for painting.static java.awt.RectanglesubtractInsets(java.awt.Rectangle r, java.awt.Insets insets)
-
-
-
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)
-
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)
-
getUIInt
public static int getUIInt(java.lang.String key, int defaultValue)
-
getUIFloat
public static float getUIFloat(java.lang.String key, float defaultValue)
-
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)
-
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. Used to paint focus indicators.
-
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.
-
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)
-
paintComponentOuterBorder
public static void paintComponentOuterBorder(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc)Paints an outer border, which is usually a focus border.The outside bounds of the painted border are
x,y,width,height. The line thickness of the painted border isfocusWidth + lineWidth. The given arc diameter refers to the inner rectangle (x,y,width,heightminusfocusWidth).
-
paintComponentBorder
public static void paintComponentBorder(java.awt.Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc)Draws the border of a component as round rectangle.The outside bounds of the painted border are
x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2). The line thickness of the painted border islineWidth. The given arc diameter refers to the painted rectangle (and not tox,y,width,height).
-
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 round rectangle.The bounds of the painted round 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).
-
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).
-
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.
-
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 or 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.
-
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 a open or closed path for the given points.
-
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)
-
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.
-
-