Class NotificationManager


  • class NotificationManager
    extends java.lang.Object
    Manages Notifications, i.e. displays them on screen.

    Don't use this class directly, but use Notification.show().

    If multiple messages are sent in a short period of time, they are put in a queue and displayed one after the other.

    The user can stop the timer (freeze the message) by moving the mouse cursor above the panel. As a visual cue, the background color changes from semi-transparent to opaque while the timer is frozen.

    • Method Detail

      • showNotification

        void showNotification​(Notification note)
        Show the given notification (unless a duplicate notification is being shown at the moment or is already queued)
        Parameters:
        note - The note to show.
        See Also:
        Notification.show()
      • replaceExistingNotification

        void replaceExistingNotification​(Notification oldNotification,
                                         Notification newNotification)
        Show the given notification by replacing the given queued/displaying notification
        Parameters:
        oldNotification - the notification to replace
        newNotification - the notification to show
      • processQueue

        private void processQueue()
        Displays the next queued notification, unless one is being displayed already or the queue is empty.

        Only the state transition is guarded by the monitor of queue. The rest waits for the EDT, and the EDT takes that very monitor as well, so holding it any longer would deadlock every caller that is not the EDT itself.

      • updateNotificationPosition

        private void updateNotificationPosition()
        Aligns the displayed notification to the map view, or to the content pane while no map view is displayed, and keeps listening to that anchor for as long as the notification is displayed.
      • detachAnchorListener

        private void detachAnchorListener()
        Stops listening to the anchor of the notification that is no longer displayed.
      • getNotificationPosition

        static java.awt.Point getNotificationPosition​(java.awt.Component anchor,
                                                      java.awt.Container container,
                                                      java.awt.Dimension size,
                                                      int margin)
        Computes the position of a notification panel in the coordinate system of container, which unlike the one of the main window does not depend on the window decorations, i.e. on fullscreen mode.

        The panel is aligned to the bottom left corner of anchor, or to its top left corner if it is taller, so that the beginning of a long message stays readable.

        Parameters:
        anchor - the component the notification is aligned to, e.g. the map view
        container - the container the notification panel is added to
        size - the size of the notification panel
        margin - the margin to keep between the notification panel and the borders of anchor
        Returns:
        the location of the upper left corner of the notification panel
      • stopHideTimer

        private void stopHideTimer​(Notification expected)
        Hides the displayed notification and starts the pause before the next one.
        Parameters:
        expected - the notification to hide, or null for whichever is displayed. Nothing happens if another notification is displayed by now.