This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 99048
Collapse All | Expand All

(-)graph/lib/apichanges.xml (+15 lines)
Lines 137-142 Link Here
137
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
137
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
138
            <issue number="98307"/>
138
            <issue number="98307"/>
139
        </change>
139
        </change>
140
141
        <change>
142
            <api name="general"/>
143
            <summary>AnimatorListener added</summary>
144
            <version major="2" minor="2"/>
145
            <date day="10" month="4" year="2007"/>
146
            <author login="dkaspar"/>
147
            <compatibility addition="yes"/>
148
            <description>
149
                AnimatorListener interface has been added. It allows listening to important events of Animator interface implementation.
150
                Built-in animators are accessible using getters on SceneAnimator class.
151
            </description>
152
            <class package="org.netbeans.api.visual.animator" name="AnimatorListener" link="yes"/>
153
            <issue number="99048"/>
154
        </change>
140
    </changes>
155
    </changes>
141
156
142
    <htmlcontents>
157
    <htmlcontents>
(-)graph/lib/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.visual
2
OpenIDE-Module: org.netbeans.api.visual
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.1
4
OpenIDE-Module-Specification-Version: 2.2
(-)graph/lib/src/org/netbeans/api/visual/animator/Animator.java (-1 / +32 lines)
Lines 20-40 Link Here
20
20
21
import org.netbeans.api.visual.widget.Scene;
21
import org.netbeans.api.visual.widget.Scene;
22
22
23
import java.util.concurrent.CopyOnWriteArrayList;
24
23
/**
25
/**
24
 * Represents an animator. An animator is registed to a scene animator and could be started.
26
 * Represents an animator. An animator is registed to a scene animator and could be started.
25
 * From that moment the scene animator automatically calls Animator.tick method for a solid period of time set by the scene animator.
27
 * From that moment the scene animator automatically calls Animator.tick method for a solid period of time set by the scene animator.
26
 * In the tick method the animation has to implemented. The animation should be independent on time-duration.
28
 * In the tick method the animation has to implemented. The animation should be independent on time-duration.
29
 * It is possible to listener on important events of the animator using <code>AnimatorListener</code> interface.
27
 *
30
 *
28
 * @author David Kaspar
31
 * @author David Kaspar
29
 */
32
 */
30
public abstract class Animator {
33
public abstract class Animator {
31
34
35
    private CopyOnWriteArrayList<AnimatorListener> listeners = new CopyOnWriteArrayList<AnimatorListener> ();
32
    private SceneAnimator sceneAnimator;
36
    private SceneAnimator sceneAnimator;
33
    private boolean reset;
37
    private boolean reset;
34
38
35
    /**
39
    /**
36
     * Creates an animator and assigns a scene animator.
40
     * Creates an animator and assigns a scene animator.
37
     * @param sceneAnimator
41
     * @param sceneAnimator the scene animator
38
     */
42
     */
39
    protected Animator (SceneAnimator sceneAnimator) {
43
    protected Animator (SceneAnimator sceneAnimator) {
40
        assert sceneAnimator != null;
44
        assert sceneAnimator != null;
Lines 53-58 Link Here
53
     * Registers and starts the animation.
57
     * Registers and starts the animation.
54
     */
58
     */
55
    protected final void start () {
59
    protected final void start () {
60
        for (AnimatorListener listener : listeners)
61
            listener.animatorStarted (this);
56
        sceneAnimator.start (this);
62
        sceneAnimator.start (this);
57
    }
63
    }
58
64
Lines 65-70 Link Here
65
    }
71
    }
66
72
67
    final void reset () {
73
    final void reset () {
74
        for (AnimatorListener listener : listeners)
75
            listener.animatorReset (this);
68
        reset = true;
76
        reset = true;
69
    }
77
    }
70
78
Lines 73-79 Link Here
73
            reset = false;
81
            reset = false;
74
            return;
82
            return;
75
        }
83
        }
84
        for (AnimatorListener listener : listeners)
85
            listener.animatorPreTick (this, progress);
76
        tick (progress);
86
        tick (progress);
87
        for (AnimatorListener listener : listeners)
88
            listener.animatorPostTick (this, progress);
89
        if (progress >= 1.0)
90
            for (AnimatorListener listener : listeners)
91
                listener.animatorFinished (this);
77
    }
92
    }
78
93
79
    /**
94
    /**
Lines 82-86 Link Here
82
     * @param progress the progress
97
     * @param progress the progress
83
     */
