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 java.awt.Color;
034: import java.util.LinkedList;
035: import java.util.List;
036:
037: import com.jgoodies.animation.Animation;
038: import com.jgoodies.animation.Animations;
039: import com.jgoodies.animation.components.BasicTextLabel;
040:
041: /**
042: * Provides a text animation that shows an overlapping sequence of
043: * texts using a bunch of different effects: color fade, scaling, glyph spacing.
044: *
045: * @author Karsten Lentzsch
046: * @version $Revision: 1.1 $
047: *
048: * @see BasicTextAnimation
049: */
050: public final class BasicTextAnimations {
051:
052: private static final int FADE_TYPE = 0;
053: private static final int SCALE_TYPE = 1;
054: private static final int SPACE_TYPE = 2;
055:
056: private BasicTextAnimations() {
057: // Override default constructor; prevents instantiation.
058: }
059:
060: /**
061: * Creates and answers the default color fade text sequence.
062: *
063: * @param label1 a text label used to blend over
064: * @param label2 a second text label used to blend over
065: * @param singleDuration the duration of a single animation
066: * @param beginOffset an initial animation time offset
067: * @param separatedTexts a sequence of texts in a string separated
068: * by the | character
069: * @param baseColor the base color for the fade
070: * @return a default fade animation
071: */
072: public static Animation defaultFade(BasicTextLabel label1,
073: BasicTextLabel label2, long singleDuration,
074: long beginOffset, String separatedTexts, Color baseColor) {
075:
076: return createTextSequence(label1, label2, singleDuration,
077: beginOffset, separatedTexts, baseColor, FADE_TYPE);
078: }
079:
080: /**
081: * Creates and answers the default scaling text sequence.
082: *
083: * @param label1 a text label used to blend over
084: * @param label2 a second text label used to blend over
085: * @param singleDuration the duration of a single animation
086: * @param beginOffset an initial animation time offset
087: * @param separatedTexts a sequence of texts in a string separated
088: * by the | character
089: * @param baseColor the base color for the fade
090: * @return a default scaling blend over animation
091: */
092: public static Animation defaultScale(BasicTextLabel label1,
093: BasicTextLabel label2, long singleDuration,
094: long beginOffset, String separatedTexts, Color baseColor) {
095:
096: return createTextSequence(label1, label2, singleDuration,
097: beginOffset, separatedTexts, baseColor, SCALE_TYPE);
098: }
099:
100: /**
101: * Creates and answers the default glyph spacing text sequence.
102: *
103: * @param label1 a text label used to blend over
104: * @param label2 a second text label used to blend over
105: * @param singleDuration the duration of a single animation
106: * @param beginOffset an initial animation time offset
107: * @param separatedTexts a sequence of texts in a string separated
108: * by the | character
109: * @param baseColor the base color for the fade
110: * @return a default space blend over animation
111: */
112: public static Animation defaultSpace(BasicTextLabel label1,
113: BasicTextLabel label2, long singleDuration,
114: long beginOffset, String separatedTexts, Color baseColor) {
115:
116: return createTextSequence(label1, label2, singleDuration,
117: beginOffset, separatedTexts, baseColor, SPACE_TYPE);
118: }
119:
120: // Private Helper Code ****************************************************
121:
122: /**
123: * Creates and returns the default glyph spacing text sequence.
124: *
125: * @param label1 the first label to render the sequence
126: * @param label2 the second label to render
127: * @param singleDuration the duration of a step in the sequence
128: * @param beginOffset an offset in ms between to steps
129: * @param separatedTexts a '|' separated lists of texts to display
130: * @param baseColor the color used as a basis for the text
131: * @param type the type of the effect used to change
132: * @return a composed animation that displays a sequence of texts
133: */
134: private static Animation createTextSequence(BasicTextLabel label1,
135: BasicTextLabel label2, long singleDuration,
136: long beginOffset, String separatedTexts, Color baseColor,
137: int type) {
138:
139: Animation animation;
140: String[] texts = separatedTexts.split("\\|");
141: List animations = new LinkedList();
142: long beginTime = 0;
143:
144: BasicTextLabel label = label1;
145: for (int i = 0; i < texts.length; i++) {
146: label = i % 2 == 0 ? label1 : label2;
147: animation = animation(label, singleDuration, texts[i],
148: baseColor, type);
149: animations.add(Animations.offset(beginTime, animation));
150: beginTime += singleDuration + beginOffset;
151: }
152:
153: return Animations.parallel(animations);
154: }
155:
156: private static Animation animation(BasicTextLabel label,
157: long duration, String text, Color baseColor, int type) {
158: switch (type) {
159: case FADE_TYPE:
160: return BasicTextAnimation.defaultFade(label, duration,
161: text, baseColor);
162:
163: case SCALE_TYPE:
164: return BasicTextAnimation.defaultScale(label, duration,
165: text, baseColor);
166:
167: case SPACE_TYPE:
168: return BasicTextAnimation.defaultSpace(label, duration,
169: text, baseColor);
170:
171: default:
172: return null;
173: }
174: }
175:
176: }
|