JIDE 3.5.15

com.jidesoft.utils
Class PortingUtils

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

public class PortingUtils
extends Object

A class that keeps all 1.4/1.3 different stuff.


Field Summary
static boolean INITIALIZE_SCREEN_AREA_USING_THREAD
           
 
Constructor Summary
PortingUtils()
           
 
Method Summary
static Rectangle containsInScreenBounds(Component invoker, Rectangle rect)
          To make sure the rectangle is within the screen bounds.
static Rectangle containsInScreenBounds(Component invoker, Rectangle rect, boolean useInvokerDevice)
          To make sure the rectangle is within the screen bounds.
static Rectangle ensureOnScreen(Rectangle rect)
          Modifies the position of rect so that it is completely on screen if that is possible.
static Rectangle ensureVisible(Component invoker, Rectangle bounds)
          Ensures the rectangle is visible on the screen.
static Rectangle getContainingScreenBounds(Rectangle rect, boolean considerInsets)
          Gets the screen bounds that contains the rect.
static Component getCurrentFocusComponent(AWTEvent event)
          Gets current focused components.
static int getFrameState(Frame frame)
          Gets frame's state.
static Rectangle getLocalScreenBounds()
          Gets the local monitor's screen bounds.
static Dimension getLocalScreenSize(Component invoker)
          Gets the screen size.
static int getMouseModifiers(MouseEvent e)
          Gets mouse modifiers.
static Area getScreenArea()
          Get screen area of all monitors.
static Rectangle getScreenBounds(Component invoker)
          Gets the screen bounds.
static Rectangle getScreenBounds(Component invoker, boolean useInvokerDevice)
          Gets the screen bounds.
static Dimension getScreenSize(Component invoker)
          Gets the screen size.
static void initializeScreenArea()
          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.
static void initializeScreenArea(int priority)
          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.
static boolean isInitalizationThreadStarted()
           
static boolean isInitializationThreadAlive()
           
static void notifyUser()
          Notifies user something is wrong.
static void notifyUser(Component component)
          Notifies user something is wrong.
static Rectangle overlapWithScreenBounds(Component invoker, 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(AbstractButton button)
          Removes the button border.
static void removeFocus(JComponent component)
          Makes sure the component won't receive the focus.
static void setFrameState(Frame frame, int state)
          Sets frame's state.
static void setMinimumSize(Component component, Dimension size)
          Sets the minimum size on a component.
static void setPreferredSize(Component component, 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

public static boolean INITIALIZE_SCREEN_AREA_USING_THREAD
Constructor Detail

PortingUtils

public PortingUtils()
Method Detail

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:
getScreenBounds(java.awt.Component, boolean)

getLocalScreenBounds

public static Rectangle getLocalScreenBounds()
Gets the local monitor's screen bounds.

Returns:
the screen bounds.

initializeScreenArea

public static void initializeScreenArea()
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.


initializeScreenArea

public static void initializeScreenArea(int priority)
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

public static boolean isInitializationThreadAlive()

isInitalizationThreadStarted

public static boolean isInitalizationThreadStarted()

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.

Parameters:
rect - Therectanglee to move onto a single screen
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.

JIDE 3.5.15