Fix always-on-top notification popup

This commit is contained in:
Cristian Maglie 2016-03-31 18:49:44 +02:00
parent 219e540573
commit 1a7eaaf8b2
2 changed files with 28 additions and 3 deletions

View File

@ -36,10 +36,14 @@ import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
import cc.arduino.view.NotificationPopup;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.Editor;
import processing.app.I18n;
import javax.swing.*;
import javax.swing.event.HyperlinkListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.util.TimerTask;
import static processing.app.I18n.tr;
@ -95,8 +99,30 @@ public class ContributionsSelfCheck extends TimerTask {
}
SwingUtilities.invokeLater(() -> {
notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, text);
notificationPopup.setVisible(true);
Editor ed = base.getActiveEditor();
notificationPopup = new NotificationPopup(ed, hyperlinkListener, text);
if (ed.isFocused()) {
notificationPopup.setVisible(true);
return;
}
// If the IDE is not focused wait until it is focused again to
// display the notification, this avoids the annoying side effect
// to "steal" the focus from another application.
WindowFocusListener wfl = new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent evt) {
}
@Override
public void windowGainedFocus(WindowEvent evt) {
notificationPopup.setVisible(true);
for (Editor e : base.getEditors())
e.removeWindowFocusListener(this);
}
};
for (Editor e : base.getEditors())
e.addWindowFocusListener(wfl);
});
}

View File

@ -61,7 +61,6 @@ public class NotificationPopup extends JDialog {
super(parent, false);
setLayout(new FlowLayout());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setUndecorated(true);
setResizable(false);