2008-03-19 22:14:38 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
import java.awt.Dimension;
|
2008-03-19 22:14:38 +00:00
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
import javax.swing.Icon;
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
import javax.swing.OverlayLayout;
|
|
|
|
|
|
|
|
|
|
|
|
public class LoadingOverlayPane extends JComponent {
|
|
|
|
|
|
|
|
public static final String LOADING_PROPERTY = "loading";
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
private final JComponent animationComponent;
|
2008-03-19 22:14:38 +00:00
|
|
|
|
|
|
|
private boolean overlayEnabled = false;
|
|
|
|
|
|
|
|
private int millisToOverlay = 500;
|
|
|
|
|
|
|
|
|
|
|
|
public LoadingOverlayPane(JComponent component, Icon animation) {
|
2008-06-21 19:24:18 +00:00
|
|
|
this(component, new JLabel(""), getView(component));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LoadingOverlayPane(JComponent component, JComponent animation) {
|
2008-03-19 22:14:38 +00:00
|
|
|
this(component, animation, getView(component));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
public LoadingOverlayPane(JComponent component, JComponent animation, JComponent view) {
|
2008-03-19 22:14:38 +00:00
|
|
|
setLayout(new OverlayLayout(this));
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
this.animationComponent = animation;
|
|
|
|
|
2008-03-19 22:14:38 +00:00
|
|
|
component.setAlignmentX(1.0f);
|
|
|
|
component.setAlignmentY(0.0f);
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
animation.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20));
|
2008-03-19 22:14:38 +00:00
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
animation.setAlignmentX(1.0f);
|
|
|
|
animation.setAlignmentY(0.0f);
|
|
|
|
animationComponent.setPreferredSize(new Dimension(48, 48));
|
|
|
|
animationComponent.setMaximumSize(animationComponent.getPreferredSize());
|
2008-03-19 22:14:38 +00:00
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
add(animation);
|
2008-03-19 22:14:38 +00:00
|
|
|
add(component);
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
setOverlayVisible(true);
|
2008-03-19 22:14:38 +00:00
|
|
|
|
|
|
|
view.addPropertyChangeListener(LOADING_PROPERTY, loadingListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-21 19:24:18 +00:00
|
|
|
@Override
|
|
|
|
public boolean isOptimizedDrawingEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-19 22:14:38 +00:00
|
|
|
private static JComponent getView(JComponent component) {
|
|
|
|
if (component instanceof JScrollPane) {
|
|
|
|
JScrollPane scrollPane = (JScrollPane) component;
|
|
|
|
return (JComponent) scrollPane.getViewport().getView();
|
|
|
|
}
|
|
|
|
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setOverlayVisible(boolean b) {
|
|
|
|
overlayEnabled = b;
|
|
|
|
|
|
|
|
if (overlayEnabled) {
|
2008-04-27 17:36:27 +00:00
|
|
|
TunedUtil.invokeLater(millisToOverlay, new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (overlayEnabled) {
|
2008-06-21 19:24:18 +00:00
|
|
|
animationComponent.setVisible(true);
|
2008-04-27 17:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2008-03-19 22:14:38 +00:00
|
|
|
} else {
|
2008-06-21 19:24:18 +00:00
|
|
|
animationComponent.setVisible(false);
|
2008-03-19 22:14:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final PropertyChangeListener loadingListener = new PropertyChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
|
Boolean loading = (Boolean) evt.getNewValue();
|
|
|
|
|
|
|
|
setOverlayVisible(loading);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|