JFXNotifications is here !! (the beginning ...)
Hello, I am @TioCoding this is my personal account. I have been working the "JFXNotifications" control until I have something mature. This is what I have developed so far.
the gif looks a bit bad :(

In the issue #439, I had worked on a simple design of JFXNotifications, but I did not like it very much because I could only have one design so that's why I did not do the Pull Request. With this implementation everyone can create their custom design by extending the class JFXAbstractNotificationTemplate, for example:
public class JFXSimpleNotificationTemplate extends JFXAbstractNotificationTemplate {
private HBox header = new HBox();
private StackPane body = new StackPane();
private FlowPane actions = new FlowPane();
public JFXSimpleNotificationTemplate() {
initialize();
header.getStyleClass().addAll("jfx-notification-header");
body.getStyleClass().addAll("jfx-notification-body");
actions.getStyleClass().addAll("jfx-notification-action");
getChildren().setAll(header, body, actions);
}
public void setHeader(Node icon, String heading, boolean closeButton) {
Label labelTitle = new Label(heading);
labelTitle.getStyleClass().addAll("label-header");
labelTitle.setMaxWidth(Double.MAX_VALUE);
header.getChildren().addAll(icon, labelTitle);
HBox.setHgrow(labelTitle, Priority.ALWAYS);
if(closeButton){
JFXRippler ripplerClose = new JFXRippler();
ripplerClose.setOnMouseClicked(__ -> { ripplerClose.setDisable(true); hide(); } );
StackPane boxClose = new StackPane();
boxClose.getStyleClass().add("box-close");
StackPane graphic = new StackPane();
graphic.getStyleClass().setAll("graphic");
boxClose.getChildren().add(graphic);
ripplerClose.setControl(boxClose);
header.getChildren().add(ripplerClose);
}
}
public void setHeader(Node icon, String heading) {
setHeader(icon,heading,true);
}
public void setBody(String subTitle, String message) {
Label labelSubTitle = new Label(subTitle);
Label labelMessage = new Label(message);
labelSubTitle.getStyleClass().addAll("label-sub-title");
labelMessage.getStyleClass().addAll("label-message");
VBox bodyContent = new VBox();
VBox.setVgrow(labelMessage, Priority.ALWAYS);
bodyContent.getChildren().addAll(labelSubTitle, labelMessage);
bodyContent.getStyleClass().add("simple-body");
body.getChildren().add(bodyContent);
}
public void setActions(JFXButton... actions) {
Arrays.asList(actions).forEach(button -> {
button.getStyleClass().add("btn-action");
button.setOnMouseClicked( __ -> hide() );
});
this.actions.getChildren().setAll(actions);
}
@Override
public String getUserAgentStylesheet() {
return JFXSimpleNotificationTemplate.class.getResource("/css/controls/jfx-notification.css").toExternalForm();
}
private static final String DEFAULT_STYLE_CLASS = "jfx-notification-template";
private void initialize() {
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
}
}
This is a simple design that I have added to the JFoenix package, but you can easily create your own.
JFXSimpleNotificationTemplate template = new JFXSimpleNotificationTemplate(); // Template Class
FontAwesomeIconView icon = new FontAwesomeIconView(FontAwesomeIcon.GLASS);
template.setHeader(icon, "Fast Food");
template.setBody("Lily (MacDonald)","Su pedido esta listo, solo debe recogerlo en el lugar mas solicitado");
JFXButton aceptar = new JFXButton("Responder");
template.setActions(aceptar);
JFXNotifications.create().position(pos)
.hideAfter(Duration.seconds(6))
.template(template)
.showMessage();
There are many templates to do, but due to lack of time I have not been able to do it :(, as well as many things that I would like to implement in JFXNotifications (for example, add the expansion of notifications, a queue for notifications, ...)
Hi @nanoclario, After a quick review, I have some comments regarding the implementation:
- I don't see a reason to not make JFXNotification extends PopupControl/Popup instead of using it as a data class/builder.
- Notifications handler should be decoupled from the Notification itself. The user should be able to provide a custom implementation of the handler.
- why limiting the notification's content to JFXAbstractNotificationTemplate instead of supporting any Node given by the user.
- owner method shouldn't take object as an argument (it's confusing)
Hello @jfoenixadmin , I detail a little the development:
- I developed it based on the notification control of
ControlsFX, it is the only notification control I found inJavaFx, so it seemed a good idea to keep part of its functionality (and its creation), so that there are not many changes. - Any user can create their own TEMPLATE by extending the
JFXAbstractNotificationTemplateclass and designing their notification. - The reason why the templates extend from
JFXAbstractNotificationTemplate, is because this class has ahide()method that allows the user to call from its implementation in order to close the Notification, I was also thinking about adding more methods of animation inJFXAbstractNotificationTemplatethat could be activated from each implementation. - My error :( ... since I inherited part of the ControlsFX implementation, I did not want to touch the code that was already working correctly.
I know that there are still many things to improve and add, and I would like to do it, but my time is very short at the moment :/.
Regards. :smiley:
Hi @nanoclario I see your point. However to be honest, I think it can be done better. (e.g why would JFXAbstractNotificationTemplate (the content) has a hide method? it makes more sense to call show/hide using the notification itself similar to a popup)
Regards,
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is amazing !!!
@jfoenixadmin do you have any prevision to merge it?
@jfoenixadmin Please have a look .
Well, I think the code needs some changes and a better abstraction, so I prefer not to merge it as is.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
any updates? @jfoenixadmin Does JFoenix support any kind of notifications?
When will JFXNotifications be added to JFoenix? This started a year and 9 months ago, and it still hasn't been implemented in JFoenix. So, what's going on? Thanks!