2008-03-19 18:14:38 -04:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
|
2008-12-27 06:35:53 -05:00
|
|
|
import net.miginfocom.swing.MigLayout;
|
2008-03-19 18:14:38 -04:00
|
|
|
|
2008-12-27 06:35:53 -05:00
|
|
|
|
|
|
|
public class LoadingOverlayPane extends JComponent {
|
2008-03-19 18:14:38 -04:00
|
|
|
|
|
|
|
public static final String LOADING_PROPERTY = "loading";
|
|
|
|
|
2008-06-21 15:24:18 -04:00
|
|
|
private final JComponent animationComponent;
|
2008-03-19 18:14:38 -04:00
|
|
|
|
|
|
|
private boolean overlayEnabled = false;
|
|
|
|
|
2008-12-28 15:04:13 -05:00
|
|
|
private int millisToOverlay = 400;
|
2008-03-19 18:14:38 -04:00
|
|
|
|
|
|
|
|
2008-12-27 06:35:53 -05:00
|
|
|
public LoadingOverlayPane(JComponent component, JComponent propertyChangeSource) {
|
|
|
|
this(component, new ProgressIndicator(), propertyChangeSource);
|
2008-03-19 18:14:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-27 06:35:53 -05:00
|
|
|
public LoadingOverlayPane(JComponent component, JComponent animationComponent, JComponent propertyChangeSource) {
|
2008-12-28 15:04:13 -05:00
|
|
|
setLayout(new MigLayout("insets 0, fill"));
|
2008-12-27 06:35:53 -05:00
|
|
|
this.animationComponent = animationComponent;
|
2008-03-19 18:14:38 -04:00
|
|
|
|
2008-12-28 15:04:13 -05:00
|
|
|
add(animationComponent, "pos n 8px 100%-18px n");
|
2008-12-27 06:35:53 -05:00
|
|
|
add(component, "grow");
|
2008-03-19 18:14:38 -04:00
|
|
|
|
2008-12-27 06:35:53 -05:00
|
|
|
animationComponent.setVisible(false);
|
2008-03-19 18:14:38 -04:00
|
|
|
|
2008-12-28 15:04:13 -05:00
|
|
|
if (propertyChangeSource != null) {
|
|
|
|
propertyChangeSource.addPropertyChangeListener(LOADING_PROPERTY, loadingListener);
|
|
|
|
}
|
2008-03-19 18:14:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-21 15:24:18 -04:00
|
|
|
@Override
|
|
|
|
public boolean isOptimizedDrawingEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-19 18:14:38 -04:00
|
|
|
public void setOverlayVisible(boolean b) {
|
|
|
|
overlayEnabled = b;
|
|
|
|
|
|
|
|
if (overlayEnabled) {
|
2008-04-27 13:36:27 -04:00
|
|
|
TunedUtil.invokeLater(millisToOverlay, new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (overlayEnabled) {
|
2008-06-21 15:24:18 -04:00
|
|
|
animationComponent.setVisible(true);
|
2008-04-27 13:36:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2008-03-19 18:14:38 -04:00
|
|
|
} else {
|
2008-06-21 15:24:18 -04:00
|
|
|
animationComponent.setVisible(false);
|
2008-03-19 18:14:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final PropertyChangeListener loadingListener = new PropertyChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
|
Boolean loading = (Boolean) evt.getNewValue();
|
|
|
|
|
|
|
|
setOverlayVisible(loading);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|