// Overlay panel
final WebProgressOverlay progressOverlay = new WebProgressOverlay ();
progressOverlay.setProgressWidth ( 35 );
// Overlay content
final WebTextArea textArea = new WebTextArea ();
textArea.setText ( "Click to load some text..." );
textArea.setLineWrap ( true );
textArea.setWrapStyleWord ( true );
WebScrollPane scrollPane = new WebScrollPane ( textArea );
scrollPane.setPreferredSize ( new Dimension ( 250, 100 ) );
progressOverlay.setComponent ( scrollPane );
// Overlaying components
final WebLabel progressLabel = new WebLabel ( "0%", WebLabel.CENTER );
progressLabel.setBoldFont ();
progressLabel.setMargin ( 5, 10, 5, 10 );
final WebPanel overlayPanel = new WebPanel ( true, progressLabel );
overlayPanel.setShadeWidth ( 5 );
overlayPanel.setVisible ( false );
overlayPanel.setPreferredSize ( new Dimension ( 60, 40 ) );
progressOverlay.addOverlay ( overlayPanel, SwingConstants.CENTER, SwingConstants.CENTER );
// Animation start action
textArea.addMouseListener ( new MouseAdapter ()
{
private String base = ExamplesManager.createSmallString ();
private String toAdd = "";
private int step = 5;
@Override
public void mousePressed ( MouseEvent e )
{
// Updating string to write
if ( toAdd.length () == 0 )
{
textArea.clear ();
toAdd = base;
}
progressOverlay.setShowLoad ( true );
overlayPanel.setVisible ( true );
new Thread ( new Runnable ()
{
@Override
public void run ()
{
while ( toAdd.length () > 0 )
{
final int left = Math.min ( step, toAdd.length () );
SwingUtils.invokeAndWaitSafely ( new Runnable ()
{
@Override
public void run ()
{
textArea.append ( toAdd.substring ( 0, left ) );
progressLabel.setText ( ( base.length () - toAdd.length () ) * 100 / base.length () + " %" );
}
} );
toAdd = toAdd.substring ( left );
ThreadUtils.sleepSafely ( 50 );