mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Refactored notification popup
This commit is contained in:
parent
8b53785c9f
commit
46641780bf
@ -37,6 +37,13 @@ import java.awt.Frame;
|
|||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.event.WindowFocusListener;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
@ -51,6 +58,8 @@ import javax.swing.event.HyperlinkListener;
|
|||||||
|
|
||||||
import cc.arduino.Constants;
|
import cc.arduino.Constants;
|
||||||
import processing.app.PreferencesData;
|
import processing.app.PreferencesData;
|
||||||
|
import processing.app.Base;
|
||||||
|
import processing.app.Editor;
|
||||||
import processing.app.Theme;
|
import processing.app.Theme;
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
@ -66,18 +75,20 @@ public class NotificationPopup extends JDialog {
|
|||||||
void onOptionalButton1Callback();
|
void onOptionalButton1Callback();
|
||||||
void onOptionalButton2Callback();
|
void onOptionalButton2Callback();
|
||||||
}
|
}
|
||||||
|
private Editor editor;
|
||||||
|
|
||||||
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
|
public NotificationPopup(Editor parent, HyperlinkListener hyperlinkListener,
|
||||||
String message) {
|
String message) {
|
||||||
this(parent, hyperlinkListener, message, true, null, null, null);
|
this(parent, hyperlinkListener, message, true, null, null, null);
|
||||||
|
editor = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
|
public NotificationPopup(Editor parent, HyperlinkListener hyperlinkListener,
|
||||||
String message, boolean _autoClose) {
|
String message, boolean _autoClose) {
|
||||||
this(parent, hyperlinkListener, message, _autoClose, null, null, null);
|
this(parent, hyperlinkListener, message, _autoClose, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
|
public NotificationPopup(Editor parent, HyperlinkListener hyperlinkListener,
|
||||||
String message, boolean _autoClose, OptionalButtonCallbacks listener, String button1Name, String button2Name) {
|
String message, boolean _autoClose, OptionalButtonCallbacks listener, String button1Name, String button2Name) {
|
||||||
super(parent, false);
|
super(parent, false);
|
||||||
|
|
||||||
@ -88,6 +99,7 @@ public class NotificationPopup extends JDialog {
|
|||||||
else {
|
else {
|
||||||
autoClose = false;
|
autoClose = false;
|
||||||
}
|
}
|
||||||
|
editor = parent;
|
||||||
optionalButtonCallbacks = listener;
|
optionalButtonCallbacks = listener;
|
||||||
|
|
||||||
setLayout(new FlowLayout());
|
setLayout(new FlowLayout());
|
||||||
@ -106,7 +118,9 @@ public class NotificationPopup extends JDialog {
|
|||||||
text.setEditable(false);
|
text.setEditable(false);
|
||||||
text.setText("<html><body style=\"font-family:sans-serif; font-size: "
|
text.setText("<html><body style=\"font-family:sans-serif; font-size: "
|
||||||
+ scale(14) + ";\"> " + message + " </body></html>");
|
+ scale(14) + ";\"> " + message + " </body></html>");
|
||||||
text.addHyperlinkListener(hyperlinkListener);
|
if (hyperlinkListener != null) {
|
||||||
|
text.addHyperlinkListener(hyperlinkListener);
|
||||||
|
}
|
||||||
add(text);
|
add(text);
|
||||||
|
|
||||||
if (button1Name != null) {
|
if (button1Name != null) {
|
||||||
@ -271,4 +285,28 @@ public class NotificationPopup extends JDialog {
|
|||||||
setModal(true);
|
setModal(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void beginWhenFocused() {
|
||||||
|
if (editor.isFocused()) {
|
||||||
|
begin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Base base = editor.getBase();
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
begin();
|
||||||
|
base.getEditors().forEach(e -> e.removeWindowFocusListener(this));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
base.getEditors().forEach(e -> e.addWindowFocusListener(wfl));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -403,6 +403,10 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
EditorConsole.setCurrentEditorConsole(console);
|
EditorConsole.setCurrentEditorConsole(console);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Base getBase() {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles files dragged & dropped from the desktop and into the editor
|
* Handles files dragged & dropped from the desktop and into the editor
|
||||||
* window. Dragging files into the editor window is the same as using
|
* window. Dragging files into the editor window is the same as using
|
||||||
|
@ -73,34 +73,11 @@ public class NewBoardListener implements PropertyChangeListener, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
|
||||||
ed = base.getActiveEditor();
|
ed = base.getActiveEditor();
|
||||||
NotificationPopup notificationPopup = new NotificationPopup(ed,
|
NotificationPopup notificationPopup = new NotificationPopup(ed,
|
||||||
new UpdatableBoardsLibsFakeURLsHandler(base),
|
new UpdatableBoardsLibsFakeURLsHandler(base),
|
||||||
newBoardManagerLink, false);
|
newBoardManagerLink, false);
|
||||||
if (ed.isFocused()) {
|
notificationPopup.beginWhenFocused();
|
||||||
notificationPopup.begin();
|
|
||||||
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.begin();
|
|
||||||
for (Editor e : base.getEditors())
|
|
||||||
e.removeWindowFocusListener(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (Editor e : base.getEditors())
|
|
||||||
e.addWindowFocusListener(wfl);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user