Changeset 12766 in josm


Ignore:
Timestamp:
2017-09-07T00:41:30+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - remove GUI stuff from MessageNotifier

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12760 r12766  
    88import java.awt.Dimension;
    99import java.awt.GraphicsEnvironment;
     10import java.awt.GridBagLayout;
    1011import java.awt.event.KeyEvent;
    1112import java.io.File;
     
    4849import javax.swing.InputMap;
    4950import javax.swing.JComponent;
     51import javax.swing.JLabel;
    5052import javax.swing.JOptionPane;
     53import javax.swing.JPanel;
    5154import javax.swing.KeyStroke;
    5255import javax.swing.LookAndFeel;
     
    8083import org.openstreetmap.josm.data.osm.DataSet;
    8184import org.openstreetmap.josm.data.osm.OsmPrimitive;
     85import org.openstreetmap.josm.data.osm.UserInfo;
    8286import org.openstreetmap.josm.data.osm.search.SearchMode;
    8387import org.openstreetmap.josm.data.validation.OsmValidator;
     
    107111import org.openstreetmap.josm.gui.util.RedirectInputMap;
    108112import org.openstreetmap.josm.gui.util.WindowGeometry;
     113import org.openstreetmap.josm.gui.widgets.UrlLabel;
    109114import org.openstreetmap.josm.io.CertificateAmendment;
    110115import org.openstreetmap.josm.io.DefaultProxySelector;
     
    122127import org.openstreetmap.josm.plugins.PluginInformation;
    123128import org.openstreetmap.josm.tools.FontsManager;
     129import org.openstreetmap.josm.tools.GBC;
    124130import org.openstreetmap.josm.tools.HttpClient;
    125131import org.openstreetmap.josm.tools.I18n;
     
    968974
    969975    static void setupCallbacks() {
     976        MessageNotifier.setNotifierCallback(MainApplication::notifyNewMessages);
    970977        DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback);
    971978    }
     
    13071314        }
    13081315    }
     1316
     1317    static void notifyNewMessages(UserInfo userInfo) {
     1318        GuiHelper.runInEDT(() -> {
     1319            JPanel panel = new JPanel(new GridBagLayout());
     1320            panel.add(new JLabel(trn("You have {0} unread message.", "You have {0} unread messages.",
     1321                    userInfo.getUnreadMessages(), userInfo.getUnreadMessages())),
     1322                    GBC.eol());
     1323            panel.add(new UrlLabel(Main.getBaseUserUrl() + '/' + userInfo.getDisplayName() + "/inbox",
     1324                    tr("Click here to see your inbox.")), GBC.eol());
     1325            panel.setOpaque(false);
     1326            new Notification().setContent(panel)
     1327                .setIcon(JOptionPane.INFORMATION_MESSAGE)
     1328                .setDuration(Notification.TIME_LONG)
     1329                .show();
     1330        });
     1331    }
    13091332}
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r12743 r12766  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trn;
    65
    7 import java.awt.GridBagLayout;
    86import java.net.Authenticator.RequestorType;
    97import java.util.concurrent.Executors;
     
    1210import java.util.concurrent.TimeUnit;
    1311
    14 import javax.swing.JLabel;
    15 import javax.swing.JOptionPane;
    16 import javax.swing.JPanel;
    17 
    1812import org.openstreetmap.josm.Main;
    1913import org.openstreetmap.josm.data.UserIdentityManager;
     
    2115import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2216import org.openstreetmap.josm.data.preferences.IntegerProperty;
    23 import org.openstreetmap.josm.gui.Notification;
    2417import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    25 import org.openstreetmap.josm.gui.util.GuiHelper;
    26 import org.openstreetmap.josm.gui.widgets.UrlLabel;
    2718import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    2819import org.openstreetmap.josm.io.auth.CredentialsAgentResponse;
    2920import org.openstreetmap.josm.io.auth.CredentialsManager;
    3021import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent;
    31 import org.openstreetmap.josm.tools.GBC;
    3222import org.openstreetmap.josm.tools.Logging;
    3323import org.openstreetmap.josm.tools.Utils;
     
    4131    private MessageNotifier() {
    4232        // 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;
    4356    }
    4457
     
    7184                    final int unread = userInfo.getUnreadMessages();
    7285                    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);
    8587                        lastUnreadCount = unread;
    8688                    }
  • trunk/src/org/openstreetmap/josm/tools/Logging.java

    r12765 r12766  
    283283    }
    284284
    285 
    286285    private static void logPrivate(Level level, String pattern, Object... args) {
    287286        logPrivate(level, () -> MessageFormat.format(pattern, args));
Note: See TracChangeset for help on using the changeset viewer.