JFoenix icon indicating copy to clipboard operation
JFoenix copied to clipboard

JFXNotifications is here !! (the beginning ...)

Open nanoclario opened this issue 6 years ago • 11 comments

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 :( JJJJJJPeek 31-03-2019 17-20

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, ...)

nanoclario avatar Mar 31 '19 22:03 nanoclario

Hi @nanoclario, After a quick review, I have some comments regarding the implementation:

  1. I don't see a reason to not make JFXNotification extends PopupControl/Popup instead of using it as a data class/builder.
  2. Notifications handler should be decoupled from the Notification itself. The user should be able to provide a custom implementation of the handler.
  3. why limiting the notification's content to JFXAbstractNotificationTemplate instead of supporting any Node given by the user.
  4. owner method shouldn't take object as an argument (it's confusing)

jfoenixadmin avatar Apr 02 '19 17:04 jfoenixadmin

Hello @jfoenixadmin , I detail a little the development:

  1. I developed it based on the notification control of ControlsFX, it is the only notification control I found in JavaFx, so it seemed a good idea to keep part of its functionality (and its creation), so that there are not many changes.
  2. Any user can create their own TEMPLATE by extending the JFXAbstractNotificationTemplate class and designing their notification.
  3. The reason why the templates extend from JFXAbstractNotificationTemplate, is because this class has a hide() 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 in JFXAbstractNotificationTemplate that could be activated from each implementation.
  4. 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:

nanoclario avatar Apr 03 '19 02:04 nanoclario

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,

jfoenixadmin avatar Apr 03 '19 13:04 jfoenixadmin

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.

stale[bot] avatar Sep 30 '19 13:09 stale[bot]

This is amazing !!!

goxr3plus avatar Dec 31 '19 12:12 goxr3plus

@jfoenixadmin do you have any prevision to merge it?

gustavooliveira7 avatar Jan 22 '20 16:01 gustavooliveira7

@jfoenixadmin Please have a look .

goxr3plus avatar Jan 23 '20 09:01 goxr3plus

Well, I think the code needs some changes and a better abstraction, so I prefer not to merge it as is.

jfoenixadmin avatar Mar 10 '20 13:03 jfoenixadmin

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.

stale[bot] avatar Sep 06 '20 14:09 stale[bot]

any updates? @jfoenixadmin Does JFoenix support any kind of notifications?

DmitryZagr avatar Sep 09 '20 09:09 DmitryZagr

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!

Alex50505 avatar Dec 07 '20 00:12 Alex50505