1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-05 08:55:08 -05:00
filebot/source/net/sourceforge/tuned/ui/LoadingOverlayPanel.java
Reinhard Pointner 4b4ca4fc68 * improved ui performance
* proper class visibility
2008-03-16 18:23:12 +00:00

91 lines
1.7 KiB
Java

package net.sourceforge.tuned.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.OverlayLayout;
import javax.swing.Timer;
public class LoadingOverlayPanel extends JPanel {
private JLabel loadingLabel = new JLabel();
private boolean overlayEnabled = false;
private int millisToOverlay = 500;
public LoadingOverlayPanel(JComponent component, Icon animation) {
setLayout(new OverlayLayout(this));
component.setAlignmentX(1.0f);
component.setAlignmentY(0.0f);
loadingLabel.setIcon(animation);
loadingLabel.setOpaque(false);
loadingLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20));
loadingLabel.setAlignmentX(1.0f);
loadingLabel.setAlignmentY(0.0f);
loadingLabel.setMaximumSize(loadingLabel.getPreferredSize());
add(loadingLabel);
add(component);
setOverlayVisible(false);
}
public void setMillisToOverlay(int millisToOverlay) {
this.millisToOverlay = millisToOverlay;
}
public int getMillisToOverlay() {
return millisToOverlay;
}
public void setOverlayVisible(boolean b) {
overlayEnabled = b;
if (overlayEnabled) {
new EnableOverlayTimer().start();
} else {
loadingLabel.setVisible(false);
}
}
private class EnableOverlayTimer extends Timer implements ActionListener {
public EnableOverlayTimer() {
super(millisToOverlay, null);
addActionListener(this);
setRepeats(false);
}
public void actionPerformed(ActionEvent e) {
if (overlayEnabled) {
loadingLabel.setVisible(true);
}
}
}
public void updateOverlay() {
revalidate();
repaint();
}
}