Class PortingUtils

java.lang.Object
com.jidesoft.utils.PortingUtils

public class PortingUtils extends Object
A class that keeps all 1.4/1.3 different stuff.
  • Field Details

    • INITIALIZE_SCREEN_AREA_USING_THREAD

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

    • PortingUtils

      public PortingUtils()
  • Method Details

    • getCurrentFocusComponent

      public static Component getCurrentFocusComponent(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(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(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(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(JComponent component)
      Makes sure the component won't receive the focus.
      Parameters:
      component - the component
    • removeButtonBorder

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

      public static Rectangle containsInScreenBounds(Component invoker, 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 Rectangle containsInScreenBounds(Component invoker, 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 Rectangle overlapWithScreenBounds(Component invoker, 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 Dimension getScreenSize(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 Dimension getLocalScreenSize(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 Rectangle getScreenBounds(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 Rectangle getScreenBounds(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:
    • getLocalScreenBounds

      public static 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 Rectangle ensureVisible(Component invoker, 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 Rectangle ensureOnScreen(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 Rectangle ensureOnScreen(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 Rectangle getContainingScreenBounds(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 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(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(Component component, 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(Component component, 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.