animation-1.2.0/0000755000175000017500000000000010444605612013431 5ustar twernertwerneranimation-1.2.0/docs/0000755000175000017500000000000010444605612014361 5ustar twernertwerneranimation-1.2.0/docs/api/0000755000175000017500000000000010444605610015130 5ustar twernertwerneranimation-1.2.0/docs/images/0000755000175000017500000000000010444605612015626 5ustar twernertwerneranimation-1.2.0/docs/images/banner.gif0000644000175000017500000001017110444605612017562 0ustar twernertwernerGIF89a.uttjii]\\nnnDDDrrr:::ZZZFFFIII}||PPPpppzzzVVV111/..eddwwwfffRRR$$$~~~cbb<<џ떉3i\@rśO$IԅѣD{]t)ђ"6H!?k)N|XrlnU*]mۦpuK7ݻxݫўW|S|"ar6~դջ xy-Z/ӨQYZ _nسy!9T/rNl.A=qe'|anʢC|;oFϾ}{˟Op Dw޾ =}6kI'j_ n!ց'ۃQT`E݇>PÊ,x}-(2a88Î3#8 1]unDhɀ"|Yx^~_ F2.WfT`⚜a$ +x9 |~*|&ah@HkvFg14I5109tޔ^z'9_{$?ik;Gb ސDa&lóF+Vk-MX>K,;jnœ] ,w}FCx#.+/7{/y&jު0C2Xu, V4F@BB `J 2x 2,8܆.3y " 5d0&0A"xi(f MDcsmFp Hؔr{ O mDa0?@oX (ahPz(Pdq a0 @ n  E4~K]fgrd%%r-^,.OOmIP0T!q>ӖДN` ' 8p!vCA~ LHhW#cHa !P^nTBoH0 (Bꗁ4 ;jڸL3'` FAL)1 `'Dth<]3/,k8āãwZ= 7g Jm5( t&n(8!$K|!`  \`Zֲ 08-S9[`uP{H0GYi5 (3 % CA9`%d(G1 B d8T W8n pY:HX:` *2$$ DORQ`I B+sKb6,}9YNg/kY\ֲ0R@RjY:JE0LD)0HBpM@_HXa0]A^L=ʴ J `1  p 2d*03La , <Jbp `vhpT:02o8Q5@! b/uY># A ;/ rJ ZIP-Rg ^pH U'wu@d.lC&,\ 9/LI{7@n@#\;K00Xr02 [uejIJ;h9lʁ†S9D DhIz/.(doې#$"L)EkT€C%qJUNwդ*uu fie/0K0;aZj)%U < Ulɘ 6vCYxk63g ir\joVP>3kZliL(EgU!aRd' Jx”-++su%|e.U`sy<^p~sЗCXB^;?UzRJRT_ 8Ԧ0R Ksxp#atxb .ѰԆ*]6LI -2ԣbw +/^x63UyΗ@,@LS4ATCH`Jj`FzgW;Lgӳ .΀ᝪ ;j[Eq7z'GyT.lN3\”eiV L5,/vĵPzJu*އ/B8&`n2\Mط';E a µ/6ρo/KR; xı\,ix| 0LdW@w+W)\$(d`ul{@:tB$CD;)DW)C0@6T'p;tC"H9VSB;s`CK@c4E]0hKK@JpLQ9Yp,rE}O@`d%pV\t=TWTTJ0z4J6;eCK T4;TVaU{47fwC'pGJHD[E@y~ F1000N6]0>wc::|Tp:քNHDB<P@YJtb:lB880D4/[.nї)3*EB'PNGBBȉvTBb2OC+Tjg]P9]pY69UPNZ%DA;%40@Idey&]A )3`P}*c>(i3= SFO&8EvPF{JPdF9qE;P,ITEE#]s*906A WSJPqpc:,)YdFrEE4Ȓq;9'/&@_dMg+p2Q[!>H)Pj0,b-V r0,)qCorFAp1qG5?C 7AH`%J`.6>3NNP3Ź~2etFT`CdP4iH>IVΧj`QdrYA8 TT!sB'.,r6r6ɒ5,Ʋ?b7bPb%n5}2,_,y--,I>z,޲(2H$di+ @@M]ruz24Z6Jb/LM/26B5wC6:(7')@ Hl"T)"}*B_B###CB$τ!QI)E#1)t//7'w*QUW+G %:jA%r%!z*ћl*b&.b:Q2&!B@Tzf$2jѫH1Ċ%xj.B2qX MϺ$&#Qzo>۪@ڬ!:rh&J8|  Iqjڰ횰+K";#;qA*  6{8:  ٱa! :++[0K2[4۴NPR;TkK{ X۵^`b;d[f{hjl۶;animation-1.2.0/docs/examples.html0000644000175000017500000000767710444605612017106 0ustar twernertwerner JGoodies Animation :: Examples
:: JGOODIES Looks :: Professional Swing Look&Feels

:: Examples ::

This package ships with the two example applications: Basic and Intro.

The Basic example demonstrates a bunch of basic Animation features. To run Basic go to the examples directory and launch:

java -jar basic.jar

The Intro example provides an animated intro panel. Launch it via:

java -jar intro.jar

(c) 2006 JGoodies
 
