Index: graph/lib/apichanges.xml =================================================================== RCS file: /cvs/graph/lib/apichanges.xml,v --- graph/lib/apichanges.xml 3 Apr 2007 16:59:58 -0000 1.8 +++ graph/lib/apichanges.xml 17 Apr 2007 10:00:22 -0000 @@ -137,6 +137,21 @@ + + + + AnimatorListener added + + + + + + AnimatorListener interface has been added. It allows listening to important events of Animator interface implementation. + Built-in animators are accessible using getters on SceneAnimator class. + + + + Index: graph/lib/manifest.mf =================================================================== RCS file: /cvs/graph/lib/manifest.mf,v --- graph/lib/manifest.mf 4 Apr 2007 12:41:10 -0000 1.8 +++ graph/lib/manifest.mf 17 Apr 2007 10:00:22 -0000 @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.visual OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/Bundle.properties -OpenIDE-Module-Specification-Version: 2.1 +OpenIDE-Module-Specification-Version: 2.2 Index: graph/lib/src/org/netbeans/api/visual/animator/Animator.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/animator/Animator.java,v --- graph/lib/src/org/netbeans/api/visual/animator/Animator.java 14 Nov 2006 10:04:15 -0000 1.8 +++ graph/lib/src/org/netbeans/api/visual/animator/Animator.java 17 Apr 2007 10:00:22 -0000 @@ -20,21 +20,26 @@ import org.netbeans.api.visual.widget.Scene; +import java.util.concurrent.CopyOnWriteArrayList; + /** * Represents an animator. An animator is registed to a scene animator and could be started. * From that moment the scene animator automatically calls Animator.tick method for a solid period of time set by the scene animator. * In the tick method the animation has to implemented. The animation should be independent on time-duration. + *

+ * Since 2.2, it is possible to listener on important events of the animator using AnimatorListener interface. * * @author David Kaspar */ public abstract class Animator { + private CopyOnWriteArrayList listeners = new CopyOnWriteArrayList (); private SceneAnimator sceneAnimator; private boolean reset; /** * Creates an animator and assigns a scene animator. - * @param sceneAnimator + * @param sceneAnimator the scene animator */ protected Animator (SceneAnimator sceneAnimator) { assert sceneAnimator != null; @@ -53,6 +58,11 @@ * Registers and starts the animation. */ protected final void start () { + if (! listeners.isEmpty ()) { + AnimatorEvent event = new AnimatorEvent (this); + for (AnimatorListener listener : listeners) + listener.animatorStarted (event); + } sceneAnimator.start (this); } @@ -65,6 +75,11 @@ } final void reset () { + if (! listeners.isEmpty ()) { + AnimatorEvent event = new AnimatorEvent (this); + for (AnimatorListener listener : listeners) + listener.animatorReset (event); + } reset = true; } @@ -73,7 +88,28 @@ reset = false; return; } + + if (! listeners.isEmpty ()) { + AnimatorEvent event = new AnimatorEvent (this, progress); + for (AnimatorListener listener : listeners) + listener.animatorPreTick (event); + } + tick (progress); + + if (! listeners.isEmpty ()) { + AnimatorEvent event = new AnimatorEvent (this, progress); + for (AnimatorListener listener : listeners) + listener.animatorPostTick (event); + } + + if (progress >= 1.0) { + if (! listeners.isEmpty ()) { + AnimatorEvent event = new AnimatorEvent (this); + for (AnimatorListener listener : listeners) + listener.animatorFinished (event); + } + } } /** @@ -82,5 +118,23 @@ * @param progress the progress */ protected abstract void tick (double progress); + + /** + * Adds an animator listener to the animator. + * @param listener the animator listener + * @since 2.2 + */ + public void addAnimatorListener (AnimatorListener listener) { + listeners.add (listener); + } + + /** + * Removes an animator listener from the animator. + * @param listener the animator listener + * @since 2.2 + */ + public void removeAnimatorListener (AnimatorListener listener) { + listeners.remove (listener); + } } Index: graph/lib/src/org/netbeans/api/visual/animator/AnimatorEvent.java =================================================================== RCS file: graph/lib/src/org/netbeans/api/visual/animator/AnimatorEvent.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/api/visual/animator/AnimatorEvent.java 17 Apr 2007 10:00:22 -0000 @@ -0,0 +1,60 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.api.visual.animator; + +/** + * This is an animator event which is used by AnimatorListener. + * It contains a reference to the animator and animation progress value which is can be used only in case of + * AnimatorListener.animatorPreTick and AnimatorListener.animatorPostTick methods. + * + * @author David Kaspar + */ +public final class AnimatorEvent { + + private Animator animator; + private double progress; + + AnimatorEvent (Animator animator) { + this (animator, Double.NaN); + } + + AnimatorEvent (Animator animator, double progress) { + this.animator = animator; + this.progress = progress; + } + + /** + * Returns the related animator instance. + * @return the animator + */ + public Animator getAnimator () { + return animator; + } + + /** + * The animation progress value. Contains valid value only when the event is received as an argument of + * AnimatorListener.animatorPreTick and AnimatorListener.animatorPostTick methods. + * @return the progress value; valid range is from 0.0 to 1.0 where 0.0 represents animator-start and 1.0 represents animator-end; + * Double.NaN if the progress value is not available + */ + public double getProgress () { + return progress; + } + +} Index: graph/lib/src/org/netbeans/api/visual/animator/AnimatorListener.java =================================================================== RCS file: graph/lib/src/org/netbeans/api/visual/animator/AnimatorListener.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/api/visual/animator/AnimatorListener.java 17 Apr 2007 10:00:22 -0000 @@ -0,0 +1,64 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.api.visual.animator; + +/** + * This interface is used for notifying about important events on Animator. + * + * @author David Kaspar + * @since 2.2 + */ +public interface AnimatorListener { + + /** + * Called when an animator is invoked to be started. + * @param event the animator event + * @since 2.2 + */ + void animatorStarted (AnimatorEvent event); + + /** + * Called when an animator is changed, so the animation has to be restarted. + * @param event the animator event + * @since 2.2 + */ + void animatorReset (AnimatorEvent event); + + /** + * Called when an animator is finished - means it was running for 500+ms. + * @param event the animator event + * @since 2.2 + */ + void animatorFinished (AnimatorEvent event); + + /** + * Called immediately before the animator performs a tick of an animation. + * @param event the animator event + * @since 2.2 + */ + void animatorPreTick (AnimatorEvent event); + + /** + * Called immediately after the animator performs a tick of an animation. + * @param event the animator event + * @since 2.2 + */ + void animatorPostTick (AnimatorEvent event); + +} Index: graph/lib/src/org/netbeans/api/visual/animator/SceneAnimator.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/animator/SceneAnimator.java,v --- graph/lib/src/org/netbeans/api/visual/animator/SceneAnimator.java 14 Nov 2006 10:04:15 -0000 1.13 +++ graph/lib/src/org/netbeans/api/visual/animator/SceneAnimator.java 17 Apr 2007 10:00:22 -0000 @@ -188,6 +188,42 @@ colorAnimator.setForegroundColor (widget, targetForegroundColor); } + /** + * Returns the preferred location animator which animates preferred location of all widgets in the scene. + * @return the preferred location animator + * @since 2.2 + */ + public Animator getPreferredLocationAnimator () { + return preferredLocationAnimator; + } + + /** + * Returns the preferred bounds animator which animates preferred bounds of all widgets in the scene. + * @return the preferred bounds animator + * @since 2.2 + */ + public Animator getPreferredBoundsAnimator () { + return preferredBoundsAnimator; + } + + /** + * Returns the zoom animator. + * @return the zoom animator + * @since 2.2 + */ + public Animator getZoomAnimator () { + return zoomAnimator; + } + + /** + * Returns the color animator which animates background and foreground colors of all widgets in the scene. + * @return the preferred location animator + * @since 2.2 + */ + public Animator getColorAnimator () { + return colorAnimator; + } + private class UpdateTask implements Runnable { public void run () { Index: graph/lib/src/org/netbeans/api/visual/animator/package.html =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/animator/package.html,v --- graph/lib/src/org/netbeans/api/visual/animator/package.html 13 Mar 2007 10:46:27 -0000 1.3 +++ graph/lib/src/org/netbeans/api/visual/animator/package.html 17 Apr 2007 10:00:22 -0000 @@ -21,5 +21,6 @@

This package contains SceneAnimator classes which is used for controlling animations on a scene. Also you can supply your own animator by implementing Animator class. +Also you can listen on each animator using AnimatorListener interface. Index: graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html,v --- graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 3 Apr 2007 17:00:00 -0000 1.7 +++ graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 17 Apr 2007 10:00:22 -0000 @@ -1906,6 +1906,11 @@

+Each animation is done by an Animator interface implementation. The Animator allows to listen +to important events of an animator started, finished, reset, pre-tick and post-tick events using AnimatorListener interface. +Instances of built-in animators can be obtained using getters of the SceneAnimator class. + +

SceneAnimator Methods

@@ -1950,6 +1955,18 @@ animateForegroundColor (Widget, Color targetForegroundColor) Starts foregroundColor animation for the widget. + +getPreferredLocationAnimator +Returns the preferred location animator which controls animation of preferred location of all widgets in the scene. + +getPreferredBoundsAnimator +Returns the preferred bounds animator which controls animation of preferred bounds of all widgets in the scene. + +getZoomAnimator +Returns the zoom animator of the scene. + +getColorAnimator +Returns the color animator which controls backgorund and foreground animation of all widgets in the scene.

Index: graph/lib/test/unit/src/apichanges/AnimatorListenerTest.java =================================================================== RCS file: graph/lib/test/unit/src/apichanges/AnimatorListenerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/test/unit/src/apichanges/AnimatorListenerTest.java 17 Apr 2007 10:00:22 -0000 @@ -0,0 +1,94 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package apichanges; + +import framework.VisualTestCase; +import org.netbeans.api.visual.animator.AnimatorEvent; +import org.netbeans.api.visual.animator.AnimatorListener; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; + +import javax.swing.*; +import java.awt.*; +import java.lang.reflect.InvocationTargetException; + +/** + * Test for #99048 - Animator listener is needed + * @author David Kaspar + */ +public class AnimatorListenerTest extends VisualTestCase { + + public AnimatorListenerTest (String name) { + super (name); + } + + public void testAnimatorListener () { + final Scene scene = new Scene (); + Widget widget = new Widget (scene); + scene.addChild (widget); + + AnimatorListener listener = new AnimatorListener() { + public void animatorStarted (AnimatorEvent event) { + getRef ().println ("Animator started"); + } + public void animatorReset (AnimatorEvent event) { + getRef ().println ("Animator reset"); + } + public void animatorFinished (AnimatorEvent event) { + getRef ().println ("Animator finished"); + } + public void animatorPreTick (AnimatorEvent event) { + if (event.getProgress () >= 1.0) + getRef ().println ("Animator pre-tick: " + event.getProgress ()); + } + public void animatorPostTick (AnimatorEvent event) { + if (event.getProgress () >= 1.0) + getRef ().println ("Animator post-tick: " + event.getProgress ()); + } + }; + scene.getSceneAnimator ().getPreferredLocationAnimator ().addAnimatorListener (listener); + widget.setPreferredLocation (new Point (0, 0)); + scene.getSceneAnimator ().animatePreferredLocation (widget, new Point (100, 100)); + + final JFrame[] frame = new JFrame[1]; + try { + SwingUtilities.invokeAndWait (new Runnable() { + public void run () { + frame[0] = showFrame (scene); + } + }); + + Thread.sleep (2000); + + SwingUtilities.invokeAndWait (new Runnable() { + public void run () { + frame[0].setVisible (false); + frame[0].dispose (); + } + }); + } catch (InterruptedException e) { + throw new AssertionError (e); + } catch (InvocationTargetException e) { + throw new AssertionError (e); + } + + compareReferenceFiles (); + } + +} Index: graph/lib/test/unit/src/apichanges/data/goldenfiles/AnimatorListenerTest/testAnimatorListener.pass =================================================================== RCS file: graph/lib/test/unit/src/apichanges/data/goldenfiles/AnimatorListenerTest/testAnimatorListener.pass --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/test/unit/src/apichanges/data/goldenfiles/AnimatorListenerTest/testAnimatorListener.pass 17 Apr 2007 10:00:22 -0000 @@ -0,0 +1,5 @@ +Animator started +Animator reset +Animator pre-tick: 1.0 +Animator post-tick: 1.0 +Animator finished