Skip to content

Commit 57c6d09

Browse files
committed
Notification pop-up is now correctly scaled
1 parent 4659c6f commit 57c6d09

File tree

3 files changed

+80
-205
lines changed

3 files changed

+80
-205
lines changed

app/src/cc/arduino/contributions/ContributionsSelfCheck.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public void run() {
8383

8484
String text;
8585
if (updatableLibraries > 0 && updatablePlatforms <= 0) {
86-
text = I18n.format(tr("<br/>Update available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
86+
text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
8787
} else if (updatableLibraries <= 0 && updatablePlatforms > 0) {
88-
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
88+
text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
8989
} else {
90-
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1} and {2}libraries{3}"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
90+
text = I18n.format(tr("Updates available for some of your {0}boards{1} and {2}libraries{3}"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
9191
}
9292

9393
if (cancelled) {

app/src/cc/arduino/view/NotificationPopup.form

-89
This file was deleted.

app/src/cc/arduino/view/NotificationPopup.java

+77-113
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,80 @@
2929

3030
package cc.arduino.view;
3131

32-
import processing.app.Base;
33-
import processing.app.BaseNoGui;
34-
35-
import javax.swing.*;
36-
import javax.swing.event.HyperlinkEvent;
32+
import java.awt.Color;
33+
import java.awt.FlowLayout;
34+
import java.awt.Frame;
35+
import java.awt.Image;
36+
import java.awt.Point;
37+
import java.awt.event.ComponentAdapter;
38+
import java.awt.event.ComponentEvent;
39+
import java.awt.event.MouseAdapter;
40+
import java.awt.event.MouseEvent;
41+
import java.awt.event.WindowAdapter;
42+
import java.awt.event.WindowEvent;
43+
44+
import javax.swing.ImageIcon;
45+
import javax.swing.JButton;
46+
import javax.swing.JDialog;
47+
import javax.swing.JEditorPane;
48+
import javax.swing.JFrame;
49+
import javax.swing.JLabel;
50+
import javax.swing.WindowConstants;
51+
import javax.swing.border.LineBorder;
3752
import javax.swing.event.HyperlinkListener;
38-
import java.awt.*;
39-
import java.awt.event.*;
40-
import java.nio.file.Paths;
4153

42-
public class NotificationPopup extends JDialog {
54+
import processing.app.Theme;
55+
import static processing.app.Theme.scale;
4356

44-
private final ComponentAdapter parentMovedListener;
57+
public class NotificationPopup extends JDialog {
4558

46-
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, String message) {
59+
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
60+
String message) {
4761
super(parent, false);
48-
initComponents();
62+
setLayout(new FlowLayout());
63+
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
64+
setAlwaysOnTop(true);
65+
setUndecorated(true);
66+
setResizable(false);
67+
68+
Image arduino = Theme.getLibImage("arduino", this, scale(40), scale(40));
69+
JLabel arduinoIcon = new JLabel(new ImageIcon(arduino));
70+
add(arduinoIcon);
71+
72+
JEditorPane text = new JEditorPane();
73+
text.setBorder(new LineBorder(new Color(0, 0, 0), 0, true));
74+
text.setContentType("text/html"); // NOI18N
75+
text.setOpaque(false);
76+
text.setEditable(false);
77+
text.setText("<html><body style=\"font-family:sans-serif; font-size: "
78+
+ scale(14) + ";\"> " + message + " </body></html>");
79+
text.addHyperlinkListener(hyperlinkListener);
80+
add(text);
81+
82+
Image close = Theme.getThemeImage("close", this, scale(22), scale(22));
83+
JButton closeButton = new JButton(new ImageIcon(close));
84+
closeButton.setBorder(null);
85+
closeButton.setBorderPainted(false);
86+
closeButton.setHideActionText(true);
87+
closeButton.setOpaque(false);
88+
closeButton.setBackground(new Color(0, 0, 0, 0));
89+
add(closeButton);
90+
91+
MouseAdapter closeOnClick = new MouseAdapter() {
92+
@Override
93+
public void mouseClicked(MouseEvent e) {
94+
close();
95+
}
96+
};
97+
addMouseListener(closeOnClick);
98+
text.addMouseListener(closeOnClick);
99+
arduinoIcon.addMouseListener(closeOnClick);
100+
closeButton.addMouseListener(closeOnClick);
101+
102+
pack();
49103

50104
updateLocation(parent);
51-
parentMovedListener = new ComponentAdapter() {
105+
ComponentAdapter parentMovedListener = new ComponentAdapter() {
52106
@Override
53107
public void componentMoved(ComponentEvent e) {
54108
updateLocation(parent);
@@ -60,35 +114,12 @@ public void componentResized(ComponentEvent e) {
60114
}
61115
};
62116
parent.addComponentListener(parentMovedListener);
63-
64-
text.setText("<html><body style=\"font-family:sans-serif;font-size:12pt\">" + message + "</body></html>");
65-
66-
text.addHyperlinkListener(hyperlinkListener);
67-
text.addHyperlinkListener(e -> {
68-
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
69-
return;
70-
}
71-
close();
72-
});
73-
74117
addWindowListener(new WindowAdapter() {
75118
@Override
76119
public void windowClosed(WindowEvent e) {
77120
parent.removeComponentListener(parentMovedListener);
78121
}
79122
});
80-
81-
Base.registerWindowCloseKeys(getRootPane(), e -> close());
82-
83-
MouseAdapter closeOnClick = new MouseAdapter() {
84-
@Override
85-
public void mouseClicked(MouseEvent e) {
86-
close();
87-
}
88-
};
89-
addMouseListener(closeOnClick);
90-
text.addMouseListener(closeOnClick);
91-
icon.addMouseListener(closeOnClick);
92123
}
93124

94125
private void updateLocation(Frame parent) {
@@ -100,87 +131,20 @@ private void updateLocation(Frame parent) {
100131
}
101132

102133
public void close() {
103-
dispatchEvent(new WindowEvent(NotificationPopup.this, WindowEvent.WINDOW_CLOSING));
134+
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
104135
}
105136

106-
/**
107-
* This method is called from within the constructor to initialize the form.
108-
* WARNING: Do NOT modify this code. The content of this method is always
109-
* regenerated by the Form Editor.
110-
*/
111-
@SuppressWarnings("unchecked")
112-
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
113-
private void initComponents() {
114-
115-
icon = new javax.swing.JLabel();
116-
text = new javax.swing.JEditorPane();
117-
closeButton = new javax.swing.JButton();
118-
119-
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
120-
setAlwaysOnTop(true);
121-
setFocusable(false);
122-
setFocusableWindowState(false);
123-
setUndecorated(true);
124-
setPreferredSize(new java.awt.Dimension(350, 70));
125-
setResizable(false);
126-
setSize(new java.awt.Dimension(350, 70));
127-
getContentPane().setLayout(null);
128-
129-
icon.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "arduino_small.png").toFile().getAbsolutePath()));
130-
getContentPane().add(icon);
131-
icon.setBounds(10, 10, 50, 50);
132-
133-
text.setEditable(false);
134-
text.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 0, true));
135-
text.setContentType("text/html"); // NOI18N
136-
text.setOpaque(false);
137-
getContentPane().add(text);
138-
text.setBounds(70, 10, 270, 50);
139-
140-
closeButton.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "theme", "close.png").toFile().getAbsolutePath()));
141-
closeButton.setBorder(null);
142-
closeButton.setBorderPainted(false);
143-
closeButton.setHideActionText(true);
144-
closeButton.addActionListener(new java.awt.event.ActionListener() {
145-
public void actionPerformed(java.awt.event.ActionEvent evt) {
146-
closeButtonActionPerformed(evt);
147-
}
148-
});
149-
getContentPane().add(closeButton);
150-
closeButton.setBounds(328, 0, 22, 22);
151-
152-
pack();
153-
}// </editor-fold>//GEN-END:initComponents
154-
155-
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
156-
close();
157-
}//GEN-LAST:event_closeButtonActionPerformed
158-
159-
/**
160-
* @param args the command line arguments
161-
*/
162137
public static void main(String args[]) {
163-
164-
/* Create and display the dialog */
165-
EventQueue.invokeLater(new Runnable() {
166-
public void run() {
167-
NotificationPopup dialog = new NotificationPopup(new JFrame(), System.out::println, "<a href='arduinoide://boardsmanager'>test</a> test test test test test test test test\n" +
168-
" test test test test test test test test test test test");
169-
dialog.addWindowListener(new WindowAdapter() {
170-
@Override
171-
public void windowClosing(WindowEvent e) {
172-
System.exit(0);
173-
}
174-
});
175-
dialog.setVisible(true);
138+
NotificationPopup dialog = new NotificationPopup(new JFrame(),
139+
System.out::println,
140+
"<a href='arduinoide://boardsmanager'>test</a> test test test test test test test test\n"
141+
+ " test test test test test test test test test test test");
142+
dialog.addWindowListener(new WindowAdapter() {
143+
@Override
144+
public void windowClosing(WindowEvent e) {
145+
System.exit(0);
176146
}
177147
});
148+
dialog.setVisible(true);
178149
}
179-
180-
// Variables declaration - do not modify//GEN-BEGIN:variables
181-
private javax.swing.JButton closeButton;
182-
private javax.swing.JLabel icon;
183-
private javax.swing.JEditorPane text;
184-
// End of variables declaration//GEN-END:variables
185-
186150
}

0 commit comments

Comments
 (0)