2007-12-23 14:28:04 -05:00
|
|
|
/*
|
|
|
|
* Created on 19.03.2005
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui.notification;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Window;
|
2008-04-27 13:36:27 -04:00
|
|
|
import java.awt.event.ComponentAdapter;
|
|
|
|
import java.awt.event.ComponentEvent;
|
|
|
|
import java.awt.event.ComponentListener;
|
2007-12-23 14:28:04 -05:00
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
|
|
|
|
import javax.swing.JWindow;
|
|
|
|
import javax.swing.Timer;
|
|
|
|
|
2008-04-27 13:36:27 -04:00
|
|
|
import net.sourceforge.tuned.ui.TunedUtil;
|
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
public class NotificationWindow extends JWindow {
|
|
|
|
|
2008-04-27 13:36:27 -04:00
|
|
|
private int timeout;
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
public NotificationWindow(Window owner, int timeout) {
|
|
|
|
this(owner, timeout, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public NotificationWindow(Window owner, int timeout, boolean closeOnClick) {
|
|
|
|
super(owner);
|
2008-04-27 13:36:27 -04:00
|
|
|
this.timeout = timeout;
|
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
setAlwaysOnTop(true);
|
|
|
|
|
|
|
|
if (closeOnClick)
|
|
|
|
getGlassPane().addMouseListener(clickListener);
|
|
|
|
|
|
|
|
getGlassPane().setVisible(true);
|
|
|
|
|
2008-04-27 13:36:27 -04:00
|
|
|
addComponentListener(visibleListener);
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public NotificationWindow(int timeout) {
|
|
|
|
this((Window) null, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public NotificationWindow(Window owner) {
|
|
|
|
this(owner, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public NotificationWindow() {
|
|
|
|
this((Window) null, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public final void close() {
|
2008-04-27 13:36:27 -04:00
|
|
|
setVisible(false);
|
2007-12-23 14:28:04 -05:00
|
|
|
|
2008-04-27 13:36:27 -04:00
|
|
|
// component hidden is not fired automatically
|
|
|
|
processComponentEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_HIDDEN));
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
|
|
|
|
2008-04-27 13:36:27 -04:00
|
|
|
private ComponentListener visibleListener = new ComponentAdapter() {
|
|
|
|
|
|
|
|
private Timer timer;
|
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
|
|
|
|
@Override
|
2008-04-27 13:36:27 -04:00
|
|
|
public void componentShown(ComponentEvent e) {
|
|
|
|
if (timeout >= 0) {
|
|
|
|
timer = TunedUtil.invokeLater(timeout, new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2008-04-27 13:36:27 -04:00
|
|
|
public void componentHidden(ComponentEvent e) {
|
|
|
|
if (timer != null) {
|
2007-12-23 14:28:04 -05:00
|
|
|
timer.stop();
|
2008-04-27 13:36:27 -04:00
|
|
|
}
|
2007-12-23 14:28:04 -05:00
|
|
|
}
|
2008-04-27 13:36:27 -04:00
|
|
|
|
2007-12-23 14:28:04 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
private MouseAdapter clickListener = new MouseAdapter() {
|
|
|
|
|
2008-04-27 13:36:27 -04:00
|
|
|
@Override
|
2007-12-23 14:28:04 -05:00
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|