Index: graph/lib/apichanges.xml
===================================================================
RCS file: /cvs/graph/lib/apichanges.xml,v
retrieving revision 1.34
diff -u -r1.34 apichanges.xml
--- graph/lib/apichanges.xml 2 Aug 2007 14:28:14 -0000 1.34
+++ graph/lib/apichanges.xml 6 Aug 2007 07:53:58 -0000
@@ -430,6 +430,21 @@
+
+
+
+ Anchor.notifyRevalidate method
+
+
+
+
+
+ Missing Anchor.notifyRevalidate method has been added. Now the Anchor should receive all necessary notification.
+ It is used by VMDNodeAnchor too.
+
+
+
+
Index: graph/lib/manifest.mf
===================================================================
RCS file: /cvs/graph/lib/manifest.mf,v
retrieving revision 1.14
diff -u -r1.14 manifest.mf
--- graph/lib/manifest.mf 1 Aug 2007 07:31:49 -0000 1.14
+++ graph/lib/manifest.mf 6 Aug 2007 07:53:58 -0000
@@ -1,4 +1,4 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.api.visual
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties
-OpenIDE-Module-Specification-Version: 2.6
+OpenIDE-Module-Specification-Version: 2.8
Index: graph/lib/src/org/netbeans/api/visual/anchor/Anchor.java
===================================================================
RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/anchor/Anchor.java,v
retrieving revision 1.15
diff -u -r1.15 Anchor.java
--- graph/lib/src/org/netbeans/api/visual/anchor/Anchor.java 24 Jan 2007 14:21:22 -0000 1.15
+++ graph/lib/src/org/netbeans/api/visual/anchor/Anchor.java 6 Aug 2007 07:53:58 -0000
@@ -157,9 +157,17 @@
}
/**
+ * Notifies when the anchor is going to be revalidated.
+ * @since 2.8
+ */
+ protected void notifyRevalidate () {
+ }
+
+ /**
* This method is called by revalidation-change of related widget and notifies all entries about the anchor change.
*/
public final void revalidateDependency () {
+ notifyRevalidate ();
for (Entry entry : entries)
entry.revalidateEntry ();
}
Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeAnchor.java
===================================================================
RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeAnchor.java,v
retrieving revision 1.11
diff -u -r1.11 VMDNodeAnchor.java
--- graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeAnchor.java 25 Jun 2007 15:55:13 -0000 1.11
+++ graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeAnchor.java 6 Aug 2007 07:53:58 -0000
@@ -91,10 +91,19 @@
requiresRecalculation = true;
}
+ /**
+ * Notifies when the anchor is going to be revalidated.
+ * @since 2.8
+ */
+ protected void notifyRevalidate () {
+ requiresRecalculation = true;
+ }
+
private void recalculate () {
if (! requiresRecalculation)
return;
+ System.out.println ("recalculate = " + this);
Widget widget = getRelatedWidget ();
Point relatedLocation = getRelatedSceneLocation ();
@@ -159,6 +168,8 @@
y = bounds.y + (a + 1) * bounds.height / (len + 1);
results.put (entry, new Result (new Point (x, y), vertical ? Direction.BOTTOM : Direction.RIGHT));
}
+
+ requiresRecalculation = false;
}
private Entry[] toArray (final HashMap map) {
Index: graph/lib/test/unit/src/apichanges/AnchorNotificationTest.java
===================================================================
RCS file: graph/lib/test/unit/src/apichanges/AnchorNotificationTest.java
diff -N graph/lib/test/unit/src/apichanges/AnchorNotificationTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ graph/lib/test/unit/src/apichanges/AnchorNotificationTest.java 6 Aug 2007 07:53:58 -0000
@@ -0,0 +1,115 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development
+ * and Distribution License (the License). You may not use this file except in
+ * compliance with the License.
+ *
+ * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
+ * or http://www.netbeans.org/cddl.txt.
+ *
+ * When distributing Covered Code, include this CDDL Header Notice in each file
+ * and include the License file at http://www.netbeans.org/cddl.txt.
+ * If applicable, add the following below the CDDL Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package apichanges;
+
+import framework.VisualTestCase;
+import org.netbeans.api.visual.widget.Scene;
+import org.netbeans.api.visual.widget.Widget;
+import org.netbeans.api.visual.widget.ConnectionWidget;
+import org.netbeans.api.visual.anchor.Anchor;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * Test for #111987 - VMDNodeAnchor recalculates unnecessarily
+ * @author David Kaspar
+ */
+public class AnchorNotificationTest extends VisualTestCase {
+
+ public AnchorNotificationTest (String testName) {
+ super (testName);
+ }
+
+ public void testNotify () {
+ StringBuffer log = new StringBuffer ();
+ Scene scene = new Scene ();
+
+ Widget w = new Widget (scene);
+ scene.addChild (w);
+
+ ConnectionWidget c = new ConnectionWidget (scene);
+ scene.addChild (c);
+ TestAnchor testAnchor = new TestAnchor (w, log);
+ c.setSourceAnchor (testAnchor);
+ c.setTargetAnchor (testAnchor);
+
+ JFrame frame = showFrame (scene);
+
+ c.setSourceAnchor (null);
+ c.setTargetAnchor (null);
+ scene.validate ();
+
+ frame.setVisible (false);
+ frame.dispose ();
+
+ assertEquals (log.toString (),
+ "notifyEntryAdded\n" +
+ "notifyUsed\n" +
+ "notifyRevalidate\n" +
+ "notifyEntryAdded\n" +
+ "notifyRevalidate\n" +
+ "notifyRevalidate\n" +
+ "compute\n" +
+ "compute\n" +
+ "notifyEntryRemoved\n" +
+ "notifyRevalidate\n" +
+ "notifyEntryRemoved\n" +
+ "notifyUnused\n" +
+ "notifyRevalidate\n"
+ );
+ }
+
+ private class TestAnchor extends Anchor {
+
+ private StringBuffer log;
+
+ protected TestAnchor (Widget relatedWidget, StringBuffer log) {
+ super (relatedWidget);
+ this.log = log;
+ }
+
+ protected void notifyEntryAdded (Entry entry) {
+ log.append ("notifyEntryAdded\n");
+ }
+
+ protected void notifyEntryRemoved (Entry entry) {
+ log.append ("notifyEntryRemoved\n");
+ }
+
+ protected void notifyUsed () {
+ log.append ("notifyUsed\n");
+ }
+
+ protected void notifyUnused () {
+ log.append ("notifyUnused\n");
+ }
+
+ protected void notifyRevalidate () {
+ log.append ("notifyRevalidate\n");
+ }
+
+ public Result compute (Entry entry) {
+ log.append ("compute\n");
+ return new Result (new Point (0, 0), DIRECTION_ANY);
+ }
+ }
+
+}