Class FlatUIUtils


  • public class FlatUIUtils
    extends java.lang.Object
    Utility methods for UI delegates.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean MAC_USE_QUARTZ  
    • 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)  
      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 a 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 or 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.Color deriveColor​(java.awt.Color color, java.awt.Color baseColor)  
      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.
      static float getBorderArc​(javax.swing.JComponent c)
      Returns the scaled arc diameter of the border for the given component.
      static float getBorderFocusWidth​(javax.swing.JComponent c)
      Returns the scaled thickness of the outer focus border for the given component.
      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 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 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)  
      static boolean isCellEditor​(java.awt.Component c)  
      static boolean isPermanentFocusOwner​(java.awt.Component c)
      Returns whether the given component is the permanent focus owner and is in the active window.
      static java.lang.Boolean isRoundRect​(java.awt.Component c)  
      static int minimumHeight​(javax.swing.JComponent c, int minimumHeight)  
      static int minimumWidth​(javax.swing.JComponent c, int minimumWidth)  
      static java.awt.Color nonUIResource​(java.awt.Color c)  
      static java.awt.Font nonUIResource​(java.awt.Font font)  
      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.
      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.
      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.
      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).
      static void setInsets​(java.awt.Insets dest, java.awt.Insets src)  
      static void setRenderingHints​(java.awt.Graphics2D g)
      Sets rendering hints used for painting.
      static java.awt.Rectangle subtractInsets​(java.awt.Rectangle r, java.awt.Insets insets)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAC_USE_QUARTZ

        public static final boolean MAC_USE_QUARTZ
    • Constructor Detail

      • FlatUIUtils

        public FlatUIUtils()
    • 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)
      • 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.
      • 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 void setRenderingHints​(java.awt.Graphics2D g)
        Sets rendering hints used for painting.
      • deriveColor

        public static java.awt.Color deriveColor​(java.awt.Color color,
                                                 java.awt.Color baseColor)
      • 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).
      • 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(). Uses HiDPIUtils.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(). Uses HiDPIUtils.drawStringUnderlineCharAtWithYCorrection(JComponent, Graphics2D, String, int, int, int).

      • hasOpaqueBeenExplicitlySet

        public static boolean hasOpaqueBeenExplicitlySet​(javax.swing.JComponent c)