// Image and loader lists
final List<WebImage> images = CollectionUtils.copy ( createImage ( "1.png" ), createImage ( "2.png" ), createImage ( "3.png" ) );
final List<WebLabel> loaders = CollectionUtils.copy ( createLoader (), createLoader (), createLoader () );
// Images panel
final WebPanel imagesPanel = new WebPanel ( new HorizontalFlowLayout ( 5, false ) );
imagesPanel.addAncestorListener ( new AncestorAdapter ()
{
@Override
public void ancestorAdded ( AncestorEvent event )
{
// Initial transition on first panel appearance
imagesPanel.removeAncestorListener ( this );
for ( int i = 0; i < imagesPanel.getComponentCount (); i++ )
{
// Delayed image fade-in
ComponentTransition componentTransition = ( ComponentTransition ) imagesPanel.getComponent ( i );
componentTransition.delayTransition ( 1000 + i * 500, images.get ( i ) );
}
}
} );
// States switch buttons
final WebButton reloadView = new WebButton ( loadIcon ( "switch.png" ) );
reloadView.setEnabled ( false );
reloadView.setDrawFocus ( false );
reloadView.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
reloadView.setEnabled ( false );
for ( int i = 0; i < imagesPanel.getComponentCount (); i++ )
{
// Switching to loader first
ComponentTransition componentTransition = ( ComponentTransition ) imagesPanel.getComponent ( i );
componentTransition.performTransition ( loaders.get ( i ) );
// Delayed image fade-in
componentTransition.delayTransition ( 1000 + i * 500, images.get ( i ) );
}
}
} );
// Transition panels
for ( int i = 0; i < images.size (); i++ )
{
// Single transition panel with loader as initial component
final ComponentTransition transition = new ComponentTransition ( loaders.get ( i ), new FadeTransitionEffect () );
imagesPanel.add ( transition );
if ( i == images.size () - 1 )
{
// Transition listener for reload button enabling
transition.addTransitionListener ( new TransitionAdapter ()