Class FlatUIUtils


  • public class FlatUIUtils
    extends Object
    Utility methods for UI delegates.
    • Field Detail

      • MAC_USE_QUARTZ

        public static final boolean MAC_USE_QUARTZ
    • Constructor Detail

      • FlatUIUtils

        public FlatUIUtils()
    • Method Detail

      • setInsets

        public static void setInsets​(Insets dest,
                                     Insets src)
      • getUIColor

        public static Color getUIColor​(String key,
                                       int defaultColorRGB)
      • getUIColor

        public static Color getUIColor​(String key,
                                       Color defaultColor)
      • 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)
      • nonUIResource

        public static Color nonUIResource​(Color c)
      • nonUIResource

        public static Font nonUIResource​(Font font)
      • 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)
      • setRenderingHints

        public static Object[] setRenderingHints​(Graphics g)
        Sets rendering hints used for painting.
      • runWithoutRenderingHints

        public static void runWithoutRenderingHints​(Graphics g,
                                                    Object[] oldRenderingHints,
                                                    Runnable runnable)
        Temporary resets rendering hints set with setRenderingHints(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 Color deriveColor​(Color color,
                                        Color baseColor)
      • 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 painting
        x - the x coordinate of the rectangle
        y - the y coordinate of the rectangle
        width - the width of the rectangle
        height - the height of the rectangle
        direction - the arrow direction (SwingConstants.NORTH, SwingConstants.SOUTH SwingConstants.WEST or SwingConstants.EAST)
        chevron - true for chevron arrow, false for triangle arrow
        arrowSize - 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
      • 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.
      • 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.