Package de.sciss.app
Class DynamicAncestorAdapter
- java.lang.Object
-
- de.sciss.app.AncestorAdapter
-
- de.sciss.app.DynamicAncestorAdapter
-
- All Implemented Interfaces:
java.util.EventListener,javax.swing.event.AncestorListener
public class DynamicAncestorAdapter extends AncestorAdapter
This class can be added as anAncestorListenerand will call the passedDynamicListeningobject when the Component becomes visible or invisible in the sense that it's ancestor window is shown or hidden.It's crucial that the
addTomethod is used to register the listener!Surfaceis an example of the use of aDynamicAncestorAdapter.- See Also:
DynamicListening
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanlistening
-
Constructor Summary
Constructors Constructor Description DynamicAncestorAdapter(DynamicListening listener)Constructs a newDynamicAncestorAdapterwhich will inform theDynamicListeningabout changes in visibility of the ancestor window of the component to which this adapter is added.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTo(javax.swing.JComponent c)Adds this adapter to aJComponent.voidancestorAdded(javax.swing.event.AncestorEvent e)Called when the tracked component or one of its ancestors gets added in the container hierarchy.voidancestorRemoved(javax.swing.event.AncestorEvent e)Called when the tracked component or one of its ancestors gets removed in the container hierarchy.javax.swing.JComponentgetComponent()booleanisListening()voidremove()protected voidstartListening()protected voidstopListening()-
Methods inherited from class de.sciss.app.AncestorAdapter
ancestorMoved
-
-
-
-
Constructor Detail
-
DynamicAncestorAdapter
public DynamicAncestorAdapter(DynamicListening listener)
Constructs a newDynamicAncestorAdapterwhich will inform theDynamicListeningabout changes in visibility of the ancestor window of the component to which this adapter is added.- Parameters:
listener- aDynamicListeningwhosestartListeningmethod is called when this adapter's host component's ancestor is shown or added to another component. the listener'sstopListeningmethod is called likewise when this adapter's host component's ancestor is hidden or removed from its parent.
-
-
Method Detail
-
addTo
public void addTo(javax.swing.JComponent c)
Adds this adapter to aJComponent. Use this method instead of callingcmp.addAncestorListener(...)because this method will automatically detect the component's window. This is crucial forJRootPanecomponents, because they are already attached to a window when you register the listener.- Parameters:
c- theJComponentwho will be tracked for ancestor changes.- See Also:
JComponent.addAncestorListener( AncestorListener )
-
remove
public void remove()
-
getComponent
public javax.swing.JComponent getComponent()
-
isListening
public boolean isListening()
-
ancestorAdded
public void ancestorAdded(javax.swing.event.AncestorEvent e)
Called when the tracked component or one of its ancestors gets added in the container hierarchy. This method checks to see if a change in the component's top level window occured, and if so, re-registers window and component listeners on that window. Also if the window is visible and the dynamic listener is not yet listening, itsstartListeningmethod is invoked.- Specified by:
ancestorAddedin interfacejavax.swing.event.AncestorListener- Overrides:
ancestorAddedin classAncestorAdapter
-
ancestorRemoved
public void ancestorRemoved(javax.swing.event.AncestorEvent e)
Called when the tracked component or one of its ancestors gets removed in the container hierarchy. If the dynamic listener was started, itsstopListeningmethod is invoked.- Specified by:
ancestorRemovedin interfacejavax.swing.event.AncestorListener- Overrides:
ancestorRemovedin classAncestorAdapter
-
startListening
protected void startListening()
-
stopListening
protected void stopListening()
-
-