animation-1.2.0/docs/style.css0000644000175000017500000000154310444605612016236 0ustar twernertwernerbody, p, td, li, h1, h2, h3 { font-family: Verdana, Arial, Helvetica, Geneva, sans-serif; } body, p, td, li, h2, h3 { font-size: 12px; } h1, h2, h3 { font-weight: bold; color:#323777; margin-bottom: 11px; } h1 { font-size:14px; } h2, h3 { margin-top: 17px; } .header { font-weight: bold; color:#323777; margin-bottom: 11px; } p { margin-top: 14px; } a { text-decoration: none; color:#323788; } a:hover { text-decoration: underline; } a.nav { text-decoration: none; color:#000000; } a.nav:hover { text-decoration: underline; } pre { font-family:Courier New, Courier, monospace; font-size:12px; } ul { list-style-type: square; margin-top: 2px; } td.header { color: #FFFFFF; background-color:#323777; } td.cell { background-color:#FFFFFF; }animation-1.2.0/lib/0000755000175000017500000000000010444605612014177 5ustar twernertwerneranimation-1.2.0/src/0000755000175000017500000000000010444605612014220 5ustar twernertwerneranimation-1.2.0/src/core/0000755000175000017500000000000010444605612015150 5ustar twernertwerneranimation-1.2.0/src/core/com/0000755000175000017500000000000010444605612015726 5ustar twernertwerneranimation-1.2.0/src/core/com/jgoodies/0000755000175000017500000000000010444605612017531 5ustar twernertwerneranimation-1.2.0/src/core/com/jgoodies/animation/0000755000175000017500000000000010444605612021510 5ustar twernertwerneranimation-1.2.0/src/core/com/jgoodies/animation/animations/0000755000175000017500000000000010444605612023652 5ustar twernertwerneranimation-1.2.0/src/core/com/jgoodies/animation/animations/BasicTextAnimation.java0000644000175000017500000003131110444605612030242 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.animations; import java.awt.Color; import com.jgoodies.animation.AbstractAnimation; import com.jgoodies.animation.AnimationFunction; import com.jgoodies.animation.AnimationFunctions; import com.jgoodies.animation.components.BasicTextLabel; /** * A basic text animation that fades in a text, changes the x and y scaling, * the position, and the space between glyphs. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see com.jgoodies.animation.Animation * @see BasicTextLabel * @see AnimationFunction * @see com.jgoodies.animation.AnimationFunctions */ public final class BasicTextAnimation extends AbstractAnimation { private final BasicTextLabel label; private final String text; private final AnimationFunction colorFunction; private final AnimationFunctions.FloatFunction offsetFunction; private final AnimationFunctions.FloatFunction scaleXFunction; private final AnimationFunctions.FloatFunction scaleYFunction; private final AnimationFunctions.FloatFunction spaceFunction; private boolean offsetEnabled = false; // Instance Creation ***************************************************** /** * Constructs a text animation, that fades in a text, scales it and * fades it out. Uses the given color and scaling functions. * * @param label the animation target component * @param duration the animation duration * @param text the text to fade in * @param colorFunction the animation function for the color * @param scaleXFunction the animation function for the horizontal scale * @param scaleYFunction the animation function for the vertical scale * @param spaceFunction the animation function for the glyph space */ public BasicTextAnimation( BasicTextLabel label, long duration, String text, AnimationFunction colorFunction, AnimationFunction scaleXFunction, AnimationFunction scaleYFunction, AnimationFunction spaceFunction) { super(duration); this.label = label; this.text = text; this.colorFunction = colorFunction != null ? colorFunction : defaultFadeColorFunction(duration, Color.DARK_GRAY); this.scaleXFunction = AnimationFunctions.asFloat( scaleXFunction != null ? scaleXFunction : AnimationFunctions.ONE); this.scaleYFunction = AnimationFunctions.asFloat( scaleYFunction != null ? scaleYFunction : AnimationFunctions.ONE); this.spaceFunction = AnimationFunctions.asFloat( spaceFunction != null ? spaceFunction : AnimationFunctions.ZERO); this.offsetFunction = AnimationFunctions.asFloat(defaultOffsetFunction()); } /** * Creates and answers an animation, that provides a text fade-in and -out. * * @param label the animation target component * @param duration the animation duration * @param text the text to fade in * @param baseColor the base color for the fade effect * @return an animation with a default text fade */ public static BasicTextAnimation defaultFade( BasicTextLabel label, long duration, String text, Color baseColor) { return new BasicTextAnimation( label, duration, text, cinemaFadeColorFunction(duration, baseColor), //defaultFadeColorFunction(duration, baseColor), null, null, null); } /** * Creates and answers an animation, that provides a text fade-in * and -out and scales the text while fading out. * * @param label the animation target component * @param duration the animation duration * @param text the text to fade in * @param baseColor the base color for the fade effect * @return an animation with a default scaling text effect */ public static BasicTextAnimation defaultScale( BasicTextLabel label, long duration, String text, Color baseColor) { return new BasicTextAnimation( label, duration, text, defaultScaleColorFunction(duration, baseColor), defaultScaleFunction(duration), defaultScaleFunction(duration), null); } /** * Creates and answers an animation, that provides a text fade-in * and -out and increases the glyph spacing. * * @param label the animation target component * @param duration the animation duration * @param text the text to fade in * @param baseColor the base color for the fade effect * @return an animation with a default glyph spacing effect */ public static BasicTextAnimation defaultSpace( BasicTextLabel label, long duration, String text, Color baseColor) { return new BasicTextAnimation( label, duration, text, defaultSpaceColorFunction(duration, baseColor), null, null, defaultSpaceFunction(duration)); } /** * Creates and answers the color animation function for the default fade. * * @param duration the animation duration * @param baseColor the base color for the fade effect * @return a Color-valued animation function for the default fade */ public static AnimationFunction defaultFadeColorFunction( long duration, Color baseColor) { return AnimationFunctions.alphaColor( AnimationFunctions.linear( duration, new Integer[] { new Integer(0), new Integer(255), new Integer(255), new Integer(0)}, new float[] { 0.0f, 0.3f, 0.7f, 1.0f }), baseColor); } /** * Creates and answers the color animation function for the default fade. * * @param duration the animation duration * @param baseColor the base color for the fade effect * @return a Color-valued animation function for the default fade */ public static AnimationFunction cinemaFadeColorFunction( long duration, Color baseColor) { return AnimationFunctions.alphaColor( AnimationFunctions.linear( duration, new Integer[] { new Integer(0), new Integer(255), new Integer(255), new Integer(0)}, new float[] { 0.0f, 0.3f, 0.85f, 1.0f }), baseColor); } /** * Creates and answers the animation function for the default scaling. * * @param duration the animation duration * @param baseColor the base color for the fade effect * @return a Color-valued animation function for the default scaling */ public static AnimationFunction defaultScaleColorFunction( long duration, Color baseColor) { return AnimationFunctions.alphaColor( AnimationFunctions.linear( duration, new Integer[] { new Integer(0), new Integer(255), new Integer(255), new Integer(0)}, new float[] { 0.0f, 0.2f, 0.85f, 1.0f }), baseColor); } /** * Creates and answers the color animation function for * the default spacing animation. * * @param duration the animation duration * @param baseColor the base color for the fade effect * @return a Color-valued animation function for the default spacing */ public static AnimationFunction defaultSpaceColorFunction( long duration, Color baseColor) { return AnimationFunctions.alphaColor( AnimationFunctions.linear( duration, new Integer[] { new Integer(0), new Integer(255), new Integer(255), new Integer(0)}, new float[] { 0.0f, 0.2f, 0.8f, 1.0f }), baseColor); } /** * Returns the animation function for the default random position offset. * * @return an animation function for a default random offset */ public static AnimationFunction defaultOffsetFunction() { return AnimationFunctions.random(-2, 2, 0.5f); } /** * Creates and answers the default scaling animation function. * * @param duration the animation duration * @return an animation function for the default scaling effect */ public static AnimationFunction defaultScaleFunction(long duration) { return AnimationFunctions.linear( duration, new Float[] { new Float(1.0f), new Float(1.0f), new Float(1.8f)}, new float[] { 0.0f, 0.85f, 1.0f }); } /** * Creates and answers the default spacing animation function. * * @param duration the animation duration * @return an animation function for the default spacing effect */ public static AnimationFunction defaultSpaceFunction(long duration) { return AnimationFunctions.fromTo(duration, 0, 10); } // ************************************************************************ /** * Applies the effect: sets color, spacing, scaling and offset, * the latter only if enabled. * * @param time the render time */ protected void applyEffect(long time) { label.setText(time == 0 ? " " : text); label.setColor((Color) colorFunction.valueAt(time)); label.setScaleX(scaleXFunction.valueAt(time)); label.setScaleY(scaleYFunction.valueAt(time)); label.setSpace(spaceFunction.valueAt(time)); if (isOffsetEnabled()) { label.setOffsetX(offsetFunction.valueAt(time)); label.setOffsetY(offsetFunction.valueAt(time)); } } /** * Answers whether the random position offset is enabled. * * @return true indicates offset enabled, false disabled */ public boolean isOffsetEnabled() { return offsetEnabled; } /** * Enables or disables the random position offset. * * @param b the new enablement */ public void setOffsetEnabled(boolean b) { offsetEnabled = b; } }animation-1.2.0/src/core/com/jgoodies/animation/animations/BasicTextAnimations.java0000644000175000017500000001601210444605612030426 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.animations; import java.awt.Color; import java.util.LinkedList; import java.util.List; import com.jgoodies.animation.Animation; import com.jgoodies.animation.Animations; import com.jgoodies.animation.components.BasicTextLabel; /** * Provides a text animation that shows an overlapping sequence of * texts using a bunch of different effects: color fade, scaling, glyph spacing. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see BasicTextAnimation */ public final class BasicTextAnimations { private static final int FADE_TYPE = 0; private static final int SCALE_TYPE = 1; private static final int SPACE_TYPE = 2; private BasicTextAnimations() { // Override default constructor; prevents instantiation. } /** * Creates and answers the default color fade text sequence. * * @param label1 a text label used to blend over * @param label2 a second text label used to blend over * @param singleDuration the duration of a single animation * @param beginOffset an initial animation time offset * @param separatedTexts a sequence of texts in a string separated * by the | character * @param baseColor the base color for the fade * @return a default fade animation */ public static Animation defaultFade( BasicTextLabel label1, BasicTextLabel label2, long singleDuration, long beginOffset, String separatedTexts, Color baseColor) { return createTextSequence(label1, label2, singleDuration, beginOffset, separatedTexts, baseColor, FADE_TYPE); } /** * Creates and answers the default scaling text sequence. * * @param label1 a text label used to blend over * @param label2 a second text label used to blend over * @param singleDuration the duration of a single animation * @param beginOffset an initial animation time offset * @param separatedTexts a sequence of texts in a string separated * by the | character * @param baseColor the base color for the fade * @return a default scaling blend over animation */ public static Animation defaultScale( BasicTextLabel label1, BasicTextLabel label2, long singleDuration, long beginOffset, String separatedTexts, Color baseColor) { return createTextSequence(label1, label2, singleDuration, beginOffset, separatedTexts, baseColor, SCALE_TYPE); } /** * Creates and answers the default glyph spacing text sequence. * * @param label1 a text label used to blend over * @param label2 a second text label used to blend over * @param singleDuration the duration of a single animation * @param beginOffset an initial animation time offset * @param separatedTexts a sequence of texts in a string separated * by the | character * @param baseColor the base color for the fade * @return a default space blend over animation */ public static Animation defaultSpace( BasicTextLabel label1, BasicTextLabel label2, long singleDuration, long beginOffset, String separatedTexts, Color baseColor) { return createTextSequence(label1, label2, singleDuration, beginOffset, separatedTexts, baseColor, SPACE_TYPE); } // Private Helper Code **************************************************** /** * Creates and returns the default glyph spacing text sequence. * * @param label1 the first label to render the sequence * @param label2 the second label to render * @param singleDuration the duration of a step in the sequence * @param beginOffset an offset in ms between to steps * @param separatedTexts a '|' separated lists of texts to display * @param baseColor the color used as a basis for the text * @param type the type of the effect used to change * @return a composed animation that displays a sequence of texts */ private static Animation createTextSequence( BasicTextLabel label1, BasicTextLabel label2, long singleDuration, long beginOffset, String separatedTexts, Color baseColor, int type) { Animation animation; String[] texts = separatedTexts.split("\\|"); List animations = new LinkedList(); long beginTime = 0; BasicTextLabel label = label1; for (int i = 0; i < texts.length; i++) { label = i % 2 == 0 ? label1 : label2; animation = animation(label, singleDuration, texts[i], baseColor, type); animations.add(Animations.offset(beginTime, animation)); beginTime += singleDuration + beginOffset; } return Animations.parallel(animations); } private static Animation animation(BasicTextLabel label, long duration, String text, Color baseColor, int type) { switch (type) { case FADE_TYPE : return BasicTextAnimation.defaultFade(label, duration, text, baseColor); case SCALE_TYPE : return BasicTextAnimation.defaultScale(label, duration, text, baseColor); case SPACE_TYPE : return BasicTextAnimation.defaultSpace(label, duration, text, baseColor); default : return null; } } }animation-1.2.0/src/core/com/jgoodies/animation/animations/FanAnimation.java0000644000175000017500000001002210444605612027054 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.animations; import com.jgoodies.animation.AbstractAnimation; import com.jgoodies.animation.AnimationFunction; import com.jgoodies.animation.AnimationFunctions; import com.jgoodies.animation.components.FanComponent; /** * An animation that rotates a fan that consists of a set * of translucent sectors. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see com.jgoodies.animation.components.FanComponent * @see com.jgoodies.animation.renderer.FanRenderer */ public final class FanAnimation extends AbstractAnimation { public static final double DEFAULT_CLOCKWISE_ROTATION = 0.01; // rotations per second public static final double DEFAULT_ANTICLOCKWISE_ROTATION = -0.02; private final FanComponent fan; private final AnimationFunctions.FloatFunction rotationFunction; /** * Constructs an animation that rotates a fan using the given fan component, * duration and rotation animation function. * * @param fan the fan component animation target * @param duration the animation duration * @param rotationFunction the rotation animation function */ public FanAnimation(FanComponent fan, long duration, AnimationFunction rotationFunction) { super(duration); this.fan = fan; this.rotationFunction = AnimationFunctions.asFloat(rotationFunction != null ? rotationFunction : defaultRotationFunction(duration)); } /** * Creates and answers the default fan animation. * * @param fan the fan component animation target * @param duration the animation duration * @return a default fan animation */ public static FanAnimation defaultFan(FanComponent fan, long duration) { return new FanAnimation(fan, duration, null); } /** * Creates and answers an animation function for the default rotation. * * @param duration the animation duration * @return an animation function for the default rotation */ public static AnimationFunction defaultRotationFunction(long duration) { return AnimationFunctions.fromTo(duration, 0f, (float) (Math.PI * 2.0f)); } /** * Applies the effect: sets the time-based rotation. * * @param time the render time */ protected void applyEffect(long time) { fan.setRotation(rotationFunction.valueAt(time)); } }animation-1.2.0/src/core/com/jgoodies/animation/animations/GlyphAnimation.java0000644000175000017500000000567610444605612027456 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.animations; import com.jgoodies.animation.AbstractAnimation; import com.jgoodies.animation.components.GlyphLabel; /** * A text based animation that changes the scaling of the text's * individual glyphs over the time. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class GlyphAnimation extends AbstractAnimation { private final GlyphLabel label; private final String text; /** * Constructs an animation that changes the scaling of individual * glyphs over the duration. * * @param label the animation target label * @param duration the animation duration * @param glyphDelay a delay used to scale glyphs differently * @param text the text to animation */ public GlyphAnimation( GlyphLabel label, long duration, long glyphDelay, String text) { super(duration); this.label = label; this.text = text; } /** * Applies the effect: sets the text and time. * * @param time the render time position */ protected void applyEffect(long time) { label.setText(time == 0 ? " " : text); if (time < duration()) label.setTime(time); } }animation-1.2.0/src/core/com/jgoodies/animation/animations/package.html0000644000175000017500000000447410444605612026144 0ustar twernertwerner Contains a bunch of prepared animations and animation factories.

Related Documentation

For more information see: animation-1.2.0/src/core/com/jgoodies/animation/components/0000755000175000017500000000000010444605612023675 5ustar twernertwerneranimation-1.2.0/src/core/com/jgoodies/animation/components/AnimatedLabel.java0000644000175000017500000004246510444605612027235 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.components; import java.awt.*; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.plaf.FontUIResource; import com.jgoodies.animation.AbstractAnimation; import com.jgoodies.animation.Animation; import com.jgoodies.animation.AnimationAdapter; import com.jgoodies.animation.AnimationEvent; import com.jgoodies.animation.Animator; /** * An anti-aliased text label that can animate text changes * using a blend over effect.

* * Note: This is preview code that is not supported. * It is more raw than other classes that you have downloaded * from JGoodies.com in the past and contains known bugs. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class AnimatedLabel extends JPanel { // Names of Bound Properties ********************************************** public static final String PROPERTYNAME_ANIMATED = "animated"; public static final String PROPERTYNAME_DURATION = "duration"; public static final String PROPERTYNAME_FOREGROUND = "foreground"; public static final String PROPERTYNAME_TEXT = "text"; // Constants ************************************************************** public static final int RIGHT = SwingConstants.RIGHT; public static final int CENTER = SwingConstants.CENTER; public static final int LEFT = SwingConstants.LEFT; // Default Values ********************************************************* public static final Color DEFAULT_BASE_COLOR = new Color(64, 64, 64); public static final int DEFAULT_FONT_EXTRA_SIZE = 8; private static final int DEFAULT_DURATION = 300; private static final int DEFAULT_ANIMATION_FPS = 30; // Instance Variables ***************************************************** private JLabel[] labels; private int foreground = 0; private int background = 1; private Color baseColor; private boolean animated; private int orientation; private long duration; private int fps; private Animation animation; private Animator animator; // Instance Creation **************************************************** /** * Constructs an AnimatedLabel with default base color, * default font extra size, and an empty text. */ public AnimatedLabel() { this(DEFAULT_BASE_COLOR, DEFAULT_FONT_EXTRA_SIZE, ""); } /** * Constructs an AnimatedLabel with the given initial text * using a left oriented label. * * @param baseColor the color used as a basis for the text color * @param fontExtraSize pixels that are added to the dialog font size * @param text the initial text to be displayed */ public AnimatedLabel(Color baseColor, int fontExtraSize, String text) { this(baseColor, fontExtraSize, text, LEFT); } /** * Constructs an AnimatedLabel with the given initial text * and orientation. * * @param baseColor the color used as a basis for the text color * @param fontExtraSize pixels that are added to the dialog font size * @param text the initial text to be displayed * @param orientation the label's orientation */ public AnimatedLabel( Color baseColor, int fontExtraSize, String text, int orientation) { this(baseColor, fontExtraSize, text, orientation, DEFAULT_DURATION, DEFAULT_ANIMATION_FPS); } /** * Constructs an AnimatedLabel with the given properties. * * @param baseColor the color used as a basis for the text color * @param fontExtraSize pixels that are added to the dialog font size * @param text the initial text to be displayed * @param orientation the label's orientation * @param duration the duration of the blend over animation * @param frames_per_second the blend over animation's frame rate */ public AnimatedLabel( Color baseColor, int fontExtraSize, String text, int orientation, int duration, int frames_per_second) { super(null); this.baseColor = baseColor; this.orientation = orientation; this.duration = duration; this.fps = frames_per_second; this.animated = true; initComponents(fontExtraSize); build(); setTextImmediately(text); } // Public API *********************************************************** /** * Answers whether the animation is currently enabled. * * @return true if the animation is enabled, false if disabled */ public boolean isAnimated() { return animated; } /** * Returns the duration of the blend over animation. * * @return the duration of the blend over animaton */ public long getDuration() { return duration; } /** * Returns the label's foreground base color. * * @return this label's foreground base color */ public Color getForeground() { return baseColor; } /** * Returns the text of the foreground label. * * @return the text of the foreground label */ public synchronized String getText() { return labels[foreground].getText(); } /** * Enables or disables the blend over effect. This can be useful in * environments with a poor rendering performance or if the user disables * all kinds of animations. You can still use this class but enable and * disable the animations. * * @param animated true to enable the blend over effect, false to disable it */ public void setAnimated(boolean animated) { boolean oldAnimated = animated; this.animated = animated; firePropertyChange(PROPERTYNAME_ANIMATED, oldAnimated, animated); } /** * Sets the animation's duration and invalidates the animation cache. * * @param newDuration the duration to be set */ public void setDuration(long newDuration) { long oldDuration = duration; duration = newDuration; animation = null; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } /** * Sets a new foreground base color. * * @param newForeground the color to be set as new foreground base color */ public void setForeground(Color newForeground) { Color oldForeground = getForeground(); baseColor = newForeground; firePropertyChange(PROPERTYNAME_FOREGROUND, oldForeground, newForeground); } /** * Sets a new text. If the animation is disabled the text will * be set immediately otherwise a blend over animation is used. * * @param newText the new text to be displayed */ public synchronized void setText(String newText) { String oldText = getText(); if (oldText.equals(newText)) return; if (!isAnimated()) { setTextImmediately(newText); return; } labels[background].setText(newText); foreground = 1 - foreground; background = 1 - background; // Ensure a previous animation is stopped before we start a new one. if (animator != null) { animator.stop(); } animator = new Animator(animation(), fps); animator.start(); firePropertyChange(PROPERTYNAME_TEXT, oldText, newText); } /** * Sets a new text without using the blend over animation. * * @param newText the text to be set */ public void setTextImmediately(String newText) { String oldText = getText(); labels[background].setText(newText); foreground = 1 - foreground; background = 1 - background; setAlpha(255, 0); firePropertyChange(PROPERTYNAME_TEXT, oldText, newText); } // Animation Creation *************************************************** /** * Lazily creates and returns the blend over animation. * * @return the lazily created blend over animation */ private Animation animation() { if (animation == null) { animation = new BlendOverAnimation(duration); animation.addAnimationListener(new AnimationAdapter() { public void animationStopped(AnimationEvent e) { setAlpha(255, 0); } }); } return animation; } // Building ************************************************************* /** * Creates and configures the UI components. The label's size is specified * using an fontExtraSize that is a delta in pixel to the * dialog font size. * * @param fontExtraSize the pixel size delta for the label sizes */ private void initComponents(int fontExtraSize) { labels = new JLabel[2]; labels[foreground] = createBoldLabel(fontExtraSize, getTranslucentColor(255)); labels[background] = createBoldLabel(fontExtraSize, getTranslucentColor(255)); } private void build() { setOpaque(false); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = anchor(); gbc.gridx = 0; gbc.gridy = 0; add(labels[foreground], gbc); add(labels[background], gbc); } private int anchor() { if (orientation == RIGHT) { return GridBagConstraints.EAST; } else if (orientation == CENTER) { return GridBagConstraints.CENTER; } else { return GridBagConstraints.WEST; } } /** * Creates and returns an anti-aliased label with a bold font for the * specified size increment and foreground color. * * @param sizeIncrement a size delta in pixels relative to * the dialog font size * @param aForeground the label's foreground base color * @return a bold anti aliased label */ private JLabel createBoldLabel(int sizeIncrement, Color aForeground) { JLabel label = new AntiAliasedLabel("", Font.BOLD, sizeIncrement); label.setForeground(aForeground); return label; } // Helper Methods ******************************************************* /** * Creates and returns a translucent color with the label's base color. * * @param alpha the current alpha value * @return a translucent color with the given alpha based on this label's * foreground base color. */ private Color getTranslucentColor(int alpha) { return new Color( baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), alpha); } /** * Sets the foreground and background colors using the given alpha values. * * @param foregroundAlpha alpha value for the foreground label * @param backgroundAlpha alpha value for the background label */ private void setAlpha0(int foregroundAlpha, int backgroundAlpha) { labels[foreground].setForeground(getTranslucentColor(foregroundAlpha)); labels[background].setForeground(getTranslucentColor(backgroundAlpha)); } /** * Sets the foreground and background colors in the event dispatch thread. * * @param foregroundAlpha alpha value for the foreground label * @param backgroundAlpha alpha value for the background label */ private void setAlpha( final int foregroundAlpha, final int backgroundAlpha) { if (SwingUtilities.isEventDispatchThread()) { setAlpha0(foregroundAlpha, backgroundAlpha); return; } Runnable runnable = new Runnable() { public void run() { setAlpha0(foregroundAlpha, backgroundAlpha); } }; SwingUtilities.invokeLater(runnable); } // Animation Class ****************************************************** /** * An animation that changes the colors of overlapping labels * to implement a blend over effect. */ private class BlendOverAnimation extends AbstractAnimation { /** * Constructs an animation that changes the colors of the * prefix and suffix labels over the duration. * * @param duration the animation's duration */ public BlendOverAnimation(long duration) { super(duration, true); } /** * Applies the effect: sets the text and time. * * @param time the time point used to apply the effect */ protected void applyEffect(long time) { int foregroundAlpha = (int) (255 * time / duration()); int backgroundAlpha = 255 - foregroundAlpha; setAlpha(foregroundAlpha, backgroundAlpha); } } // Helper Class *********************************************************** private static final class AntiAliasedLabel extends JLabel { private final int fontExtraSize; private final int fontStyle; /** * Constructs an AntiAliasedLabel for the given text, * font style and font extra size. * * @param text the label's initial text * @param fontStyle the font style attribute * @param fontExtraSize a size delta in pixel relative to the dialog * font size in pixels */ private AntiAliasedLabel( String text, int fontStyle, int fontExtraSize) { super(text); this.fontStyle = fontStyle; this.fontExtraSize = fontExtraSize; updateUI(); } /** * Enables text anti-aliasing on, paints, and restores the old state. * * @param g the Graphics object to render on */ public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Object oldHint = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); super.paint(g2); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldHint); } /** * Restores the font after the UI has changed. */ public void updateUI() { super.updateUI(); Font font = getFont(); if (0 == fontExtraSize) { if (font.getStyle() != fontStyle) setFont(new FontUIResource(font.deriveFont(fontStyle))); } else setFont( new FontUIResource( new Font( font.getName(), fontStyle, font.getSize() + fontExtraSize))); } } }animation-1.2.0/src/core/com/jgoodies/animation/components/BasicTextLabel.java0000644000175000017500000001722610444605612027376 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.components; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JComponent; import com.jgoodies.animation.renderer.BasicTextRenderer; import com.jgoodies.animation.renderer.HeightMode; /** * A Swing text component that can change the text, x and y scaling, * glyph space, x and y offset and alignment mode. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see BasicTextRenderer */ public final class BasicTextLabel extends JComponent { // Names of the bound bean properties ************************************* public static final String PROPERTYNAME_COLOR = "color"; public static final String PROPERTYNAME_HEIGHT_MODE = "heightMode"; public static final String PROPERTYNAME_SCALE = "scale"; public static final String PROPERTYNAME_SCALE_X = "scaleX"; public static final String PROPERTYNAME_SCALE_Y = "scaleY"; public static final String PROPERTYNAME_SPACE = "space"; public static final String PROPERTYNAME_TEXT = "text"; public static final String PROPERTYNAME_OFFSET_X = "offsetX"; public static final String PROPERTYNAME_OFFSET_Y = "offsetY"; /** * Refers to the object that renders the text onto a graphics2D. */ private final BasicTextRenderer renderer; // Instance Creation ****************************************************** /** * Constructs a animation text Swing label with an empty initial text. */ public BasicTextLabel() { this(""); } /** * Constructs a animation text Swing label for the given text. * * @param text the initial text to be displayed */ public BasicTextLabel(String text) { renderer = new BasicTextRenderer(text); } // Public Accessors ******************************************************* public Color getColor() { return renderer.getColor(); } public HeightMode getHeightMode() { return renderer.getHeightMode(); } public float getScale() { return Math.max(getScaleX(), getScaleX()); } public float getScaleX() { return renderer.getScaleX(); } public float getScaleY() { return renderer.getScaleY(); } public float getSpace() { return renderer.getSpace(); } public float getOffsetX() { return renderer.getOffsetX(); } public float getOffsetY() { return renderer.getOffsetY(); } public String getText() { return renderer.getText(); } public void setColor(Color newColor) { Color oldColor = getColor(); if (oldColor.equals(newColor)) return; renderer.setColor(newColor); firePropertyChange(PROPERTYNAME_COLOR, oldColor, newColor); repaint(); } public void setHeightMode(HeightMode heightMode) { HeightMode oldMode = getHeightMode(); renderer.setHeightMode(heightMode); firePropertyChange(PROPERTYNAME_HEIGHT_MODE, oldMode, heightMode); repaint(); } public void setScale(float newScale) { float oldScale = getScale(); renderer.setScaleX(newScale); renderer.setScaleY(newScale); firePropertyChange(PROPERTYNAME_SCALE, oldScale, newScale); repaint(); } public void setScaleX(float newScaleX) { float oldScaleX = getScaleX(); if (oldScaleX == newScaleX) return; float oldScale = getScale(); renderer.setScaleX(newScaleX); firePropertyChange(PROPERTYNAME_SCALE_X, oldScaleX, newScaleX); firePropertyChange(PROPERTYNAME_SCALE, oldScale, getScale()); repaint(); } public void setScaleY(float newScaleY) { float oldScaleY = getScaleY(); if (oldScaleY == newScaleY) return; float oldScale = getScale(); renderer.setScaleY(newScaleY); firePropertyChange(PROPERTYNAME_SCALE_Y, oldScaleY, newScaleY); firePropertyChange(PROPERTYNAME_SCALE, oldScale, getScale()); repaint(); } public void setSpace(float newSpace) { float oldSpace = getSpace(); if (oldSpace == newSpace) return; renderer.setSpace(newSpace); firePropertyChange(PROPERTYNAME_SPACE, oldSpace, newSpace); repaint(); } public void setOffsetX(float offsetX) { float oldOffsetX = getOffsetX(); renderer.setOffsetX(offsetX); firePropertyChange(PROPERTYNAME_OFFSET_X, oldOffsetX, offsetX); repaint(); } public void setOffsetY(float offsetY) { float oldOffsetY = getOffsetY(); renderer.setOffsetY(offsetY); firePropertyChange(PROPERTYNAME_OFFSET_Y, oldOffsetY, offsetY); repaint(); } public void setText(String newText) { String oldText = getText(); if (oldText.equals(newText)) return; renderer.setText(newText); firePropertyChange(PROPERTYNAME_TEXT, oldText, newText); repaint(); } // Painting *************************************************************** /** * Paints the component. Enabled anti-aliasing and sets high quality hints, * then renderers the component via the underlying renderer. * * @param g the Graphics object to render on */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderer.setFont(getFont()); renderer.render(g2, getWidth(), getHeight()); } }animation-1.2.0/src/core/com/jgoodies/animation/components/CircleComponent.java0000644000175000017500000000660410444605612027632 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.components; import java.awt.*; import javax.swing.JComponent; /** * A Swing component that paints a circle with a given center, radius and color. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class CircleComponent extends JComponent { private Point center; private int radius; private Color color; /** * Constructs a CircleComponent. */ public CircleComponent() { center = new Point(0, 0); radius = 30; color = Color.BLACK; } public void setCenter(Point p) { this.center = p; } public void setRadius(int radius) { this.radius = radius; } public void setColor(Color color) { this.color = color; } /** * Sets the bounds and center point. * * @param x the horizontal origin * @param y the vertical origin * @param w the width, the horizontal extent * @param h the height, the vertical extent */ public void setBounds(int x, int y, int w, int h) { super.setBounds(x, y, w, h); setCenter(new Point(x + w / 2, y + h / 2)); } /** * Paints the circle with anti-aliasing enabled. * * @param g the Graphics object to render on */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; int diameter = radius * 2; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(color); g2.setStroke(new BasicStroke(4)); g2.drawOval(center.x - radius, center.y - radius, diameter, diameter); } }animation-1.2.0/src/core/com/jgoodies/animation/components/FanComponent.java0000644000175000017500000001050710444605612027132 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.components; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.RenderingHints; import java.awt.geom.Point2D; import javax.swing.JComponent; import com.jgoodies.animation.renderer.FanRenderer; /** * A Swing component that paints a set of triangles as a fan. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see com.jgoodies.animation.animations.FanAnimation * @see com.jgoodies.animation.renderer.FanRenderer */ public final class FanComponent extends JComponent { private final FanRenderer renderer; // Instance Creation **************************************************** /** * Constructs a FanComponent for the specified * number of triangles and base color. * * @param triangleCount the number of triangles to be displayed * @param baseColor the base color used to build the translucent * triangle colors from */ public FanComponent(int triangleCount, Color baseColor) { this.renderer = new FanRenderer(triangleCount, baseColor); } // Accessors ************************************************************ public Point2D getOrigin() { return renderer.getOrigin(); } public double getRotation() { return renderer.getRotation(); } /** * Sets a new origin of the fan. * * @param origin the origin to be set */ public void setOrigin(Point2D origin) { renderer.setOrigin(origin); repaint(); } /** * Sets a new rotation. * * @param rotation the rotation to be set */ public void setRotation(double rotation) { renderer.setRotation(rotation); repaint(); } /** * Delegates painting to the fan renderer. Switches on anti-aliasing * and the high quality mode before invoking the renderer. * * @param g the Graphics object to render on */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); Insets insets = getInsets(); int x = insets.left; int y = insets.top; int w = getWidth() - x - insets.right; int h = getHeight() - y - insets.bottom; g2.translate(x, y); renderer.render(g2, w, h); g2.translate(-x, -y); } }animation-1.2.0/src/core/com/jgoodies/animation/components/GlyphLabel.java0000644000175000017500000001620010444605612026562 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.components; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JComponent; import com.jgoodies.animation.AnimationFunction; import com.jgoodies.animation.AnimationFunctions; import com.jgoodies.animation.renderer.GlyphRenderer; import com.jgoodies.animation.renderer.HeightMode; /** * A Swing component that can transform a text's individual glyphs. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class GlyphLabel extends JComponent { // Names of the bound bean properties ************************************* public static final String PROPERTYNAME_HEIGHT_MODE = "heightMode"; public static final String PROPERTYNAME_TEXT = "text"; public static final String PROPERTYNAME_TIME = "time"; /** * Refers to the renderer that paints the individual glyphs. */ private final GlyphRenderer renderer; // Instance Creation ****************************************************** /** * Creates a GlyphLabel for the given text, duration and * delay between the individual glyphs. * * @param text the initial text * @param duration the duration of the whole animation * @param glyphDelay a delay between the animation of the individual glyphs */ public GlyphLabel(String text, long duration, long glyphDelay) { this(text, duration, glyphDelay, Color.DARK_GRAY); } /** * Creates a GlyphLabel for the given text, duration, base color * and delay between the individual glyphs. * * @param text the initial text * @param duration the duration of the whole animation * @param glyphDelay a delay between the animation of the individual glyphs * @param baseColor the color used as a basis for the translucent * glyph foreground colors */ public GlyphLabel( String text, long duration, long glyphDelay, Color baseColor) { renderer = new GlyphRenderer( text, defaultScaleFunction(duration), AnimationFunctions.ZERO, defaultColorFunction(duration, baseColor), glyphDelay); } /** * Creates and returns the default scale function for the given duration. * * @param duration the duration of the whole animation * @return an animation function that maps times to glyph scales */ public static AnimationFunction defaultScaleFunction(long duration) { return AnimationFunctions.linear( duration, new Float[] { new Float(5.0f), new Float(0.8f), new Float(1.0f), new Float(1.0f)}, new float[] { 0.0f, 0.1f, 0.12f, 1.0f }); } /** * Creates and returns the default color function for the given duration * and base color. * * @param duration the duration of the animation * @param baseColor the color used as a basis for the translucent colors * @return an animation function that maps times to translucent glyph colors */ public static AnimationFunction defaultColorFunction( long duration, Color baseColor) { return AnimationFunctions.alphaColor( AnimationFunctions.linear( duration, new Integer[] { new Integer(0), new Integer(255), new Integer(255)}, new float[] { 0.0f, 0.15f, 1.0f }), baseColor); } // Accessors ************************************************************** public HeightMode getHeightMode() { return renderer.getHeightMode(); } public String getText() { return renderer.getText(); } public long getTime() { return renderer.getTime(); } public void setHeightMode(HeightMode newHeightMode) { HeightMode oldHeightMode = getHeightMode(); renderer.setHeightMode(newHeightMode); firePropertyChange(PROPERTYNAME_HEIGHT_MODE, oldHeightMode, newHeightMode); repaint(); } public void setText(String newText) { String oldText = getText(); renderer.setText(newText); firePropertyChange(PROPERTYNAME_TEXT, oldText, newText); repaint(); } public void setTime(long newTime) { long oldTime = getTime(); renderer.setTime(newTime); firePropertyChange(PROPERTYNAME_TIME, oldTime, newTime); repaint(); } // Rendering ************************************************************** /** * Paints the component. Sets high-fidelity rendering hints, * then invoke the renderer to render the glyphs. * * @param g the Graphics object to render on */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderer.setFont(getFont()); renderer.render(g2, getWidth(), getHeight()); } }animation-1.2.0/src/core/com/jgoodies/animation/components/package.html0000644000175000017500000000446010444605612026162 0ustar twernertwerner Consists of a bunch of prepared animated components.

Related Documentation

For more information see: animation-1.2.0/src/core/com/jgoodies/animation/renderer/0000755000175000017500000000000010444605612023316 5ustar twernertwerneranimation-1.2.0/src/core/com/jgoodies/animation/renderer/AbstractTextRenderer.java0000644000175000017500000001714710444605612030272 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.renderer; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; import java.awt.geom.Rectangle2D; import com.jgoodies.animation.*; /** * An abstract superclass that helps implementing typographic animation renderers. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public abstract class AbstractTextRenderer implements AnimationRenderer { private String text; private Font font; private Color color; private HeightMode heightMode = HeightMode.CAPITAL_ASCENT; // Cached data ------------------------------------------- protected GlyphVector cachedGlyphVector; protected Shape[] cachedGlyphShapes; protected float cachedTextWidth; protected float cachedTextAscent; protected float cachedTextHeight; protected float capitalMAscent = -1f; // Ascent of a capital M private boolean cacheValid = false; // Instance Creation ****************************************************** AbstractTextRenderer(String text) { this(text, null); } AbstractTextRenderer(String text, Font font) { this.text = text == null ? "Karsten Lentzsch" : text; this.font = font == null ? createDefaultFont() : font; this.color = Color.BLACK; } /** * Creates and returns a default font object. * * @return a default font object */ private static Font createDefaultFont() { return new Font("dialog", Font.BOLD, 12); } // Accessors ************************************************************** public Color getColor() { return color; } public Font getFont() { return font; } public String getText() { return text; } public HeightMode getHeightMode() { return heightMode; } public void setColor(Color color) { this.color = color; } public void setHeightMode(HeightMode heightMode) { this.heightMode = heightMode; } /** * Sets the renderer's font. * * @param newFont the font to be set */ public void setFont(Font newFont) { if (newFont == null) throw new NullPointerException("The font must not be null."); if (newFont.equals(font)) return; font = newFont; invalidateCache(); } /** * Sets the renderer's text. * * @param newText the text to be set */ public void setText(String newText) { if (newText == null) throw new NullPointerException("The text must not be null."); if (newText.equals(text)) return; text = newText; invalidateCache(); } /** * Computes and answers the text ascent using the current height mode. * * @return the ascent adjusted using the current height mode * @see #getHeightMode() */ protected float getAdjustedAscent() { if (heightMode == HeightMode.CAPITAL_ASCENT) return capitalMAscent; else if (heightMode == HeightMode.TEXT_ASCENT) return cachedTextAscent; else return cachedTextHeight; } /** * Computes and answers the text descent using the current height mode. * * @return the descent adjusted to the current height mode * @see #getHeightMode() */ protected float getAdjustedDescent() { if (heightMode == HeightMode.CAPITAL_ASCENT) return 0; else if (heightMode == HeightMode.TEXT_ASCENT) return 0; else return cachedTextHeight - cachedTextAscent; } // Caching **************************************************************** protected boolean isCacheValid() { return cacheValid; } protected void setCacheValid(boolean b) { cacheValid = b; } protected void ensureValidCache(Graphics2D g2) { if (!isCacheValid()) validateCache(g2); } /** * Validates the cache, here: creates a GlyphVector * and computes and stores its size information. * * @param g2 the Graphics object used to get the font render context */ protected void validateCache(Graphics2D g2) { FontRenderContext frc = g2.getFontRenderContext(); ensureCapitalMAscentComputed(frc); cachedGlyphVector = font.createGlyphVector(frc, text); Rectangle2D bounds = cachedGlyphVector.getVisualBounds(); cachedTextWidth = (float) bounds.getWidth(); cachedTextAscent = (float) - bounds.getY(); cachedTextHeight = (float) bounds.getHeight(); int glyphCount = cachedGlyphVector.getNumGlyphs(); cachedGlyphShapes = new Shape[glyphCount]; for (int i = 0; i < glyphCount; i++) { cachedGlyphShapes[i] = cachedGlyphVector.getGlyphOutline(i); } setCacheValid(true); /* Debug lines System.out.println("Text = " + text); System.out.println("GV visual bounds = " + glyphVector.getVisualBounds()); */ } /** * Ensures that the ascent of a capital M has been computed. * * @param frc the font render context used to create the glyph vector */ private void ensureCapitalMAscentComputed(FontRenderContext frc) { if (capitalMAscent > 0) return; GlyphVector mGlyphVector = font.createGlyphVector(frc, "M"); capitalMAscent = (float) - mGlyphVector.getVisualBounds().getY(); } /** * Invalidates the cache. */ protected void invalidateCache() { setCacheValid(false); cachedGlyphVector = null; cachedGlyphShapes = null; } }animation-1.2.0/src/core/com/jgoodies/animation/renderer/BasicTextRenderer.java0000644000175000017500000001024510444605612027540 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.renderer; import java.awt.Graphics2D; /** * Renders a text with modifiable scaling, color, glyph spacing and position. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class BasicTextRenderer extends AbstractTextRenderer { private float offsetX = 0.0f; private float offsetY = 0.0f; private float scaleX = 1.0f; private float scaleY = 1.0f; private float space = 0.0f; /** * Constructs a renderer for a text that can be scaled, moved, and * change inter-glyph space. * * @param text the text to be displayed */ public BasicTextRenderer(String text) { super(text); } public float getOffsetX() { return offsetX; } public float getOffsetY() { return offsetY; } public float getSpace() { return space; } public void setOffsetX(float offsetX){ this.offsetX = offsetX; } public void setOffsetY(float offsetY){ this.offsetY = offsetY; } public void setSpace(float space) { this.space = space; } public float getScaleX() { return scaleX; } public float getScaleY() { return scaleY; } public void setScaleX(float scaleX) { if (scaleX <= 0.0f) throw new IllegalArgumentException("scaleX must be positive."); this.scaleX = scaleX; } public void setScaleY(float scaleY) { if (scaleY <= 0.0f) throw new IllegalArgumentException("scaleY must be positive."); this.scaleY = scaleY; } /** * Renders the text. Firstly ensures a valid cache, then sets * the color, and finally paints the cached glyph shapes. * * @param g2 the graphics context to render on * @param width the width of the drawing surface * @param height the height of the drawing surface */ public void render(Graphics2D g2, int width, int height) { ensureValidCache(g2); int glyphCount = cachedGlyphShapes.length; float totalSpace = (glyphCount - 1) * space; float totalWidth = cachedTextWidth + totalSpace; float textHeight = getAdjustedAscent(); float xOffset = getOffsetX() + (width - totalWidth * scaleX) / 2.0f; float yOffset = getOffsetY() + (height + textHeight * scaleY) / 2.0f - getAdjustedDescent(); g2.setColor(getColor()); g2.translate(xOffset, yOffset); g2.scale(scaleX, scaleY); for (int i = 0; i < glyphCount; i++) { g2.fill(cachedGlyphShapes[i]); g2.translate(space, 0); } g2.scale(1.0f / scaleX, 1.0f / scaleY); g2.translate(-totalSpace -xOffset, -yOffset); } }animation-1.2.0/src/core/com/jgoodies/animation/renderer/FanRenderer.java0000644000175000017500000001274410444605612026364 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.renderer; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.geom.GeneralPath; import java.awt.geom.Point2D; import java.util.Random; import com.jgoodies.animation.AnimationRenderer; /** * Paints two colored and often translucent fans that can be rotated. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see com.jgoodies.animation.animations.FanAnimation * @see com.jgoodies.animation.components.FanComponent */ public final class FanRenderer implements AnimationRenderer { private static final Random random = new Random(System.currentTimeMillis()); private final Triangle[] triangles; private Point2D origin; private double rotation; public FanRenderer(Triangle[] triangles) { this.triangles = triangles; } public FanRenderer(int triangleCount, Color baseColor) { this(createSectors(triangleCount, baseColor)); } public static Triangle[] createSectors(int count, Color baseColor) { Triangle[] result = new Triangle[count]; double sectorAngle = Math.PI * 2 / count; for (int i = 0; i < count; i++) { double rotation = i * sectorAngle + (random.nextFloat() - 0.5) * Math.PI/10; double angle = sectorAngle * (0.2 + random.nextFloat() * 0.4); result[i] = new Triangle(rotation, angle, nextColor(baseColor)); } return result; } private static Color nextColor(Color baseColor) { float[] hsb = new float[3]; Color.RGBtoHSB(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), hsb); float brightness = 0.8f + random.nextFloat() * 0.2f; return Color.getHSBColor(hsb[0], hsb[1], brightness); } public Point2D getOrigin() { return origin; } public void setOrigin(Point2D origin) { this.origin = origin; } public double getRotation() { return rotation; } public void setRotation(double rotation) { this.rotation = rotation; } public void render(Graphics2D g2, int width, int height) { double radius = Math.sqrt(width * width + height * height); Point2D p = getOrigin() != null ? getOrigin() : getDefaultOrigin(width, height); g2.translate(p.getX(), p.getY()); g2.rotate(rotation); for (int i = 0; i < triangles.length; i++) { triangles[i].render(g2, radius); } g2.rotate(-rotation); g2.translate(-p.getX(), -p.getY()); } private Point2D getDefaultOrigin(int width, int height) { return new Point2D.Double(width * 0.75, height * 0.75); } // Helper Class *********************************************************** /** * A helper class that models and renders a single sector. */ private static final class Triangle { private final double aRotation; private final double angle; private final Color color; private Triangle(double rotation, double angle, Color color) { this.aRotation = rotation; this.angle = angle; this.color = color; } private static Shape createPolygon(double rotation, double angle, double radius) { double startAngle = rotation - angle / 2; double stopAngle = startAngle + angle; double hypothenusis = radius / Math.cos(angle / 2); float x0 = 0.0f; float y0 = 0.0f; float x1 = (float) (x0 - hypothenusis * Math.cos(startAngle)); float y1 = (float) (y0 - hypothenusis * Math.sin(startAngle)); float x2 = (float) (x0 - hypothenusis * Math.cos(stopAngle)); float y2 = (float) (y0 - hypothenusis * Math.sin(stopAngle)); GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); polygon.moveTo(x0, y0); polygon.lineTo(x1, y1); polygon.lineTo(x2, y2); polygon.closePath(); return polygon; } void render(Graphics2D g2, double radius) { g2.setColor(color); g2.fill(createPolygon(aRotation, angle, radius)); } } }animation-1.2.0/src/core/com/jgoodies/animation/renderer/GlyphRenderer.java0000644000175000017500000001242010444605612026732 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.renderer; import java.awt.Color; import java.awt.Graphics2D; import com.jgoodies.animation.AnimationFunction; import com.jgoodies.animation.AnimationFunctions; /** * Renders the glyphs of a string with individual scaling, transform, and color. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class GlyphRenderer extends AbstractTextRenderer { private final AnimationFunction colorFunction; private final AnimationFunctions.FloatFunction scaleFunction; private final long glyphDelay; private long time; // Instance Creation ****************************************************** /** * Constructs a GlyphRenderer that paints * individual glyphs with different transforms. * * @param text the initial text * @param scaleFunction maps times to glyph scales * @param translateFunction maps times to glyph translations * @param colorFunction maps times to colors * @param glyphDelay a time delay between the glyph animations */ public GlyphRenderer( String text, AnimationFunction scaleFunction, AnimationFunction translateFunction, AnimationFunction colorFunction, long glyphDelay) { super(text); this.scaleFunction = AnimationFunctions.asFloat(scaleFunction); this.colorFunction = colorFunction; this.glyphDelay = glyphDelay; this.time = 0; } // Accessors ************************************************************** public long getTime() { return time; } public void setTime(long time) { this.time = time; } private long relativeTime(int glyphIndex) { return Math.max(0, time - glyphDelay * glyphIndex); } private float scaleAt(int glyphIndex) { return scaleFunction.valueAt(relativeTime(glyphIndex)); } private Color colorAt(int glyphIndex) { return (Color) colorFunction.valueAt(relativeTime(glyphIndex)); } /** * Renders the text. Firstly, ensures a valid cache, * then sets the color, and finally paints the cached glyph shaped, * using individual transforms. * * @param g2 the graphics object to render on * @param width the width of the graphics area * @param height the height of the graphics area */ public void render(Graphics2D g2, int width, int height) { ensureValidCache(g2); int glyphCount = cachedGlyphShapes.length; float offsetX = (width - cachedTextWidth) / 2.0f; float offsetY = (height + cachedTextHeight) / 2.0f - getAdjustedDescent(); g2.translate(offsetX, offsetY); for (int i = glyphCount - 1; i >= 0; i--) { float scale = scaleAt(i); //float translate = translateAt(i); g2.setColor(colorAt(i)); //g2.translate(translate, 0); double glyphX = cachedGlyphVector.getGlyphPosition(i).getX(); double glyphY = cachedGlyphVector.getGlyphVisualBounds(i).getBounds2D().getHeight(); double adjustX = -glyphX * (scale - 1.0f); double adjustY = glyphY * (scale - 1.0f) / 2.0f; g2.translate(adjustX, adjustY); g2.scale(scale, scale); g2.fill(cachedGlyphShapes[i]); g2.scale(1.0f / scale, 1.0f / scale); g2.translate(-adjustX, -adjustY); //g2.translate(-translate, 0); } g2.translate(-offsetX, -offsetY); } }animation-1.2.0/src/core/com/jgoodies/animation/renderer/HeightMode.java0000644000175000017500000000446110444605612026203 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.renderer; /** * A type-safe enumeration used to vertically align texts by using * the capital or text ascent, or the text's height. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class HeightMode { private final String name; public static final HeightMode CAPITAL_ASCENT = new HeightMode("Capital ascent"); public static final HeightMode TEXT_ASCENT = new HeightMode("Text ascent"); public static final HeightMode TEXT_HEIGHT = new HeightMode("Text height"); private HeightMode(String name) { this.name = name; } public String toString() { return name; } }animation-1.2.0/src/core/com/jgoodies/animation/renderer/package.html0000644000175000017500000000444210444605612025603 0ustar twernertwerner Contains prepared animation renderers.

Related Documentation

For more information see: animation-1.2.0/src/core/com/jgoodies/animation/AbstractAnimation.java0000644000175000017500000001527310444605612025766 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import java.util.Iterator; import java.util.LinkedList; import java.util.List; /** * An abstract class that minimizes the effort required to implement * the {@link Animation} interface. Defines the duration and freezed state * and provides a listener list. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public abstract class AbstractAnimation implements Animation { private final long duration; private final boolean freezed; private final List listenerList = new LinkedList(); private boolean active = false; // Instance Creation ***************************************************** /** * Constructs an Animation with the specified duration. * * @param duration the animation's duration */ protected AbstractAnimation(long duration) { this(duration, false); } /** * Constructs an Animation with the specified duration * and freezed mode. * * @param duration the animation's duration * @param freezed true indicates that the effect will be retained after * the animation is finished, false resets the effect to the time 0 */ protected AbstractAnimation(long duration, boolean freezed) { this.duration = duration; this.freezed = freezed; } // *********************************************************************** /** * Returns this animation's duration. * * @return this animation's duration */ public final long duration() { return duration; } /** * Answers whether the animation effect should be freezed after * we exceeded the animation's duration. If this is not the case, * the animation effect of time 0 will be set. * * @return true indicates that the effect will be retained if the * animation duration exceeded; false indicates that the effect * will be reset */ public final boolean isFreezed() { return freezed; } /** * Applies the animation effect for the given time to the animation target. * * @param time the time used to determine the animation effect */ protected abstract void applyEffect(long time); /** * Performs the animation at the given time: applies the animation * effect to the animation target, fires appropriate events, * and resets the effect if we exceeded the animations duration. * * @param time the time used to determine the animation effect */ public void animate(long time) { if (time >= duration) { if (active) { applyEffect(isFreezed() ? duration - 1 : 0); fireAnimationStopped(time); active = false; } return; } if (!active) { active = true; fireAnimationStarted(time); } applyEffect(time); } /** * Adds an AnimationListener to this animation. * * @param listener the AnimationListener to add */ public final void addAnimationListener(AnimationListener listener) { listenerList.add(listener); } /** * Removes an AnimationListener to this animation. * * @param listener the AnimationListener to remove */ public final void removeAnimationListener(AnimationListener listener) { listenerList.remove(listener); } /** * Fires an event that indicates that the animation has been started * at the specified time. * * @param time the time that will be reported in the event */ protected final void fireAnimationStarted(long time) { AnimationEvent e = new AnimationEvent(this, AnimationEvent.STARTED, time); for (Iterator i = listenerList.iterator(); i.hasNext();) { AnimationListener listener = (AnimationListener) i.next(); listener.animationStarted(e); } } /** * Fires an event that indicates that the animation has been stopped * at the specified time. * * @param time the time that will be reported in the event */ protected final void fireAnimationStopped(long time) { AnimationEvent e = new AnimationEvent(this, AnimationEvent.STOPPED, time); for (Iterator i = listenerList.iterator(); i.hasNext();) { AnimationListener listener = (AnimationListener) i.next(); listener.animationStopped(e); } } /** * Returns a string representation for this animation. * * @return a string representation for this animation */ public String toString() { return "[" + getClass().getName() + "; duration=" + duration + "; active=" + active + ']'; } }animation-1.2.0/src/core/com/jgoodies/animation/AbstractAnimationFunction.java0000644000175000017500000000711510444605612027470 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; /** * An abstract class that minimizes the effort required to implement * the {@link AnimationFunction} interface. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see AnimationFunctions */ public abstract class AbstractAnimationFunction implements AnimationFunction { /** * Describes this animation function's duration. */ private final long duration; // Instance Creation ****************************************************** /** * Constructs an AbstractAnimationFunction using the given * duration. * * @param duration the function's duration * @throws IllegalArgumentException if the duration is negative */ protected AbstractAnimationFunction(long duration) { if (duration < 0) throw new IllegalArgumentException("The duration must not be negative."); this.duration = duration; } // ************************************************************************ /** * Checks whether the given time is in the valid time range, that is * a non-negative time that is smaller than this function's duration. * If not, an IllegalArgumentException is thrown. * * @param time the time to be checked * @throws IllegalArgumentException if the time is outside the valid time * range */ protected void checkTimeRange(long time) { if ((time < 0) || (time >= duration())) throw new IllegalArgumentException( "The time must be larger than 0 and smaller than " + duration() + "."); } /** * Returns this animation function's duration. * * @return this animation function's duration */ public final long duration() { return duration; } }animation-1.2.0/src/core/com/jgoodies/animation/Animation.java0000644000175000017500000000565310444605612024303 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; /** * This interface describes time based animations. Basically, * the #animate method applies an animation effect * to an animation target over the animation's duration. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see AbstractAnimation * @see Animations */ public interface Animation { /** * Returns this animation's duration. * * @return this animation duration */ long duration(); /** * Animates for the given time, that is, applies the animation effect * to the animation target and fires events when the animation is * started, stopped or repeated. * * @param time the time used to determine the animation effect */ void animate(long time); /** * Adds the given AnimationListener to this animation. * * @param listener the AnimationListener to add */ void addAnimationListener(AnimationListener listener); /** * Removes the given AnimationListener from this animation. * * @param listener the AnimationListener to remove */ void removeAnimationListener(AnimationListener listener); }animation-1.2.0/src/core/com/jgoodies/animation/AnimationAdapter.java0000644000175000017500000000504210444605612025574 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; /** * An abstract adapter that implements the AnimationListener * interface. Consists only of methods with empty bodies - that do nothing. * This class minimizes the effort required to write animation listeners. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public class AnimationAdapter implements AnimationListener { /** * Invoked if the animation has been started. * * @param evt the related AnimationEvent */ public void animationStarted(AnimationEvent evt) { // Just a convenience implementation. } /** * Invoked if the animation has been stopped. * * @param evt the related AnimationEvent */ public void animationStopped(AnimationEvent evt) { // Just a convenience implementation. } }animation-1.2.0/src/core/com/jgoodies/animation/AnimationEvent.java0000644000175000017500000001111110444605612025267 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; /** * Describes events appropriate for animations: started or stopped. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see AnimationListener */ public final class AnimationEvent { /** * The animation event type for an animation that has been started. */ public static final Type STARTED = new Type("Started"); /** * The animation event type for an animation that has been stopped. */ public static final Type STOPPED = new Type("Stopped"); /** * The animation that has been started or stopped. */ private final Animation source; /** * Describes the state change of the animation: started or stopped. */ private final Type type; /** * Describes when the event has been created. */ private final long time; // Instance Creation ****************************************************** /** * Constructs an AnimationEvent for the * initiating animation, event type, and time. * * @param source the Animation that has originated the event * @param type the event type: start or stop * @param time the time the event has happened, which is likely * before the event has been created */ AnimationEvent(Animation source, Type type, long time) { this.source = source; this.type = type; this.time = time; } // ************************************************************************ /** * Returns the animation the has originated this event. * * @return the animation that has originated this event */ public Animation getSource() { return source; } /** * Returns the event type: started or stopped. * * @return the event type: started or stopped */ public Type type() { return type; } /** * Returns the time when this event has been created. * * @return the event creation time */ public long time() { return time; } /** * Returns an appropriate string representation. * * @return a string representation for this event */ public String toString() { return "[type= " + type + "; time= " + time + "; source=" + source + ']'; } // Helper Class *********************************************************** /** * A typesafe enumeration for the event types. */ private static final class Type { private final String name; private Type(String name) { this.name = name; } public String toString() { return name; } } }animation-1.2.0/src/core/com/jgoodies/animation/AnimationFunction.java0000644000175000017500000000512610444605612026004 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; /** * This interface describes time-based animation functions by * their duration and a mapping from time to animation effects.

* * For each time in the animation's valid time interval, * the #valueAt method returns a value that will be used * to apply an animation effect. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see AnimationFunctions * @see AbstractAnimationFunction */ public interface AnimationFunction { /** * Returns the length of this function's valid time interval. * * @return the length of this function's valid time interval */ long duration(); /** * Returns the animation effect for a given time in the valid time interval. * * @param time the time used to determine the animation effect * @return the animation effect at the given time */ Object valueAt(long time); }animation-1.2.0/src/core/com/jgoodies/animation/AnimationFunctions.java0000644000175000017500000006017710444605612026176 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import java.awt.Color; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Random; /** * This class consists only of static methods that construct and operate on * {@link AnimationFunction}s. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see AnimationFunction */ public final class AnimationFunctions { /** * A constant {@link AnimationFunction} that returns * 1 all the time. */ public static final AnimationFunction ONE = constant(Integer.MAX_VALUE, new Float(1.0f)); /** * A constant {@link AnimationFunction} that returns * 0.0f all the time. */ public static final AnimationFunction ZERO = constant(Integer.MAX_VALUE, new Float(0.0f)); private AnimationFunctions() { // Overrides the default constructor; prevents instantiation. } /** * Creates and returns an animation function that returns time-based * sRGB colors that are built from a given base color and * an animation function of alpha values. *

* Useful for fading effects. * * @param f the animation function of alpha values * @param baseColor the base color * @return an animation function of colors */ public static AnimationFunction alphaColor( AnimationFunction f, Color baseColor) { return new AlphaColorAnimationFunction(f, baseColor); } /** * Creates a time-based function that wraps the given Float-based animation * function to return the corresponding float values. * * @param f the underlying animation function of floats * @return an animation function the returns Float objects */ public static FloatFunction asFloat(AnimationFunction f) { return new FloatFunction(f); } /** * Concatenates the fiven animation functions and returns a compound * animation function that represents the concatenation. * * @param first the concatenation's first AnimationFunction * @param second the concatenation's second AnimationFunction * @return the concatenated animation function */ public static AnimationFunction concat( AnimationFunction first, AnimationFunction second) { List sequence = new LinkedList(); sequence.add(first); sequence.add(second); return new SequencedAnimationFunction(sequence); } /** * Creates and returns an animation function that returns a constant value * over the given duration. * * @param duration the function's duration * @param value the Object that will be returned all the time * @return a constant animation function */ public static AnimationFunction constant(long duration, Object value) { return discrete(duration, new Object[] { value }); } /** * Creates and returns a discrete animation function for the * given duration and values. The values are equally distributed * over the duration. * * @param duration the function's duration * @param values an array of discrete result values * @return a discrete animation function */ public static AnimationFunction discrete( long duration, Object[] values) { return discrete(duration, values, null); } /** * Creates and returns a discrete animation function for the given duration, * values and interpolation key times. * * @param duration the function's duration * @param values an array of discrete result values * @param keyTimes an array of key times used to distribute the * result values over the time * @return a discrete animation function */ public static AnimationFunction discrete( long duration, Object[] values, float[] keyTimes) { return new InterpolatedAnimationFunction( duration, values, keyTimes, InterpolatedAnimationFunction.MODE_DISCRETE); } /** * Creates and returns a linear animation function for the given duration * that returns Float in interval [from, from + by]. * * @param duration the animation duration * @param from the initial result value * @param by the difference that is added to the initial value * @return a linear animation function with values in [from, from + by] */ public static AnimationFunction fromBy( long duration, float from, float by) { return fromTo(duration, from, from + by); } /** * Ceates and returns a linear animation function with the given duration. * The function values are Floats in the intervall [from, to]. * * @param duration the animation duration * @param from the initial result value * @param to the last result value * @return a linear animation function with values in [from, to] */ public static AnimationFunction fromTo( long duration, float from, float to) { return linear( duration, new Float[] { new Float(from), new Float(to)}); } /** * Creates and returns a linear animation function that is defined * by an array of numeric values; these are distributed equally * over the duration. * * @param duration the animation duration * @param values an array of values * @return a linear animation function for the given values */ public static AnimationFunction linear(long duration, Object[] values) { return linear(duration, values, null); } /** * Creates and returns a linear animation function that is defined * by an array of numeric values and an array of relative key times. * * @param duration the animation duration * @param values an array of values * @param keyTimes an array of key times used to distribute the * result values over the time * @return a linear animation function for the given values */ public static AnimationFunction linear( long duration, Object[] values, float[] keyTimes) { return new InterpolatedAnimationFunction( duration, values, keyTimes, InterpolatedAnimationFunction.MODE_LINEAR); } /** * Creates an AnimationFunction that maps times * to instances of Color. The mapping is interpolated * from an array of Colors using an array of key times. * * @param duration the duration of this animation function * @param colors the colors to interpolate. * @param keyTimes an array of key times used to distribute * the result values over the time. * @return An {@link AnimationFunction} that maps times to sRGB colors. * This mapping is defined by an arry of Color values * and a corresponding array of key times that is used to interpolate * sub-AnimationFunction for the red, green, blue and alpha values. */ public static AnimationFunction linearColors( long duration, Color[] colors, float[] keyTimes) { return new ColorFunction(duration, colors, keyTimes); } /** * Creates and returns an animation function that returns random values * from the interval [min, max] with a given change probability. * * @param min the minimum result value * @param max the maximum result value * @param changeProbability the probability that the value changes * @return an animation function with random values in [min, max] */ public static AnimationFunction random( int min, int max, float changeProbability) { return new RandomAnimationFunction(min, max, changeProbability); } /** * Creates and returns an animation function that is defined * by repeating the specified animation function. * * @param f the animation function to repeat * @param repeatTime the time to repeat the function * @return the repeated animation function */ public static AnimationFunction repeat( AnimationFunction f, long repeatTime) { return new RepeatedAnimationFunction(f, repeatTime); } /** * Creates and returns an animation function that is defined * by reverting the given animation function in time. * * @param f the animation function to reverse * @return the reversed animation function */ public static AnimationFunction reverse(AnimationFunction f) { return new ReversedAnimationFunction(f); } // Helper Classes ********************************************************* /** * Helper class for animation functions that answer translucent colors. */ private static final class AlphaColorAnimationFunction implements AnimationFunction { private final Color baseColor; private final AnimationFunction fAlpha; private AlphaColorAnimationFunction( AnimationFunction fAlpha, Color baseColor) { this.fAlpha = fAlpha; this.baseColor = baseColor; } public long duration() { return fAlpha.duration(); } // Constructs colors from the sRGB color space. public Object valueAt(long time) { int alpha = ((Float) fAlpha.valueAt(time)).intValue(); return new Color( baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), alpha); } } /** * Helper class for interpolating colors. */ private static final class ColorFunction extends AbstractAnimationFunction { /** * Refers to an AnimationFunction of float values that maps * a time to the red component of an sRGB color value. */ private final AnimationFunctions.FloatFunction redFunction; /** * Refers to an AnimationFunction of float values that maps * a time to the green component of an sRGB color value. */ private final AnimationFunctions.FloatFunction greenFunction; /** * Refers to an AnimationFunction of float values that maps * a time to the blue component of an sRGB color value. */ private final AnimationFunctions.FloatFunction blueFunction; /** * Refers to an AnimationFunction of float values that maps * a time to the alpha value of an sRGB color value. */ private final AnimationFunctions.FloatFunction alphaFunction; // Instance creation ****************************************************** /** * Creates an AnimationFunction that maps times * to instances of Color. The mapping is interpolated * from an array of Colors using an array of key times. * * @param duration the duration of this animation function * @param colors the colors to interpolate. * @param keyTimes an array of key times used to distribute * the result values over the time. */ private ColorFunction(long duration, Color[] colors, float[] keyTimes) { super(duration); Float[] red = new Float[colors.length]; Float[] green = new Float[colors.length]; Float[] blue = new Float[colors.length]; Float[] alpha = new Float[colors.length]; for (int i = 0; i < colors.length; i++) { red[i] = new Float(colors[i].getRed()); green[i] = new Float(colors[i].getGreen()); blue[i] = new Float(colors[i].getBlue()); alpha[i] = new Float(colors[i].getAlpha()); } redFunction = AnimationFunctions.asFloat(AnimationFunctions.linear( duration, red, keyTimes)); greenFunction = AnimationFunctions.asFloat(AnimationFunctions.linear( duration, green, keyTimes)); blueFunction = AnimationFunctions.asFloat(AnimationFunctions.linear( duration, blue, keyTimes)); alphaFunction = AnimationFunctions.asFloat(AnimationFunctions.linear( duration, alpha, keyTimes)); } // AnimationFunction Implementation *************************************** /** * Returns the interpolated color for a given time in the valid * time interval. This method is required to implement the * AnimationFunction interface and just forwards to the type-safe * counterpart #colorValueAt * * @param time the time used to determine the interpolated color * @return the interpolated color for the given time * @see ColorFunction#colorValueAt(long) */ public Object valueAt(long time) { return colorValueAt(time); } /** * Returns the interpolated color for a given time in the valid * time interval. * * @param time the time used to determine the interpolated color. * @return the interpolated color for the given time * @see ColorFunction#valueAt(long) */ private Color colorValueAt(long time) { checkTimeRange(time); return new Color( (int) redFunction.valueAt(time), (int) greenFunction.valueAt(time), (int) blueFunction.valueAt(time), (int) alphaFunction.valueAt(time)); } } /** * Helper class that wraps a Float-based animation function to answer floats. */ public static class FloatFunction { private final AnimationFunction f; FloatFunction(AnimationFunction f) { this.f = f; } public long duration() { return f.duration(); } public float valueAt(long time) { return ((Number) f.valueAt(time)).floatValue(); } } /** * Helper class for interpolation based animation functions. */ private static final class InterpolatedAnimationFunction extends AbstractAnimationFunction { static final int MODE_DISCRETE = 1; static final int MODE_LINEAR = 2; private final float[] keyTimes; private final int mode; /* Left for long winter nights in northern Germany. static final int MODE_PACED = 4; static final int MODE_SPLINE = 8; */ private final Object[] values; private InterpolatedAnimationFunction( long duration, Object[] values, float[] keyTimes, int mode) { super(duration); this.values = values; this.keyTimes = keyTimes; this.mode = mode; checkValidKeyTimes(values.length, keyTimes); } private void checkValidKeyTimes(int valuesLength, float[] theKeyTimes) { if (theKeyTimes == null) return; if (valuesLength < 2 || valuesLength != theKeyTimes.length) throw new IllegalArgumentException("The values and key times arrays must be non-empty and must have equal length."); for (int index = 0; index < theKeyTimes.length - 2; index++) { if (theKeyTimes[index] >= theKeyTimes[index + 1]) throw new IllegalArgumentException("The key times must be increasing."); } } private Object discreteValueAt(long time) { return values[indexAt(time, values.length)]; } private int indexAt(long time, int intervalCount) { long duration = duration(); // Gleichlange Zeitabschnitte if (keyTimes == null) { return (int) (time * intervalCount / duration); } for (int index = keyTimes.length - 1; index > 0; index--) { if (time >= duration * keyTimes[index]) return index; } return 0; } /** * Currently we provide only linear interpolations that are based on floats. * * @param value1 the first interpolation key point * @param value2 the second interpolation key point * @param time the time to get an interpolated value for * @param duration the duration of the whole animation * @return the interpolated value at the given time */ private Object interpolateLinear( Object value1, Object value2, long time, long duration) { float f1 = ((Number) value1).floatValue(); float f2 = ((Number) value2).floatValue(); float value = f1 + (f2 - f1) * time / duration; return new Float(value); } private Object linearValueAt(long time) { int segments = values.length - 1; int beginIndex = indexAt(time, segments); int endIndex = beginIndex + 1; long lastTime = duration() - 1; long beginTime = keyTimes == null ? beginIndex * lastTime / segments : (long) (keyTimes[beginIndex] * lastTime); long endTime = keyTimes == null ? endIndex * lastTime / segments : (long) (keyTimes[endIndex] * lastTime); return interpolateLinear( values[beginIndex], values[endIndex], time - beginTime, endTime - beginTime); } public Object valueAt(long time) { checkTimeRange(time); switch (mode) { case MODE_DISCRETE : return discreteValueAt(time); case MODE_LINEAR : return linearValueAt(time); default : throw new IllegalStateException("Unsupported interpolation mode."); } } } /** * Helper class for animation function that answer random values. */ private static final class RandomAnimationFunction implements AnimationFunction { private final float changeProbability; private final int max; private final int min; private final Random random; private Object value; private RandomAnimationFunction( int min, int max, float changeProbability) { this.random = new Random(); this.min = min; this.max = max; this.changeProbability = changeProbability; } public long duration() { return Integer.MAX_VALUE; } public Object valueAt(long time) { if ((value == null) || (random.nextFloat() < changeProbability)) { value = new Integer(min + random.nextInt(max - min)); } return value; } } /** * Helper class used to repeat or sequence an animation function. */ private static final class RepeatedAnimationFunction extends AbstractAnimationFunction { private final AnimationFunction f; private final long simpleDuration; private RepeatedAnimationFunction( AnimationFunction f, long repeatTime) { super(repeatTime); this.f = f; this.simpleDuration = f.duration(); } public Object valueAt(long time) { return f.valueAt(time % simpleDuration); } } /** * Helper class for reversing an animation function. */ private static final class ReversedAnimationFunction extends AbstractAnimationFunction { private final AnimationFunction f; private ReversedAnimationFunction(AnimationFunction f) { super(f.duration()); this.f = f; } public Object valueAt(long time) { return f.valueAt(duration() - time); } } /** * Helper class to compose an animation functions from a sequences of such functions. */ private static final class SequencedAnimationFunction implements AnimationFunction { private final List functions; private SequencedAnimationFunction(List functions) { this.functions = Collections.unmodifiableList(functions); if (this.functions.isEmpty()) throw new IllegalArgumentException("The list of functions must not be empty."); } public long duration() { long cumulatedDuration = 0; for (Iterator i = functions.iterator(); i.hasNext();) { AnimationFunction f = (AnimationFunction) i.next(); cumulatedDuration += f.duration(); } return cumulatedDuration; } public Object valueAt(long time) { if (time < 0) throw new IllegalArgumentException("The time must be positive."); long begin = 0; long end; for (Iterator i = functions.iterator(); i.hasNext();) { AnimationFunction f = (AnimationFunction) i.next(); end = begin + f.duration(); if (time < end) return f.valueAt(time - begin); begin = end; } throw new IllegalArgumentException("The time must be smaller than the total duration."); } } }animation-1.2.0/src/core/com/jgoodies/animation/AnimationListener.java0000644000175000017500000000452410444605612026005 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import java.util.EventListener; /** * Defines an interface for objects that listen to animation events. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ * * @see AnimationEvent * @see AnimationAdapter */ public interface AnimationListener extends EventListener { /** * Invoked if the animation has been started. * * @param evt the related AnimationEvent */ void animationStarted(AnimationEvent evt); /** * Invoked if the animation has been stopped. * * @param evt the related AnimationEvent */ void animationStopped(AnimationEvent evt); }animation-1.2.0/src/core/com/jgoodies/animation/AnimationRenderer.java0000644000175000017500000000443710444605612025771 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import java.awt.Graphics2D; /** * This interface describes renderers for use in animations and so helps build * render containers and animated panels. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public interface AnimationRenderer { /** * Renders the animation on the specified graphics object * using the given width and height. * * @param g2 the graphics to render on * @param width the used width of the render surface * @param height the used height of the render surface */ void render(Graphics2D g2, int width, int height); }animation-1.2.0/src/core/com/jgoodies/animation/AnimationUtils.java0000644000175000017500000000666610444605612025331 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import javax.swing.SwingUtilities; /** * Provides some behavior useful in the animation framework, * or to implement custom animation functions and animations. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class AnimationUtils { private AnimationUtils() { // Override the default constructor; prevents instantiation. } /** * Invokes the given runnable when the specified animation stopped. * * @param animation the animation that is observed * @param runnable the runnable that will be executed on animation stop */ public static void invokeOnStop(Animation animation, Runnable runnable) { animation.addAnimationListener(new StopListener(runnable)); } /** * Returns an array of strings by splitting a given text * into tokens, that are separated by the '|' character. * * @param separatedTexts a string that encodes a bunch of texts * separated by a | character * @return an array of the separated texts * @deprecated Use {@link String#split(java.lang.String)} instead. */ public static String[] splitTexts(String separatedTexts) { return separatedTexts.split("\\|"); } // Helper Code *********************************************************** /** * Performs a runnable at animation stop. */ private static final class StopListener extends AnimationAdapter { private final Runnable runnable; private StopListener(Runnable runnable) { this.runnable = runnable; } public void animationStopped(AnimationEvent e) { SwingUtilities.invokeLater(runnable); } } }animation-1.2.0/src/core/com/jgoodies/animation/Animations.java0000644000175000017500000002752710444605612024472 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; /** * This class consists only of static methods that either * operate on animations or create useful standard animations. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class Animations { private Animations() { // Overrides the default constructor; prevents instantiation. } /** * Creates and returns an animation that is defined by a given * animation and offset; the resulting animation applies * the original effect shifted in time. * * @param beginTime the time to begin the shifted animation * @param animation the animation to shift * @return the shifted animation */ public static Animation offset(long beginTime, Animation animation) { return new OffsetAnimation(beginTime, animation); } /** * Creates and returns a parallel time container, that is an animation * that applies the effect of the given animations all at the same time. * * @param animations a List of animations * @return a parallel time container for the given animations */ public static Animation parallel(List animations) { return new ParallelAnimation(animations); } /** * Creates and returns a parallel time container for the given animations, * that is an animation that applies the effect of the given animations * at the same time. * * @param animation1 one of the animations to parallelize * @param animation2 the other animation to parallelize * @return the parallelized animation */ public static Animation parallel(Animation animation1, Animation animation2) { List list = new LinkedList(); list.add(animation1); list.add(animation2); return parallel(list); } /** * Creates and returns a pausing animation that has no effect * but a duration. It is useful in combination with sequenced * and parallel time containers. * * @param duration the pause duration * @return an animation that has no effect */ public static Animation pause(long duration) { return new PauseAnimation(duration); } /** * Creates and answers an animation that is defined by repeating * the given animation. The result's duration is the * duration times repeatCount. * * @param repeatCount the number of repetitions * @param animation the animation to repeat * @return the repeated animation */ public static Animation repeat(float repeatCount, Animation animation) { long duration = (long) (animation.duration() * repeatCount); return new RepeatedAnimation(duration, animation); } /** * Creates and returns an animation that is defined by reverting * the given animation over the time. * * @param animation the animation to reverse * @return the reversed animation */ public static Animation reverse(Animation animation) { return new ReversedAnimation(animation); } /** * Creates and returns a sequenced time container that is an animation, * that concatenates the given list of animations over the time. * * @param animations a List of animations * @return the sequenced animation */ public static Animation sequential(List animations) { return new SequencedAnimation(animations); } /** * Creates and returns a sequenced time container that is an animation, * that concatenates the given array of animations over the time. * * @param animations an array of animations * @return the sequenced animation */ public static Animation sequential(Animation[] animations) { return sequential(Arrays.asList(animations)); } /** * Creates and returns an animation that is defined by concatenating * the two given animations. * * @param first the first animation in the sequence * @param second the second animation in the sequence * @return a sequenced animation */ public static Animation sequential(Animation first, Animation second) { List sequence = new LinkedList(); sequence.add(first); sequence.add(second); return sequential(sequence); } // Helper Classes ********************************************************* /** * Helper class that wraps an animation to give it a time offset. */ private static final class OffsetAnimation extends AbstractAnimation { private final Animation animation; private final long beginTime; private OffsetAnimation(long beginTime, Animation animation) { super(beginTime + animation.duration(), true); this.animation = animation; this.beginTime = beginTime; } protected void applyEffect(long time) { long relativeTime = time - beginTime; if (relativeTime >= 0) animation.animate(relativeTime); } } /** * Used to apply an effect one-time only. */ public abstract static class OneTimeAnimation extends AbstractAnimation { private boolean effectApplied; /** * Constructs a OneTimeAnimation. */ public OneTimeAnimation() { super(0, true); effectApplied = false; } /** * Applies the effect to the animation target, * only if is hasn't been applied before. * * @param time the time used to determine the animation effect */ public void animate(long time) { if (effectApplied) return; fireAnimationStarted(time); applyEffect(time); fireAnimationStopped(time); effectApplied = true; } } /** * Helper class to parallelize animations. */ private static final class ParallelAnimation extends AbstractAnimation { private final List animations; private ParallelAnimation(List animations) { super(maxDuration(animations), true); this.animations = animations; } private static long maxDuration(List animations) { long maxDuration = 0; for (Iterator i = animations.iterator(); i.hasNext();) { Animation animation = (Animation) i.next(); long duration = animation.duration(); if (duration > maxDuration) maxDuration = duration; } return maxDuration; } protected void applyEffect(long time) { for (Iterator i = animations.iterator(); i.hasNext();) { Animation animation = (Animation) i.next(); animation.animate(time); } } } /** * Helper class for a pause, an animation, that has no effect. */ private static final class PauseAnimation extends AbstractAnimation { PauseAnimation(long duration) { super(duration, true); } protected void applyEffect(long time) { // Just pause, do nothing. } } /** * Helper class to repeat an animation. */ private static final class RepeatedAnimation extends AbstractAnimation { private final Animation animation; private final long simpleDuration; private RepeatedAnimation(long duration, Animation animation) { super(duration, true); this.animation = animation; this.simpleDuration = animation.duration(); } protected void applyEffect(long time) { animation.animate(time % simpleDuration); } } /** * Helper class to reverse an animation over the time. */ private static final class ReversedAnimation extends AbstractAnimation { private final Animation animation; private ReversedAnimation(Animation animation) { super(animation.duration(), true); this.animation = animation; } protected void applyEffect(long time) { long reversedTime = duration() - time; if (reversedTime < 0) throw new IllegalArgumentException("The time is outside the valid time interval."); animation.animate(reversedTime); } } /** * Helper class to create a sequence of animations. */ private static final class SequencedAnimation extends AbstractAnimation { private final List animations; private SequencedAnimation(List animations) { super(cumulatedDuration(animations), true); this.animations = Collections.unmodifiableList(animations); if (this.animations.isEmpty()) throw new IllegalArgumentException("The list of animations must not be empty."); } private static long cumulatedDuration(List animations) { long cumulatedDuration = 0; for (Iterator i = animations.iterator(); i.hasNext();) { Animation animation = (Animation) i.next(); cumulatedDuration += animation.duration(); } return cumulatedDuration; } protected void applyEffect(long time) { long startTime = 0; for (Iterator i = animations.iterator(); i.hasNext();) { Animation animation = (Animation) i.next(); long relativeTime = time - startTime; if (relativeTime > 0) animation.animate(relativeTime); startTime += animation.duration(); } } } }animation-1.2.0/src/core/com/jgoodies/animation/Animator.java0000644000175000017500000001361310444605612024131 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; /** * Starts and stops an animation and triggers * the animation at a given frame rate. * * @author Karsten Lentzsch * @version $Revision: 1.1 $ */ public final class Animator implements ActionListener { private final Animation animation; private final Timer timer; private final int framesPerSecond; private long startTime; private long elapsedTime = 0; // Instance Creation ***************************************************** /** * Constructs an Animator for the given animation and frame rate. * * @param animation the animation to animate * @param framesPerSecond the desired frame rate * @throws NullPointerException if the animation is null * @throws IllegalArgumentException if the frame rate is non-positive */ public Animator(Animation animation, int framesPerSecond) { if (animation == null) throw new NullPointerException("The animation must not be null."); if (framesPerSecond <= 0) throw new IllegalArgumentException("The frame rate must be positive."); this.animation = animation; this.framesPerSecond = framesPerSecond; this.timer = createTimer(framesPerSecond); } // ************************************************************************ /** * Returns the animator's animation. * * @return the animator's animation */ public Animation animation() { return animation; } /** * Returns the desired frame rate. * * @return the desired frame rate per second */ public int framesPerSecond() { return framesPerSecond; } /** * Returns the elapsed time since animation start. * * @return time elapsed since the animation start */ public long elapsedTime() { if (!timer.isRunning()) return elapsedTime; long now = System.currentTimeMillis(); if (startTime == -1) { startTime = now; } return now - startTime + elapsedTime; } /** * Starts the animator and in turn the animation. */ public void start() { if (!timer.isRunning()) { registerStopListener(); startTime = -1; timer.start(); } } /** * Stops the animator. */ public void stop() { if (timer.isRunning()) { elapsedTime = elapsedTime(); timer.stop(); } } /** * Implements the ActionListener interface used by the Timer. * * @param e the action event */ public void actionPerformed(ActionEvent e) { // System.out.println("t=" + elapsedTime()); animation.animate(elapsedTime()); } /** * Returns a string representation for the animator. * * @return a string representation for the animator */ public String toString() { return "elapsedTime=" + elapsedTime() + "; fps=" + framesPerSecond; } // Helper Code ************************************************************ /** * Creates and configures a Timer object. * * @param fps the frames per second * @return a Timer with the specified frame rate */ private Timer createTimer(int fps) { int delay = 1000 / fps; Timer aTimer = new Timer(delay, this); aTimer.setInitialDelay(0); aTimer.setCoalesce(true); return aTimer; } /** * Registers a listener that stops the animator if the animation stopped. */ private void registerStopListener() { animation.addAnimationListener(new AnimationAdapter() { public void animationStopped(AnimationEvent e) { //System.out.println("All animations stopped."); stop(); //animation.animate(animation.duration()); } }); } }animation-1.2.0/src/core/com/jgoodies/animation/package.html0000644000175000017500000000465610444605612024004 0ustar twernertwerner Contains the core types of the JGoodies Animation library.

Related Documentation

For more information see: @see com.jgoodies.animation.animations @see com.jgoodies.animation.components @see com.jgoodies.animation.renderer animation-1.2.0/src/test/0000755000175000017500000000000010444605612015177 5ustar twernertwerneranimation-1.2.0/src/test/com/0000755000175000017500000000000010444605612015755 5ustar twernertwerneranimation-1.2.0/src/test/com/jgoodies/0000755000175000017500000000000010444605612017560 5ustar twernertwerneranimation-1.2.0/src/test/com/jgoodies/animation/0000755000175000017500000000000010444605612021537 5ustar twernertwerneranimation-1.2.0/src/test/com/jgoodies/animation/tests/0000755000175000017500000000000010444605612022701 5ustar twernertwerneranimation-1.2.0/src/test/com/jgoodies/animation/tests/AllAnimationTests.java0000644000175000017500000000445410444605612027146 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tests; import junit.framework.Test; import junit.framework.TestSuite; /** * A test suite for all tests related to the JGoodies Animation library. * * @author Karsten Lentzsch * @version $Revision: 1.4 $ */ public final class AllAnimationTests { public static void main(String[] args) { junit.textui.TestRunner.run(AllAnimationTests.class); } public static Test suite() { TestSuite suite = new TestSuite("Test for com.jgoodies.animation"); //$JUnit-BEGIN$ suite.addTest(new TestSuite(AnimationFunctionsTest.class)); //$JUnit-END$ return suite; } } animation-1.2.0/src/test/com/jgoodies/animation/tests/AnimationFunctionsTest.java0000644000175000017500000002444710444605612030227 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tests; import junit.framework.TestCase; import com.jgoodies.animation.AnimationFunction; import com.jgoodies.animation.AnimationFunctions; /** * A test case for class {@link AnimationFunctions}. * * @author Karsten Lentzsch * @version $Revision: 1.6 $ */ public final class AnimationFunctionsTest extends TestCase { private static Float FLOAT_VALUE1 = new Float(5.12f); private static Float FLOAT_VALUE2 = new Float(19.67f); private static Float FLOAT_VALUE3 = new Float(18.5f); private static Float FLOAT_VALUE4 = new Float(19.80f); private static float FROM_VALUE = 1.0f; private static float TO_VALUE = 3.0f; private static float[] KEY_TIMES = {0.0f, 0.25f, 0.5f, 0.75f}; private AnimationFunction constant1; private AnimationFunction constant2; private AnimationFunction discrete1; private AnimationFunction discrete2; private AnimationFunction linear; protected void setUp() throws Exception { super.setUp(); constant1 = AnimationFunctions.constant(1000, FLOAT_VALUE1); constant2 = AnimationFunctions.constant(3000, FLOAT_VALUE2); discrete1 = AnimationFunctions.discrete(4000, new Object[]{ FLOAT_VALUE1, FLOAT_VALUE2, FLOAT_VALUE3, FLOAT_VALUE4}); discrete2 = AnimationFunctions.discrete(4000, new Object[]{ FLOAT_VALUE1, FLOAT_VALUE2, FLOAT_VALUE3, FLOAT_VALUE4}, KEY_TIMES ); linear = AnimationFunctions.fromTo(7000, FROM_VALUE, TO_VALUE); } protected void tearDown() throws Exception { super.tearDown(); constant1 = null; constant2 = null; discrete1 = null; discrete2 = null; linear = null; } /** * Checks if negative durations throw an IllegalArgumentException. */ public void testIllegalDuration() { try { AnimationFunctions.constant(-100, new Integer(42)); fail("Should prevent negative durations."); } catch (IllegalArgumentException e) { // The expected behavior } } /** * Checks if value request outside the duration throw an IllegalArgumentException. */ public void testIllegalInterval() { try { constant1.valueAt(-100); fail("#valueAt should forbid an invalid time (-100)."); } catch (IllegalArgumentException e) { // The expected behavior. } try { constant1.valueAt(-1); fail("#valueAt should forbid an invalid time (-1)."); } catch (IllegalArgumentException e) { // The expected behavior. } try { constant1.valueAt(constant1.duration()); fail("#valueAt should forbid an invalid time (duration)."); } catch (IllegalArgumentException e) { // The expected behavior. } } /** * Checks that #constant answers an AnimationFunction that in turn * answers a sole value over the whole time interval. */ public void testConstant() { long duration1 = constant1.duration(); long step = duration1 / 10; for (long time = 0; time < duration1; time += step) { assertSame( "A constant function should answer a constant value.", constant1.valueAt(time), FLOAT_VALUE1); } } /** * Checks that #concat sums up the durations and answers the related values. */ public void testConcat() { AnimationFunction concatenated = AnimationFunctions.concat(constant1, constant2); long duration1 = constant1.duration(); long duration2 = constant2.duration(); long durationSum = duration1 + duration2; assertEquals("Concat does not sum up the durations.", concatenated.duration(), durationSum); long t0 = 0; long t1 = duration1; long t2 = durationSum - 1; assertSame("concat.valueAt(" + (t0) + ") failed.", concatenated.valueAt(t0), FLOAT_VALUE1); assertSame("concat.valueAt(" + (t1 - 1) + ") failed.", concatenated.valueAt(t1 -1), FLOAT_VALUE1); assertSame("concat.valueAt(" + (t1) + ") failed.", concatenated.valueAt(t1), FLOAT_VALUE2); assertSame("concat.valueAt(" + (t2) + ") failed.", concatenated.valueAt(t2), FLOAT_VALUE2); try { concatenated.valueAt(durationSum); fail("concat.valueAt(totalDuration) is illegal."); } catch (IllegalArgumentException e) { // The expected behavior. } } /** * Checks that a discrete animation function answers the correct values * over the duration. */ public void testDiscrete() { long duration = discrete1.duration(); long intervalLength = duration /4; long t0 = 0; long t1 = 1 * intervalLength; long t2 = 2 * intervalLength; long t3 = 3 * intervalLength; long t4 = duration - 1; assertSame("discrete(" + t0 + ") failed", discrete1.valueAt(t0), FLOAT_VALUE1); assertSame("discrete(" + (t1 - 1) + ") failed", discrete1.valueAt(t1 - 1), FLOAT_VALUE1); assertSame("discrete(" + t1 + ") failed", discrete1.valueAt(t1), FLOAT_VALUE2); assertSame("discrete(" + (t2 - 1) + ") failed", discrete1.valueAt(t2 - 1), FLOAT_VALUE2); assertSame("discrete(" + t2 + ") failed", discrete1.valueAt(t2), FLOAT_VALUE3); assertSame("discrete(" + (t3 - 1) + ") failed", discrete1.valueAt(t3 - 1), FLOAT_VALUE3); assertSame("discrete(" + t3 + ") failed", discrete1.valueAt(t3), FLOAT_VALUE4); assertSame("discrete(" + (t4) + ") failed", discrete1.valueAt(t4), FLOAT_VALUE4); } /** * Checks that a discrete animation function answers the correct values * over the duration. */ public void testDiscreteKeyTimes() { long duration = discrete2.duration(); long t0 = 0; long t1 = (long) (duration * KEY_TIMES[1]); long t2 = (long) (duration * KEY_TIMES[2]); long t3 = (long) (duration * KEY_TIMES[3]); long t4 = duration - 1; assertSame("discrete(" + t0 + ") failed", discrete1.valueAt(t0), FLOAT_VALUE1); assertSame("discrete(" + (t1 - 1) + ") failed", discrete1.valueAt(t1 - 1), FLOAT_VALUE1); assertSame("discrete(" + t1 + ") failed", discrete1.valueAt(t1), FLOAT_VALUE2); assertSame("discrete(" + (t2 - 1) + ") failed", discrete1.valueAt(t2 - 1), FLOAT_VALUE2); assertSame("discrete(" + t2 + ") failed", discrete1.valueAt(t2), FLOAT_VALUE3); assertSame("discrete(" + (t3 - 1) + ") failed", discrete1.valueAt(t3 - 1), FLOAT_VALUE3); assertSame("discrete(" + t3 + ") failed", discrete1.valueAt(t3), FLOAT_VALUE4); assertSame("discrete(" + (t4) + ") failed", discrete1.valueAt(t4), FLOAT_VALUE4); } /** * Checks that a linear animation function answers the correct values * over the duration. */ public void testLinear() { if (!linear.valueAt(0).equals(new Float(FROM_VALUE))) fail("The linear function should answer the from value at t0."); Object expected = new Float(TO_VALUE); Object answered = linear.valueAt(linear.duration() - 1); if (!answered.equals(expected)) fail("The linear function should answer the to value at t1." + "\nanswered=" + answered + "\nexpected=" + expected); } } animation-1.2.0/src/tutorial/0000755000175000017500000000000010444605612016063 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/0000755000175000017500000000000010444605612016641 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/0000755000175000017500000000000010444605612020444 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/0000755000175000017500000000000010444605612022423 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/0000755000175000017500000000000010444605612024266 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/0000755000175000017500000000000010444605612026270 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/AlphaConverter.java0000644000175000017500000000645710444605612032064 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.component; import java.awt.Color; import com.jgoodies.binding.value.AbstractConverter; import com.jgoodies.binding.value.ValueModel; /** * This implementation of ValueModel converts integers * between 0 and 255 to Color instances that use this integer as alpha value. * * @author Karsten Lentzsch * @version $Revision: 1.3 $ * * @see Color */ final class AlphaConverter extends AbstractConverter { /** * Constructs an AlphaConverter on the given subject. * * @param subject the underlying ValueModel */ AlphaConverter(ValueModel subject) { super(subject); } /** * Converts a Color to the color's alpha value. * * @param subjectValue the subject's Color * @return the color's alpha value * @throws ClassCastException if the subject value is not of type * Color */ public Object convertFromSubject(Object subjectValue) { Color color = (Color) subjectValue; return new Integer(color.getAlpha()); } /** * Converts an alpha value between 0 and 255 to a Color with that * integer as brightness. * * @param newValue the new alpha value * @throws ClassCastException if the new value is not of type * Integer */ public void setValue(Object newValue) { int alpha = ((Integer) newValue).intValue(); Color oldColor = (Color) subject.getValue(); subject.setValue(new Color(oldColor.getRed(), oldColor.getGreen(), oldColor.getBlue(), alpha)); } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/AnimatedLabelExample.java0000644000175000017500000001737610444605612033147 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.component; import java.awt.Color; import java.awt.event.ActionEvent; import javax.swing.*; import com.jgoodies.animation.components.AnimatedLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.beans.BeanAdapter; import com.jgoodies.binding.beans.Model; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Demonstrates the features of the {@link AnimatedLabel}. * Consists of a preview panel that displays an AnimatedLabel and a * tools panel to edit its duration, animated state and to change the text. * * @author Karsten Lentzsch * @version $Revision: 1.7 $ */ public final class AnimatedLabelExample extends Model { private static final Color AMAZON_ORANGE = new Color(255, 142, 12); private static final String[] TEXTS = { "The AnimatedLabel", "Uses an Animation", "That Blends Over", "Texts.", "YOU CAN CONFIGURE", "THE DURATION", "AND ANIMATED STATE" }; /** * The current index in the above array of sample texts. */ private int textIndex; /** * Refers to the animated label that is demonstrated in this example. */ private AnimatedLabel animatedLabel; private JTextField durationField; private JComponent animatedBox; private Action nextTextAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: AnimatedLabel"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new AnimatedLabelExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public AnimatedLabelExample() { initComponents(); } // Component Creation and Initialization ********************************** /** * Creates the animated label, duration text field, a check box * for the animated state and an Action to set the new text. */ private void initComponents() { textIndex = 0; // Setup an AnimatedLabel with an Amazon.com organe and a font // 16 pt larger than the dialog font. animatedLabel = new AnimatedLabel(AMAZON_ORANGE, 16, TEXTS[textIndex]); // Create a bean adapter that vends property adapters. BeanAdapter beanAdapter = new BeanAdapter(animatedLabel, true); // Create a text field bound to the label's blend over duration. durationField = BasicComponentFactory.createIntegerField( beanAdapter.getValueModel(AnimatedLabel.PROPERTYNAME_DURATION)); durationField.setColumns(5); animatedBox = BasicComponentFactory.createCheckBox( beanAdapter.getValueModel(AnimatedLabel.PROPERTYNAME_ANIMATED), "animated"); // Create an Action to set the next text. nextTextAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:p:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "50dlu, left:200dlu:grow, 50dlu", "fill:100dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(animatedLabel, new CellConstraints(2, 1)); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "p, 3dlu, p, 6dlu, p, 24dlu:grow, p", "p"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.addLabel("Duration:", cc.xy(1, 1)); builder.add(durationField, cc.xy(3, 1)); builder.add(animatedBox, cc.xy(5, 1)); builder.add(buildButtonBar(), cc.xy(7, 1)); return builder.getPanel(); } private JComponent buildButtonBar() { ButtonBarBuilder builder = new ButtonBarBuilder(); builder.addGridded(new JButton(nextTextAction)); return builder.getPanel(); } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Next Text"); } public void actionPerformed(ActionEvent e) { if (++textIndex == TEXTS.length) textIndex = 0; animatedLabel.setText(TEXTS[textIndex]); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/BasicTextExample.java0000644000175000017500000003331610444605612032343 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.component; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import javax.swing.*; import com.jgoodies.animation.Animation; import com.jgoodies.animation.AnimationAdapter; import com.jgoodies.animation.AnimationEvent; import com.jgoodies.animation.Animator; import com.jgoodies.animation.animations.BasicTextAnimation; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.adapter.BoundedRangeAdapter; import com.jgoodies.binding.beans.BeanAdapter; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.beans.PropertyAdapter; import com.jgoodies.binding.value.ConverterFactory; import com.jgoodies.binding.value.ValueModel; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Demonstrates the features of the {@link BasicTextLabel}. * Consists of a preview panel that displays a BasicTextLabel, * and a tool panel for configuration the label's properties * and for running default animations on that label. * * @author Karsten Lentzsch * @version $Revision: 1.10 $ * * @see com.jgoodies.animation.animations.BasicTextAnimation * @see com.jgoodies.animation.animations.BasicTextAnimations * @see com.jgoodies.animation.renderer.BasicTextRenderer */ public final class BasicTextExample extends Model { private static final String PROPERTYNAME_DURATION = "duration"; private static final String INITIAL_TEXT = "BasicTextLabel"; private BasicTextLabel textLabel; private JComponent textField; private JSlider alphaSlider; private JSlider scaleSlider; private JSlider spaceSlider; private int duration; private JComponent durationField; private Action fadeAction; private Action scaleAction; private Action spaceAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Basic Text"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new BasicTextExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public BasicTextExample() { duration = 4000; initComponents(); } // Bound Properties ******************************************************* public int getDuration() { return duration; } public void setDuration(int newDuration) { int oldDuration = getDuration(); duration = newDuration; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Setup a BasicTextLabel with dark gray, bold Tahoma 24 pt. textLabel = new BasicTextLabel(INITIAL_TEXT); textLabel.setFont(new Font("Tahoma", Font.BOLD, 24)); textLabel.setColor(Color.DARK_GRAY); // Create a bean adapter that vends property adapters. BeanAdapter beanAdapter = new BeanAdapter(textLabel, true); // Create a text field bound to the label's text. textField = BasicComponentFactory.createTextField( beanAdapter.getValueModel(BasicTextLabel.PROPERTYNAME_TEXT), false); // Create a slider for the color alpha value. alphaSlider = new JSlider(); ValueModel colorAdapter = beanAdapter.getValueModel(BasicTextLabel.PROPERTYNAME_COLOR); alphaSlider.setModel(new BoundedRangeAdapter( new AlphaConverter(colorAdapter), 0, 0, 255)); // Create a slider for the text label's scale in interval [0.5, 3]. scaleSlider = new JSlider(); ValueModel scaleAdapter = beanAdapter.getValueModel(BasicTextLabel.PROPERTYNAME_SCALE); scaleSlider.setModel(new BoundedRangeAdapter( ConverterFactory.createFloatToIntegerConverter(scaleAdapter, 100), 0, 50, 300)); // Create a slider for the text glyph space in interval [-10, 20]. spaceSlider = new JSlider(); ValueModel spaceAdapter = beanAdapter.getValueModel(BasicTextLabel.PROPERTYNAME_SPACE); spaceSlider.setModel(new BoundedRangeAdapter( ConverterFactory.createFloatToIntegerConverter(spaceAdapter, 100), 0, -1000, 2000)); // Create a text field bound to the duration. durationField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_DURATION)); // Create Actions for three default animations fadeAction = new FadeAction(); scaleAction = new ScaleAction(); spaceAction = new SpaceAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:200dlu:grow", "fill:100dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(textLabel, new CellConstraints()); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 25dlu, pref", "fill:pref"); //layout.setColumnGroups(new int[][]{{1, 3}}); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.add(buildPropertiesPanel(), cc.xy(1, 1)); builder.add(buildAnimationsPanel(), cc.xy(3, 1)); return builder.getPanel(); } private JComponent buildPropertiesPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, right:pref, 2dlu, 60dlu, 2dlu, right:pref", "p, 6dlu, p, 6dlu, p, 6dlu, p, 6dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Properties", cc.xyw(1, 1, 7)); builder.addLabel("Text:", cc.xy (1, 3)); builder.add(textField, cc.xyw(3, 3, 5)); addSlider(builder, 5, "Alpha:", alphaSlider, "0", "255"); addSlider(builder, 7, "Scale:", scaleSlider, "0.5", "3"); addSlider(builder, 9, "Space:", spaceSlider, "-10", "20"); return builder.getPanel(); } private JComponent buildAnimationsPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, 40dlu, 0:grow", "p, 6dlu, p, 9dlu, p:grow"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Animations", cc.xyw(1, 1, 4)); builder.addLabel("Duration:", cc.xy (1, 3)); builder.add(durationField, cc.xy (3, 3)); builder.add(buildButtonBar(), cc.xyw(1, 5, 4, "fill, bottom")); return builder.getPanel(); } private JComponent buildButtonBar() { ButtonBarBuilder builder = new ButtonBarBuilder(); builder.addGridded(new JButton(fadeAction)); builder.addRelatedGap(); builder.addGridded(new JButton(scaleAction)); builder.addRelatedGap(); builder.addGridded(new JButton(spaceAction)); return builder.getPanel(); } private void addSlider(PanelBuilder builder, int row, String title, JSlider slider, String leftText, String rightText) { CellConstraints cc = new CellConstraints(); builder.addLabel(title, cc.xy(1, row)); builder.addLabel(leftText, cc.xy(3, row)); builder.add(slider, cc.xy(5, row)); builder.addLabel(rightText, cc.xy(7, row)); } // Animation Actions ************************************************************ private void setActionsEnabled(boolean enabled) { fadeAction.setEnabled(enabled); scaleAction.setEnabled(enabled); spaceAction.setEnabled(enabled); } private abstract class AnimationAction extends AbstractAction { private AnimationAction(String text) { super(text); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } abstract Animation createAnimation(); } private final class FadeAction extends AnimationAction { private FadeAction() { super("Fade"); } public Animation createAnimation() { return BasicTextAnimation.defaultFade(textLabel, getDuration(), textLabel.getText(), Color.DARK_GRAY); } } private final class ScaleAction extends AnimationAction { private ScaleAction() { super("Scale"); } public Animation createAnimation() { return BasicTextAnimation.defaultScale(textLabel, getDuration(), textLabel.getText(), Color.DARK_GRAY); } } private final class SpaceAction extends AnimationAction { private SpaceAction() { super("Space"); } public Animation createAnimation() { return BasicTextAnimation.defaultSpace(textLabel, getDuration(), textLabel.getText(), Color.DARK_GRAY); } } /** * Disables the actions at animation start and enables them * when the animation stopped. Also restores the text label's text. */ private final class StartStopHandler extends AnimationAdapter { private String text; public void animationStarted(AnimationEvent e) { setActionsEnabled(false); text = textLabel.getText(); } public void animationStopped(AnimationEvent e) { setActionsEnabled(true); textLabel.setText(text); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/BlurredIcon.java0000644000175000017500000000773110444605612031353 0ustar twernertwernerpackage com.jgoodies.animation.tutorial.component; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import javax.swing.Icon; import javax.swing.ImageIcon; import com.jgoodies.binding.beans.Model; public final class BlurredIcon extends Model implements Icon { public static final String EAGER_INITIALIZATION = "eager"; public static final String LAZY_INITIALIZATION = "lazy"; private static final int PAD = 0; // Parameters private final ImageIcon icon; private final long duration; private final int numOfBuffers; private int index; private long time; // Cached data private boolean hasValidCache = false; private BufferedImage[] buffer = null; // Instance Creation ****************************************************** public BlurredIcon( ImageIcon icon, long duration, int numOfBuffers) { this(icon, duration, numOfBuffers, EAGER_INITIALIZATION); } public BlurredIcon( ImageIcon icon, long duration, int numOfBuffers, String initializationMode) { this.icon = icon; this.duration = duration; this.numOfBuffers = numOfBuffers; index = 0; if (EAGER_INITIALIZATION.equals(initializationMode)) validateCache(); } // ************************************************************************ private ConvolveOp createSimpleBlur() { float f = 1.0f / 8.9f; return new ConvolveOp( new Kernel(3, 3, new float[] { f, f, f, f, f, f, f, f, f }), ConvolveOp.EDGE_NO_OP, null); } private void ensureValidCache() { if (hasValidCache) return; validateCache(); } private int computeIndex(long time) { float f = (float) time / duration; return (int) ((buffer.length - 1) * f); } private void initialize() { int iconWidth = icon.getIconWidth(); int iconHeight = icon.getIconHeight(); int paddedWidth = iconWidth + 2 * PAD; int paddedHeight = iconHeight + 2 * PAD; // Allocating the arrays. buffer = new BufferedImage[numOfBuffers]; ConvolveOp blur = createSimpleBlur(); // Initialize the image. for (int i = 0; i < numOfBuffers; i++) { buffer[i] = /*0 == i ? icon.getImage() :*/ new BufferedImage(paddedWidth, paddedHeight, BufferedImage.TYPE_INT_ARGB); if (i == 0) { Graphics g = buffer[i].getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, paddedWidth, paddedHeight); g.drawImage(icon.getImage(), PAD, PAD, null); } else { blur.filter(buffer[i - 1], buffer[i]); } } } public void release() { hasValidCache = false; buffer = null; //System.out.println("Releasing cache for text " + text); } private void validateCache() { initialize(); hasValidCache = true; //System.out.println("Validating cache for text " + text); } // Implementing the Icon Interface **************************************** public int getIconWidth() { return icon.getIconWidth() + 2 * PAD; } public int getIconHeight() { return icon.getIconHeight() + 2 * PAD; } public void paintIcon(Component c, Graphics g, int x, int y) { ensureValidCache(); //int x0 = (width - buffer[0].getWidth()) / 2; //int y0 = (height - buffer[0].getHeight()) / 2; g.drawImage(buffer[getIndex()], x, y, null); } // API ******************************************************************** public int getIndex() { return index; } public long getTime() { return time; } public void setTime(long newTime) { long oldTime = getTime(); time = newTime; index = computeIndex(time); firePropertyChange("time", oldTime, newTime); } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/BlurredIconExample.java0000644000175000017500000002060010444605612032655 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.component; import java.awt.Color; import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.net.URL; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.binding.adapter.BoundedRangeAdapter; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.beans.PropertyAdapter; import com.jgoodies.binding.value.ConverterFactory; import com.jgoodies.binding.value.ValueModel; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Demonstrates the BlurredIcon. * * @author Karsten Lentzsch * @version $Revision: 1.6 $ */ public final class BlurredIconExample extends Model { private static final String ICON_FILENAME = "com/jgoodies/animation/tutorial/component/JavaOne.jpg"; private static final long DURATION = 2000; private BlurredIcon blurredIcon; private JLabel iconLabel; private JSlider timeSlider; private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: BlurredIcon"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new BlurredIconExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public BlurredIconExample() { initComponents(); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Load the JavaOne logo. URL url = getClass().getClassLoader().getResource(ICON_FILENAME); ImageIcon javaOneLogo = new ImageIcon(url); // Setup a BlurredIcon with a JavaOne logo. blurredIcon = new BlurredIcon(javaOneLogo, DURATION, 100); // Have a label that uses the blurred Icon iconLabel = new JLabel(blurredIcon); // Create a slider for the label's time in interval [0, 5000] timeSlider = new JSlider(); ValueModel timeAdapter = new PropertyAdapter(blurredIcon, "time", true); timeSlider.setModel(new BoundedRangeAdapter( ConverterFactory.createLongToIntegerConverter(timeAdapter), 0, 0, (int) DURATION)); timeAdapter.addValueChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { iconLabel.repaint(); } }); // Create an Action to animate the blur effect animateAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:200dlu:grow", "fill:150dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(iconLabel, new CellConstraints()); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 3dlu, 50dlu, 12dlu, 50dlu", "pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.addLabel("Time", cc.xy(1, 1)); builder.add(timeSlider, cc.xy(3, 1)); builder.add(new JButton(animateAction), cc.xy(5, 1)); return builder.getPanel(); } // Animation ************************************************************** private Animation createAnimation() { Animation blurAnimation = new BlurAnimation(DURATION / 2); return Animations.sequential(Animations.reverse(blurAnimation), blurAnimation); } private final class BlurAnimation extends AbstractAnimation { private BlurAnimation(long duration) { super(duration, true); } public void applyEffect(long time) { blurredIcon.setTime(time*2); iconLabel.repaint(); } } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } } /** * Disables the animate action at animation start and * enables it when the animation stopped. */ private final class StartStopHandler extends AnimationAdapter { public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/GlyphLabelExample.java0000644000175000017500000002574110444605612032503 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.component; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import javax.swing.*; import com.jgoodies.animation.Animation; import com.jgoodies.animation.AnimationAdapter; import com.jgoodies.animation.AnimationEvent; import com.jgoodies.animation.Animator; import com.jgoodies.animation.animations.GlyphAnimation; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.components.GlyphLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.adapter.BoundedRangeAdapter; import com.jgoodies.binding.beans.BeanAdapter; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.value.ConverterFactory; import com.jgoodies.binding.value.ValueModel; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Demonstrates the features of the {@link GlyphLabel}. * Consists of a preview panel that displays a GlyphLabel, * and a tool panel for configuration the label's properties * and for running animations on that label. * * @author Karsten Lentzsch * @version $Revision: 1.10 $ */ public final class GlyphLabelExample extends Model { private static final String PROPERTYNAME_DURATION = "duration"; private static final String INITIAL_TEXT = "GlyphLabel"; private GlyphLabel glyphLabel; private JComponent textField; private JSlider timeSlider; private int duration; private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Glyph Label"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new GlyphLabelExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public GlyphLabelExample() { duration = 4000; initComponents(); } // Bound Properties ******************************************************* public int getDuration() { return duration; } public void setDuration(int newDuration) { int oldDuration = getDuration(); duration = newDuration; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Setup a GlyphLabel with dark gray, bold Tahoma 24 pt. glyphLabel = new GlyphLabel(INITIAL_TEXT, 4000, 150); glyphLabel.setFont(new Font("Tahoma", Font.BOLD, 24)); //glyphLabel.setColor(Color.DARK_GRAY); // Create a bean adapter that vends property adapters. BeanAdapter beanAdapter = new BeanAdapter(glyphLabel, true); // Create a slider for the label's time in interval [0, 2000] timeSlider = new JSlider(); ValueModel timeAdapter = beanAdapter.getValueModel(GlyphLabel.PROPERTYNAME_TIME); timeSlider.setModel(new BoundedRangeAdapter( ConverterFactory.createLongToIntegerConverter(timeAdapter), 0, 0, 2000)); textField = BasicComponentFactory.createTextField( beanAdapter.getValueModel(BasicTextLabel.PROPERTYNAME_TEXT), false); // Create a text field bound to the duration. //durationField = BasicComponentFactory.createIntegerField( // new PropertyAdapter(this, PROPERTYNAME_DURATION)); // Create an Action to animate the GlyphLabel animateAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:200dlu:grow", "fill:100dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(glyphLabel, new CellConstraints()); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 25dlu, pref", "fill:pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.add(buildPropertiesPanel(), cc.xy(1, 1)); builder.add(buildAnimationsPanel(), cc.xy(3, 1)); return builder.getPanel(); } private JComponent buildPropertiesPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, right:pref, 2dlu, 60dlu, 2dlu, right:pref", "p, 6dlu, p, 6dlu, p, 6dlu, p, 6dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Properties", cc.xyw(1, 1, 7)); builder.addLabel("Text:", cc.xy (1, 3)); builder.add(textField, cc.xyw(3, 3, 5)); addSlider(builder, 5, "Time:", timeSlider, "0", "4000"); return builder.getPanel(); } private JComponent buildAnimationsPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, 40dlu, 50dlu:grow", "p, 6dlu, p, 9dlu, p:grow"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Animations", cc.xyw(1, 1, 4)); //builder.addLabel("Duration:", cc.xy (1, 3)); //builder.add(durationField, cc.xy (3, 3)); builder.add(buildButtonBar(), cc.xyw(1, 3, 4, "fill, bottom")); return builder.getPanel(); } private JComponent buildButtonBar() { ButtonBarBuilder builder = new ButtonBarBuilder(); builder.addGridded(new JButton(animateAction)); return builder.getPanel(); } private void addSlider(PanelBuilder builder, int row, String title, JSlider slider, String leftText, String rightText) { CellConstraints cc = new CellConstraints(); builder.addLabel(title, cc.xy(1, row)); builder.addLabel(leftText, cc.xy(3, row)); builder.add(slider, cc.xy(5, row)); builder.addLabel(rightText, cc.xy(7, row)); } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } private Animation createAnimation() { return new GlyphAnimation( glyphLabel, getDuration(), 150, // Ignored glyphLabel.getText()); } } /** * Disables the actions at animation start and enables them * when the animation stopped. Also restores the text label's text. */ private class StartStopHandler extends AnimationAdapter { private String text; public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); text = glyphLabel.getText(); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); glyphLabel.setText(text); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/component/JavaOne.jpg0000644000175000017500000003064010444605612030320 0ustar twernertwernerJFIFddDuckyPAdobed      b    !1Q Aaq"2u8R#v7Bbrst6$U3TdԕW!1qAQa"2Rr5Bb34Ⴒ#sS$TC ?@(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(?P~,Ӎ'Ȇ2qYh8:k߻Hť,/*iԨ$GM)܍pI}jE.(ƒ\J<=5Z`/qvf_Z7pqZ{K4JP@(P @(P 덲uiiV!)JR5*$ $n][cHh"wSn if)AE$T,ૻUq|eSDp iVOibK֢A&Vizӛ} *p[ҿgIR3LՃ= @(P @(P @(Ye_ w͓Q!!ɏ\"tOM?#z6)P @(P @(IuԍzlpTL~ο2p͔>\@4>RiWu2~|9F^1"I&41\2[b6V,BA$tTsQNRx%mds6.Zm2۷\rt j-[rޔ)hhn^n&Ώ;]&aPrmI~$CVg.ͭP8kZEP*J=/7w_~6qn ybyZ+jRY[^MC<궒x=zMbJfI FzGO r1ђȮBj{"Zh9zkR),_"Ro 5m/]Sq=?G$_ڜqO<ܡ=ՍtՍ5 1e6ns 1m8:ϱ3k6 u'>\^( R8+5Z(zok *s\ܯO!sO1&pL" ..ioG#> kD"|F+}]It;{GgЇޘVU]Yz^F +ghohr2fJ}$"@RTUJ|C,}xu2ɚN?-?\~ƶwm`a:2@u>O!'N5MgGzw=̖u֘sSvks|,"Mڐ 䣁i9wN$fa$XO*S~TuRqEKQ'MoE$"Բ_/ݧtn*$8HPnA@\)JFyYἷ}%Zk+YucL"_C"J)qe$CgЦաvoXF=iU|kk{ǯW{13QF[QFՍjqRIԓgR[|RVpӶ[:Rv2q{ Y+RPs=x2ڷtfl]or-eSHXZ$ 6r6xY11\ 5`*D+eODws m7FOKGZ>ma{7d aCÑ5-Hhd+>k_m{ hOgyͲ՗kӮ60@ V@jŝ tUIч2cOP @(+?̫!]Nj;>6t1?@n>I_]`iw_FBV!i BJx OAO+NNj?^.yNy=D6:kp@GܤR758#BB;)9MՆqt1ӄӘtT)kYG}y}zY}Q⪨#joVD{#UIQ&Jjw)O mY^b%<-ܮaC0ݔ&KvQoBo sǔEaoin@Y561RO2(T^pjKCFqNT$$OSLُo2\H ^Eg=䧀>TDķSg?oNQOAQ2{7KB滅:h I 9Oܨ6aG(q]'Yvi)/wv_=WݏI`[Ҧbv mM+G<7;񄩾GY<.hE{qܖ]*X/2LJmzju{iC%GCSܵjJ+dV/GE {#`YKT%uC"]˙wO7/4yjTK>ZXm0Nj2[Oy.)ПRkoRpՉW=ɘSqrQ4b>[۹O|% ؎[GR)GmƮjp3n {G1x$ ]4כƫָa7>R[7#q\YbQi1 {`qJ@BCq)W) F^fbPxxYTkAocSkn lR y M8{+"Ox? @TR- (U^%[ Z-_(x~#!ǴRR~n})}#j=4V(5ONȟ9ޥZ5?q̪.daqOQ,.{ieM]a5>[&?qG VrO5m=f- J(r&GlXPk%O2ZՋ儻k.CURpg̡]̯SQFA NGenܓ]Ҟ,&حŴrXɯRTU,hmW̠ڍ\OeKx/9q6s2weV8KBo ֝J]RAeQx0ਸI >Pi$F :m nGgG#SkZcd 8Rzt(l|aĵCʳ綮W"[/8O"Oگ4ok0.Ngʒ`SE>rgE\۝Kq`DG BG۵*F\Ib"kO =Kyi+CF Km?$kZnWB* Mڰ+*KGtsL 3|rs89#ŎS-@8({L>kI7giw5);ٙb+N3>գ*/{9Zq.W9,=xZJ ȠP @(Ye_ w͓Q!!ɏ\"tOM?#z6)t1A{_#~̶Ύ5& I(zTOڒ]&^ .Ilcz꣧t;cu:tZgmћ\~25fԅȚ-T%D[:ښj+dlcgiV2{9 Ghr0LGKX> SMԫ-N;/`{-^V\'DO^J cyk.T S¤w_8_^r>ہ):-8Vͪ2h:˻dt4y\`Y>L"xr\qfyR;5W9J=\ؐrTLŠ/-TӕIn6bP#`uQۧD}= ˊmJ5k;5gO7Xӵy ߍ=ݷ$ վKv!_җΰ 'Ǎa{5nIQl.Uk7$xkx`gtV#og..|ł@62y+jIu![L_F$XjcKc%ű3܋zAQؠ(ۮ2^GAh &3[G, Iΰؐ=کm?.yZ˟~|<(ls+Qnܿn_s:zwζ܋j2b{uXtqQסCXsNkZ>Fmr>Mt+-Ke咵b;P#`G_}jDGG(uG[Pf"Y4{h:\QW[*9t,ۓv#Gƛ xjd<՟xw ,hޣ]P:J疵QZ^1|}jZ1""VGm^X ]՚΄c0Vۚ,$'nkuwe46t1?@n>I_]`iw_FW]rܴAYb2-}J~*y9EG$ZԺ43I.v+߾7w.7+^?sꖦYa8Y-t d)E}}> ]5NV+:ʕP IMv5P-Rآ6;F6 =jg% Ùo*?aH>oOQ|+msoG,إsq)j:BRG*+׼ ޤ2scN^Ol̗B$;ѻ{ęEOKqZ@F(BAYYCo<) TT\"^'L2-yѠ|X4$uuRemO}=&G<ơޫXQ- 'gtUD>Qu)ww vm<@d0x['KH/}>'Z cP. ؆-a.] 6uAr;me$'JuUj)7Q٪(P ʿ[&CCk7O#Do _7-L6[~Gu>Z_^-O:SA(I<9ZFJKJKn}%?|]yvzJi[54R|PBU x't/թK*/mRF@[#8V{nqŐ!I<~+[&-xWI p) xC \Ao-l^v.b`M >O 3$fQDI-Jili\B)ROWmbdnpt4FۥaKIB1ۼ5*`Ԛח4|3;O"VcaF}&/ۉ'smy7Ki7(wsx~k#,<>]:5yp~qQRU??1Irw3|pSkNuBЃ#kV]^+i}ssy=inGl7Y.]L^VlqDkrYqZwDQ MK#<2ʵ*u,;ؼgȹHKkj͡Z#H׳!HҪpbMO9kU,v{pYD"yt!8Al[RRTyAtN_J6go;M- ߴΊ<>$o,ElX;;RW~<5+2R9_F%'Z]㳺Y}qX s&k6r kEReE%@kq(SX$J;d眿8²!Y,KOTBOuGx%yOI5ԋb|'dsdp|B<޾[֡Z3$ X>ԿIr_U;2w3ME-+W=GqOm]ȹ4~ i.wYSYj[O24!½OގZ_ +RD^I8ҖL,<[Ob \mB<te\n/v3E0lw3KK~=z\Go.+SO#|5=uͬ;kR,i/l/eodx׫=Ť\e 5XJaJ ևmQӫ.F\ucٞ&Dlͱ ^Blޱ*pC*o$+T+AH#CXԥJn։YR-&X6 ߫pS؎H?]RFo5xFJ`b {:$\4OۈF2&9 ڪk.tTJXzyTy5ח^k`r^{]=^w2E;E һO)nCmMz܎sw<,Z+|r8ukPd%e FAbk~L٩;(ܟ<.f HM0Ye qLDo'UIc[ kONRM=/tΟݴzr{qF#'ş(+`jVW(\򻄽(mBB]'A*0E]nN'kW.oCs>B᎔U3̽baȲ"3-ڒt)Rzl%xA-iR-yu[q$O6+B~Sړμ$uuVV)D^I`Gl'MYݢ$Xp6@ZMC pj>*{IT<*lJ$~s.`^~)Y0vϊoX",;T}*QԨIִKQ)SmJAKjObZvn*E<&x/,|.U8ei~q{[ ZdTB_RjX}KXIc8*q12ٖ R9t:ր[ EW(P5,M,ܫfE%%l;TtTC=U*/k:KLj,f~}-<*VGHKD0[\r#̴#B֯ů;HכmZ_ }i>ĺKwT3wN=nc0?H Ph8gZ#OU_FL㧟S$':ݶ=GzbJ_q9$RAݹӴ(5['Iw(44 ImnmVphKu _(J: E" ٬oөlкޙ36_q'TE)*emFU 뤪,R2F{}S,+CzkSnY::5{vAbO$y#8ǖI{ T-G"aފ,K-@ I#qQKG1yWU6&/=&t1x_[k xHn]r%MRy)'C Y, +oI.;*Une(M5%th!ȉYN;ĵ>,Kx`Ud쳛?ֺfN>Dl*ufnڕr$Ian,fvR;-gen1X9}brMjiAh$IW{jERdObaӷVZe3?83blvgh[-[4(x\ԸTxg9Y\!ʁ19̮<mԔ'MHp=&th+fwMvn G_fǎ >"ui±씫ɥZYLS!{3TQ'I 8t$7v?Qͭu=@q-lGP.zuqbo5rs [w !28JHRO2VӢ!I:*aZ.X_噥[qyn:*'o0&A Ch%N pDҍ tVI#gU|[/VũtΪ@(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(P @(animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/intro/0000755000175000017500000000000010444605612025421 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/intro/BasicTextLabelIntro.java0000644000175000017500000002200210444605612032122 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.intro; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.animations.BasicTextAnimation; import com.jgoodies.animation.animations.BasicTextAnimations; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Builds a page that consists of two BasicTextLabels * that render an intro animation. * * @author Karsten Lentzsch * @version $Revision: 1.6 $ * * @see Animation * @see BasicTextLabel */ public final class BasicTextLabelIntro { // UI Components private BasicTextLabel label1; private BasicTextLabel label2; /** * Refers to the Action that starts the intro animation. */ private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: BasicTextLabel Intro"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new BasicTextLabelIntro().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public BasicTextLabelIntro() { //duration = 4000; initComponents(); } // Building ************************************************************* /** * Creates and configures the UI components. */ private void initComponents() { Font font = new Font("Tahoma", Font.BOLD, 18); label1 = new BasicTextLabel(" "); label1.setFont(font); //label1.setBounds(0, 0, 350, 100); label1.setOpaque(false); label2 = new BasicTextLabel(" "); label2.setFont(font); //label2.setBounds(0, 0, 350, 100); label2.setOpaque(false); animateAction = new AnimateAction(); } /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } /** * Builds this intro panel with two overlayed labels in the center. * * @return the panel that contains the two overlayed labels */ public JPanel buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:200dlu:grow", "fill:100dlu:grow"); JPanel panel = new JPanel(layout); CellConstraints cc = new CellConstraints(); panel.setBackground(Color.WHITE); panel.add(label1, cc.xy(1, 1)); panel.add(label2, cc.xy(1, 1)); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "right:pref:grow", "pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.add(new JButton(animateAction), cc.xy(1, 1)); return builder.getPanel(); } // Animation Creation *************************************************** /** * Creates and returns a composed animation for the intro. * * @return the composed animation */ private Animation createAnimation() { Animation welcome = BasicTextAnimation.defaultFade( label1, 2500, "Welcome To", Color.DARK_GRAY); Animation theJGoodiesAnimation = BasicTextAnimation.defaultFade( label1, 3000, "The JGoodies Animation", Color.DARK_GRAY); Animation description = BasicTextAnimations.defaultFade( label1, label2, 2000, -100, "An open source framework|" + "for time-based|real-time animations|in Java.", Color.DARK_GRAY); Animation features = BasicTextAnimations.defaultFade( label1, label2, 3000, 500, "Main Features:", Color.DARK_GRAY); Animation featureList = BasicTextAnimations.defaultFade( label1, label2, 1750, 0, "Seamless|flexible|and powerful integration|with Java.|" + "small library size", Color.DARK_GRAY); Animation all = Animations.sequential( new Animation[] { Animations.pause(1000), welcome, Animations.pause(1000), theJGoodiesAnimation, Animations.pause(1000), description, Animations.pause(1000), features, Animations.pause(1000), featureList, Animations.pause(1500), }); return all; } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } } /** * Disables the actions at animation start and enables them * when the animation stopped. Also restores the text label's text. */ private final class StartStopHandler extends AnimationAdapter { public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/intro/HorizontalBarsIntro.java0000644000175000017500000003035010444605612032242 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.intro; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.util.LinkedList; import java.util.List; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.animation.tutorial.panel.HorizontalBarsPanel; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.beans.PropertyAdapter; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * An intro that combines the HorizontalBarsPanel and a BasicTextLabel. * * @author Karsten Lentzsch * @version $Revision: 1.8 $ */ public final class HorizontalBarsIntro extends Model { private static final Color JAVAONE_RED = new Color(209, 33, 36); // private static final String FLOMP_FILENAME = // "com/jgoodies/animation/tutorial/sound/wav/flomp.wav"; private static final String PROPERTYNAME_DURATION = "duration"; private static final String PROPERTYNAME_PAUSE = "pause"; private HorizontalBarsPanel horizontalBarsPanel; private BasicTextLabel textLabel; private int duration; private long pause; private JComponent durationField; private JComponent pauseField; private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Horizontal Bars Intro"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new HorizontalBarsIntro().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public HorizontalBarsIntro() { duration = 350; pause = 2000; initComponents(); } // Bound Properties ******************************************************* public int getDuration() { return duration; } public void setDuration(int newDuration) { int oldDuration = getDuration(); duration = newDuration; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } public long getPause() { return pause; } public void setPause(long newPause) { long oldPause = getPause(); pause = newPause; firePropertyChange(PROPERTYNAME_PAUSE, oldPause, newPause); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Setup a BasicTextLabel with red, bold Tahoma 24 pt. textLabel = new BasicTextLabel(" "); textLabel.setFont(new Font("Tahoma", Font.BOLD, 24)); textLabel.setColor(JAVAONE_RED); horizontalBarsPanel = new HorizontalBarsPanel(textLabel); horizontalBarsPanel.setBackground(Color.WHITE); durationField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_DURATION)); pauseField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_PAUSE)); // Create an Action to animate the bars animateAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:250dlu:grow", "fill:150dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(horizontalBarsPanel, new CellConstraints()); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 3dlu, 25dlu, 12dlu, pref, 3dlu, 25dlu, 12dlu:grow, 50dlu", "pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.addLabel("Duration", cc.xy(1, 1)); builder.add(durationField, cc.xy(3, 1)); builder.addLabel("Pause", cc.xy(5, 1)); builder.add(pauseField, cc.xy(7, 1)); builder.add(new JButton(animateAction), cc.xy(9, 1)); return builder.getPanel(); } // Animation ************************************************************** private Animation createAnimation() { // Animation soundAnimation = createSoundAnimation(); String WAIT = "wait"; String[] texts = new String[]{ "Welcome", WAIT, "To the JavaOne 2004!", WAIT, "Java on the Desktop", "Is Back!", WAIT, "This Demo Uses", "The JGoodies Animation", "A Framework", "For Time-Based", "Real-Time Animations",WAIT}; List sequence = new LinkedList(); sequence.add(Animations.pause(pause)); int offset = -1; for (int i = 1; i < texts.length; i++) { if ((texts[i].equals(WAIT))) { offset = -2; } else { Animation moveBarsAnimation = new MoveBarsAnimation(texts[i+offset], texts[i], duration); sequence.add(moveBarsAnimation); // sequence.add(soundAnimation == null // ? moveBarsAnimation // : Animations.parallel(soundAnimation, moveBarsAnimation)); offset = -1; } sequence.add(Animations.pause(pause)); } textLabel.setText(texts[0]); return Animations.sequential(sequence); } // private Animation createSoundAnimation() { // try { // ClassLoader loader = getClass().getClassLoader(); // URL url = loader.getResource(FLOMP_FILENAME); // Clip clip = MP3SoundUtils.getOpenClip(url); // return new SoundAnimation(clip, duration); // } catch (Exception e) { // System.out.println("Failed to create the sound animation."); // return null; // } // } private final class MoveBarsAnimation extends AbstractAnimation { private final AnimationFunction fractionFunction; private final AnimationFunction colorFunction; private final AnimationFunction stringFunction; private MoveBarsAnimation(String text1, String text2, long duration) { super(duration, true); fractionFunction = createFractionFunction(duration); colorFunction = AnimationFunctions.alphaColor( createAlphaFunction(duration), JAVAONE_RED); stringFunction = createStringFunction(text1, text2, duration); } private AnimationFunction createFractionFunction(long duration) { return AnimationFunctions.linear( duration, new Float[]{ new Float(0.45f), new Float(1.0d), new Float(0.45f)}, new float[]{ 0.0f, 0.5f, 1.0f}); } private AnimationFunction createAlphaFunction(long duration) { return AnimationFunctions.linear( duration, new Integer[]{ new Integer(255), new Integer(0), new Integer(255)}, new float[]{ 0.0f, 0.5f, 1.0f}); } private AnimationFunction createStringFunction( String text1, String text2, long duration) { return AnimationFunctions.discrete( duration, new String[]{text1, text2}); } public void applyEffect(long time) { Float fraction = (Float) fractionFunction.valueAt(time); horizontalBarsPanel.setFraction(fraction.doubleValue()); textLabel.setColor((Color) colorFunction.valueAt(time)); textLabel.setText((String) stringFunction.valueAt(time)); } } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } } /** * Disables the animate action at animation start and * enables it when the animation stopped. */ private final class StartStopHandler extends AnimationAdapter { public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/intro/VerticalBarsIntro.java0000644000175000017500000002742710444605612031675 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.intro; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.util.LinkedList; import java.util.List; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.animation.tutorial.panel.VerticalBarsPanel; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.beans.PropertyAdapter; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * An intro that combines a VerticalBarsPanel with a BasicTextLabel. * * @author Karsten Lentzsch * @version $Revision: 1.8 $ */ public final class VerticalBarsIntro extends Model { private static final Color JAVAONE_BLUE = new Color(46, 49, 146); // private static final String ZOINK_FILENAME = // "com/jgoodies/animation/tutorial/sound/mp3/zoink.mp3"; private static final String PROPERTYNAME_DURATION = "duration"; private static final String PROPERTYNAME_PAUSE = "pause"; private VerticalBarsPanel verticalBarsPanel; private BasicTextLabel textLabel; private int duration; private long pause; private JComponent durationField; private JComponent pauseField; private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Vertical Bars Intro"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new VerticalBarsIntro().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public VerticalBarsIntro() { duration = 350; pause = 2000; initComponents(); } // Bound Properties ******************************************************* public int getDuration() { return duration; } public void setDuration(int newDuration) { int oldDuration = getDuration(); duration = newDuration; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } public long getPause() { return pause; } public void setPause(long newPause) { long oldPause = getPause(); pause = newPause; firePropertyChange(PROPERTYNAME_PAUSE, oldPause, newPause); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Setup a BasicTextLabel with blue, bold Tahoma 20 pt. textLabel = new BasicTextLabel(" "); textLabel.setFont(new Font("Tahoma", Font.BOLD, 20)); textLabel.setColor(JAVAONE_BLUE); verticalBarsPanel = new VerticalBarsPanel(textLabel); verticalBarsPanel.setBackground(Color.WHITE); verticalBarsPanel.setFraction(0.2); durationField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_DURATION)); pauseField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_PAUSE)); // Create an Action to animate the bars animateAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:275dlu:grow", "50dlu:grow, fill:50dlu, 50dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(verticalBarsPanel, new CellConstraints(1, 2)); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 3dlu, 25dlu, 12dlu, pref, 3dlu, 25dlu, 12dlu:grow, 50dlu", "pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.addLabel("Duration", cc.xy(1, 1)); builder.add(durationField, cc.xy(3, 1)); builder.addLabel("Pause", cc.xy(5, 1)); builder.add(pauseField, cc.xy(7, 1)); builder.add(new JButton(animateAction), cc.xy(9, 1)); return builder.getPanel(); } // Animation ************************************************************** private Animation createAnimation() { // Animation soundAnimation = createSoundAnimation(); String[] texts = new String[]{ "With Swing", "And Java2D", "YOU can build", "Cool Java Apps", "Today!"}; textLabel.setText(texts[0]); List sequence = new LinkedList(); sequence.add(Animations.pause(pause)); for (int i = 1; i < texts.length; i++) { Animation moveBarsAnimation = new MoveBarsAnimation(texts[i-1], texts[i], duration); sequence.add(moveBarsAnimation); // sequence.add(soundAnimation == null // ? moveBarsAnimation // : Animations.parallel(soundAnimation, moveBarsAnimation)); sequence.add(Animations.pause(pause)); } return Animations.sequential(sequence); } // private Animation createSoundAnimation() { // try { // return new SoundAnimation(ZOINK_FILENAME, duration); // } catch (Exception e) { // System.out.println("Failed to create the sound animation."); // return null; // } // } private final class MoveBarsAnimation extends AbstractAnimation { private final AnimationFunction fractionFunction; private final AnimationFunction colorFunction; private final AnimationFunction stringFunction; private MoveBarsAnimation(String text1, String text2, long duration) { super(duration, true); fractionFunction = createFractionFunction(duration); colorFunction = AnimationFunctions.alphaColor( createAlphaFunction(duration), JAVAONE_BLUE); stringFunction = createStringFunction(text1, text2, duration); } private AnimationFunction createFractionFunction(long duration) { return AnimationFunctions.linear( duration, new Float[]{ new Float(0.4f), new Float(0.75d), new Float(0.4f)}, new float[]{ 0.0f, 0.5f, 1.0f}); } private AnimationFunction createAlphaFunction(long duration) { return AnimationFunctions.linear( duration, new Integer[]{ new Integer(255), new Integer(0), new Integer(255)}, new float[]{ 0.0f, 0.5f, 1.0f}); } private AnimationFunction createStringFunction( String text1, String text2, long duration) { return AnimationFunctions.discrete( duration, new String[]{text1, text2}); } public void applyEffect(long time) { Float fraction = (Float) fractionFunction.valueAt(time); verticalBarsPanel.setFraction(fraction.doubleValue()); textLabel.setColor((Color) colorFunction.valueAt(time)); textLabel.setText((String) stringFunction.valueAt(time)); } } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } } /** * Disables the animate action at animation start and * enables it when the animation stopped. */ private final class StartStopHandler extends AnimationAdapter { public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/misc/0000755000175000017500000000000010444605612025221 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/misc/AnimationListenerExample.java0000644000175000017500000002121410444605612033025 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.misc; import java.awt.Color; import java.awt.Font; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.animations.BasicTextAnimation; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * A test class for a bunch of animations. * * @author Karsten Lentzsch * @version $Revision: 1.6 $ * * @see Animation * @see BasicTextLabel */ public final class AnimationListenerExample { private static final int DEFAULT_FRAME_RATE = 30; private JLabel reportLabel; private BasicTextLabel label1; private BasicTextLabel label2; private BasicTextLabel label3; public static void main(String[] args) { // Try to get the framerate from the command-line. int fps = DEFAULT_FRAME_RATE; if (args.length > 0) { try { fps = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.out.println("Could not parse the custom frame rate: " + args[0]); } } System.out.println("The desired framerate is " + fps + '.'); try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Animation Listener"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); AnimationListenerExample example = new AnimationListenerExample(); JComponent panel = example.buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); example.startAnimation(fps); } /** * Constructs an animation demo using the specified frame rate. */ private AnimationListenerExample() { initComponents(); } /** * @param fps the frames per second */ private void startAnimation(int fps) { Runnable runnable = new Runnable() { public void run() { JOptionPane.showMessageDialog(null, "The End."); } }; Animation animation = createComposedAnimation(); AnimationUtils.invokeOnStop(animation, runnable); Animator animator = new Animator(animation, fps); animator.start(); } // Building *************************************************************** /** * Creates and configures the components used by the animations. */ private void initComponents() { Font font = new Font("dialog", Font.BOLD, 16); reportLabel = new JLabel(); label1 = new BasicTextLabel(" "); label1.setFont(font); label2 = new BasicTextLabel(" "); label2.setFont(font); label3 = new BasicTextLabel(" "); label3.setFont(font); } /** * Builds and returns the frame's content pane. * * @return the built content */ private JComponent buildPanel() { initComponents(); FormLayout layout = new FormLayout( "fill:max(250dlu;pref):grow", "fill:pref:grow, 6dlu, f:40dlu, 6dlu, f:40dlu, 6dlu, f:40dlu, 6dlu"); PanelBuilder builder = new PanelBuilder(layout); builder.getPanel().setBackground(Color.WHITE); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.add(reportLabel, cc.xy(1, 1)); builder.add(label1, cc.xy(1, 3)); builder.add(label2, cc.xy(1, 5)); builder.add(label3, cc.xy(1, 7)); return builder.getPanel(); } // Animation Creation ***************************************************** /** * Creates and returns a parallel animation that is composed of * four animations: report, fade, scaling, and spacing. * * @return the composed animation */ private Animation createComposedAnimation() { List animations = new LinkedList(); animations.add(Animations.repeat(5f, new SimpleReportAnimation(reportLabel, 2000))); animations.add(BasicTextAnimation.defaultFade(label1, 5000, "Default Fade", Color.DARK_GRAY)); animations.add(BasicTextAnimation.defaultScale(label2, 4000, "Default Scale", Color.DARK_GRAY)); animations.add(BasicTextAnimation.defaultSpace(label3, 3000, "Default Space", Color.DARK_GRAY)); int count = 1; for (Iterator i = animations.iterator(); i.hasNext();) { Animation element = (Animation) i.next(); element.addAnimationListener(new AnimationLogger("Animation " + count++)); } Animation composedAnimation = Animations.parallel(animations); composedAnimation.addAnimationListener(new AnimationLogger("Composed animation")); return composedAnimation; } // Helper Code *********************************************************** private static final class SimpleReportAnimation extends AbstractAnimation { private final JLabel target; private long frameNumber = 0; private long startTime = -1; /** * Constructs a simple report animation. * * @param target the JLabel used to display * @param duration the animation's duration */ private SimpleReportAnimation(JLabel target, long duration) { super(duration); this.target = target; } /** * Applies the animation effect: sets a text for the time, total time, * iteration, frame number, and - after a second - the total frame rate. * * @param time the current time */ protected void applyEffect(long time) { frameNumber++; long totalTime = totalTime(); float fps = totalTime < 1000 ? 0 : frameNumber * 1000 / totalTime; int iteration = (int) (totalTime / duration()); target.setText( "time=" + time / 1000 + "s" + "; total=" + totalTime / 1000 + "s" + "; iteration=" + iteration + "; frame=" + frameNumber + "; fps= " + fps); } private long totalTime() { if (startTime == -1) { startTime = System.currentTimeMillis(); } return System.currentTimeMillis() - startTime; } } /** * Logs animation events to the console. */ private static final class AnimationLogger extends AnimationAdapter { private final String name; AnimationLogger(String name) { this.name = name; } public void animationStarted(AnimationEvent e) { System.out.println(name + " started."); } public void animationStopped(AnimationEvent e) { System.out.println(name + " stopped."); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/panel/0000755000175000017500000000000010444605612025365 5ustar twernertwerneranimation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/panel/HorizontalBarsExample.java0000644000175000017500000002741710444605612032520 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.panel; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.adapter.BoundedRangeAdapter; import com.jgoodies.binding.beans.BeanAdapter; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.beans.PropertyAdapter; import com.jgoodies.binding.value.ConverterFactory; import com.jgoodies.binding.value.ValueModel; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Demonstrates the features of the {@link HorizontalBarsPanel}. * Consists of a preview panel that displays a BasicTextLabel * as center component of a HorizontalBarPanel. * * @author Karsten Lentzsch * @version $Revision: 1.12 $ */ public final class HorizontalBarsExample extends Model { private static final Color JAVAONE_RED = new Color(209, 33, 36); private static final String PROPERTYNAME_DURATION = "duration"; private static final String INITIAL_TEXT = "HorizontalBarsPanel"; private HorizontalBarsPanel horizontalBarsPanel; private BasicTextLabel textLabel; private JComponent textField; private JSlider fractionSlider; private int duration; private JComponent durationField; private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Horizontal Bars"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new HorizontalBarsExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public HorizontalBarsExample() { duration = 500; initComponents(); } // Bound Properties ******************************************************* public int getDuration() { return duration; } public void setDuration(int newDuration) { int oldDuration = getDuration(); duration = newDuration; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Setup a BasicTextLabel with read, bold Tahoma 24 pt. textLabel = new BasicTextLabel(INITIAL_TEXT); textLabel.setFont(new Font("Tahoma", Font.BOLD, 24)); textLabel.setColor(JAVAONE_RED); horizontalBarsPanel = new HorizontalBarsPanel(textLabel); horizontalBarsPanel.setBackground(Color.WHITE); // Create a bean adapter that vends property adapters. BeanAdapter beanAdapter = new BeanAdapter(horizontalBarsPanel, true); // Create a slider for the panel's fraction in interval [0.0d, 1.0d] fractionSlider = new JSlider(); ValueModel fractionAdapter = beanAdapter.getValueModel( HorizontalBarsPanel.PROPERTYNAME_FRACTION); fractionSlider.setModel(new BoundedRangeAdapter( ConverterFactory.createDoubleToIntegerConverter(fractionAdapter, 100), 0, 0, 100)); textField = BasicComponentFactory.createTextField( new PropertyAdapter(textLabel, BasicTextLabel.PROPERTYNAME_TEXT, true), true); // Create a text field bound to the duration. durationField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_DURATION)); // Create an Action to animate the bars animateAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:200dlu:grow", "fill:150dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(horizontalBarsPanel, new CellConstraints()); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 25dlu, pref", "fill:pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.add(buildPropertiesPanel(), cc.xy(1, 1)); builder.add(buildAnimationsPanel(), cc.xy(3, 1)); return builder.getPanel(); } private JComponent buildPropertiesPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, right:pref, 2dlu, 60dlu, 2dlu, right:pref", "p, 6dlu, p, 6dlu, p, 6dlu, p, 6dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Properties", cc.xyw(1, 1, 7)); builder.addLabel("Text:", cc.xy (1, 3)); builder.add(textField, cc.xyw(3, 3, 5)); addSlider(builder, 5, "Fraction:", fractionSlider, "0", "100"); return builder.getPanel(); } private JComponent buildAnimationsPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, 40dlu, 50dlu:grow", "p, 6dlu, p, 6dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Animation", cc.xyw(1, 1, 4)); builder.addLabel("Duration:", cc.xy (1, 3)); builder.add(durationField, cc.xy (3, 3)); builder.add(buildButtonBar(), cc.xyw(1, 5, 4, "fill, bottom")); return builder.getPanel(); } private JComponent buildButtonBar() { ButtonBarBuilder builder = new ButtonBarBuilder(); builder.addGridded(new JButton(animateAction)); return builder.getPanel(); } private void addSlider(PanelBuilder builder, int row, String title, JSlider slider, String leftText, String rightText) { CellConstraints cc = new CellConstraints(); builder.addLabel(title, cc.xy(1, row)); builder.addLabel(leftText, cc.xy(3, row)); builder.add(slider, cc.xy(5, row)); builder.addLabel(rightText, cc.xy(7, row)); } // Animation ************************************************************** private static final class MoveBarsAnimation extends AbstractAnimation { private final HorizontalBarsPanel panel; private final AnimationFunction fractionFunction; private MoveBarsAnimation(HorizontalBarsPanel horizontalBarsPanel, long duration) { super(duration); panel = horizontalBarsPanel; fractionFunction = AnimationFunctions.linear( duration, new Float[]{ new Float(0.45f), new Float(1.0d), new Float(0.45f)}, new float[]{ 0.0f, 0.4f, 1.0f}); } public void applyEffect(long time) { Float fraction = (Float) fractionFunction.valueAt(time); panel.setFraction(fraction.doubleValue()); } } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } } private Animation createAnimation() { return new MoveBarsAnimation(horizontalBarsPanel, getDuration()); } /** * Disables the actions at animation start and enables them * when the animation stopped. Also restores the text label's text. */ private final class StartStopHandler extends AnimationAdapter { public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/panel/HorizontalBarsPanel.java0000644000175000017500000001234610444605612032157 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.panel; import java.awt.Color; import javax.swing.JComponent; import javax.swing.JPanel; import com.jgoodies.animation.renderer.BasicTextRenderer; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.forms.layout.RowSpec; import com.jgoodies.forms.layout.Sizes; /** * A Swing component that consists of a top, center, bottom separated * by horizontal bars. These bars can be moved up and down. * * @author Karsten Lentzsch * @version $Revision: 1.4 $ * * @see BasicTextRenderer */ public final class HorizontalBarsPanel extends JPanel { // Names of the bound bean properties ************************************* public static final String PROPERTYNAME_COLOR = "color"; public static final String PROPERTYNAME_FRACTION = "fraction"; private double fraction; // Instance Creation ****************************************************** /** * Constructs a panel with horizontal bars and * the given component in its center. * * @param centerComponent the component in the panel's center */ public HorizontalBarsPanel(JComponent centerComponent) { this(null, centerComponent, null); } /** * Constructs a panel with horizontal bars and * the given component in its center. * * @param topComponent the component in the panel's top * @param centerComponent the component in the panel's center * @param bottomComponent the component in the panel's bottom */ public HorizontalBarsPanel( JComponent topComponent, JComponent centerComponent, JComponent bottomComponent) { super(new FormLayout( "fill:pref:grow", "fill:0:grow, 6dlu, fill:0:grow, 6dlu, fill:0:grow")); CellConstraints cc = new CellConstraints(); if (topComponent != null){ add(topComponent, cc.xy(1, 1)); } add(createFiller(), cc.xy(1, 2)); add(centerComponent, cc.xy(1, 3)); add(createFiller(), cc.xy(1, 4)); if (bottomComponent != null) { add(bottomComponent, cc.xy(1, 5)); } setFraction(0.45); } // Public Accessors ******************************************************* public double getFraction() { return fraction; } public void setFraction(double newFraction) { double oldFraction = getFraction(); fraction = newFraction; getFormLayout().setRowSpec(1, createOuterRowSpec(newFraction)); getFormLayout().setRowSpec(3, createCenterRowSpec(newFraction)); getFormLayout().setRowSpec(5, createOuterRowSpec(newFraction)); firePropertyChange(PROPERTYNAME_FRACTION, oldFraction, newFraction); revalidate(); repaint(); } // Helper Code ************************************************************ private JComponent createFiller() { JPanel bar = new JPanel(null); bar.setBackground(Color.GRAY); return bar; } private FormLayout getFormLayout() { return (FormLayout) getLayout(); } private RowSpec createOuterRowSpec(double aFraction) { return new RowSpec(RowSpec.FILL, Sizes.ZERO, aFraction); } private RowSpec createCenterRowSpec(double aFraction) { return new RowSpec(RowSpec.FILL, Sizes.ZERO, 1.0d - aFraction); } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/panel/VerticalBarsExample.java0000644000175000017500000002752010444605612032133 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.panel; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import javax.swing.*; import com.jgoodies.animation.*; import com.jgoodies.animation.components.BasicTextLabel; import com.jgoodies.animation.tutorial.TutorialUtils; import com.jgoodies.binding.adapter.BasicComponentFactory; import com.jgoodies.binding.adapter.BoundedRangeAdapter; import com.jgoodies.binding.beans.BeanAdapter; import com.jgoodies.binding.beans.Model; import com.jgoodies.binding.beans.PropertyAdapter; import com.jgoodies.binding.value.ConverterFactory; import com.jgoodies.binding.value.ValueModel; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.PanelBuilder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; /** * Demonstrates the features of the {@link VerticalBarsPanel}. * Consists of a preview panel that displays a BasicTextLabel * as middle component of a VerticalBarsPanel. * * @author Karsten Lentzsch * @version $Revision: 1.12 $ */ public final class VerticalBarsExample extends Model { private static final Color JAVAONE_BLUE = new Color(46, 49, 146); private static final String PROPERTYNAME_DURATION = "duration"; private static final String INITIAL_TEXT = "VerticalBarsPanel"; private VerticalBarsPanel verticalBarsPanel; private BasicTextLabel textLabel; private JComponent textField; private JSlider fractionSlider; private int duration; private JComponent durationField; private Action animateAction; // Self Starter *********************************************************** public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); } catch (Exception e) { // Likely PlasticXP is not in the class path; ignore. } JFrame frame = new JFrame(); frame.setTitle("Animation Tutorial :: Vertical Bars"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComponent panel = new VerticalBarsExample().buildPanel(); frame.getContentPane().add(panel); frame.pack(); TutorialUtils.locateOnOpticalScreenCenter(frame); frame.setVisible(true); } // Instance Creation ****************************************************** public VerticalBarsExample() { duration = 200; initComponents(); } // Bound Properties ******************************************************* public int getDuration() { return duration; } public void setDuration(int newDuration) { int oldDuration = getDuration(); duration = newDuration; firePropertyChange(PROPERTYNAME_DURATION, oldDuration, newDuration); } // Component Creation and Initialization ********************************** /** * Creates the text label, sliders and animation Actions. * Binds sliders to bound properties of the text label. */ private void initComponents() { // Setup a BasicTextLabel with blue, bold Tahoma 24 pt. textLabel = new BasicTextLabel(INITIAL_TEXT); textLabel.setFont(new Font("Tahoma", Font.BOLD, 24)); textLabel.setColor(JAVAONE_BLUE); verticalBarsPanel = new VerticalBarsPanel(textLabel); verticalBarsPanel.setBackground(Color.WHITE); verticalBarsPanel.setFraction(0.25); // Create a bean adapter that vends property adapters. BeanAdapter beanAdapter = new BeanAdapter(verticalBarsPanel, true); // Create a slider for the panel's fraction in interval [0.0d, 1.0d] fractionSlider = new JSlider(); ValueModel fractionAdapter = beanAdapter.getValueModel( HorizontalBarsPanel.PROPERTYNAME_FRACTION); fractionSlider.setModel(new BoundedRangeAdapter( ConverterFactory.createDoubleToIntegerConverter(fractionAdapter, 100), 0, 0, 100)); textField = BasicComponentFactory.createTextField( new PropertyAdapter(textLabel, BasicTextLabel.PROPERTYNAME_TEXT, true), true); // Create a text field bound to the duration. durationField = BasicComponentFactory.createIntegerField( new PropertyAdapter(this, PROPERTYNAME_DURATION)); // Create an Action to animate the bars animateAction = new AnimateAction(); } // Building ************************************************************* /** * Builds and returns a panel with the preview in the top * and the tool panel in the bottom. * * @return the built panel */ private JComponent buildPanel() { FormLayout layout = new FormLayout( "fill:pref:grow", "fill:pref:grow, p, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(buildPreviewPanel(), cc.xy(1, 1)); builder.addSeparator("", cc.xy(1, 2)); builder.add(buildToolsPanel(), cc.xy(1, 3)); return builder.getPanel(); } public JComponent buildPreviewPanel() { FormLayout layout = new FormLayout( "fill:200dlu:grow", "50dlu:grow, fill:50dlu, 50dlu:grow"); JPanel panel = new JPanel(layout); panel.setBackground(Color.WHITE); panel.add(verticalBarsPanel, new CellConstraints(1, 2)); return panel; } public JComponent buildToolsPanel() { FormLayout layout = new FormLayout( "pref, 25dlu, pref", "fill:pref"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.add(buildPropertiesPanel(), cc.xy(1, 1)); builder.add(buildAnimationsPanel(), cc.xy(3, 1)); return builder.getPanel(); } private JComponent buildPropertiesPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, right:pref, 2dlu, 60dlu, 2dlu, right:pref", "p, 6dlu, p, 6dlu, p, 6dlu, p, 6dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Properties", cc.xyw(1, 1, 7)); builder.addLabel("Text:", cc.xy (1, 3)); builder.add(textField, cc.xyw(3, 3, 5)); addSlider(builder, 5, "Fraction:", fractionSlider, "0", "100"); return builder.getPanel(); } private JComponent buildAnimationsPanel() { FormLayout layout = new FormLayout( "right:pref, 3dlu, 40dlu, 50dlu:grow", "p, 6dlu, p, 6dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addSeparator("Animation", cc.xyw(1, 1, 4)); builder.addLabel("Duration:", cc.xy (1, 3)); builder.add(durationField, cc.xy (3, 3)); builder.add(buildButtonBar(), cc.xyw(1, 5, 4, "fill, bottom")); return builder.getPanel(); } private JComponent buildButtonBar() { ButtonBarBuilder builder = new ButtonBarBuilder(); builder.addGridded(new JButton(animateAction)); return builder.getPanel(); } private void addSlider(PanelBuilder builder, int row, String title, JSlider slider, String leftText, String rightText) { CellConstraints cc = new CellConstraints(); builder.addLabel(title, cc.xy(1, row)); builder.addLabel(leftText, cc.xy(3, row)); builder.add(slider, cc.xy(5, row)); builder.addLabel(rightText, cc.xy(7, row)); } // Animation ************************************************************** private static final class MoveBarsAnimation extends AbstractAnimation { private final VerticalBarsPanel panel; private final AnimationFunction fractionFunction; private MoveBarsAnimation(VerticalBarsPanel verticalBarsPanel, long duration) { super(duration); panel = verticalBarsPanel; fractionFunction = AnimationFunctions.linear( duration, new Float[]{ new Float(0.25f), new Float(0.75d), new Float(0.25f)}, new float[]{ 0.0f, 0.5f, 1.0f}); } public void applyEffect(long time) { Float fraction = (Float) fractionFunction.valueAt(time); panel.setFraction(fraction.doubleValue()); } } // Animation Action ******************************************************* private final class AnimateAction extends AbstractAction { private AnimateAction() { super("Animate"); } public void actionPerformed(ActionEvent e) { Animation animation = createAnimation(); int fps = 30; animation.addAnimationListener(new StartStopHandler()); new Animator(animation, fps).start(); } } private Animation createAnimation() { return new MoveBarsAnimation(verticalBarsPanel, getDuration()); } /** * Disables the actions at animation start and enables them * when the animation stopped. Also restores the text label's text. */ private final class StartStopHandler extends AnimationAdapter { public void animationStarted(AnimationEvent e) { animateAction.setEnabled(false); } public void animationStopped(AnimationEvent e) { animateAction.setEnabled(true); } } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/panel/VerticalBarsPanel.java0000644000175000017500000001246710444605612031603 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial.panel; import java.awt.Color; import javax.swing.JComponent; import javax.swing.JPanel; import com.jgoodies.animation.renderer.BasicTextRenderer; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.ColumnSpec; import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.forms.layout.Sizes; /** * A Swing component that consists of three parts left, middle, right, * separated by vertical bars. These bars can be moved via the bound * bean property fraction. * * @author Karsten Lentzsch * @version $Revision: 1.4 $ * * @see BasicTextRenderer */ public final class VerticalBarsPanel extends JPanel { // Names of the bound bean properties ************************************* public static final String PROPERTYNAME_COLOR = "color"; public static final String PROPERTYNAME_FRACTION = "fraction"; private double fraction; // Instance Creation ****************************************************** /** * Constructs a panel with horizontal bars and * the given component in its center. * * @param middleComponent the component in the panel's center */ public VerticalBarsPanel(JComponent middleComponent) { this(null, middleComponent, null); } /** * Constructs a panel with horizontal bars and * the given component in its center. * * @param leftComponent the component in the panel's top * @param middleComponent the component in the panel's center * @param rightComponent the component in the panel's bottom */ public VerticalBarsPanel( JComponent leftComponent, JComponent middleComponent, JComponent rightComponent) { super(new FormLayout( "fill:0:grow, 6dlu, fill:0:grow, 6dlu, fill:0:grow", "fill:pref:grow")); CellConstraints cc = new CellConstraints(); if (leftComponent != null){ add(leftComponent, cc.xy(1, 1)); } add(createFiller(), cc.xy(2, 1)); add(middleComponent, cc.xy(3, 1)); add(createFiller(), cc.xy(4, 1)); if (rightComponent != null) { add(rightComponent, cc.xy(5, 1)); } setFraction(0.45); } // Public Accessors ******************************************************* public double getFraction() { return fraction; } public void setFraction(double newFraction) { double oldFraction = getFraction(); fraction = newFraction; getFormLayout().setColumnSpec(1, createOuterColumnSpec(newFraction)); getFormLayout().setColumnSpec(3, createMiddleColumnSpec(newFraction)); getFormLayout().setColumnSpec(5, createOuterColumnSpec(newFraction)); firePropertyChange(PROPERTYNAME_FRACTION, oldFraction, newFraction); revalidate(); repaint(); } // Helper Code ************************************************************ private JComponent createFiller() { JPanel bar = new JPanel(null); bar.setBackground(Color.GRAY); return bar; } private FormLayout getFormLayout() { return (FormLayout) getLayout(); } private ColumnSpec createOuterColumnSpec(double aFraction) { return new ColumnSpec(ColumnSpec.FILL, Sizes.ZERO, aFraction); } private ColumnSpec createMiddleColumnSpec(double aFraction) { return new ColumnSpec(ColumnSpec.FILL, Sizes.ZERO, 1.0d - aFraction); } }animation-1.2.0/src/tutorial/com/jgoodies/animation/tutorial/TutorialUtils.java0000644000175000017500000000524710444605612027765 0ustar twernertwerner/* * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * o Neither the name of JGoodies Karsten Lentzsch nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package com.jgoodies.animation.tutorial; import java.awt.Component; import java.awt.Dimension; /** * Consists only of static convenience methods used throughout * the examples of the JGoodies Animation tutorial. * * @author Karsten Lentzsch * @version $Revision: 1.2 $ */ public final class TutorialUtils { private TutorialUtils() { // Suppresses default constructor, ensuring non-instantiability. } // Screen Position ******************************************************** /** * Locates the given component on the screen's center. * * @param component the component to be centered */ public static void locateOnOpticalScreenCenter(Component component) { Dimension paneSize = component.getSize(); Dimension screenSize = component.getToolkit().getScreenSize(); component.setLocation((screenSize.width - paneSize.width) / 2, (int) ((screenSize.height - paneSize.height) * 0.45)); } } animation-1.2.0/LICENSE.txt0000644000175000017500000000323610444605612015260 0ustar twernertwerner The BSD License for the JGoodies Animation ========================================== Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. o Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. o Neither the name of JGoodies Karsten Lentzsch nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. animation-1.2.0/README.html0000644000175000017500000001400410444605612015253 0ustar twernertwerner JGoodies Animation :: README
:: JGOODIES Looks :: Professional Swing Look&Feels

:: Readme :: Animation 1.2 ::

The JGoodies Animation framework enables you to produce sophisticated time-based real-time animations in Java. It has been designed for a seemless, flexible and powerful integration with Java, ease-of-use and a small library size.

The Animation framework requires Java 1.4 or later.

Top Questions

:: Can I use the Animation in a commercial product?
:: How to get started?
:: Where do I get support?
:: How to report a problem?

Distribution Contents

animation-1.2.0.jar   the binary library jar
 
LICENSE.txt   the BSD license agreement
README.html   this readme file
RELEASE-NOTES.txt   Release Notes
build.xml   ANT build file
default.properties   ANT default build properties
 
docs/api   JavaDocs directory
docs/guide.pdf   user's guide
 
lib   libraries required for the tutorial
 
src/core   Java sources for the library core
src/tutorial   Java tutorial sources
src/test   Java sources for unit tests
(c) 2006 JGoodies
 
animation-1.2.0/RELEASE-NOTES.txt0000644000175000017500000000752110444605612016145 0ustar twernertwerner JGoodies Animation Version 1.2 Release Notes INTRODUCTION This release fixes two bugs, ships with an overhauled tutorial, and comes in a new distribution format. BUGS FIXED o Incorrect sector computation in linear interpolations. o Animator startTime is set too early, so that animations with a short duration may never get started and stopped. CHANGES THAT AFFECT THE COMPATIBILITY O AnimatedLabel#animationEnabled -> AnimatedLabel#animated DISTRIBUTION CHANGES The sources now ship in the directory structure used by the CVS. This makes it easier to build the distribution using ANT. If you want to attach the library sources in an IDE, point to folder 'src/core'. OTHER CHANGES: o Corrected implementation title and vendor in the JAR manifest. o Fixed broken package information in the JAR manifest. o Added project name tag to the ANT build file. o Set 'build.compile.source' and 'build.compile.target' to '1.4' in the default.properties; build.xml honors the source setting. o Tutorial cleanup. --------------------------------------------------------------------------- Find below the change history for older releases. JGoodies Animation, Version 1.1.3 Release Notes INTRODUCTION This maintenance release is primarily a documentation cleanup. OTHER CHANGES: o Fixed typo in Intro demo. o Added JavaDoc @version tags to all classes. o Added JavaDoc @see tags to many class comments. o AnimatedLabel#getText now synchronized. --------------------------------------------------------------------------- Find below the change history for older releases. JGoodies Animation, Version 1.1.2 Release Notes INTRODUCTION This maintenance release is primarily a documentation cleanup. And since this version the Animation framework requires Java 1.4. NEW FEATURES o Main: AnimationFunctions.linearColor BUGS FIXED o The background in AnimatedLabel is now transparent. OTHER CHANGES o Added package.html files. o Added many JavaDoc @param tags. --------------------------------------------------------------------------- Find below the change history for older releases. JGoodies Animation, Version 1.1.1 Release Notes INTRODUCTION This release just adds a preliminary version of the AnimatedLabel. NEW FEATURES o Main: Added preliminary version of the AnimatedLabel OTHER CHANGES o Documented empty blocks. --------------------------------------------------------------------------- Find below the change history for older releases. JGoodies Animation, Version 1.1 Release Notes INTRODUCTION This release contains minor bug fixes and brings more documentation. DISTRIBUTION CHANGES o Library sources ship as a single ZIP file o Documentation changed to HTML o Added a test infrastructure and a few tests o Added the Intro example o Removed example code from the library jar BUGS FIXED o Incorrect rounding in interpolations --------------------------------------------------------------------------- 1.0.9 (July-17-2003) o Code is now available under the BSD license o Packaging reflects the new license o Library jar is unobfuscated o Library jar is unsigned o Build overhauled animation-1.2.0/build.xml0000644000175000017500000003310210444605612015251 0ustar twernertwerner animation-1.2.0/default.properties0000644000175000017500000000601110444605612017171 0ustar twernertwerner# ------------------------------------------------------------- # DEFAULT JGOODIES ANIMATION BUILD PROPERTIES # ------------------------------------------------------------- # # DO NOT EDIT THIS FILE IN ORDER TO CUSTOMIZE BUILD PROPERTIES. # CREATE AND EDIT build.properties FILE INSTEAD. # # Project Properties ------------------------------------------ Name=JGoodies Animation name=animation spec.version=1.2 impl.version=1.2.0 dist.version=1_2_0-20060616 spec.title=${Name} API Specification impl.title=${Name} spec.vendor=JGoodies Karsten Lentzsch impl.vendor=JGoodies Karsten Lentzsch copyright.date=2001-2006 copyright.owner=JGoodies Karsten Lentzsch copyright.message=Copyright © ${copyright.date} ${copyright.owner}. All Rights Reserved. top.dir=${basedir} # Source Properties ------------------------------------------- src.dir = ${top.dir}/src src.core.dir = ${src.dir}/core src.test.dir = ${src.dir}/test src.tutorial.dir = ${src.dir}/tutorial docs.dir = ${top.dir}/docs # Library Properties ------------------------------------------ lib.dir = ${top.dir}/lib lib.binding.jar = ${lib.dir}/binding-1.1.1.jar lib.forms.jar = ${lib.dir}/forms-1.0.7.jar lib.jlayer.jar = ${lib.dir}/jl1.0.jar # JavaDoc Properties ------------------------------------------ javadoc.link=http://java.sun.com/j2se/1.4/docs/api/ javadoc.packages=com.jgoodies.animation.* javadoc.overview=${src.core.dir}/overview.html # Build Properties -------------------------------------------- build.compiler.pedantic=false build.compile.debug=on build.compile.deprecation=off build.compile.fork=no build.compile.nowarn=on build.compile.source=1.4 build.compile.target=1.4 build.encoding=ISO-8859-1 build.dir = ${top.dir}/build build.classes.dir = ${build.dir}/classes build.core.dir = ${build.classes.dir}/core build.test.dir = ${build.classes.dir}/test build.tutorial.dir = ${build.classes.dir}/tutorial build.docs.dir = ${build.dir}/docs build.javadocs.dir = ${build.docs.dir}/api build.reports.dir = ${build.dir}/test-reports build.core.jar = ${build.dir}/${name}.jar build.maven.dir = ${build.dir}/maven build.maven.pom.template = ${top.dir}/conf/maven-pom-template.xml # Dist Properties ----------------------------------------------- dist.root.dir = ${top.dir}/dist dist.name = ${name}-${impl.version} deploy.name = ${name}-${dist.version} dist.subdir = ${dist.name} dist.dir = ${dist.root.dir}/${dist.subdir} dist.zip = ${dist.root.dir}/${deploy.name}.zip dist.docs.dir = ${dist.dir}/docs dist.examples.dir = ${dist.dir}/examples dist.lib.dir = ${dist.dir}/lib dist.src.dir = ${dist.dir}/src dist.core.jar = ${dist.dir}/${dist.name}.jar dist.maven.pom = ${build.maven.dir}/pom.xml dist.maven.bin.jar = ${build.maven.dir}/${dist.name}.jar dist.maven.src.jar = ${build.maven.dir}/${dist.name}-sources.jar dist.maven.bundle = ${dist.root.dir}/${dist.name}-bundle.jar