org.bushe.swing.event
Class ContainerEventServiceRegistrar

java.lang.Object
  extended by org.bushe.swing.event.ContainerEventServiceRegistrar

public class ContainerEventServiceRegistrar
extends Object

Registers a component with it's Container's EventService while keeping track of the component's container.

Registering with a component's ContainerEventService is tricky since components may not be in their hierarchy when they want to register with it, or components may move (though rarely). This class subscribes a component with it's container event service. If it is unavailable, the registrar waits until the component's Container becomes available and subscribes at that time. If the component changes Containers, the registrar unsubscribes the component from its old container and subscribes it to the new one.


Constructor Summary
ContainerEventServiceRegistrar(JComponent jComp)
          Create a registrar that will keep track of the container event service, typically used in the publish-only cases where the getContainerEventServer() call will be made before publication.
ContainerEventServiceRegistrar(JComponent jComp, EventSubscriber eventSubscriber, Class eventClass)
          Create a registrar that will keep track of the container event service, and subscribe the subscriber to the eventClass when the ContainerEventService is available and when it changes.
ContainerEventServiceRegistrar(JComponent jComp, EventSubscriber eventSubscriber, Class[] eventClasses)
          Create a registrar that will keep track of the container event service, and subscribe the subscriber to the event classes when the ContainerEventService is available and when it changes.
ContainerEventServiceRegistrar(JComponent jComp, EventSubscriber eventSubscriber, Class[] eventClasses, EventTopicSubscriber eventTopicSubscriber, String[] topics)
          Create a registrar that will keep track of the container event service, and subscribe the subscriber to the topics and the event classes when the ContainerEventService is available and when it changes.
ContainerEventServiceRegistrar(JComponent jComp, EventTopicSubscriber eventTopicSubscriber, String topic)
          Create a registrar that will keep track of the container event service, and subscribe the subscriber to the topic when the ContainerEventService is available and when it changes.
ContainerEventServiceRegistrar(JComponent jComp, EventTopicSubscriber eventTopicSubscriber, String[] topics)
          Create a registrar that will keep track of the container event service, and subscribeStrongly the subscriber to the topics when the ContainerEventService is available and when it changes.
 
Method Summary
 EventService getContainerEventService()
           
protected  void updateContainerEventService()
          Called by this class when the container may have changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContainerEventServiceRegistrar

public ContainerEventServiceRegistrar(JComponent jComp)
Create a registrar that will keep track of the container event service, typically used in the publish-only cases where the getContainerEventServer() call will be made before publication.

Parameters:
jComp - the component whose container to monitor

ContainerEventServiceRegistrar

public ContainerEventServiceRegistrar(JComponent jComp,
                                      EventSubscriber eventSubscriber,
                                      Class eventClass)
Create a registrar that will keep track of the container event service, and subscribe the subscriber to the eventClass when the ContainerEventService is available and when it changes.

Parameters:
jComp - the component whose container to monitor
eventSubscriber - the subscriber to register to the Container EventServer
eventClass - the class of event to register for

ContainerEventServiceRegistrar

public ContainerEventServiceRegistrar(JComponent jComp,
                                      EventTopicSubscriber eventTopicSubscriber,
                                      String topic)
Create a registrar that will keep track of the container event service, and subscribe the subscriber to the topic when the ContainerEventService is available and when it changes.

Parameters:
jComp - the component whose container to monitor
eventTopicSubscriber - the topic subscriber to register to the Container EventServer
topic - the event topic name to register for

ContainerEventServiceRegistrar

public ContainerEventServiceRegistrar(JComponent jComp,
                                      EventSubscriber eventSubscriber,
                                      Class[] eventClasses)
Create a registrar that will keep track of the container event service, and subscribe the subscriber to the event classes when the ContainerEventService is available and when it changes.

Parameters:
jComp - the component whose container to monitor
eventSubscriber - the subscriber to register to the Container EventServer
eventClasses - the classes of event to register for

ContainerEventServiceRegistrar

public ContainerEventServiceRegistrar(JComponent jComp,
                                      EventTopicSubscriber eventTopicSubscriber,
                                      String[] topics)
Create a registrar that will keep track of the container event service, and subscribeStrongly the subscriber to the topics when the ContainerEventService is available and when it changes.

Parameters:
jComp - the component whose container to monitor
eventTopicSubscriber - the topic subscriber to register to the Container EventServer
topics - the event topic names to register for

ContainerEventServiceRegistrar

public ContainerEventServiceRegistrar(JComponent jComp,
                                      EventSubscriber eventSubscriber,
                                      Class[] eventClasses,
                                      EventTopicSubscriber eventTopicSubscriber,
                                      String[] topics)
Create a registrar that will keep track of the container event service, and subscribe the subscriber to the topics and the event classes when the ContainerEventService is available and when it changes.

Parameters:
jComp - the component whose container to monitor
eventSubscriber - the subscriber to register to the Container EventServer
eventClasses - the classes of event to register for
eventTopicSubscriber - the topic subscriber to keep registered to the topic(s)
topics - the event topic names to register for
Method Detail

updateContainerEventService

protected void updateContainerEventService()
Called by this class when the container may have changed.

Override this method and call super if your class wants to be notified when the container changes (compare the references of getContainerEventService() around the calls to super.updateContainerEventService()).


getContainerEventService

public EventService getContainerEventService()
Returns:
the container event service, if null, it tries to find it, but it still may be null if this object is not in a container.


Copyright © 2011 Bushe Enterprises, Inc.. All Rights Reserved.