Class FlatUIUtils
- java.lang.Object
-
- com.formdev.flatlaf.ui.FlatUIUtils
-
public class FlatUIUtils extends Object
Utility 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 DimensionaddInsets(Dimension dim, Insets insets)static InsetsaddInsets(Insets insets1, Insets insets2)static RectangleaddInsets(Rectangle r, Insets insets)static ShapecreateArrowShape(int direction, boolean chevron, float w, float h)Creates a chevron or triangle arrow shape for the given direction and size.static ShapecreateComponentRectangle(float x, float y, float w, float h, float arc)Creates a (rounded) rectangle used to paint components (border, background, etc).static Path2DcreatePath(boolean close, double... points)Creates a open or closed path for the given points.static Path2DcreatePath(double... points)Creates a closed path for the given points.static Path2DcreateRectangle(float x, float y, float width, float height, float lineWidth)Creates a not-filled rectangle shape with the given line width.static 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 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 ComponentUIcreateSharedUI(Object key, Supplier<ComponentUI> newInstanceSupplier)Creates a shared component UI for the given key and the current Laf.static ColorderiveColor(Color color, Color baseColor)static voiddrawString(JComponent c, Graphics g, String text, int x, int y)Draws the given string at the specified location.static voiddrawStringUnderlineCharAt(JComponent c, Graphics g, String text, int underlinedIndex, int x, int y)Draws the given string at the specified location underlining the specified character.static booleangetBoolean(JComponent c, String systemPropertyKey, String clientPropertyKey, String uiKey, boolean defaultValue)static floatgetBorderArc(JComponent c)Returns the scaled arc diameter of the border for the given component.static floatgetBorderFocusWidth(JComponent c)Returns the scaled thickness of the outer focus border for the given component.static FlatBordergetOutsideFlatBorder(JComponent c)static ColorgetParentBackground(JComponent c)Gets the background color of the first opaque parent.static booleangetUIBoolean(String key, boolean defaultValue)static ColorgetUIColor(String key, int defaultColorRGB)static ColorgetUIColor(String key, Color defaultColor)static ColorgetUIColor(String key, String defaultKey)static floatgetUIFloat(String key, float defaultValue)static intgetUIInt(String key, int defaultValue)static booleanhasOpaqueBeenExplicitlySet(JComponent c)static booleanhasRoundBorder(JComponent c)static booleanisCellEditor(Component c)static booleanisChevron(String arrowType)static booleanisFullScreen(Component c)Returns whether the given component is in a window that is in full-screen mode.static booleanisPermanentFocusOwner(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 BooleanisRoundRect(Component c)static booleanisUseSharedUIs()Returns whether shared UI delegates are used.static intminimumHeight(JComponent c, int minimumHeight)static intminimumWidth(JComponent c, int minimumWidth)static ColornonUIResource(Color c)static FontnonUIResource(Font font)static voidpaintArrow(Graphics2D g, int x, int y, int width, int height, int direction, boolean chevron, int arrowSize, float xOffset, float yOffset)Paints a chevron or triangle arrow in the center of the given rectangle.static voidpaintComponentBackground(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(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(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(Graphics g, int x, int y, int width, int height, boolean horizontal, int dotCount, int dotSize, int gap, boolean centerPrecise)static voidpaintParentBackground(Graphics g, JComponent c)Fill background with parent's background color because the visible component is smaller than its bounds (for the focus decoration).static voidresetRenderingHints(Graphics g, Object[] oldRenderingHints)Resets rendering hints previously set withsetRenderingHints(java.awt.Graphics).static voidrunWithoutRenderingHints(Graphics g, Object[] oldRenderingHints, Runnable runnable)Temporary resets rendering hints set withsetRenderingHints(java.awt.Graphics)and runs the given runnable.static voidsetInsets(Insets dest, Insets src)static Object[]setRenderingHints(Graphics g)Sets rendering hints used for painting.static booleansetUseSharedUIs(boolean useSharedUIs)Specifies whether shared UI delegates are used.static RectanglesubtractInsets(Rectangle r, Insets insets)
-
-
-
Method Detail
-
getUIBoolean
public static boolean getUIBoolean(String key, boolean defaultValue)
- Since:
- 1.1
-
getUIInt
public static int getUIInt(String key, int defaultValue)
-
getUIFloat
public static float getUIFloat(String key, float defaultValue)
-
getBoolean
public static boolean getBoolean(JComponent c, String systemPropertyKey, String clientPropertyKey, String uiKey, boolean defaultValue)
- Since:
- 1.1.2
-
isChevron
public static boolean isChevron(String arrowType)
-
minimumWidth
public static int minimumWidth(JComponent c, int minimumWidth)
-
minimumHeight
public static int minimumHeight(JComponent c, int minimumHeight)
-
isCellEditor
public static boolean isCellEditor(Component c)
-
isPermanentFocusOwner
public static boolean isPermanentFocusOwner(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.
-
isFullScreen
public static boolean isFullScreen(Component c)
Returns whether the given component is in a window that is in full-screen mode.
-
getBorderFocusWidth
public static float getBorderFocusWidth(JComponent c)
Returns the scaled thickness of the outer focus border for the given component.
-
getBorderArc
public static float getBorderArc(JComponent c)
Returns the scaled arc diameter of the border for the given component.
-
hasRoundBorder
public static boolean hasRoundBorder(JComponent c)
-
getOutsideFlatBorder
public static FlatBorder getOutsideFlatBorder(JComponent c)
-
setRenderingHints
public static Object[] setRenderingHints(Graphics g)
Sets rendering hints used for painting.
-
resetRenderingHints
public static void resetRenderingHints(Graphics g, Object[] oldRenderingHints)
Resets rendering hints previously set withsetRenderingHints(java.awt.Graphics).
-
runWithoutRenderingHints
public static void runWithoutRenderingHints(Graphics g, Object[] oldRenderingHints, 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).
-
paintComponentOuterBorder
public static void paintComponentOuterBorder(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(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(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 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(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(Graphics g, 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 Color getParentBackground(JComponent c)
Gets the background color of the first opaque parent.
-
createRectangle
public static 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 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 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.
-
paintArrow
public static void paintArrow(Graphics2D g, int x, int y, int width, int height, int direction, boolean chevron, int arrowSize, 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.SOUTHSwingConstants.WESTorSwingConstants.EAST)chevron-truefor chevron arrow,falsefor triangle arrowarrowSize- the width of the painted arrow (for vertical direction) (will be scaled)xOffset- a offset added to the x coordinate of the arrow to paint it out-of-center. Usually zero. (will be scaled)yOffset- a offset added to the y coordinate of the arrow to paint it out-of-center. Usually zero. (will be scaled)- Since:
- 1.1
-
createArrowShape
public static 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 a 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.SOUTHSwingConstants.WESTorSwingConstants.EAST)chevron-truefor chevron arrow,falsefor triangle arroww- the width of the returned shapeh- the height of the returned shape- Since:
- 1.1
-
createPath
public static Path2D createPath(double... points)
Creates a closed path for the given points.
-
createPath
public static Path2D createPath(boolean close, double... points)
Creates a open or closed path for the given points.
-
drawString
public static void drawString(JComponent c, Graphics g, 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(JComponent c, Graphics g, 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(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 ComponentUI createSharedUI(Object key, Supplier<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.
-
-