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 |
} |