Class NotificationManager
- java.lang.Object
-
- org.openstreetmap.josm.gui.NotificationManager
-
class NotificationManager extends java.lang.Object
ManagesNotifications, 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classNotificationManager.FreezeMouseListenerprivate static classNotificationManager.NotificationPanelprivate classNotificationManager.PauseFinishedEventstatic classNotificationManager.RoundedPanelA panel with rounded edges and line border.private classNotificationManager.UnfreezeEvent
-
Field Summary
Fields Modifier and Type Field Description private java.awt.event.ComponentListeneranchorListenerkeeps the displayed notification aligned when the layout around it changes, e.g.private NotificationcurrentNotificationprivate NotificationManager.NotificationPanelcurrentNotificationPanelprivate longdisplayTimeStartprivate longelapsedTimeprivate javax.swing.TimerhideTimerprivate static NotificationManagerinstanceprivate MapFrameListenermapFrameListenerbrings the displayed notification over to the map view as soon as one is opened, and back when it is closedprivate static intMARGINmargin between the notification panel and the borders of its anchor, in unscaled pixelsprivate java.awt.ComponentnotificationAnchorthe componentcurrentNotificationPanelis aligned to,nullwhile nothing is displayedprivate static java.awt.ColorPANEL_OPAQUEprivate static java.awt.ColorPANEL_SEMITRANSPARENTprivate static IntegerPropertypauseTimeprivate javax.swing.TimerpauseTimerprivate java.util.Deque<Notification>queueprivate booleanrunningprivate java.awt.event.HierarchyListenershowingListenerrealigns the displayed notification when toggling fullscreen, before the window is painted with it at its old positionprivate javax.swing.TimerunfreezeDelayTimer
-
Constructor Summary
Constructors Constructor Description NotificationManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddetachAnchorListener()Stops listening to the anchor of the notification that is no longer displayed.static NotificationManagergetInstance()(package private) static java.awt.PointgetNotificationPosition(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 ofcontainer, which unlike the one of the main window does not depend on the window decorations, i.e.private voidprocessQueue()Displays the next queued notification, unless one is being displayed already or the queue is empty.(package private) voidreplaceExistingNotification(Notification oldNotification, Notification newNotification)Show the given notification by replacing the given queued/displaying notification(package private) voidshowNotification(Notification note)Show the given notification (unless a duplicate notification is being shown at the moment or is already queued)private voidstartHideTimer()private voidstopHideTimer(Notification expected)Hides the displayed notification and starts the pause before the next one.private voidupdateNotificationPosition()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.
-
-
-
Field Detail
-
hideTimer
private final javax.swing.Timer hideTimer
-
pauseTimer
private final javax.swing.Timer pauseTimer
-
unfreezeDelayTimer
private final javax.swing.Timer unfreezeDelayTimer
-
running
private boolean running
-
currentNotification
private Notification currentNotification
-
currentNotificationPanel
private NotificationManager.NotificationPanel currentNotificationPanel
-
notificationAnchor
private java.awt.Component notificationAnchor
the componentcurrentNotificationPanelis aligned to,nullwhile nothing is displayed
-
anchorListener
private final java.awt.event.ComponentListener anchorListener
keeps the displayed notification aligned when the layout around it changes, e.g. in fullscreen mode
-
showingListener
private final java.awt.event.HierarchyListener showingListener
realigns the displayed notification when toggling fullscreen, before the window is painted with it at its old position
-
mapFrameListener
private final MapFrameListener mapFrameListener
brings the displayed notification over to the map view as soon as one is opened, and back when it is closed
-
queue
private final java.util.Deque<Notification> queue
-
pauseTime
private static final IntegerProperty pauseTime
-
displayTimeStart
private long displayTimeStart
-
elapsedTime
private long elapsedTime
-
instance
private static NotificationManager instance
-
MARGIN
private static final int MARGIN
margin between the notification panel and the borders of its anchor, in unscaled pixels- See Also:
- Constant Field Values
-
PANEL_SEMITRANSPARENT
private static final java.awt.Color PANEL_SEMITRANSPARENT
-
PANEL_OPAQUE
private static final java.awt.Color PANEL_OPAQUE
-
-
Constructor Detail
-
NotificationManager
NotificationManager()
-
-
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 replacenewNotification- 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 ofcontainer, 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 viewcontainer- the container the notification panel is added tosize- the size of the notification panelmargin- the margin to keep between the notification panel and the borders ofanchor- Returns:
- the location of the upper left corner of the notification panel
-
startHideTimer
private void startHideTimer()
-
stopHideTimer
private void stopHideTimer(Notification expected)
Hides the displayed notification and starts the pause before the next one.- Parameters:
expected- the notification to hide, ornullfor whichever is displayed. Nothing happens if another notification is displayed by now.
-
getInstance
public static NotificationManager getInstance()
-
-