98
     */
84
    protected abstract void tick (double progress);
99
    protected abstract void tick (double progress);
100
101
    /**
102
     * Adds an animator listener to the animator.
103
     * @param listener the animator listener
104
     */
105
    public void addAnimatorListener (AnimatorListener listener) {
106
        listeners.add (listener);
107
    }
108
109
    /**
110
     * Removes an animator listener from the animator.
111
     * @param listener the animator listener
112
     */
113
    public void removeAnimatorListener (AnimatorListener listener) {
114
        listeners.remove (listener);
115
    }
85
116
86
}
117
}
(-)graph/lib/src/org/netbeans/api/visual/animator/AnimatorListener.java (+60 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.api.visual.animator;
20
21
/**
22
 * This interface is used for notifying about important events on <code>Animator</code>.
23
 *
24
 * @author David Kaspar
25
 */
26
public interface AnimatorListener {
27
28
    /**
29
     * Called when an animator is invoked to be started.
30
     * @param animator the animator
31
     */
32
    void animatorStarted (Animator animator);
33
34
    /**
35
     * Called when an animator is changed, so the animation has to be restarted.
36
     * @param animator the animator
37
     */
38
    void animatorReset (Animator animator);
39
40
    /**
41
     * Called when an animator is finished - is running for 500+ms.
42
     * @param animator the animator
43
     */
44
    void animatorFinished (Animator animator);
45
46
    /**
47
     * Called immediately before the animator performs a tick of an animation.
48
     * @param animator the animator
49
     * @param progress the animation progress; 0.0 is the start, 1.0 is the end
50
     */
51
    void animatorPreTick (Animator animator, double progress);
52
53
    /**
54
     * Called immediately after the animator performs a tick of an animation.
55
     * @param animator the animator
56
     * @param progress the animation progress; 0.0 is the start, 1.0 is the end
57
     */
58
    void animatorPostTick (Animator animator, double progress);
59
60
}
(-)graph/lib/src/org/netbeans/api/visual/animator/SceneAnimator.java (+32 lines)
Lines 188-193 Link Here
188
        colorAnimator.setForegroundColor (widget, targetForegroundColor);
188
        colorAnimator.setForegroundColor (widget, targetForegroundColor);
189
    }
189
    }
190
190
191
    /**
192
     * Returns the preferred location animator which animates preferred location of all widgets in the scene.
193
     * @return the preferred location animator
194
     */
195
    public Animator getPreferredLocationAnimator () {
196
        return preferredLocationAnimator;
197
    }
198
199
    /**
200
     * Returns the preferred bounds animator which animates preferred bounds of all widgets in the scene.
201
     * @return the preferred bounds animator
202
     */
203
    public Animator getPreferredBoundsAnimator () {
204
        return preferredBoundsAnimator;
205
    }
206
207
    /**
208
     * Returns the zoom animator.
209
     * @return the zoom animator
210
     */
211
    public Animator getZoomAnimator () {
212
        return zoomAnimator;
213
    }
214
215
    /**
216
     * Returns the color animator which animates background and foreground colors of all widgets in the scene.
217
     * @return the preferred location animator
218
     */
219
    public Animator getColorAnimator () {
220
        return colorAnimator;
221
    }
