Richboy - 2014-03-22

Usage Guide

jHolla is quite easy to use and with just few lines of code you can create standard notifications. Let us get off the first and simple way...

JHollaManager.getInstance().addNotification(JHolla.create().addMessage("Hello World!"));

Very well then how about adding a title and another message?
JHollaManager.getInstance().addNotification(JHolla.create()
    .setNotificationTitle("Hey Dude!")
    .addMessage("Hello World!")
    .addMessage("This is another message for this cute Notification."));

I see you now understand the pattern...Most of the methods return a reference to the object which you just simply use to do more on your jHolla notification. How about some more?

Let us create a jHolla Notification without a Timeout
JHollaManager.getInstance().addNotification(JHolla.create()
    .setNotificationTitle("Test JHolla with Icon and without Timeout")
    .addMessage(new JLabel("Simple Label for a test"))
    .addMessage("A sample message for a sample notification which has no timeout. This notification would only be closed via the close button.")
    .addIcon(new ImageIcon(getClass().getResource("check.png")))
    .setTimeout(0));

From above, the timeout has been set to zero, meaning the notification can only be removed with the close button or programatically. Basically, any number less than or equal to zero will do this same job. Timeout is specified in milliseconds and the default timeout is 10 seconds.

We also got to add an icon to the Notification. No matter the size of the image, the image would be resampled to having a height of 24px and the proportional width.

Let us set a minimum width for our jHolla Notification and listen out for Events
JHollaManager.getInstance().addNotification(JHolla.create()
    .setNotificationTitle("Test JHolla with JHollaListener")
    .addMessage(new JLabel("Simple label"))
    .setTimeout(30000)
    .setMinWidth(400)               
    .addJHollaListener(new JHollaListener() {

        @Override
        public void removed() {
            log.append("JHolla Removed\n");
        }

        @Override
        public void mouseExited() {
            log.append("Mouse Exited JHolla\n");
        }

        @Override
        public void mouseEntered() {
            log.append("Mouse Entered JHolla\n");
        }

        @Override
        public void closeButtonClick() {
            log.append("JHolla Close Button clicked\n");
        }

        @Override
        public void clicked() {
            log.append("JHolla Clicked\n");
        }
    }));

When you specify a String as the parameter to the JHolla addMessage method, a JTextArea is created with the text as its content.

The setMinWidth method basically sets the width of the very first JComponent added via the call to addMessage on the JHolla. In this case, the JLabel. If the argument to the addMessage method was a String, and it was the first added Message, the width would be applied to the JTextArea holding the text. This method is so rightly named cause JHolla has paddings (Empty Borders) around the first component and so the specified width would not be the exact width of the entire JHolla Notification.

JHollaListener is an inner class in the JHolla class and has all the methods listed above for your convenience. The call to addJHollaListener also returns a reference to the working JHolla object.

Let us create a custom remove button for our JHolla
final JHolla n = JHolla.create();
JButton removeButton = new JButton("Remove Me");
removeButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent event){
        n.remove();//remove/close notification
    }
});

JHollaManager.getInstance().addNotification(n
    .setNotificationTitle("Test JHolla with Custom Close Button")
    .addMessage("A sample message for a sample notification")
    .addMessage("What next when you get to add more messages to this beautiful JHolla")
    .addMessage("You can actually add infinite messages to this JHolla. I also hope your system's height is infinite...lol")
    .setClosable(false)
    .addComponent(removeButton)
    .setMinWidth(400));

From the above, we first create our JHolla Notification, and then a remove button which will be one means to remove the Notification.

The setClosable method simply determines if JHolla should show a close button or not and does not mean JHolla would not be closed automatically by the default timeout.

You can add any JComponent via the addComponent method. The addMessage method has been defined for just a String and a JLabel. Using the addMessage to add a JLabel would remove some default formatting from the label, The font would be forced to plain, and the setOpaque method would be set to false. Using the addComponent retains most of the formatting you apply.

To summarize the function of this example above, the JHolla would be able to be removed by two means only - The default timeout and the added custom remove button.

 

Last edit: Richboy 2014-03-22