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 111987
Collapse All | Expand All

(-)graph/lib/apichanges.xml (+15 lines)
Lines 430-435 Link Here
430
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
430
            <class package="org.netbeans.api.visual.widget" name="Widget" link="yes"/>
431
            <issue number="108856"/>
431
            <issue number="108856"/>
432
        </change>
432
        </change>
433
434
        <change>
435
            <api name="general"/>
436
            <summary>Anchor.notifyRevalidate method</summary>
437
            <version major="2" minor="8"/>
438
            <date day="6" month="8" year="2007"/>
439
            <author login="dkaspar"/>
440
            <compatibility addition="yes"/>
441
            <description>
442
                Missing Anchor.notifyRevalidate method has been added. Now the Anchor should receive all necessary notification.
443
                It is used by VMDNodeAnchor too.
444
            </description>
445
            <class package="org.netbeans.api.visual.anchor" name="Anchor" link="yes"/>
446
            <issue number="111987"/>
447
        </change>
433
    </changes>
448
    </changes>
434
449
435
    <htmlcontents>
450
    <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/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.6
4
OpenIDE-Module-Specification-Version: 2.8
(-)graph/lib/src/org/netbeans/api/visual/anchor/Anchor.java (+8 lines)
Lines 157-165 Link Here
157
    }
157
    }
158
158
159
    /**
159
    /**
160
     * Notifies when the anchor is going to be revalidated.
161
     * @since 2.8
162
     */
163
    protected void notifyRevalidate () {
164
    }
165
166
    /**
160
     * This method is called by revalidation-change of related widget and notifies all entries about the anchor change.
167
     * This method is called by revalidation-change of related widget and notifies all entries about the anchor change.
161
     */
168
     */
162
    public final void revalidateDependency () {
169
    public final void revalidateDependency () {
170
        notifyRevalidate ();
163
        for (Entry entry : entries)
171
        for (Entry entry : entries)
164
            entry.revalidateEntry ();
172
            entry.revalidateEntry ();
165
    }
173
    }
(-)graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeAnchor.java (+11 lines)
Lines 91-100 Link Here
91
        requiresRecalculation = true;
91
        requiresRecalculation = true;
92
    }
92
    }
93
93
94
    /**
95
     * Notifies when the anchor is going to be revalidated.
96
     * @since 2.8
97
     */
98
    protected void notifyRevalidate () {
99
        requiresRecalculation = true;
100
    }
101
94
    private void recalculate () {
102
    private void recalculate () {
95
        if (! requiresRecalculation)
103
        if (! requiresRecalculation)
96
            return;
104
            return;
97
105
106
        System.out.println ("recalculate = " + this);
98
        Widget widget = getRelatedWidget ();
107
        Widget widget = getRelatedWidget ();
99
        Point relatedLocation = getRelatedSceneLocation ();
108
        Point relatedLocation = getRelatedSceneLocation ();
100
109
Lines 159-164 Link Here
159
                y = bounds.y + (a + 1) * bounds.height / (len + 1);
168
                y = bounds.y + (a + 1) * bounds.height / (len + 1);
160
            results.put (entry, new Result (new Point (x, y), vertical ? Direction.BOTTOM : Direction.RIGHT));
169
            results.put (entry, new Result (new Point (x, y), vertical ? Direction.BOTTOM : Direction.RIGHT));
161
        }
170
        }
171
172
        requiresRecalculation = false;
162
    }
173
    }
163
174
164
    private Entry[] toArray (final HashMap<Entry, Float> map) {
175
    private Entry[] toArray (final HashMap<Entry, Float> map) {
(-)graph/lib/test/unit/src/apichanges/AnchorNotificationTest.java (+115 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-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
}

Return to bug 111987