Class AbstractMFXNotificationSystem
- All Implemented Interfaces:
INotificationSystem
- Direct Known Subclasses:
MFXNotificationCenterSystem,MFXNotificationSystem
- The Screen on which to show the notification
- The Window on which the notification system's stage depends (more on that later)
- A MFXPopup which contains the notification
- The NotificationPos to compute the shown notifications' position
- Allows to specify some extra spacing between the screen's borders and the notification
- By default is animated but it can also be disabled
- By default notifications will close automatically after 3 seconds (by default)
To fix issue #80 and similar, the notification system do not uses the focused window anymore but it has its own "dummy" stage. It is a UTILITY stage, so that no icon appear in the taskbar, and its opacity is 0. While this is a great improvement over the old design there's also a downside. When the JavaFX's primary stage is closed the app won't close because the "dummy" stage is still open, to fix this a notification system must be initialized with an owner window, so that when owner is closed the "dummy" stage is closed too. Any notification system ideally must implement the following behaviors:- publish: the method that accepts and manages new notifications
- show: ideally called by the publish method, serves to specify how to show the new notification
- close: serves to specify how a notification should be closed
- scheduleReopen: this method specifies how the notification system behaves when a new notification is published but it already is in a showing/closing state. Ideally this method should instruct the notification system to ignore the new notification and recall publish as soon as the current notification is being closed.
- computePosition: computes the position of the notification as a TransitionPositionBean for use
with animations too. (for non animated systems just subtract the deltas from their respective coordinates)
ResettableBooleanProperty to
specify that the notification is showing/closing a notification. Show and hide methods should set these properties
to true as the first operation, and then reset them once the notification is closed (see implementations source code for examples).
The scheduleReopen should instruct the system to call publish as soon as the closing property becomes false.
Last note: notification systems ideally should be singletons.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Durationprotected final PauseTransitionprotected booleanprotected final ResettableBooleanPropertyprotected final Stageprotected final EventHandler<WindowEvent>protected Windowprotected final MFXPopupprotected NotificationPosprotected Screenprotected final ResettableBooleanPropertyprotected Insets -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidclose()Closes a notification by manipulating the popup's coordinates and content.protected abstract TransitionPositionBeanResponsible for computing the popup's coordinates.delaySetPosition(NotificationPos position) Safer version ofsetPosition(NotificationPos).protected voidinit()Default implementation is empty.booleanbooleanbooleanbooleanprotected abstract voidscheduleReopen(INotification notification) Instructs the notification system to shown the specified notification when possible.setAnimated(boolean animated) Enables/Disables animations.setCloseAfter(Duration closeAfter) Sets the duration of time after which the notifications are automatically closed ifisCloseAutomatically()is truesetCloseAutomatically(boolean closeAutomatically) Enables/Disables notifications automatic close.setPosition(NotificationPos position) Sets the position at which notifications will be shown.Sets the screen on which to show the notifications.setSpacing(Insets spacing) Sets the Insets object that specifies the spacing between notifications and the screen borders.protected abstract voidshow()Shows a notification by manipulating the popup's coordinates and content.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.palexdev.materialfx.notifications.base.INotificationSystem
dispose, initOwner, publish
-
Field Details
-
screen
-
owner
-
dummyStage
-
onClose
-
popup
-
position
-
spacing
-
animated
protected boolean animated -
closeAutomatically
protected boolean closeAutomatically -
closeAfter
-
closeAfterTransition
-
showing
-
closing
-
-
Constructor Details
-
AbstractMFXNotificationSystem
protected AbstractMFXNotificationSystem()
-
-
Method Details
-
show
protected abstract void show()Shows a notification by manipulating the popup's coordinates and content. -
close
protected abstract void close()Closes a notification by manipulating the popup's coordinates and content.The popup should be closed as well!
-
scheduleReopen
Instructs the notification system to shown the specified notification when possible. -
computePosition
Responsible for computing the popup's coordinates. -
init
protected void init()Default implementation is empty. -
getScreen
- Returns:
- the screen on which to show the notifications
-
setScreen
Sets the screen on which to show the notifications. -
getPosition
- Returns:
- the position at which notifications will be shown
-
setPosition
Sets the position at which notifications will be shown. -
delaySetPosition
Safer version ofsetPosition(NotificationPos). If the notification system is currently showing it's not a good idea to change the position as the close method could then misbehave, this method changes the position as soon as the notification system has been closed. If it's already closed then the position is set immediately. -
getSpacing
- Returns:
- the Insets object that specifies the spacing between notifications and the screen borders
-
setSpacing
Sets the Insets object that specifies the spacing between notifications and the screen borders. -
isAnimated
public boolean isAnimated()- Returns:
- whether the notification system is animated
-
setAnimated
Enables/Disables animations. -
isCloseAutomatically
public boolean isCloseAutomatically()- Returns:
- whether notifications should close automatically
-
setCloseAutomatically
Enables/Disables notifications automatic close. -
getCloseAfter
- Returns:
- the duration of time after which the notifications are automatically closed
if
isCloseAutomatically()is true
-
setCloseAfter
Sets the duration of time after which the notifications are automatically closed ifisCloseAutomatically()is true -
isShowing
public boolean isShowing()- Returns:
- whether the notification system is showing a notification
-
isClosing
public boolean isClosing()- Returns:
- whether the notification system is closing
-