Changeset 12766 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2017-09-07T00:41:30+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/MessageNotifier.java
r12743 r12766 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn;6 5 7 import java.awt.GridBagLayout;8 6 import java.net.Authenticator.RequestorType; 9 7 import java.util.concurrent.Executors; … … 12 10 import java.util.concurrent.TimeUnit; 13 11 14 import javax.swing.JLabel;15 import javax.swing.JOptionPane;16 import javax.swing.JPanel;17 18 12 import org.openstreetmap.josm.Main; 19 13 import org.openstreetmap.josm.data.UserIdentityManager; … … 21 15 import org.openstreetmap.josm.data.preferences.BooleanProperty; 22 16 import org.openstreetmap.josm.data.preferences.IntegerProperty; 23 import org.openstreetmap.josm.gui.Notification;24 17 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 25 import org.openstreetmap.josm.gui.util.GuiHelper;26 import org.openstreetmap.josm.gui.widgets.UrlLabel;27 18 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 28 19 import org.openstreetmap.josm.io.auth.CredentialsAgentResponse; 29 20 import org.openstreetmap.josm.io.auth.CredentialsManager; 30 21 import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent; 31 import org.openstreetmap.josm.tools.GBC;32 22 import org.openstreetmap.josm.tools.Logging; 33 23 import org.openstreetmap.josm.tools.Utils; … … 41 31 private MessageNotifier() { 42 32 // Hide default constructor for utils classes 33 } 34 35 /** 36 * Called when new new messages are detected. 37 * @since xxx 38 */ 39 @FunctionalInterface 40 public interface NotifierCallback { 41 /** 42 * Perform the actual notification of new messages. 43 * @param userInfo the new user information, that includes the number of unread messages 44 */ 45 void notifyNewMessages(UserInfo userInfo); 46 } 47 48 private static NotifierCallback callback; 49 50 /** 51 * Sets the {@link NotifierCallback} responsible of notifying the user when new messages are received. 52 * @param notifierCallback the new {@code NotifierCallback} 53 */ 54 public static void setNotifierCallback(NotifierCallback notifierCallback) { 55 callback = notifierCallback; 43 56 } 44 57 … … 71 84 final int unread = userInfo.getUnreadMessages(); 72 85 if (unread > 0 && unread != lastUnreadCount) { 73 GuiHelper.runInEDT(() -> { 74 JPanel panel = new JPanel(new GridBagLayout()); 75 panel.add(new JLabel(trn("You have {0} unread message.", "You have {0} unread messages.", unread, unread)), 76 GBC.eol()); 77 panel.add(new UrlLabel(Main.getBaseUserUrl() + '/' + userInfo.getDisplayName() + "/inbox", 78 tr("Click here to see your inbox.")), GBC.eol()); 79 panel.setOpaque(false); 80 new Notification().setContent(panel) 81 .setIcon(JOptionPane.INFORMATION_MESSAGE) 82 .setDuration(Notification.TIME_LONG) 83 .show(); 84 }); 86 callback.notifyNewMessages(userInfo); 85 87 lastUnreadCount = unread; 86 88 }
Note:
See TracChangeset
for help on using the changeset viewer.