org.bushe.swing.event
Class ContainerEventServiceFinder
java.lang.Object
org.bushe.swing.event.ContainerEventServiceFinder
public class ContainerEventServiceFinder
- extends Object
This class finds a component's container event service, and creates one if necessary and possible.
A Container EventService is, unlike the EventBus, an EventService that is container specific, in other words, it is
shared only amongst components within a container. For example, a Form component can supply an EventService used
only by components in the form. The Form's components can publish value change events on their Container's Event
Service. The Form's Model and Validator may listen to these events to collect data and show errors, respectively.
Most importantly, Container EventService's cuts down event traffic, avoid naming and listener clashes, promotes
componentization, and splits events usage into logical subsets.
The finder will walk up a component's hierarchy searching for a parent that implements ContainerEventServiceSupplier.
If it find one, it returns it. If it doesn't find one, the top level JComponent (specifically, the highest parent in
the hierarchy, typically a JRootPane) has a client property added to it (if not already set) that has the value of a
new SwingEventService, which is then returned. The EventBus is never returned.
Method Summary |
static EventService |
getEventService(Component component)
Walks the component's parents until it find an ContainerEventServiceSupplier and returns the supplier's
EventService. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CLIENT_PROPERTY_KEY_TOP_LEVEL_EVENT_SERVICE
public static final String CLIENT_PROPERTY_KEY_TOP_LEVEL_EVENT_SERVICE
- The client property used to put a new SwingEventService on top-level components.
- See Also:
- Constant Field Values
ContainerEventServiceFinder
public ContainerEventServiceFinder()
getEventService
public static EventService getEventService(Component component)
- Walks the component's parents until it find an ContainerEventServiceSupplier and returns the supplier's
EventService. If the component in the tree is a JPopupMenu, then the menu's invoker is walked.
- Parameters:
component
- any component
- Returns:
- the ContainerEventService of the nearest parent
Copyright © 2011 Bushe Enterprises, Inc.. All Rights Reserved.