Class WindowUtils


  • public final class WindowUtils
    extends Object

    A static utility class providing useful functionality for dealing with Window objects.

    The methods defined in this utility class can be used to obtain information about window objects. They support casts to the Window interface and allow for accessing the underlying GUI library specific window implementation.

    Version:
    $Id: WindowUtils.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Method Detail

      • toWindow

        public static Window toWindow​(Object wnd)
        Tries to cast the specified object into a Window. If this is possible, the resulting Window is returned. Otherwise the return value is null.
        Parameters:
        wnd - the object to cast to a Window
        Returns:
        the Window object or null
      • toWindowEx

        public static Window toWindowEx​(Object wnd)
                                 throws IllegalArgumentException
        Tries to cast the specified object into a Window. Different to toWindow(), this method will never return null. Instead, if the passed in object cannot be cast to a Window, an IllegalArgumentException exception will be thrown.
        Parameters:
        wnd - the object to cast to a Window
        Returns:
        the casted object
        Throws:
        IllegalArgumentException - if casting fails
      • windowFromEvent

        public static Window windowFromEvent​(WindowEvent event)
        Tries to cast the source window from the specified event object into a Window object. If this is possible, the Window object is returned. Otherwise the return value is null. This method is useful when dealing with WindowEvent objects because it handles null input gracefully.
        Parameters:
        event - the event object; if null, the return value will be null, too
        Returns:
        the extracted Window or null
      • windowFromEventEx

        public static Window windowFromEventEx​(WindowEvent event)
                                        throws IllegalArgumentException
        Tries to cast the source window from the specified event object into a Window object. Works like windowFromEvent(), but throws an IllegalArgumentException exception if the source window cannot be determined.
        Parameters:
        event - the event object
        Returns:
        the casted window
        Throws:
        IllegalArgumentException - if the source window cannot be obtained
      • getPlatformWindow

        public static Object getPlatformWindow​(Window window)
                                        throws IllegalArgumentException
        Returns the platform (or GUI library) specific window that is represented by the passed in Window object. This method checks if the passed in object implements the WindowWrapper interface. If this is the case, the wrapped window will be fetched and checked again. Otherwise the window itself will be returned.
        Parameters:
        window - the window (must not be null)
        Returns:
        the underlying platform specific window
        Throws:
        IllegalArgumentException - if the parameter is null