{
// Invoker component window
final Window invokerWindow = SwingUtils.getWindowAncestor ( invoker );
// Invoker window follow adapter
final WindowFollowAdapter windowFollowAdapter = new WindowFollowAdapter ( WebPopOver.this, invokerWindow )
{
@Override
public boolean isEnabled ()
{
return !attached;
}
};
invokerWindow.addComponentListener ( windowFollowAdapter );
// Invoker window adapter
final ComponentAdapter invokerWindowAdapter = new ComponentAdapter ()
{
@Override
public void componentMoved ( final ComponentEvent e )
{
if ( attached )
{
updatePopOverLocation ( invoker, invokerBoundsProvider );
windowFollowAdapter.updateLastLocation ();
}
}
};
invokerWindow.addComponentListener ( invokerWindowAdapter );
// Invoker component adapter
final ComponentAdapter invokerAdapter = new ComponentAdapter ()
{
@Override
public void componentMoved ( final ComponentEvent e )
{
if ( attached )
{
updatePopOverLocation ( invoker, invokerBoundsProvider );
windowFollowAdapter.updateLastLocation ();
}
}
@Override
public void componentResized ( final ComponentEvent e )
{
if ( attached )
{
updatePopOverLocation ( invoker, invokerBoundsProvider );
windowFollowAdapter.updateLastLocation ();
}
}
};
invoker.addComponentListener ( invokerAdapter );
final AncestorAdapter ancestorAdapter;
if ( invoker instanceof JComponent )
{
ancestorAdapter = new AncestorAdapter ()
{
@Override
public void ancestorMoved ( final AncestorEvent event )
{
if ( attached )
{
updatePopOverLocation ( invoker, invokerBoundsProvider );
windowFollowAdapter.updateLastLocation ();
}
}
// todo Probably hide WebPopOver in some cases here?
// @Override
// public void ancestorRemoved ( final AncestorEvent event )
// {
// super.ancestorRemoved ( event );
// }
};
( ( JComponent ) invoker ).addAncestorListener ( ancestorAdapter );
}
else
{
ancestorAdapter = null;
}
// WebPopOver orientation change listener
final PropertyChangeListener orientationListener = new PropertyChangeListener ()
{
@Override
public void propertyChange ( final PropertyChangeEvent evt )
{
updatePopOverLocation ( invoker, invokerBoundsProvider );
windowFollowAdapter.updateLastLocation ();
}
};
addPropertyChangeListener ( WebLookAndFeel.ORIENTATION_PROPERTY, orientationListener );
// Removing all listeners on window close event