222
191
    private class UpdateTask implements Runnable {
223
    private class UpdateTask implements Runnable {
192
224
193
        public void run () {
225
        public void run () {
(-)graph/lib/src/org/netbeans/api/visual/animator/package.html (+1 lines)
Lines 21-25 Link Here
21
<p>
21
<p>
22
This package contains <code>SceneAnimator</code> classes which is used for controlling animations on a scene.
22
This package contains <code>SceneAnimator</code> classes which is used for controlling animations on a scene.
23
Also you can supply your own animator by implementing <code>Animator</code> class.
23
Also you can supply your own animator by implementing <code>Animator</code> class.
24
Also you can listen on each animator using <code>AnimatorListener</code> interface.
24
</body>
25
</body>
25
</html>
26
</html>
(-)graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html (+17 lines)
Lines 1906-1911 Link Here
1906
</ul>
1906
</ul>
1907
1907
1908
<p>
1908
<p>
1909
Each animation is done by an <code>Animator</code> interface implementation. The <code>Animator</code> allows to listen
1910
to important events of an animator <strong>started</strong>, <strong>finished</strong>, <strong>reset</strong>, <strong>pre-tick</strong> and <strong>post-tick</strong> events using <code>AnimatorListener</code> interface.
1911
Instances of built-in animators can be obtained using getters of the <code>SceneAnimator</code> class.
1912
1913
<p>
1909
1914
1910
<a name="SceneAnimatorMethods">
1915
<a name="SceneAnimatorMethods">
1911
<h3>SceneAnimator Methods</h3>
1916
<h3>SceneAnimator Methods</h3>
Lines 1950-1955 Link Here
1950
<tr>
1955
<tr>
1951
<td>animateForegroundColor (Widget, Color targetForegroundColor)
1956
<td>animateForegroundColor (Widget, Color targetForegroundColor)
1952
<td>Starts foregroundColor animation for the widget.
1957
<td>Starts foregroundColor animation for the widget.
1958
<tr>
1959
<td>getPreferredLocationAnimator
1960
<td>Returns the preferred location animator which controls animation of preferred location of all widgets in the scene.
1961
<tr>
1962
<td>getPreferredBoundsAnimator
1963
<td>Returns the preferred bounds animator which controls animation of preferred bounds of all widgets in the scene.
1964
<tr>
1965
<td>getZoomAnimator
1966
<td>Returns the zoom animator of the scene.
1967
<tr>
1968
<td>getColorAnimator
1969
<td>Returns the color animator which controls backgorund and foreground animation of all widgets in the scene.
1953
</table>
1970
</table>
1954
1971
1955
<p>
1972
<p>
(-)graph/lib/test/unit/src/apichanges/AnimatorListenerTest.java (+94 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package apichanges;
20
21
import framework.VisualTestCase;
22
import org.netbeans.api.visual.widget.Scene;
23
import org.netbeans.api.visual.widget.Widget;
24
import org.netbeans.api.visual.animator.AnimatorListener;
25
import org.netbeans.api.visual.animator.Animator;
26
27
import javax.swing.*;
28
import java.lang.reflect.InvocationTargetException;
29
import java.awt.*;
30
31
/**
32
 * Test for #99048 - Animator listener is needed
33
 * @author David Kaspar
34
 */
35
public class AnimatorListenerTest extends VisualTestCase {
36
37
    public AnimatorListenerTest (String name) {
38
        super (name);
39
    }
40
41
    public void testAnimatorListener () {
42
        final Scene scene = new Scene ();
43
        Widget widget = new Widget (scene);
44
        scene.addChild (widget);
45
46
        AnimatorListener listener = new AnimatorListener() {
47
            public void animatorStarted (Animator animator) {
48
                getRef ().println ("Animator started");
49
            }
50
            public void animatorReset (Animator animator) {
51
                getRef ().println ("Animator reset");
52
            }
53
            public void animatorFinished (Animator animator) {
54
                getRef ().println ("Animator finished");
55
            }
56
            public void animatorPreTick (Animator animator, double progress) {
57
                if (progress >= 1.0)
58
                    getRef ().println ("Animator pre-tick: " + progress);
59
            }
60
            public void animatorPostTick (Animator animator, double progress) {
61
                if (progress >= 1.0)
62
                getRef ().println ("Animator post-tick: " + progress);
63
            }
64
        };
65
        scene.getSceneAnimator ().getPreferredLocationAnimator ().addAnimatorListener (listener);
66
        widget.setPreferredLocation (new Point (0, 0));
67
        scene.getSceneAnimator ().animatePreferredLocation (widget, new Point (100, 100));
68
69
        final JFrame[] frame = new JFrame[1];
70
        try {
71
            SwingUtilities.invokeAndWait (new Runnable() {
72
                public void run () {
73
                    frame[0] = showFrame (scene);
74
                }
75
            });
76
77
            Thread.sleep (2000);
78
79
            SwingUtilities.invokeAndWait (new Runnable() {
80
                public void run () {
81
                    frame[0].setVisible (false);
82
                    frame[0].dispose ();
83
                }
84
            });
85
        } catch (InterruptedException e) {
86
            throw new AssertionError (e);
87
        } catch (InvocationTargetException e) {
88
            throw new AssertionError (e);
89
        }
90
91
        compareReferenceFiles ();
92
    }
93
94
}
(-)graph/lib/test/unit/src/apichanges/data/goldenfiles/AnimatorListenerTest/testAnimatorListener.pass (+5 lines)
Added Link Here
1
Animator started
2
Animator reset
3
Animator pre-tick: 1.0
4
Animator post-tick: 1.0
5
Animator finished

Return to bug 99048