Class GraphicUtils


  • public final class GraphicUtils
    extends Object
    GraphicsUtils class defines common user-interface related utility functions.
    • Field Detail

      • SELECTION_COLOR

        public static final Color SELECTION_COLOR
      • TOOLTIP_COLOR

        public static final Color TOOLTIP_COLOR
      • component

        protected static final Component component
    • Method Detail

      • centerWindowOnScreen

        public static void centerWindowOnScreen​(Window window)
        Sets the location of the specified window so that it is centered on screen.
        Parameters:
        window - The window to be centered.
      • createImageIcon

        public static ImageIcon createImageIcon​(Image image)
      • getPopupMenuShowPoint

        public static Point getPopupMenuShowPoint​(JPopupMenu popup,
                                                  MouseEvent event)
        Returns a point where the given popup menu should be shown. The point is calculated by adjusting the X and Y coordinates from the given mouse event so that the popup menu will not be clipped by the screen boundaries.
        Parameters:
        popup - the popup menu
        event - the mouse event
        Returns:
        the point where the popup menu should be shown
      • getPopupMenuShowPoint

        public static Point getPopupMenuShowPoint​(JPopupMenu popup,
                                                  int x,
                                                  int y)
        Returns a point where the given popup menu should be shown. The point is calculated by adjusting the X and Y coordinates so that the popup menu will not be clipped by the screen boundaries.
        Parameters:
        popup - the popup menu
        x - the x position in screen coordinate
        y - the y position in screen coordinates
        Returns:
        the point where the popup menu should be shown in screen coordinates
      • centerWindowOnComponent

        public static void centerWindowOnComponent​(Window window,
                                                   Component over)
        Centers the window over a component (usually another window). The window must already have been sized.
        Parameters:
        window - the window to center
        over - the component over which to center it
      • isAncestorOfFocusedComponent

        public static boolean isAncestorOfFocusedComponent​(Component c)
        Parameters:
        c - the component
        Returns:
        returns true if the component of one of its child has the focus
      • getFocusableComponentOrChild

        public static Component getFocusableComponentOrChild​(Component c,
                                                             boolean deepest)
        Returns the first component in the tree of c that can accept the focus.
        Parameters:
        c - the root of the component hierarchy to search
        deepest - if deepest is true the method will return the first and deepest component that can accept the focus. For example, if both a child and its parent are focusable and deepest is true, the child is returned.
        Returns:
        the first component that can accept focus
        See Also:
        focusComponentOrChild(java.awt.Component)
      • focusComponentOrChild

        public static Component focusComponentOrChild​(Component c,
                                                      boolean deepest)
        Puts the focus on the first component in the tree of c that can accept the focus.
        Parameters:
        c - the root of the component hierarchy to search
        deepest - if deepest is true the method will focus the first and deepest component that can accept the focus. For example, if both a child and its parent are focusable and deepest is true, the child is focused.
        Returns:
        the component which has focus
        See Also:
        getFocusableComponentOrChild(java.awt.Component, boolean)
      • loadFromResource

        public static Image loadFromResource​(String imageName,
                                             Class cls)
        Loads an Image named imageName as a resource relative to the Class cls. If the Image can not be loaded, then null is returned. Images loaded here will be added to an internal cache based upon the full URL to their location.

        This method replaces legacy code from JDeveloper 3.x and earlier.

        Parameters:
        imageName - the name of the image
        cls - the class relative to the which the image resource should be obtained
        Returns:
        the image
        See Also:
        Class.getResource(String), Toolkit.createImage(URL)
      • getScreenBounds

        public static Rectangle[] getScreenBounds()
      • makeSameSize

        public static final void makeSameSize​(JComponent[] comps)
      • toHTMLColor

        public static final String toHTMLColor​(Color c)
        Return the hexidecimal color from a java.awt.Color
        Parameters:
        c - the colour
        Returns:
        hexadecimal string
      • createToolTip

        public static final String createToolTip​(String text,
                                                 int width)
      • createToolTip

        public static final String createToolTip​(String text)