org.pietschy.command.delegate
Class FocusTrackingDelegateMediator

java.lang.Object
  extended by org.pietschy.command.delegate.DelegateMediator
      extended by org.pietschy.command.delegate.FocusTrackingDelegateMediator

public class FocusTrackingDelegateMediator
extends DelegateMediator

This mediator derives the DelegateContainer heirarchy by traversing up the component hierarchy from the currently focused component. The final container list consists of any static constainers (see setStaticContainers(DelegateContainer[])) and those compulted from the focus hierarchy. Those found from the focus hierarchy are given precedence over the static containers.

This mediator is used when you install the FocusTrackingDelegateMediatorFactory into the DelegateManager. There are also convenience methods for getting the current mediator from the DelegateManager without explicitly casting.

See Also:
DelegateMediator.setDelegateContainers(DelegateContainer[]), DelegateMediator.setDelegateContainer(DelegateContainer), getMediatorFor(java.awt.Window), getMediatorFor(java.awt.Component), DelegateManager.setDelegateMediatorFactory(DelegateMediatorFactory)

Field Summary
 
Fields inherited from class org.pietschy.command.delegate.DelegateMediator
EMPTY_CONTAINER_ARRAY
 
Constructor Summary
FocusTrackingDelegateMediator(java.awt.Window window, RelatedWindowDiscriminator discriminator)
          Creates a new DelegateManager for the specified window.
 
Method Summary
static FocusTrackingDelegateMediator getMediatorFor(java.awt.Component component)
          Conveinence method for DelegateManager.getMediatorFor(java.awt.Component) for when the FocusTrackingDelegateMediatorFactory is being used.
static FocusTrackingDelegateMediator getMediatorFor(java.awt.Window window)
          Conveinence method for DelegateManager.getMediatorFor(java.awt.Window) for when the FocusTrackingDelegateMediatorFactory is being used.
 void setRelatedWindowDiscriminator(RelatedWindowDiscriminator relatedWindowDiscriminator)
          Sets the discriminator to use when tracking focus events.
 void setStaticContainer(DelegateContainer staticContainer)
          Sets the current static container list to be the specified container.
 void setStaticContainers(DelegateContainer[] containers)
          Sets the current static container list to the specified list.
 
Methods inherited from class org.pietschy.command.delegate.DelegateMediator
addDelegateTrackerListener, fireDelegatesChanged, getDelegateContainers, nullSafeArray, nullSafeArray, removeDelegateTrackerListener, setDelegateContainer, setDelegateContainers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FocusTrackingDelegateMediator

public FocusTrackingDelegateMediator(java.awt.Window window,
                                     RelatedWindowDiscriminator discriminator)
Creates a new DelegateManager for the specified window.

Parameters:
window - the window of interest.
Method Detail

getMediatorFor

public static FocusTrackingDelegateMediator getMediatorFor(java.awt.Window window)
Conveinence method for DelegateManager.getMediatorFor(java.awt.Window) for when the FocusTrackingDelegateMediatorFactory is being used.

Parameters:
window - the window of interest.
Returns:
Throws:
java.lang.IllegalStateException - if the mediator isn't an instance of FocusTrackingDelegateMediator.

getMediatorFor

public static FocusTrackingDelegateMediator getMediatorFor(java.awt.Component component)
Conveinence method for DelegateManager.getMediatorFor(java.awt.Component) for when the FocusTrackingDelegateMediatorFactory is being used.

Parameters:
component - the component of interest.
Returns:
Throws:
java.lang.IllegalStateException - if the mediator isn't an instance of FocusTrackingDelegateMediator.

setStaticContainer

public void setStaticContainer(DelegateContainer staticContainer)
Sets the current static container list to be the specified container. This method will removed all focus specific containers until the next focus change. If the container is null then the static container list will be emptied, thus clearing all delegates until the next focus event.

Parameters:
staticContainer - the container to use or null to clear the static container list.

setStaticContainers

public void setStaticContainers(DelegateContainer[] containers)
Sets the current static container list to the specified list. This method will removed all focus specific containers until the next focus change. If containers is null then the container list will be emptied, thus clearing all delegates until the next focus event.

Parameters:
containers - the containers to use or null to clear the container list.

setRelatedWindowDiscriminator

public void setRelatedWindowDiscriminator(RelatedWindowDiscriminator relatedWindowDiscriminator)
Sets the discriminator to use when tracking focus events. The discriminator is used to determine if the currently focused window should be tracked for delegates pertaining to DelegatingCommands bound to the parent window.

The default discriminator only tracks delegates in the same window as the DelegatingCommand.

Parameters:
relatedWindowDiscriminator - the discriminator to use.
Throws:
java.lang.NullPointerException - if the discriminator is null.