001: /*
002: * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.animation.animations;
032:
033: import com.jgoodies.animation.AbstractAnimation;
034: import com.jgoodies.animation.AnimationFunction;
035: import com.jgoodies.animation.AnimationFunctions;
036: import com.jgoodies.animation.components.FanComponent;
037:
038: /**
039: * An animation that rotates a fan that consists of a set
040: * of translucent sectors.
041: *
042: * @author Karsten Lentzsch
043: * @version $Revision: 1.1 $
044: *
045: * @see com.jgoodies.animation.components.FanComponent
046: * @see com.jgoodies.animation.renderer.FanRenderer
047: */
048: public final class FanAnimation extends AbstractAnimation {
049:
050: public static final double DEFAULT_CLOCKWISE_ROTATION = 0.01; // rotations per second
051: public static final double DEFAULT_ANTICLOCKWISE_ROTATION = -0.02;
052:
053: private final FanComponent fan;
054: private final AnimationFunctions.FloatFunction rotationFunction;
055:
056: /**
057: * Constructs an animation that rotates a fan using the given fan component,
058: * duration and rotation animation function.
059: *
060: * @param fan the fan component animation target
061: * @param duration the animation duration
062: * @param rotationFunction the rotation animation function
063: */
064: public FanAnimation(FanComponent fan, long duration,
065: AnimationFunction rotationFunction) {
066: super (duration);
067: this .fan = fan;
068: this .rotationFunction = AnimationFunctions
069: .asFloat(rotationFunction != null ? rotationFunction
070: : defaultRotationFunction(duration));
071: }
072:
073: /**
074: * Creates and answers the default fan animation.
075: *
076: * @param fan the fan component animation target
077: * @param duration the animation duration
078: * @return a default fan animation
079: */
080: public static FanAnimation defaultFan(FanComponent fan,
081: long duration) {
082: return new FanAnimation(fan, duration, null);
083: }
084:
085: /**
086: * Creates and answers an animation function for the default rotation.
087: *
088: * @param duration the animation duration
089: * @return an animation function for the default rotation
090: */
091: public static AnimationFunction defaultRotationFunction(
092: long duration) {
093: return AnimationFunctions.fromTo(duration, 0f,
094: (float) (Math.PI * 2.0f));
095: }
096:
097: /**
098: * Applies the effect: sets the time-based rotation.
099: *
100: * @param time the render time
101: */
102: protected void applyEffect(long time) {
103: fan.setRotation(rotationFunction.valueAt(time));
104: }
105:
106: }
|