
com.alkacon.geranium.client.util.ChangeHeightAnimation Maven / Gradle / Ivy
Show all versions of geranium-client Show documentation
/*
* This library is part of Geranium -
* an open source UI library for GWT.
*
* Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)-
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.alkacon.geranium.client.util;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Command;
/**
* Changes the elements height until the target height is reached.
*/
public class ChangeHeightAnimation extends A_Animation {
/** The element style. */
private Style m_elementStyle;
/** The height of the fully visible element. */
private int m_height;
/** The difference between the target height and the original height. */
private int m_heightDiff;
/** The height when the animation should stop. */
private int m_targetHeight;
/**
* Constructor.
*
* @param element the element to animate
* @param targetHeight the height when the animation should stop
* @param callback the callback executed after the animation is completed
*/
public ChangeHeightAnimation(Element element, int targetHeight, Command callback) {
super(callback);
m_elementStyle = element.getStyle();
m_height = DomUtil.getCurrentStyleInt(element, DomUtil.Style.height);
m_targetHeight = targetHeight;
m_heightDiff = m_targetHeight - m_height;
}
/**
* Slides the given element into view executing the callback afterwards.
*
* @param element the element to slide in
* @param targetHeight the height when the animation should stop
* @param callback the callback executed after the animation is completed
* @param duration the animation duration
*
* @return the running animation object
*/
public static ChangeHeightAnimation change(Element element, int targetHeight, Command callback, int duration) {
ChangeHeightAnimation animation = new ChangeHeightAnimation(element, targetHeight, callback);
animation.run(duration);
return animation;
}
/**
* @see com.google.gwt.animation.client.Animation#onComplete()
*/
@Override
protected void onComplete() {
m_elementStyle.setHeight(m_targetHeight, Unit.PX);
if (m_callback != null) {
m_callback.execute();
}
}
/**
* @see com.google.gwt.animation.client.Animation#onUpdate(double)
*/
@Override
protected void onUpdate(double progress) {
m_elementStyle.setHeight((m_heightDiff * progress * progress) + m_height, Unit.PX);
}
}