From 3c81fa098bd8ffe8f59af51fec49922dc5e140d4 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 14 May 2009 12:37:00 +0000 Subject: [PATCH] Avoid flickering of fading animation. null check to avoid multiple animations. svn changeset:7808/svn branch:6.0 --- .../terminal/gwt/client/ui/VNotification.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java index 5567e2d534..23e48437a3 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java @@ -133,35 +133,39 @@ public class VNotification extends VToolkitOverlay { public void fade() { DOM.removeEventPreview(this); cancelDelay(); - fader = new Timer() { - private final long start = new Date().getTime(); - - @Override - public void run() { - /* - * To make animation smooth, don't count that event happens on - * time. Reduce opacity according to the actual time spent - * instead of fixed decrement. - */ - long now = new Date().getTime(); - long timeEplaced = now - start; - float remainingFraction = 1 - timeEplaced / (float) fadeMsec; - int opacity = (int) (startOpacity * remainingFraction); - if (opacity <= 0) { - cancel(); - hide(); - if (BrowserInfo.get().isOpera()) { - // tray notification on opera needs to explicitly define - // size, reset it - DOM.setStyleAttribute(getElement(), "width", ""); - DOM.setStyleAttribute(getElement(), "height", ""); + if (fader == null) { + fader = new Timer() { + private final long start = new Date().getTime(); + + @Override + public void run() { + /* + * To make animation smooth, don't count that event happens + * on time. Reduce opacity according to the actual time + * spent instead of fixed decrement. + */ + long now = new Date().getTime(); + long timeEplaced = now - start; + float remainingFraction = 1 - timeEplaced + / (float) fadeMsec; + int opacity = (int) (startOpacity * remainingFraction); + if (opacity <= 0) { + cancel(); + hide(); + if (BrowserInfo.get().isOpera()) { + // tray notification on opera needs to explicitly + // define + // size, reset it + DOM.setStyleAttribute(getElement(), "width", ""); + DOM.setStyleAttribute(getElement(), "height", ""); + } + } else { + setOpacity(getElement(), opacity); } - } else { - setOpacity(getElement(), opacity); } - } - }; - fader.scheduleRepeating(FADE_ANIMATION_INTERVAL); + }; + fader.scheduleRepeating(FADE_ANIMATION_INTERVAL); + } } public void setPosition(int position) { -- 2.39.5