Class PortingUtils


  • public class PortingUtils
    extends java.lang.Object
    A class that keeps all 1.4/1.3 different stuff.
    • Constructor Summary

      Constructors 
      Constructor Description
      PortingUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.awt.Rectangle containsInScreenBounds​(java.awt.Component invoker, java.awt.Rectangle rect)
      To make sure the rectangle is within the screen bounds.
      static java.awt.Rectangle containsInScreenBounds​(java.awt.Component invoker, java.awt.Rectangle rect, boolean useInvokerDevice)
      To make sure the rectangle is within the screen bounds.
      static java.awt.Rectangle ensureOnScreen​(java.awt.Rectangle rect)
      Modifies the position of rect so that it is completely on screen if that is possible.
      static java.awt.Rectangle ensureOnScreen​(java.awt.Rectangle rect, boolean allowCrossScreen)
      Modifies the position of rect so that it is completely on screen if that is possible.
      static java.awt.Rectangle ensureVisible​(java.awt.Component invoker, java.awt.Rectangle bounds)
      Ensures the rectangle is visible on the screen.
      static java.awt.Rectangle getContainingScreenBounds​(java.awt.Rectangle rect, boolean considerInsets)
      Gets the screen bounds that contains the rect.
      static java.awt.Component getCurrentFocusComponent​(java.awt.AWTEvent event)
      Gets current focused components.
      static int getFrameState​(java.awt.Frame frame)
      Gets frame's state.
      static java.awt.Rectangle getLocalScreenBounds()
      Gets the local monitor's screen bounds.
      static java.awt.Dimension getLocalScreenSize​(java.awt.Component invoker)
      Gets the screen size.
      static int getMouseModifiers​(java.awt.event.MouseEvent e)
      Gets mouse modifiers.
      static java.awt.geom.Area getScreenArea()
      Get screen area of all monitors.
      static java.awt.Rectangle getScreenBounds​(java.awt.Component invoker)
      Gets the screen bounds.
      static java.awt.Rectangle getScreenBounds​(java.awt.Component invoker, boolean useInvokerDevice)
      Gets the screen bounds.
      static java.awt.Dimension getScreenSize​(java.awt.Component invoker)
      Gets the screen size.
      static void initializeScreenArea()
      Deprecated.
      Call GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
      static void initializeScreenArea​(int priority)
      Deprecated.
      Call GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
      static void invalidateScreenArea()
      Deprecated.
      Cache no longer used.
      static boolean isInitializationThreadAlive()
      Deprecated.
      No longer used.
      static boolean isInitializationThreadStarted()
      Deprecated.
      No longer used.
      static void notifyUser()
      Notifies user something is wrong.
      static void notifyUser​(java.awt.Component component)
      Notifies user something is wrong.
      static java.awt.Rectangle overlapWithScreenBounds​(java.awt.Component invoker, java.awt.Rectangle rect)
      To make sure the rectangle has overlap with the screen bounds.
      static void prerequisiteChecking()
      Checks the prerequisite needed by JIDE demos.
      static void removeButtonBorder​(javax.swing.AbstractButton button)
      Removes the button border.
      static void removeFocus​(javax.swing.JComponent component)
      Makes sure the component won't receive the focus.
      static void setFrameState​(java.awt.Frame frame, int state)
      Sets frame's state.
      static void setMinimumSize​(java.awt.Component component, java.awt.Dimension size)
      Sets the minimum size on a component.
      static void setPreferredSize​(java.awt.Component component, java.awt.Dimension size)
      Sets the preferred size on a component.
      • Methods inherited from class java.lang.Object

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

      • INITIALIZE_SCREEN_AREA_USING_THREAD

        @Deprecated
        public static boolean INITIALIZE_SCREEN_AREA_USING_THREAD
        Deprecated.
        No longer used.
    • Constructor Detail

      • PortingUtils

        public PortingUtils()
    • Method Detail

      • getCurrentFocusComponent

        public static java.awt.Component getCurrentFocusComponent​(java.awt.AWTEvent event)
        Gets current focused components. If 1.3, just uses event's source; 1.4, used keyboard focus manager to get the correct focused component.
        Parameters:
        event - the AWT event
        Returns:
        current focused component
      • getFrameState

        public static int getFrameState​(java.awt.Frame frame)
        Gets frame's state. In 1.3, used getState; in 1.4, uses getExtendedState.
        Parameters:
        frame - the frame
        Returns:
        frame's state
      • setFrameState

        public static void setFrameState​(java.awt.Frame frame,
                                         int state)
        Sets frame's state. In 1.3, uses sets frame's state; in 1.4, uses gets frame's state.
        Parameters:
        frame - the frame
        state - the state
      • getMouseModifiers

        public static int getMouseModifiers​(java.awt.event.MouseEvent e)
        Gets mouse modifiers. If 1.3, uses getModifiers; 1.4, getModifiersEx.
        Parameters:
        e - the mouse event
        Returns:
        mouse modifiers
      • removeFocus

        public static void removeFocus​(javax.swing.JComponent component)
        Makes sure the component won't receive the focus.
        Parameters:
        component - the component
      • removeButtonBorder

        public static void removeButtonBorder​(javax.swing.AbstractButton button)
        Removes the button border.
        Parameters:
        button - the button
      • containsInScreenBounds

        public static java.awt.Rectangle containsInScreenBounds​(java.awt.Component invoker,
                                                                java.awt.Rectangle rect)
        To make sure the rectangle is within the screen bounds.
        Parameters:
        invoker - the invoker component
        rect - the rectangle
        Returns:
        the rectangle that is in the screen bounds.
      • containsInScreenBounds

        public static java.awt.Rectangle containsInScreenBounds​(java.awt.Component invoker,
                                                                java.awt.Rectangle rect,
                                                                boolean useInvokerDevice)
        To make sure the rectangle is within the screen bounds.
        Parameters:
        invoker - the invoker component
        rect - the rectangle
        useInvokerDevice - the flag to return invoker device or not
        Returns:
        the rectangle that is in the screen bounds.
        Since:
        3.4.1
      • overlapWithScreenBounds

        public static java.awt.Rectangle overlapWithScreenBounds​(java.awt.Component invoker,
                                                                 java.awt.Rectangle rect)
        To make sure the rectangle has overlap with the screen bounds.
        Parameters:
        invoker - the invoker component
        rect - the rectangle
        Returns:
        the rectangle that has overlap with the screen bounds.
      • getScreenSize

        public static java.awt.Dimension getScreenSize​(java.awt.Component invoker)
        Gets the screen size. In JDK1.4+, the returned size will exclude task bar area on Windows OS.
        Parameters:
        invoker - the invoker component
        Returns:
        the screen size.
      • getLocalScreenSize

        public static java.awt.Dimension getLocalScreenSize​(java.awt.Component invoker)
        Gets the screen size. In JDK1.4+, the returned size will exclude task bar area on Windows OS.
        Parameters:
        invoker - the invoker component
        Returns:
        the screen size.
      • getScreenBounds

        public static java.awt.Rectangle getScreenBounds​(java.awt.Component invoker,
                                                         boolean useInvokerDevice)
        Gets the screen bounds. In JDK1.4+, the returned bounds will exclude task bar area on Windows OS. If the invoker is null, the whole screen bounds including all display devices will be returned. If the invoker is not null and the useInvokeDevice flag is true, the screen of the display device for the invoker will be returned.
        Parameters:
        invoker - the invoker component
        useInvokerDevice - the flag to return invoker device or not
        Returns:
        the screen bounds.
      • getScreenBounds

        public static java.awt.Rectangle getScreenBounds​(java.awt.Component invoker)
        Gets the screen bounds. In JDK1.4+, the returned bounds will exclude task bar area on Windows OS.

        By default, it will not use invoker graphic device automatically.

        Parameters:
        invoker - the invoker component
        Returns:
        the screen bounds.
        See Also:
        getScreenBounds(java.awt.Component, boolean)
      • getLocalScreenBounds

        public static java.awt.Rectangle getLocalScreenBounds()
        Gets the local monitor's screen bounds.
        Returns:
        the screen bounds.
      • initializeScreenArea

        @Deprecated
        public static void initializeScreenArea()
        Deprecated.
        Call GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
        If you use methods such as ensureOnScreen(java.awt.Rectangle), getContainingScreenBounds(java.awt.Rectangle, boolean) or getScreenArea() for the first time, it will take up to a few seconds to run because it needs to get device information. To avoid any slowness, you can call call this method in the class where you will use those three methods. This method will spawn a thread to retrieve device information thus it will return immediately. Hopefully, when you use the three methods, the thread is done so user will not notice any slowness.
      • invalidateScreenArea

        @Deprecated
        public static void invalidateScreenArea()
        Deprecated.
        Cache no longer used.
        Invalidate the screen area so that initializeScreenArea will discard the cache and recalculate the screen bounds. Only call this when you detect the screen display setting changed on the system.
      • initializeScreenArea

        @Deprecated
        public static void initializeScreenArea​(int priority)
        Deprecated.
        Call GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
        If you use methods such as ensureOnScreen(java.awt.Rectangle), getContainingScreenBounds(java.awt.Rectangle, boolean) or getScreenArea() for the first time, it will take up to a couple of seconds to run because it needs to get device information. To avoid any slowness, you can call initializeScreenArea() method in the class where you will use those three methods. This method will spawn a thread to retrieve device information thus it will return immediately. Hopefully, when you use the three methods, the thread is done so user will not notice any slowness.
        Parameters:
        priority - as we will use a thread to calculate the screen area, you can use this parameter to control the priority of the thread. If you are waiting for the result before the next step, you should use normal priority (which is 5). If you just want to calculate when app starts, you can use a lower priority (such as 3). For example, AbstractComboBox needs screen size so that the popup doesn't go beyond the screen. So when AbstractComboBox is used, we will kick off the thread at priority 3. If user clicks on the drop down after the thread finished, there will be no time delay.
      • isInitializationThreadAlive

        @Deprecated
        public static boolean isInitializationThreadAlive()
        Deprecated.
        No longer used.
      • isInitializationThreadStarted

        @Deprecated
        public static boolean isInitializationThreadStarted()
        Deprecated.
        No longer used.
      • ensureVisible

        public static java.awt.Rectangle ensureVisible​(java.awt.Component invoker,
                                                       java.awt.Rectangle bounds)
        Ensures the rectangle is visible on the screen.
        Parameters:
        invoker - the invoking component
        bounds - the input bounds
        Returns:
        the modified bounds.
      • ensureOnScreen

        public static java.awt.Rectangle ensureOnScreen​(java.awt.Rectangle rect)
        Modifies the position of rect so that it is completely on screen if that is possible. By default, it will allow the rect to cross two screens. You can call ensureOnScreen(java.awt.Rectangle, boolean) and set the second parameter to false if you don't want to allow that case.
        Parameters:
        rect - The rectangle to be moved to a single screen
        Returns:
        rect after its position has been modified
      • ensureOnScreen

        public static java.awt.Rectangle ensureOnScreen​(java.awt.Rectangle rect,
                                                        boolean allowCrossScreen)
        Modifies the position of rect so that it is completely on screen if that is possible.
        Parameters:
        rect - The rectangle to be moved to a single screen
        allowCrossScreen - a flag to allow or disallow when the rect is cross two screens.
        Returns:
        rect after its position has been modified
      • getContainingScreenBounds

        public static java.awt.Rectangle getContainingScreenBounds​(java.awt.Rectangle rect,
                                                                   boolean considerInsets)
        Gets the screen bounds that contains the rect. The screen bounds consider the screen insets if any.
        Parameters:
        rect - the rect of the component.
        considerInsets - if consider the insets. The insets is for thing like Windows Task Bar.
        Returns:
        the screen bounds that contains the rect.
      • getScreenArea

        public static java.awt.geom.Area getScreenArea()
        Get screen area of all monitors.
        Returns:
        Union of all screens
      • notifyUser

        public static void notifyUser()
        Notifies user something is wrong. We use Toolkit beep method by default.
      • notifyUser

        public static void notifyUser​(java.awt.Component component)
        Notifies user something is wrong. We use Toolkit beep method by default.
        Parameters:
        component - the component that has the error or null if the error is not associated with any component.
      • prerequisiteChecking

        public static void prerequisiteChecking()
        Checks the prerequisite needed by JIDE demos. If the prerequisite doesn't meet, it will prompt a message box and exit.
      • setPreferredSize

        public static void setPreferredSize​(java.awt.Component component,
                                            java.awt.Dimension size)
        Sets the preferred size on a component. This method is there mainly to fix the issue that setPreferredSize method is there on Component only after JDK5. For JDK1.4 and before, you need to cast to JComponent first. So this method captures this logic and only call setPreferedSize when the JDK is 1.5 and above or when the component is instance of JComponent.
        Parameters:
        component - the component
        size - the preferred size.
      • setMinimumSize

        public static void setMinimumSize​(java.awt.Component component,
                                          java.awt.Dimension size)
        Sets the minimum size on a component. This method is there mainly to fix the issue that setMinimumSize method is there on Component only after JDK5. For JDK1.4 and before, you need to cast to JComponent first. So this method captures this logic and only call setMinimumSize when the JDK is 1.5 and above or when the component is
        Parameters:
        component - the component
        size - the preferred size.