net.sf.jguiraffe.gui.platform.swing.builder.window
Class WindowHelper

java.lang.Object
  extended by net.sf.jguiraffe.gui.platform.swing.builder.window.WindowHelper

 class WindowHelper
extends java.lang.Object

An internally used helper class for the Swing window package.

This class implements some functionality common to all Swing window implementations. It further defines some helper methods. Because of Swing's inheritence hierarchy it is not possible to implement this functionality in common base classes, so the composition approach is used.

Version:
$Id: WindowHelper.java 27 2006-04-12 16:59:19Z oheger $
Author:
Oliver Heger

Constructor Summary
WindowHelper(SwingWindow window)
          Creates a new instance of WindowHelper and initializes it with the associated window.
 
Method Summary
 void addWindowListener(WindowListener l)
          Registers the specified window listener at this window.
static void center(java.awt.Component c, Window parent)
          Sets the location of the specified component so that it gets centered in the area of its parent window.
 void closeWindow()
          Called when the window should be closed.
protected  void doOpenWindow()
          Opens the window directly.
static javax.swing.JDesktopPane findDesktopPane(java.awt.Container container)
          Tries to find a desktop pane in the given container or its children.
 Window getParentWindow()
          Returns the window's parent.
 SwingWindow getSwingWindow()
           
 WindowClosingStrategy getWindowClosingStrategy()
          Returns the window's closing strategy.
 java.lang.Object getWindowController()
          Returns the window's controller.
 java.util.Collection getWindowListeners()
          Returns a collection with all registered window listeners.
static void initComponentBounds(java.awt.Component comp, WindowData data)
          Determines the bounds of the given component based on the passed in window data object.
 void openWindow()
          Opens this window.
 void removeWindowListener(WindowListener l)
          Removes the specified window listener from this window.
 void setParent(Window parent)
          Sets the window's parent.
 void setWindowClosingStrategy(WindowClosingStrategy windowClosingStrategy)
          Sets the window's closing strategy.
 void setWindowController(java.lang.Object ctrl)
          Allows to set the window's controller.
static boolean sizeDefined(WindowData data)
          Checks if in the given window data object the window's size is fully defined.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WindowHelper

public WindowHelper(SwingWindow window)
Creates a new instance of WindowHelper and initializes it with the associated window.

Parameters:
window - the window
Method Detail

getSwingWindow

public SwingWindow getSwingWindow()

getWindowClosingStrategy

public WindowClosingStrategy getWindowClosingStrategy()
Returns the window's closing strategy. This implementation will never return null. If no closing strategy has been set, a default instance will be returned.

Returns:
the window closing strategy

setWindowClosingStrategy

public void setWindowClosingStrategy(WindowClosingStrategy windowClosingStrategy)
Sets the window's closing strategy.

Parameters:
windowClosingStrategy - the new closing strategy

getWindowController

public java.lang.Object getWindowController()
Returns the window's controller.

Returns:
the window's controller

setWindowController

public void setWindowController(java.lang.Object ctrl)
Allows to set the window's controller.

Parameters:
ctrl - the new controller

getParentWindow

public Window getParentWindow()
Returns the window's parent.

Returns:
the parent window

setParent

public void setParent(Window parent)
Sets the window's parent.

Parameters:
parent - the parent window

addWindowListener

public void addWindowListener(WindowListener l)
Registers the specified window listener at this window. This is only done if this listener has not been registered before.

Parameters:
l - the listener to register

removeWindowListener

public void removeWindowListener(WindowListener l)
Removes the specified window listener from this window. If this listener is not registered at this window, this operation has no effect.

Parameters:
l - the listener to remove

getWindowListeners

public java.util.Collection getWindowListeners()
Returns a collection with all registered window listeners.

Returns:
a collection with the registered window listeners

closeWindow

public void closeWindow()
Called when the window should be closed. Checks the closing strategy and only delegates this call if the it returns true.


openWindow

public void openWindow()
Opens this window. This implementation ensures that this action is performed on the event dispatching thread, but synchronously.


sizeDefined

public static boolean sizeDefined(WindowData data)
Checks if in the given window data object the window's size is fully defined. If this is not the case, the window must be packed.

Parameters:
data - the window data object
Returns:
a flag if the window's size is defined

findDesktopPane

public static javax.swing.JDesktopPane findDesktopPane(java.awt.Container container)
Tries to find a desktop pane in the given container or its children. This method is useful if an internal frame is to be added to a frame window's desktop. The container's children are recursively searched until a desktop pane component is found.

Parameters:
container - the container to search
Returns:
the desktop panel or null if none is found

center

public static void center(java.awt.Component c,
                          Window parent)
Sets the location of the specified component so that it gets centered in the area of its parent window. The size of the component must have been determined before. If no parent window exists, the component is centered on the screen.

Parameters:
c - the component to center
parent - the parent window

initComponentBounds

public static void initComponentBounds(java.awt.Component comp,
                                       WindowData data)
Determines the bounds of the given component based on the passed in window data object. This method does the following: If the window's bounds are fully defined, they are simply set. If the location is missing, default values are set. The size is only set, if it is fully defined (otherwise the calling must ensure that the pack() method is invoked on the window).

Parameters:
comp - the component to initialize
data - the data object with the bounds

doOpenWindow

protected void doOpenWindow()
Opens the window directly. Called by openWindow().



Copyright 2007 null. All Rights Reserved.