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-2007 Sun |
17 |
* Microsystems, Inc. All Rights Reserved. |
18 |
*/ |
19 |
|
20 |
package apichanges; |
21 |
|
22 |
import framework.VisualTestCase; |
23 |
import org.netbeans.api.visual.widget.Scene; |
24 |
import org.netbeans.api.visual.widget.Widget; |
25 |
import org.netbeans.api.visual.widget.ConnectionWidget; |
26 |
import org.netbeans.api.visual.anchor.Anchor; |
27 |
|
28 |
import javax.swing.*; |
29 |
import java.awt.*; |
30 |
|
31 |
/** |
32 |
* Test for #111987 - VMDNodeAnchor recalculates unnecessarily |
33 |
* @author David Kaspar |
34 |
*/ |
35 |
public class AnchorNotificationTest extends VisualTestCase { |
36 |
|
37 |
public AnchorNotificationTest (String testName) { |
38 |
super (testName); |
39 |
} |
40 |
|
41 |
public void testNotify () { |
42 |
StringBuffer log = new StringBuffer (); |
43 |
Scene scene = new Scene (); |
44 |
|
45 |
Widget w = new Widget (scene); |
46 |
scene.addChild (w); |
47 |
|
48 |
ConnectionWidget c = new ConnectionWidget (scene); |
49 |
scene.addChild (c); |
50 |
TestAnchor testAnchor = new TestAnchor (w, log); |
51 |
c.setSourceAnchor (testAnchor); |
52 |
c.setTargetAnchor (testAnchor); |
53 |
|
54 |
JFrame frame = showFrame (scene); |
55 |
|
56 |
c.setSourceAnchor (null); |
57 |
c.setTargetAnchor (null); |
58 |
scene.validate (); |
59 |
|
60 |
frame.setVisible (false); |
61 |
frame.dispose (); |
62 |
|
63 |
assertEquals (log.toString (), |
64 |
"notifyEntryAdded\n" + |
65 |
"notifyUsed\n" + |
66 |
"notifyRevalidate\n" + |
67 |
"notifyEntryAdded\n" + |
68 |
"notifyRevalidate\n" + |
69 |
"notifyRevalidate\n" + |
70 |
"compute\n" + |
71 |
"compute\n" + |
72 |
"notifyEntryRemoved\n" + |
73 |
"notifyRevalidate\n" + |
74 |
"notifyEntryRemoved\n" + |
75 |
"notifyUnused\n" + |
76 |
"notifyRevalidate\n" |
77 |
); |
78 |
} |
79 |
|
80 |
private class TestAnchor extends Anchor { |
81 |
|
82 |
private StringBuffer log; |
83 |
|
84 |
protected TestAnchor (Widget relatedWidget, StringBuffer log) { |
85 |
super (relatedWidget); |
86 |
this.log = log; |
87 |
} |
88 |
|
89 |
protected void notifyEntryAdded (Entry entry) { |
90 |
log.append ("notifyEntryAdded\n"); |
91 |
} |
92 |
|
93 |
protected void notifyEntryRemoved (Entry entry) { |
94 |
log.append ("notifyEntryRemoved\n"); |
95 |
} |
96 |
|
97 |
protected void notifyUsed () { |
98 |
log.append ("notifyUsed\n"); |
99 |
} |
100 |
|
101 |
protected void notifyUnused () { |
102 |
log.append ("notifyUnused\n"); |
103 |
} |
104 |
|
105 |
protected void notifyRevalidate () { |
106 |
log.append ("notifyRevalidate\n"); |
107 |
} |
108 |
|
109 |
public Result compute (Entry entry) { |
110 |
log.append ("compute\n"); |
111 |
return new Result (new Point (0, 0), DIRECTION_ANY); |
112 |
} |
113 |
} |
114 |
|
115 |
} |