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 / +55 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
 * <p>
30
 * Since 2.2, it is possible to listener on important events of the animator using <code>AnimatorListener</code> interface.
27
 *
31
 *
28
 * @author David Kaspar
32
 * @author David Kaspar
29
 */
33
 */
30
public abstract class Animator {
34
public abstract class Animator {
31
35
36
    private CopyOnWriteArrayList<AnimatorListener> listeners = new CopyOnWriteArrayList<AnimatorListener> ();
32
    private SceneAnimator sceneAnimator;
37
    private SceneAnimator sceneAnimator;
33
    private boolean reset;
38
    private boolean reset;
34
39
35
    /**
40
    /**
36
     * Creates an animator and assigns a scene animator.
41
     * Creates an animator and assigns a scene animator.
37
     * @param sceneAnimator
42
     * @param sceneAnimator the scene animator
38
     */
43
     */
39
    protected Animator (SceneAnimator sceneAnimator) {
44
    protected Animator (SceneAnimator sceneAnimator) {
40
        assert sceneAnimator != null;
45
        assert sceneAnimator != null;
Lines 53-58 Link Here
53
     * Registers and starts the animation.
58
     * Registers and starts the animation.
54
     */
59
     */
55
    protected final void start () {
60
    protected final void start () {
61
        if (! listeners.isEmpty ()) {
62
            AnimatorEvent event = new AnimatorEvent (this);
63
            for (AnimatorListener listener : listeners)
64
                listener.animatorStarted (event);
65
        }
56
        sceneAnimator.start (this);
66
        sceneAnimator.start (this);
57
    }
67
    }
58
68
Lines 65-70 Link Here
65
    }
75
    }
66
76
67
    final void reset () {
77
    final void reset () {
78
        if (! listeners.isEmpty ()) {
79
            AnimatorEvent event = new AnimatorEvent (this);
80
            for (AnimatorListener listener : listeners)
81
                listener.animatorReset (event);
82
        }
68
        reset = true;
83
        reset = true;
69
    }
84
    }
70
85
Lines 73-79 Link Here
73
            reset = false;
88
            reset = false;
74
            return;
89
            return;
75
        }
90
        }
91
92
        if (! listeners.isEmpty ()) {
93
            AnimatorEvent event = new AnimatorEvent (this, progress);
94
            for (AnimatorListener listener : listeners)
95
                listener.animatorPreTick (event);
96
        }
97
76
        tick (progress);
98
        tick (progress);
99
100
        if (! listeners.isEmpty ()) {
101
            AnimatorEvent event = new AnimatorEvent (this, progress);
102
            for (AnimatorListener listener : listeners)
103
                listener.animatorPostTick (event);
104
        }
105
106
        if (progress >= 1.0) {
107
            if (! listeners.isEmpty ()) {
108
                AnimatorEvent event = new AnimatorEvent (this);
109
                for (AnimatorListener listener : listeners)
110
                    listener.animatorFinished (event);
111
            }
112
        }
77
    }
113
    }
78
114
79
    /**
115
    /**
Lines 82-86 Link Here
82
     * @param progress the progress
118
     * @param progress the progress
83
     */
119
     */
84
    protected abstract void tick (double progress);
120
    protected abstract void tick (double progress);
121
122
    /**
123
     * Adds an animator listener to the animator.
124
     * @param listener the animator listener
125
     * @since 2.2
126
     */
127
    public void addAnimatorListener (AnimatorListener listener) {
128
        listeners.add (listener);
129
    }
130
131
    /**
132
     * Removes an animator listener from the animator.
133
     * @param listener the animator listener
134
     * @since 2.2
135
     */
136
    public void removeAnimatorListener (AnimatorListener listener) {
137
        listeners.remove (listener);
138
    }
85
139
86
}
140
}
(-)graph/lib/src/org/netbeans/api/visual/animator/AnimatorEvent.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 is an animator event which is used by <code>AnimatorListener</code>.
23
 * It contains a reference to the animator and animation progress value which is can be used only in case of
24
 * <code>AnimatorListener.animatorPreTick</code> and <code>AnimatorListener.animatorPostTick</code> methods.
25
 *
26
 * @author David Kaspar
27
 */
