Module MaterialFX

Class MFXNotificationCenter

All Implemented Interfaces:
MFXMenuControl, Styleable, EventTarget, Skinnable

public class MFXNotificationCenter extends Control implements MFXMenuControl
A quite complex but easy to use implementation of a modern notification center.

For the notifications it uses TransformableListWrapper as list implementation, this allows not only basic operations such additions, removals and replacements, but also filter and sort operations.

It's composed by an icon and a popup that contains the list of notifications.

A complete list of the features the notification center offers:

- Uses a virtual flow to show the notifications and have high performance

- Uses MFXNotificationCell as cells to contain the notifications, those special cells perfectly integrate with the selection mode feature of the notification center to show a checkbox when needed

- Has a MultipleSelectionModel to keep track of the selected notifications

- Has a property that keeps track of the number of unread notifications

- Has two styles for the unread counter: as a DOT, or as a dot with the NUMBER

- Allows to change the header's text

- Allows to toggle a "Do not disturb" mode

- Has a property that specifies whether the popup is showing or not

- Has a property that specifies whether the mouse is on the popup (it's bound, cannot be set, nor unbound)

- Allows to specify the space between the bell icon and the popup

- Allows to specify the popup's size. Must be greater than 0 and should always be larger than the bell's icon

- Has a context menu that opens when right-clicking on the virtual flow, by default it contains items to perform selection, filter and sort actions. It can also be disabled by using MFXMenuControl.setContextMenuDisabled(boolean).

- Has a flag to specify whether the notification center is animated or not

- Has a flag to specify whether visible notifications should be set as READ when the popup is shown

- Has a flag to specify whether notifications should be set as READ when they are dismissed

- Allows specifying the action to perform when the bell icon is pressed, by default inverts the value of the showingProperty() to inform the popup that it should open/hide

Has an executor that runs every 60 seconds (by default, can be changed) that updates all the notifications. By update, I mean that INotification.updateElapsed() is called. The service can be stopped and started whenever desired, by default it is always started.

As you can see it as a LOT to offer, and to be honest it's not everything I wanted to implement, but I decided to restrain myself for now, as adding any other feature would add more and more complexity.
  • Property Details

  • Constructor Details

    • MFXNotificationCenter

      public MFXNotificationCenter()
  • Method Details

    • defaultContextMenu

      protected void defaultContextMenu()
      Responsible for building and setting the default context menu.
    • startNotificationsUpdater

      public void startNotificationsUpdater(long period, TimeUnit timeUnit)
      Starts the notifications updater service to run the update task periodically, according to the given period and time unit.
      See Also:
    • stopNotificationsUpdater

      public void stopNotificationsUpdater()
      Immediately stops the notifications updater service.
    • markNotificationsAs

      public void markNotificationsAs(NotificationState state, INotification... notifications)
      Sets all the given notifications' state to the given state.

      At the end recomputes the number of unread notifications.

    • markVisibleNotificationsAs

      public void markVisibleNotificationsAs(NotificationState state)
      Sets all the visible notifications' state to the given state.
    • markSelectedNotificationsAs

      public void markSelectedNotificationsAs(NotificationState state)
      Sets all the selected notifications' state to the given state.
    • markAllNotificationsAs

      public void markAllNotificationsAs(NotificationState state)
      Sets all the notifications' state to the given state.
    • dismiss

      public void dismiss(INotification... notifications)
      Sets all the given notifications' state to READ, then removes them from the notifications list.
    • dismissVisible

      public void dismissVisible()
      Sets all the visible notifications' state to READ, then removes them from the notifications list.
    • dismissSelected

      public void dismissSelected()
      Sets all the selected notifications' state to READ, then removes them from the notifications list.
    • dismissAll

      public void dismissAll()
      Sets all the notifications' state to READ, then removes them from the notifications list.
    • getNotifications

      public TransformableListWrapper<INotification> getNotifications()
      Returns:
      the list of notifications
    • getSelectionModel

      public MultipleSelectionModel<INotification> getSelectionModel()
      Returns:
      the selection model instance used to keep track of selected notifications
    • isSelectionMode

      public boolean isSelectionMode()
      Gets the value of the property selectionMode.
      Property description:
      Specifies if the notification center is in selection mode.

      By default this mode triggers MFXNotificationCell to show a checkbox for selection
    • selectionModeProperty

      public BooleanProperty selectionModeProperty()
      Specifies if the notification center is in selection mode.

      By default this mode triggers MFXNotificationCell to show a checkbox for selection
      See Also:
    • setSelectionMode

      public void setSelectionMode(boolean selectionMode)
      Sets the value of the property selectionMode.
      Property description:
      Specifies if the notification center is in selection mode.

      By default this mode triggers MFXNotificationCell to show a checkbox for selection
    • getUnreadCount

      public long getUnreadCount()
      Gets the value of the property unreadCount.
      Property description:
      Specifies the number of unread notifications.
    • unreadCountProperty

      public ReadOnlyLongProperty unreadCountProperty()
      Specifies the number of unread notifications.
      See Also:
    • getCounterStyle

      public NotificationCounterStyle getCounterStyle()
      Gets the value of the property counterStyle.
      Property description:
      Specifies the style of the unread counter.
    • counterStyleProperty

      public ObjectProperty<NotificationCounterStyle> counterStyleProperty()
      Specifies the style of the unread counter.
      See Also:
    • setCounterStyle

      public void setCounterStyle(NotificationCounterStyle counterStyle)
      Sets the value of the property counterStyle.
      Property description:
      Specifies the style of the unread counter.
    • getHeaderTextProperty

      public String getHeaderTextProperty()
    • headerTextPropertyProperty

      public StringProperty headerTextPropertyProperty()
      Specifies the header's text.
    • setHeaderTextProperty

      public void setHeaderTextProperty(String headerTextProperty)
    • isDoNotDisturb

      public boolean isDoNotDisturb()
      Gets the value of the property doNotDisturb.
      Property description:
      Specifies if the notification center is in "Do not disturb" mode.
    • doNotDisturbProperty

      public BooleanProperty doNotDisturbProperty()
      Specifies if the notification center is in "Do not disturb" mode.
      See Also:
    • setDoNotDisturb

      public void setDoNotDisturb(boolean doNotDisturb)
      Sets the value of the property doNotDisturb.
      Property description:
      Specifies if the notification center is in "Do not disturb" mode.
    • isShowing

      public boolean isShowing()
      Gets the value of the property showing.
      Property description:
      Specifies if the popup is shown/hidden.

      Can also be used to control the popup.

    • showingProperty

      public BooleanProperty showingProperty()
      Specifies if the popup is shown/hidden.

      Can also be used to control the popup.

      See Also:
    • setShowing

      public void setShowing(boolean showing)
      Sets the value of the property showing.
      Property description:
      Specifies if the popup is shown/hidden.

      Can also be used to control the popup.

    • isPopupHover

      public boolean isPopupHover()
      Gets the value of the property popupHover.
      Property description:
      Specifies if the mouse is on the popup.

      Despite being a Read-Write property, it is bound to the popup's hover property and cannot be unbound. Attempts to set this will always fail with an exception.
    • popupHoverProperty

      public BooleanProperty popupHoverProperty()
      Specifies if the mouse is on the popup.

      Despite being a Read-Write property, it is bound to the popup's hover property and cannot be unbound. Attempts to set this will always fail with an exception.
      See Also:
    • getPopupSpacing

      public double getPopupSpacing()
      Gets the value of the property popupSpacing.
      Property description:
      Specifies the space between the bell icon and the popup
    • popupSpacingProperty

      public DoubleProperty popupSpacingProperty()
      Specifies the space between the bell icon and the popup
      See Also:
    • setPopupSpacing

      public void setPopupSpacing(double popupSpacing)
      Sets the value of the property popupSpacing.
      Property description:
      Specifies the space between the bell icon and the popup
    • getPopupWidth

      public double getPopupWidth()
      Gets the value of the property popupWidth.
      Property description:
      Specifies the popups' width.
    • popupWidthProperty

      public DoubleProperty popupWidthProperty()
      Specifies the popups' width.
      See Also:
    • setPopupWidth

      public void setPopupWidth(double popupWidth)
      Sets the value of the property popupWidth.
      Property description:
      Specifies the popups' width.
    • getPopupHeight

      public double getPopupHeight()
      Gets the value of the property popupHeight.
      Property description:
      Specifies the popup's height.
    • popupHeightProperty

      public DoubleProperty popupHeightProperty()
      Specifies the popup's height.
      See Also:
    • setPopupHeight

      public void setPopupHeight(double popupHeight)
      Sets the value of the property popupHeight.
      Property description:
      Specifies the popup's height.
    • getMFXContextMenu

      public MFXContextMenu getMFXContextMenu()
      Specified by:
      getMFXContextMenu in interface MFXMenuControl
      Returns:
      the currently built MFXContextMenu
    • isAnimated

      public boolean isAnimated()
      Specifies whether the notification center is animated.
    • setAnimated

      public void setAnimated(boolean animated)
    • isMarkAsReadOnShow

      public boolean isMarkAsReadOnShow()
      Specifies whether visible notification should be marked as read when the popup is shown.
    • setMarkAsReadOnShow

      public void setMarkAsReadOnShow(boolean markAsReadOnShow)
    • isMarkAsReadOnDismiss

      public boolean isMarkAsReadOnDismiss()
      Specifies whether dismissed notifications should be set as READ.

      For this to work use one of the dismiss methods offered by the control.
    • setMarkAsReadOnDismiss

      public void setMarkAsReadOnDismiss(boolean markAsReadOnDismiss)
    • getOnIconClicked

      public EventHandler<MouseEvent> getOnIconClicked()
      Specifies the action to perform when the bell icon is clicked.
    • setOnIconClicked

      public void setOnIconClicked(EventHandler<MouseEvent> onIconClicked)
    • getCell

      public MFXNotificationCell getCell(int index)
      Delegate method for SimpleVirtualFlow.getCell(int).
    • getCells

      public Map<Integer,MFXNotificationCell> getCells()
      Delegate method for SimpleVirtualFlow.getCells().
    • scrollBy

      public void scrollBy(double pixels)
      Delegate method for SimpleVirtualFlow.scrollBy(double).
    • scrollTo

      public void scrollTo(int index)
      Delegate method for SimpleVirtualFlow.scrollTo(int).
    • scrollToFirst

      public void scrollToFirst()
      Delegate method for SimpleVirtualFlow.scrollToFirst().
    • scrollToLast

      public void scrollToLast()
      Delegate method for SimpleVirtualFlow.scrollToLast().
    • scrollToPixel

      public void scrollToPixel(double pixel)
      Delegate method for SimpleVirtualFlow.scrollToPixel(double).
    • setHSpeed

      public void setHSpeed(double unit, double block)
      Delegate method for SimpleVirtualFlow.setHSpeed(double, double).
    • setVSpeed

      public void setVSpeed(double unit, double block)
      Delegate method for SimpleVirtualFlow.setVSpeed(double, double).
    • getVerticalPosition

      public double getVerticalPosition()
      Delegate method for SimpleVirtualFlow.getVerticalPosition().
    • getHorizontalPosition

      public double getHorizontalPosition()
      Delegate method for SimpleVirtualFlow.getHorizontalPosition().
    • setCellFactory

      public void setCellFactory(Function<INotification,MFXNotificationCell> cellFactory)
      Delegate method for SimpleVirtualFlow.setCellFactory(Function).
    • features

      public io.github.palexdev.virtualizedfx.flow.simple.SimpleVirtualFlow<INotification,MFXNotificationCell>.io.github.palexdev.virtualizedfx.flow.simple.SimpleVirtualFlow.Features features()
      Delegate method for SimpleVirtualFlow.features().
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class Control