[SOLVED] Fade in/out effect on notification popups

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

[SOLVED] Fade in/out effect on notification popups

Postby frizinator » Wed Sep 10, 2014 7:15 am

I was just wondering, how exactly the notification popup fade animations are created/handled? I have some fade in/out code in the works but it's sub-par and not exactly what I'd like. I'm working on a custom Notification system where the popups are little more dynamic.
frizinator
 
Posts: 12
Joined: Fri Dec 07, 2012 8:14 am

Re: Fade in/out effect on notification popups

Postby mgarin » Wed Sep 10, 2014 11:35 am

In case of WebNotification component (which is basically a heavyweight popup extension) - animation is pretty complex in terms of implementation, but basically what it does (aside of various checks and logic) - it changes popup window opacity to fade in / fade out window.

Window opacity feature is native but it is properly supported by all platforms and safe to use. With WebLaF window opacity can be changed easily for any Web- window or popup by calling this method:
Code: Select all
setWindowOpacity ( final float opacity );

You can also call it separately on any Swing/AWT window or dialog using this utility method:
Code: Select all
ProprietaryUtils.setWindowOpacity ( final Window window, final float opacity );

I recommend using these methods and not AWTUtilities or window base methods as they are JDK-version-independant and will behave equally on any JDK and platform unlike the ones offered by the JDK.


In case of WebInnerNotification (which is basically some kind of lightweight popup) transparency is set through paint method and passed to child components within the notification components tree. WebPopup component does all that stuff. But I guess you are interested more in a separate window notifications so I won't go deep into describing this one.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Fade in/out effect on notification popups

Postby frizinator » Thu Sep 11, 2014 4:16 am

Hmm, I see. What I was attempting to create was a click to open notification. For example, if you were to display a WebNotificationPopup through NotificationManager, the notification will appear but only showing the Icon. Then you click on the notification and expands displaying the content. Click again and it disappears. I gave up on the fade in and out and message with the WebNotificationPopup source a little bit to see if I'd be able to get something close to that, but couldn't accomplish that either.
frizinator
 
Posts: 12
Joined: Fri Dec 07, 2012 8:14 am

Re: Fade in/out effect on notification popups

Postby mgarin » Thu Sep 11, 2014 11:10 am

Well, actully what you asked for should be doable with WebLaF notification manager.

Here is an example:
Code: Select all
public class Example
{
    public static void main ( final String[] args )
    {
        WebLookAndFeel.install ();
        TestFrame.show ( new WebButton ( "Show notification", new ActionListener ()
        {
            @Override
            public void actionPerformed ( final ActionEvent e )
            {
                // Custom notification content container
                final WebPanel content = new WebPanel ( "transparent", new BorderLayout ( 10, 0 ) );

                // Icon displayed all the time
                final WebImage icon = new WebImage ( WebLookAndFeel.getIcon ( 32 ) );
                content.add ( icon, BorderLayout.WEST );

                // Text to be displayed later
                final WebLabel text = new WebLabel ( "Some custom notification description" );

                // Displaying notification
                final WebNotification notification = NotificationManager.showNotification ( content, ( Icon ) null );

                // Custom content change event
                icon.addMouseListener ( new MouseAdapter ()
                {
                    @Override
                    public void mousePressed ( final MouseEvent e )
                    {
                        if ( !content.contains ( text ) )
                        {
                            content.add ( text, BorderLayout.CENTER );
                            NotificationManager.updateNotificationLayouts ();
                        }
                        else
                        {
                            notification.acceptAndHide ();
                        }
                    }
                } );
            }
        } ), 150 );
    }
}

There might be some issues with this code in current release version (v1.28) but they will be gone with next update (v1.29) - like empty space where default icon should be - I have already fixed and committed that.

But overall this code does exactly what you asked for:
I was attempting to create was a click to open notification. For example, if you were to display a WebNotificationPopup through NotificationManager, the notification will appear but only showing the Icon. Then you click on the notification and expands displaying the content

It will also work properly with multiply notifications being displayed at the same time.

Basically WebLaF NotificationManager simply opens and positions a customized popup window, but you are free to do whatever you want with it and its content.

You just need to be aware that NotificationManager frequently updates that popup size (to preferred) and position in case other notifications are being displayed/hidden to properly place the notification on screen. Though I can add a custom mark to disable auto-positioning after first display later on if it is needed.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Fade in/out effect on notification popups

Postby mgarin » Tue Sep 30, 2014 12:21 pm

Does this solve the case? :)
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Fade in/out effect on notification popups

Postby mgarin » Fri Oct 31, 2014 11:49 am

I'll mark this case solved.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron