com.gargoylesoftware.base.gui

Class DelayedComponentLoaderPanel

public class DelayedComponentLoaderPanel extends JComponent

A panel that supports delayed loading of its contents. This is useful when the component that will fill this panel will take a long time to load. A "please wait" message will be displayed while the component is being loaded. When loading is complete, the new component will be made a child of this panel so that it can become visible.

The following sample will create a delayed loader with a default "please wait" message.

 final DelayedComponentLoaderPanel panel = new DelayedComponentLoaderPanel();
 panel.setComponentLoader( new DefaultComponentLoader(MyExpensiveComponent.class) );
 
This sample has a custom message.
 final JLabel label = new JLabel("My custom wait message");
 final DelayedComponentLoaderPanel panel = new DelayedComponentLoaderPanel(label);
 panel.setComponentLoader( new DefaultComponentLoader(MyExpensiveComponent.class) );
 

Version: $Revision: 1.6 $

Author: Mike Bowler

Field Summary
Setlisteners_
static intLOADER_FINISHED
static intLOADER_STARTED
static longserialVersionUID
ComponentwaitingComponent_
Constructor Summary
DelayedComponentLoaderPanel()
Create a new panel that will display a simple "please wait" message when it is loading.
DelayedComponentLoaderPanel(Component waitingComponent)
Create a new panel that will display the specified waitingComponent while it is loading.
Method Summary
voidaddDelayedComponentLoaderListener(DelayedComponentLoaderListener listener)
Add the specified listener.
protected voidassertNotNull(String fieldName, Object object)
Throw an exception if the specified object is null
voidfireComponentLoadingEvent(int action, ComponentLoader loader, Component loadedComponent)
Fire the component loading event.
voidremoveDelayedComponentLoaderListener(DelayedComponentLoaderListener listener)
Remove the specified listener.
voidreplaceComponent(Component component)
Replace the current child with the specified component
voidsetComponentLoader(ComponentLoader loader)
Set the new component loader.

Field Detail

listeners_

private Set listeners_

LOADER_FINISHED

private static final int LOADER_FINISHED

LOADER_STARTED

private static final int LOADER_STARTED

serialVersionUID

private static final long serialVersionUID

waitingComponent_

private Component waitingComponent_

Constructor Detail

DelayedComponentLoaderPanel

public DelayedComponentLoaderPanel()
Create a new panel that will display a simple "please wait" message when it is loading.

DelayedComponentLoaderPanel

public DelayedComponentLoaderPanel(Component waitingComponent)
Create a new panel that will display the specified waitingComponent while it is loading.

Parameters: waitingComponent The component to display while loading is in progress.

Method Detail

addDelayedComponentLoaderListener

public void addDelayedComponentLoaderListener(DelayedComponentLoaderListener listener)
Add the specified listener.

Parameters: listener The new listener

assertNotNull

protected final void assertNotNull(String fieldName, Object object)
Throw an exception if the specified object is null

Parameters: fieldName The name of the paremeter we are checking object The value of the parameter we are checking

fireComponentLoadingEvent

private void fireComponentLoadingEvent(int action, ComponentLoader loader, Component loadedComponent)
Fire the component loading event.

Parameters: action The action id loader The loader loadedComponent The component that was just loaded.

removeDelayedComponentLoaderListener

public void removeDelayedComponentLoaderListener(DelayedComponentLoaderListener listener)
Remove the specified listener.

Parameters: listener the listener to remove.

replaceComponent

private void replaceComponent(Component component)
Replace the current child with the specified component

Parameters: component The new component.

setComponentLoader

public void setComponentLoader(ComponentLoader loader)
Set the new component loader. The waiting component will be displayed immediately and component loading will start on a background thread. If the new loader is null then no loading will take place and the waiting component will be displayed indefinitely

Parameters: loader The new component loader.