28
public final class AnimatorEvent {
29
30
    private Animator animator;
31
    private double progress;
32
33
    AnimatorEvent (Animator animator) {
34
        this (animator, Double.NaN);
35
    }
36
37
    AnimatorEvent (Animator animator, double progress) {
38
        this.animator = animator;
39
        this.progress = progress;
40
    }
41
42
    /**
43
     * Returns the related animator instance.
44
     * @return the animator
45
     */
46
    public Animator getAnimator () {
47
        return animator;
48
    }
49
50
    /**
51
     * The animation progress value. Contains valid value only when the event is received as an argument of
52
     * <code>AnimatorListener.animatorPreTick</code> and <code>AnimatorListener.animatorPostTick</code> methods.
53
     * @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;
54
     *     Double.NaN if the progress value is not available
55
     */
56
    public double getProgress () {
57
        return progress;
58
    }
59
60
}
(-)graph/lib/src/org/netbeans/api/visual/animator/AnimatorListener.java (+64 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
 * @since 2.2
26
 */
27
public interface AnimatorListener {
28
29
    /**
30
     * Called when an animator is invoked to be started.
31
     * @param event the animator event
32
     * @since 2.2
33
     */
34
    void animatorStarted (AnimatorEvent event);
35
36
    /**
37
     * Called when an animator is changed, so the animation has to be restarted.
38
     * @param event the animator event
39
     * @since 2.2
40
     */
41
    void animatorReset (AnimatorEvent event);
42
43
    /**
44
     * Called when an animator is finished - means it was running for 500+ms.
45
     * @param event the animator event
46
     * @since 2.2
47
     */
48
    void animatorFinished (AnimatorEvent event);
49
50
    /**
51
     * Called immediately before the animator performs a tick of an animation.
52
     * @param event the animator event
53
     * @since 2.2
54
     */
55
    void animatorPreTick (AnimatorEvent event);
56
57
    /**
58
     * Called immediately after the animator performs a tick of an animation.
59
     * @param event the animator event
60
     * @since 2.2
61
     */
62
    void animatorPostTick (AnimatorEvent event);
63
64
}
(-)graph/lib/src/org/netbeans/api/visual/animator/SceneAnimator.java (+36 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
     * @since 2.2
195
     */
196
    public Animator getPreferredLocationAnimator () {
197
        return preferredLocationAnimator;
198
    }
199
200
    /**
201
     * Returns the preferred bounds animator which animates preferred bounds of all widgets in the scene.
202
     * @return the preferred bounds animator
203
     * @since 2.2
204
     */
205
    public Animator getPreferredBoundsAnimator () {
206
        return preferredBoundsAnimator;
207
    }
208
209
    /**
210
     * Returns the zoom animator.
211
     * @return the zoom animator
212
     * @since 2.2
213
     */
214
    public Animator getZoomAnimator () {
215
        return zoomAnimator;
216
    }
217
218
    /**
219
     * Returns the color animator which animates background and foreground colors of all widgets in the scene.
220
     * @return the preferred location animator
221
     * @since 2.2
222
     */
223
    public Animator getColorAnimator () {
224
        return colorAnimator;
225
    }
226
191
    private class UpdateTask implements Runnable {
227
    private class UpdateTask implements Runnable {
192
228
193
        public void run () {
229
        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.animator.AnimatorEvent;
23
import org.netbeans.api.visual.animator.AnimatorListener;
24
import org.netbeans.api.visual.widget.Scene;
25
import org.netbeans.api.visual.widget.Widget;
26
27
import javax.swing.*;
28
import java.awt.*;
29
import java.lang.reflect.InvocationTargetException;
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 (AnimatorEvent event) {
48
                getRef ().println ("Animator started");
49
            }
50
            public void animatorReset (AnimatorEvent event) {
51
                getRef ().println ("Animator reset");
52
            }
53
            public void animatorFinished (AnimatorEvent event) {
54
                getRef ().println ("Animator finished");
55
            }
56
            public void animatorPreTick (AnimatorEvent event) {
57
                if (event.getProgress () >= 1.0)
58
                    getRef ().println ("Animator pre-tick: " + event.getProgress ());
59
            }
60
            public void animatorPostTick (AnimatorEvent event) {
61
                if (event.getProgress () >= 1.0)
62
                getRef ().println ("Animator post-tick: " + event.getProgress ());
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