de.sciss.app
Class DynamicAncestorAdapter

java.lang.Object
  extended by de.sciss.app.AncestorAdapter
      extended by 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 an AncestorListener and will call the passed DynamicListening object when the Component becomes visible or invisible in the sense that it's ancestor window is shown or hidden.

It's crucial that the addTo method is used to register the listener!

Surface is an example of the use of a DynamicAncestorAdapter.

Version:
0.12, 25-Feb-08
Author:
Hanns Holger Rutz
See Also:
DynamicListening

Field Summary
protected  boolean listening
           
 
Constructor Summary
DynamicAncestorAdapter(DynamicListening listener)
          Constructs a new DynamicAncestorAdapter which will inform the DynamicListening about changes in visibility of the ancestor window of the component to which this adapter is added.
 
Method Summary
 void addTo(javax.swing.JComponent c)
          Adds this adapter to a JComponent.
 void ancestorAdded(javax.swing.event.AncestorEvent e)
          Called when the tracked component or one of its ancestors gets added in the container hierarchy.
 void ancestorRemoved(javax.swing.event.AncestorEvent e)
          Called when the tracked component or one of its ancestors gets removed in the container hierarchy.
 javax.swing.JComponent getComponent()
           
 boolean isListening()
           
 void remove()
           
protected  void startListening()
           
protected  void stopListening()
           
 
Methods inherited from class de.sciss.app.AncestorAdapter
ancestorMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listening

protected boolean listening
Constructor Detail

DynamicAncestorAdapter

public DynamicAncestorAdapter(DynamicListening listener)
Constructs a new DynamicAncestorAdapter which will inform the DynamicListening about changes in visibility of the ancestor window of the component to which this adapter is added.

Parameters:
listener - a DynamicListening whose startListening method is called when this adapter's host component's ancestor is shown or added to another component. the listener's stopListening method 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 a JComponent. Use this method instead of calling cmp.addAncestorListener(...) because this method will automatically detect the component's window. This is crucial for JRootPane components, because they are already attached to a window when you register the listener.

Parameters:
c - the JComponent who 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, its startListening method is invoked.

Specified by:
ancestorAdded in interface javax.swing.event.AncestorListener
Overrides:
ancestorAdded in class AncestorAdapter

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, its stopListening method is invoked.

Specified by:
ancestorRemoved in interface javax.swing.event.AncestorListener
Overrides:
ancestorRemoved in class AncestorAdapter

startListening

protected void startListening()

stopListening

protected void stopListening()