From a43757d5c3b7b343ecac9c4885441ef5dc5ef116 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 4 Aug 2015 15:50:50 +0200 Subject: [PATCH] Update notification: UX feedback --- .../contributions/ContributionsSelfCheck.java | 8 +- .../cc/arduino/view/NotificationPopup.form | 84 +++++------------ .../cc/arduino/view/NotificationPopup.java | 91 ++++++------------- 3 files changed, 56 insertions(+), 127 deletions(-) diff --git a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java index 527b8e1ea..83491108e 100644 --- a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java +++ b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java @@ -59,11 +59,11 @@ public class ContributionsSelfCheck extends TimerTask { String text; if (updatableLibraries > 0 && updatablePlatforms <= 0) { - text = I18n.format(_("Some {0}libraries{1} may be updated"), "", ""); + text = I18n.format(_("
Update available for some of your {0}libraries{1}"), "", ""); } else if (updatableLibraries <= 0 && updatablePlatforms > 0) { - text = I18n.format(_("Some {0}boards{1} may be updated"), "", ""); + text = I18n.format(_("
Update available for some of your {0}boards{1}"), "", ""); } else { - text = I18n.format(_("Some {0}boards{1} and some {2}libraries{3} may be updated"), "", "", "", ""); + text = I18n.format(_("
Update available for some of your {0}boards{1} and {2}libraries{3}"), "", "", "", ""); } if (cancelled) { @@ -71,7 +71,7 @@ public class ContributionsSelfCheck extends TimerTask { } SwingUtilities.invokeLater(() -> { - notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text); + notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, text); notificationPopup.setVisible(true); }); } diff --git a/app/src/cc/arduino/view/NotificationPopup.form b/app/src/cc/arduino/view/NotificationPopup.form index 48daea67e..5e6f68cc1 100644 --- a/app/src/cc/arduino/view/NotificationPopup.form +++ b/app/src/cc/arduino/view/NotificationPopup.form @@ -7,7 +7,13 @@ + + + + + + @@ -23,74 +29,24 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - + - - - - + + + + + @@ -103,6 +59,11 @@ + + + + + @@ -118,6 +79,11 @@ + + + + + diff --git a/app/src/cc/arduino/view/NotificationPopup.java b/app/src/cc/arduino/view/NotificationPopup.java index 7119672bd..8938afa38 100644 --- a/app/src/cc/arduino/view/NotificationPopup.java +++ b/app/src/cc/arduino/view/NotificationPopup.java @@ -29,7 +29,6 @@ package cc.arduino.view; -import cc.arduino.Constants; import processing.app.Base; import processing.app.BaseNoGui; @@ -43,9 +42,8 @@ import java.nio.file.Paths; public class NotificationPopup extends JDialog { private final ComponentAdapter parentMovedListener; - private final Timer autoCloseAfterTimeout; - public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, String titleText, String message) { + public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, String message) { super(parent, false); initComponents(); @@ -58,10 +56,15 @@ public class NotificationPopup extends JDialog { }; parent.addComponentListener(parentMovedListener); - title.setText(titleText); - text.setText("" + message.replace("\n", "
") + ""); + text.setText("" + message + ""); text.addHyperlinkListener(hyperlinkListener); + text.addHyperlinkListener(e -> { + if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { + return; + } + close(); + }); addWindowListener(new WindowAdapter() { @Override @@ -70,24 +73,17 @@ public class NotificationPopup extends JDialog { } }); - autoCloseAfterTimeout = new Timer(Constants.NOTIFICATION_POPUP_AUTOCLOSE_DELAY, (e) -> close()); - autoCloseAfterTimeout.start(); - - text.addHyperlinkListener(e -> { - if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { - return; - } - close(); - }); - Base.registerWindowCloseKeys(getRootPane(), e -> close()); - addMouseListener(new MouseAdapter() { + MouseAdapter closeOnClick = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { close(); } - }); + }; + addMouseListener(closeOnClick); + text.addMouseListener(closeOnClick); + icon.addMouseListener(closeOnClick); } private void updateLocation(Frame parent) { @@ -95,14 +91,10 @@ public class NotificationPopup extends JDialog { int parentX = Double.valueOf(parentLocation.getX()).intValue(); int parentY = Double.valueOf(parentLocation.getY()).intValue(); - setLocation(parentX + parent.getWidth() - getWidth(), parentY + parent.getHeight() - getHeight()); + setLocation(parentX, parentY + parent.getHeight() - getHeight()); } public void close() { - if (autoCloseAfterTimeout.isRunning()) { - autoCloseAfterTimeout.stop(); - } - dispatchEvent(new WindowEvent(NotificationPopup.this, WindowEvent.WINDOW_CLOSING)); } @@ -115,8 +107,7 @@ public class NotificationPopup extends JDialog { // //GEN-BEGIN:initComponents private void initComponents() { - title = new javax.swing.JLabel(); - javax.swing.JLabel jLabel1 = new javax.swing.JLabel(); + icon = new javax.swing.JLabel(); text = new javax.swing.JEditorPane(); closeButton = new javax.swing.JButton(); @@ -125,16 +116,21 @@ public class NotificationPopup extends JDialog { 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); - title.setFont(title.getFont().deriveFont(title.getFont().getStyle() | java.awt.Font.BOLD)); - - jLabel1.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "arduino_small.png").toFile().getAbsolutePath())); + 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); @@ -145,41 +141,8 @@ public class NotificationPopup extends JDialog { closeButtonActionPerformed(evt); } }); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addGroup(layout.createSequentialGroup() - .addComponent(title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(24, 24, 24) - .addComponent(closeButton)))) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(title)) - .addComponent(closeButton)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); + getContentPane().add(closeButton); + closeButton.setBounds(328, 0, 22, 22); pack(); }// //GEN-END:initComponents @@ -196,7 +159,7 @@ public class NotificationPopup extends JDialog { /* Create and display the dialog */ EventQueue.invokeLater(new Runnable() { public void run() { - NotificationPopup dialog = new NotificationPopup(new JFrame(), System.out::println, "title", "test test test test test test test test test\n" + + 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 @@ -211,8 +174,8 @@ public class NotificationPopup extends JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton closeButton; + private javax.swing.JLabel icon; private javax.swing.JEditorPane text; - private javax.swing.JLabel title; // End of variables declaration//GEN-END:variables }