From 57c6d096f6c48089628b5ae1d8061c0bd524d9dc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sun, 17 Jan 2016 13:07:50 +0200 Subject: [PATCH] Notification pop-up is now correctly scaled --- .../contributions/ContributionsSelfCheck.java | 6 +- .../cc/arduino/view/NotificationPopup.form | 89 --------- .../cc/arduino/view/NotificationPopup.java | 188 +++++++----------- 3 files changed, 79 insertions(+), 204 deletions(-) delete mode 100644 app/src/cc/arduino/view/NotificationPopup.form diff --git a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java index 5803189ef..1031effc3 100644 --- a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java +++ b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java @@ -83,11 +83,11 @@ public class ContributionsSelfCheck extends TimerTask { String text; if (updatableLibraries > 0 && updatablePlatforms <= 0) { - text = I18n.format(tr("
Update available for some of your {0}libraries{1}"), "", ""); + text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "", ""); } else if (updatableLibraries <= 0 && updatablePlatforms > 0) { - text = I18n.format(tr("
Update available for some of your {0}boards{1}"), "", ""); + text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "", ""); } else { - text = I18n.format(tr("
Update available for some of your {0}boards{1} and {2}libraries{3}"), "", "", "", ""); + text = I18n.format(tr("Updates available for some of your {0}boards{1} and {2}libraries{3}"), "", "", "", ""); } if (cancelled) { diff --git a/app/src/cc/arduino/view/NotificationPopup.form b/app/src/cc/arduino/view/NotificationPopup.form deleted file mode 100644 index 5e6f68cc1..000000000 --- a/app/src/cc/arduino/view/NotificationPopup.form +++ /dev/null @@ -1,89 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/app/src/cc/arduino/view/NotificationPopup.java b/app/src/cc/arduino/view/NotificationPopup.java index 947047da7..6a80ded36 100644 --- a/app/src/cc/arduino/view/NotificationPopup.java +++ b/app/src/cc/arduino/view/NotificationPopup.java @@ -29,26 +29,80 @@ package cc.arduino.view; -import processing.app.Base; -import processing.app.BaseNoGui; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Image; +import java.awt.Point; +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 javax.swing.*; -import javax.swing.event.HyperlinkEvent; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.WindowConstants; +import javax.swing.border.LineBorder; import javax.swing.event.HyperlinkListener; -import java.awt.*; -import java.awt.event.*; -import java.nio.file.Paths; + +import processing.app.Theme; +import static processing.app.Theme.scale; public class NotificationPopup extends JDialog { - private final ComponentAdapter parentMovedListener; - - public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, String message) { + public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, + String message) { super(parent, false); - initComponents(); + setLayout(new FlowLayout()); + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + setAlwaysOnTop(true); + setUndecorated(true); + setResizable(false); + + Image arduino = Theme.getLibImage("arduino", this, scale(40), scale(40)); + JLabel arduinoIcon = new JLabel(new ImageIcon(arduino)); + add(arduinoIcon); + + JEditorPane text = new JEditorPane(); + text.setBorder(new LineBorder(new Color(0, 0, 0), 0, true)); + text.setContentType("text/html"); // NOI18N + text.setOpaque(false); + text.setEditable(false); + text.setText(" " + message + " "); + text.addHyperlinkListener(hyperlinkListener); + add(text); + + Image close = Theme.getThemeImage("close", this, scale(22), scale(22)); + JButton closeButton = new JButton(new ImageIcon(close)); + closeButton.setBorder(null); + closeButton.setBorderPainted(false); + closeButton.setHideActionText(true); + closeButton.setOpaque(false); + closeButton.setBackground(new Color(0, 0, 0, 0)); + add(closeButton); + + MouseAdapter closeOnClick = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + close(); + } + }; + addMouseListener(closeOnClick); + text.addMouseListener(closeOnClick); + arduinoIcon.addMouseListener(closeOnClick); + closeButton.addMouseListener(closeOnClick); + + pack(); updateLocation(parent); - parentMovedListener = new ComponentAdapter() { + ComponentAdapter parentMovedListener = new ComponentAdapter() { @Override public void componentMoved(ComponentEvent e) { updateLocation(parent); @@ -60,35 +114,12 @@ public class NotificationPopup extends JDialog { } }; parent.addComponentListener(parentMovedListener); - - text.setText("" + message + ""); - - text.addHyperlinkListener(hyperlinkListener); - text.addHyperlinkListener(e -> { - if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { - return; - } - close(); - }); - addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { parent.removeComponentListener(parentMovedListener); } }); - - Base.registerWindowCloseKeys(getRootPane(), e -> close()); - - MouseAdapter closeOnClick = new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - close(); - } - }; - addMouseListener(closeOnClick); - text.addMouseListener(closeOnClick); - icon.addMouseListener(closeOnClick); } private void updateLocation(Frame parent) { @@ -100,87 +131,20 @@ public class NotificationPopup extends JDialog { } public void close() { - dispatchEvent(new WindowEvent(NotificationPopup.this, WindowEvent.WINDOW_CLOSING)); + dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - icon = new javax.swing.JLabel(); - text = new javax.swing.JEditorPane(); - closeButton = new javax.swing.JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setAlwaysOnTop(true); - setFocusable(false); - setFocusableWindowState(false); - setUndecorated(true); - setPreferredSize(new java.awt.Dimension(350, 70)); - setResizable(false); - setSize(new java.awt.Dimension(350, 70)); - getContentPane().setLayout(null); - - icon.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "arduino_small.png").toFile().getAbsolutePath())); - getContentPane().add(icon); - icon.setBounds(10, 10, 50, 50); - - text.setEditable(false); - text.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 0, true)); - text.setContentType("text/html"); // NOI18N - text.setOpaque(false); - getContentPane().add(text); - text.setBounds(70, 10, 270, 50); - - closeButton.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "theme", "close.png").toFile().getAbsolutePath())); - closeButton.setBorder(null); - closeButton.setBorderPainted(false); - closeButton.setHideActionText(true); - closeButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - closeButtonActionPerformed(evt); - } - }); - getContentPane().add(closeButton); - closeButton.setBounds(328, 0, 22, 22); - - pack(); - }// //GEN-END:initComponents - - private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed - close(); - }//GEN-LAST:event_closeButtonActionPerformed - - /** - * @param args the command line arguments - */ public static void main(String args[]) { - - /* Create and display the dialog */ - EventQueue.invokeLater(new Runnable() { - public void run() { - NotificationPopup dialog = new NotificationPopup(new JFrame(), System.out::println, "test test test test test test test test test\n" + - " test test test test test test test test test test test"); - dialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - dialog.setVisible(true); + NotificationPopup dialog = new NotificationPopup(new JFrame(), + System.out::println, + "test test test test test test test test test\n" + + " test test test test test test test test test test test"); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); } }); + dialog.setVisible(true); } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton closeButton; - private javax.swing.JLabel icon; - private javax.swing.JEditorPane text; - // End of variables declaration//GEN-END:variables - }