Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nanoclario
Copy link

@nanoclario nanoclario commented Mar 31, 2019

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

@jfoenixadmin
Copy link
Collaborator

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)

@nanoclario
Copy link
Author

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. 😃

@jfoenixadmin
Copy link
Collaborator

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,

@stale
Copy link

stale bot commented Sep 30, 2019

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 stale bot added the wontfix label Sep 30, 2019
@stale stale bot closed this Oct 7, 2019
@jfoenixadmin jfoenixadmin reopened this Oct 8, 2019
@stale stale bot removed the wontfix label Oct 8, 2019
@goxr3plus
Copy link

This is amazing !!!

@gustavooliveira7
Copy link

gustavooliveira7 commented Jan 22, 2020

@jfoenixadmin do you have any prevision to merge it?

@goxr3plus
Copy link

@jfoenixadmin Please have a look .

@jfoenixadmin
Copy link
Collaborator

jfoenixadmin commented Mar 10, 2020

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

@stale
Copy link

stale bot commented Sep 6, 2020

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 stale bot added the stale label Sep 6, 2020
@DmitryZagr
Copy link

DmitryZagr commented Sep 9, 2020

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

@stale stale bot removed the stale label Sep 9, 2020
@Alex50505
Copy link

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!

Repository owner deleted a comment from palexdev Jun 8, 2021
Repository owner deleted a comment from palexdev Jun 8, 2021
Repository owner deleted a comment from palexdev Jun 8, 2021
Repository owner deleted a comment from Alex50505 Jun 8, 2021
Repository owner deleted a comment from Alex50505 Jun 8, 2021
Repository owner deleted a comment from goxr3plus Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants