Source Code Cross Referenced for BasicTextAnimation.java in  » Swing-Library » jgoodies-animation » com » jgoodies » animation » animations » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jgoodies animation » com.jgoodies.animation.animations 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:
035:        import com.jgoodies.animation.AbstractAnimation;
036:        import com.jgoodies.animation.AnimationFunction;
037:        import com.jgoodies.animation.AnimationFunctions;
038:        import com.jgoodies.animation.components.BasicTextLabel;
039:
040:        /**
041:         * A basic text animation that fades in a text, changes the x and y scaling,
042:         * the position, and the space between glyphs.
043:         * 
044:         * @author Karsten Lentzsch
045:         * @version $Revision: 1.1 $
046:         * 
047:         * @see com.jgoodies.animation.Animation
048:         * @see BasicTextLabel
049:         * @see AnimationFunction
050:         * @see com.jgoodies.animation.AnimationFunctions
051:         */
052:        public final class BasicTextAnimation extends AbstractAnimation {
053:
054:            private final BasicTextLabel label;
055:            private final String text;
056:            private final AnimationFunction colorFunction;
057:            private final AnimationFunctions.FloatFunction offsetFunction;
058:            private final AnimationFunctions.FloatFunction scaleXFunction;
059:            private final AnimationFunctions.FloatFunction scaleYFunction;
060:            private final AnimationFunctions.FloatFunction spaceFunction;
061:
062:            private boolean offsetEnabled = false;
063:
064:            // Instance Creation *****************************************************
065:
066:            /**
067:             * Constructs a text animation, that fades in a text, scales it and 
068:             * fades it out. Uses the given color and scaling functions.
069:             * 
070:             * @param label           the animation target component
071:             * @param duration        the animation duration 
072:             * @param text            the text to fade in
073:             * @param colorFunction   the animation function for the color
074:             * @param scaleXFunction  the animation function for the horizontal scale
075:             * @param scaleYFunction  the animation function for the vertical scale
076:             * @param spaceFunction   the animation function for the glyph space
077:             */
078:            public BasicTextAnimation(BasicTextLabel label, long duration,
079:                    String text, AnimationFunction colorFunction,
080:                    AnimationFunction scaleXFunction,
081:                    AnimationFunction scaleYFunction,
082:                    AnimationFunction spaceFunction) {
083:
084:                super (duration);
085:                this .label = label;
086:                this .text = text;
087:                this .colorFunction = colorFunction != null ? colorFunction
088:                        : defaultFadeColorFunction(duration, Color.DARK_GRAY);
089:                this .scaleXFunction = AnimationFunctions
090:                        .asFloat(scaleXFunction != null ? scaleXFunction
091:                                : AnimationFunctions.ONE);
092:                this .scaleYFunction = AnimationFunctions
093:                        .asFloat(scaleYFunction != null ? scaleYFunction
094:                                : AnimationFunctions.ONE);
095:                this .spaceFunction = AnimationFunctions
096:                        .asFloat(spaceFunction != null ? spaceFunction
097:                                : AnimationFunctions.ZERO);
098:                this .offsetFunction = AnimationFunctions
099:                        .asFloat(defaultOffsetFunction());
100:            }
101:
102:            /**
103:             * Creates and answers an animation, that provides a text fade-in and -out.
104:             * 
105:             * @param label           the animation target component
106:             * @param duration        the animation duration 
107:             * @param text            the text to fade in
108:             * @param baseColor       the base color for the fade effect
109:             * @return an animation with a default text fade
110:             */
111:            public static BasicTextAnimation defaultFade(BasicTextLabel label,
112:                    long duration, String text, Color baseColor) {
113:
114:                return new BasicTextAnimation(label, duration, text,
115:                        cinemaFadeColorFunction(duration, baseColor),
116:                        //defaultFadeColorFunction(duration, baseColor),
117:                        null, null, null);
118:            }
119:
120:            /**
121:             * Creates and answers an animation, that provides a text fade-in 
122:             * and -out and scales the text while fading out.
123:             * 
124:             * @param label           the animation target component
125:             * @param duration        the animation duration 
126:             * @param text            the text to fade in
127:             * @param baseColor       the base color for the fade effect
128:             * @return an animation with a default scaling text effect
129:             */
130:            public static BasicTextAnimation defaultScale(BasicTextLabel label,
131:                    long duration, String text, Color baseColor) {
132:
133:                return new BasicTextAnimation(label, duration, text,
134:                        defaultScaleColorFunction(duration, baseColor),
135:                        defaultScaleFunction(duration),
136:                        defaultScaleFunction(duration), null);
137:            }
138:
139:            /**
140:             * Creates and answers an animation, that provides a text fade-in 
141:             * and -out and increases the glyph spacing. 
142:             * 
143:             * @param label           the animation target component
144:             * @param duration        the animation duration 
145:             * @param text            the text to fade in
146:             * @param baseColor       the base color for the fade effect
147:             * @return an animation with a default glyph spacing effect
148:             */
149:            public static BasicTextAnimation defaultSpace(BasicTextLabel label,
150:                    long duration, String text, Color baseColor) {
151:
152:                return new BasicTextAnimation(label, duration, text,
153:                        defaultSpaceColorFunction(duration, baseColor), null,
154:                        null, defaultSpaceFunction(duration));
155:            }
156:
157:            /**
158:             * Creates and answers the color animation function for the default fade.
159:             * 
160:             * @param duration        the animation duration 
161:             * @param baseColor       the base color for the fade effect
162:             * @return a Color-valued animation function for the default fade
163:             */
164:            public static AnimationFunction defaultFadeColorFunction(
165:                    long duration, Color baseColor) {
166:                return AnimationFunctions.alphaColor(AnimationFunctions.linear(
167:                        duration, new Integer[] { new Integer(0),
168:                                new Integer(255), new Integer(255),
169:                                new Integer(0) }, new float[] { 0.0f, 0.3f,
170:                                0.7f, 1.0f }), baseColor);
171:            }
172:
173:            /**
174:             * Creates and answers the color animation function for the default fade.
175:             * 
176:             * @param duration        the animation duration 
177:             * @param baseColor       the base color for the fade effect
178:             * @return a Color-valued animation function for the default fade
179:             */
180:            public static AnimationFunction cinemaFadeColorFunction(
181:                    long duration, Color baseColor) {
182:                return AnimationFunctions.alphaColor(AnimationFunctions.linear(
183:                        duration, new Integer[] { new Integer(0),
184:                                new Integer(255), new Integer(255),
185:                                new Integer(0) }, new float[] { 0.0f, 0.3f,
186:                                0.85f, 1.0f }), baseColor);
187:            }
188:
189:            /**
190:             * Creates and answers the animation function for the default scaling.
191:             * 
192:             * @param duration        the animation duration 
193:             * @param baseColor       the base color for the fade effect
194:             * @return a Color-valued animation function for the default scaling
195:             */
196:            public static AnimationFunction defaultScaleColorFunction(
197:                    long duration, Color baseColor) {
198:                return AnimationFunctions.alphaColor(AnimationFunctions.linear(
199:                        duration, new Integer[] { new Integer(0),
200:                                new Integer(255), new Integer(255),
201:                                new Integer(0) }, new float[] { 0.0f, 0.2f,
202:                                0.85f, 1.0f }), baseColor);
203:            }
204:
205:            /**
206:             * Creates and answers the color animation function for 
207:             * the default spacing animation.
208:             * 
209:             * @param duration        the animation duration 
210:             * @param baseColor       the base color for the fade effect
211:             * @return a Color-valued animation function for the default spacing
212:             */
213:            public static AnimationFunction defaultSpaceColorFunction(
214:                    long duration, Color baseColor) {
215:                return AnimationFunctions.alphaColor(AnimationFunctions.linear(
216:                        duration, new Integer[] { new Integer(0),
217:                                new Integer(255), new Integer(255),
218:                                new Integer(0) }, new float[] { 0.0f, 0.2f,
219:                                0.8f, 1.0f }), baseColor);
220:            }
221:
222:            /** 
223:             * Returns the animation function for the default random position offset.
224:             * 
225:             * @return an animation function for a default random offset
226:             */
227:            public static AnimationFunction defaultOffsetFunction() {
228:                return AnimationFunctions.random(-2, 2, 0.5f);
229:            }
230:
231:            /** 
232:             * Creates and answers the default scaling animation function.
233:             * 
234:             * @param duration    the animation duration
235:             * @return an animation function for the default scaling effect
236:             */
237:            public static AnimationFunction defaultScaleFunction(long duration) {
238:                return AnimationFunctions.linear(duration, new Float[] {
239:                        new Float(1.0f), new Float(1.0f), new Float(1.8f) },
240:                        new float[] { 0.0f, 0.85f, 1.0f });
241:            }
242:
243:            /** 
244:             * Creates and answers the default spacing animation function.
245:             * 
246:             * @param duration    the animation duration
247:             * @return an animation function for the default spacing effect
248:             */
249:            public static AnimationFunction defaultSpaceFunction(long duration) {
250:                return AnimationFunctions.fromTo(duration, 0, 10);
251:            }
252:
253:            // ************************************************************************
254:
255:            /**
256:             * Applies the effect: sets color, spacing, scaling and offset,
257:             * the latter only if enabled.
258:             * 
259:             * @param time    the render time
260:             */
261:            protected void applyEffect(long time) {
262:                label.setText(time == 0 ? " " : text);
263:                label.setColor((Color) colorFunction.valueAt(time));
264:                label.setScaleX(scaleXFunction.valueAt(time));
265:                label.setScaleY(scaleYFunction.valueAt(time));
266:                label.setSpace(spaceFunction.valueAt(time));
267:                if (isOffsetEnabled()) {
268:                    label.setOffsetX(offsetFunction.valueAt(time));
269:                    label.setOffsetY(offsetFunction.valueAt(time));
270:                }
271:            }
272:
273:            /**
274:             * Answers whether the random position offset is enabled.
275:             * 
276:             * @return true indicates offset enabled, false disabled 
277:             */
278:            public boolean isOffsetEnabled() {
279:                return offsetEnabled;
280:            }
281:
282:            /**
283:             * Enables or disables the random position offset.
284:             * 
285:             * @param b  the new enablement
286:             */
287:            public void setOffsetEnabled(boolean b) {
288:                offsetEnabled = b;
289:            }
290:
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.