com.jgoodies.uif.util
Class WindowUtils.SizeChangeHandler

java.lang.Object
  extended by java.awt.event.ComponentAdapter
      extended by com.jgoodies.uif.util.WindowUtils.SizeChangeHandler
All Implemented Interfaces:
ComponentListener, EventListener
Enclosing class:
WindowUtils

public static final class WindowUtils.SizeChangeHandler
extends ComponentAdapter

A ComponentListener that handles size changes in Windows to ensure a minimum size. For Frames it also stores the bounds and state, if the frame has been moved or resized.

This class works around a nasty issue with AWT component moved events. We want to store the frame bounds only if the frame is not maximized. If a frame is maximized by the user, AWT send a component moved event before it indicates the frame maximized state. So we need to re-order of these two events.

This implementation handles component moved events a bit later, using a DelayedReadValueModel from the JGoodies Binding. If the component moves, the componentMovedModel is updated immediately. But the DelayedComponentMovedHandler doesn't listen to this model directly, it observes its delayed wrapper. This has two effects: 1) multiple component moved events are coalesced to one, and 2) after the delay the frame maximization state is already updated. So in #componentMoved we can check the maximization state and it'll report if the component moved event was a maximized event or not.

See Also:
WindowUtils.storeBounds(Preferences, Frame), WindowUtils.storeState(Preferences, Frame)

Constructor Summary
WindowUtils.SizeChangeHandler(JDialog dialog)
          Constructs a SizeChangeHandler for the given Swing dialog.
WindowUtils.SizeChangeHandler(JFrame frame)
          Constructs a SizeChangeHandler for the given Swing frame.
WindowUtils.SizeChangeHandler(JWindow window)
          Constructs a SizeChangeHandler for the given Swing window.
 
Method Summary
 void componentMoved(ComponentEvent evt)
          If a frame has been moved, we update the componentMovedModel.
 void componentResized(ComponentEvent evt)
          If this window provides a minimum size the window's size is adjusted after a resize to ensure this minimum size.
 
Methods inherited from class java.awt.event.ComponentAdapter
componentHidden, componentShown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WindowUtils.SizeChangeHandler

public WindowUtils.SizeChangeHandler(JWindow window)
Constructs a SizeChangeHandler for the given Swing window.

Parameters:
window - the window to be observed

WindowUtils.SizeChangeHandler

public WindowUtils.SizeChangeHandler(JDialog dialog)
Constructs a SizeChangeHandler for the given Swing dialog.

Parameters:
dialog - the dialog to be observed

WindowUtils.SizeChangeHandler

public WindowUtils.SizeChangeHandler(JFrame frame)
Constructs a SizeChangeHandler for the given Swing frame.

Parameters:
frame - the frame to be observed
Method Detail

componentMoved

public void componentMoved(ComponentEvent evt)
If a frame has been moved, we update the componentMovedModel. This in turn will notify the DelayedComponentMovedHandler after a delay.

Specified by:
componentMoved in interface ComponentListener
Overrides:
componentMoved in class ComponentAdapter

componentResized

public void componentResized(ComponentEvent evt)
If this window provides a minimum size the window's size is adjusted after a resize to ensure this minimum size. If the window is a JFrame, the frame bounds are stored if the frame doesn't cover the full screen.

Specified by:
componentResized in interface ComponentListener
Overrides:
componentResized in class ComponentAdapter
Parameters:
evt - the given component event


Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.