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

(-)fad7cefb79f2 (+167 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.visual.apichanges;
42
43
import org.netbeans.modules.visual.framework.VisualTestCase;
44
import org.netbeans.api.visual.widget.LabelWidget;
45
import org.netbeans.api.visual.widget.LayerWidget;
46
import org.netbeans.api.visual.widget.Widget;
47
import org.netbeans.api.visual.anchor.AnchorFactory;
48
import org.netbeans.api.visual.border.BorderFactory;
49
import org.netbeans.api.visual.graph.GraphScene;
50
import org.netbeans.api.visual.graph.layout.GraphLayout;
51
import org.netbeans.api.visual.graph.layout.GraphLayoutFactory;
52
import org.netbeans.api.visual.widget.ConnectionWidget;
53
54
import java.awt.*;
55
import java.awt.image.BufferedImage;
56
import org.netbeans.api.visual.graph.layout.GraphLayoutSupport;
57
import org.netbeans.api.visual.layout.LayoutFactory;
58
import org.netbeans.api.visual.layout.SceneLayout;
59
60
/**
61
 * Test for #178705 - Enhancement to the TreeGraphLayout (gaps between nodes can be minimized now)
62
 * @author David Kaspar
63
 */
64
public class MinimizeGapTreeGraphLayoutTest extends VisualTestCase {
65
66
    public MinimizeGapTreeGraphLayoutTest (String testName) {
67
        super (testName);
68
    }
69
70
    public void testMinimizeGap () {
71
        TestScene scene = new TestScene ();
72
        // hiding the connections to simplify cleaness check
73
        scene.connLayer.setVisible(false);
74
75
        scene.addNode("Root");
76
        scene.addNode ("1-1");
77
        scene.addNode ("1-2");
78
        scene.addNode ("1-3");
79
        scene.addNode ("2-1");
80
        scene.addNode ("2-2");
81
        scene.addNode ("2-3");
82
83
        scene.addEdge ("Root", "1-1");
84
        scene.addEdge ("Root", "1-2");
85
        scene.addEdge ("Root", "1-3");
86
        scene.addEdge ("1-2", "2-1");
87
        scene.addEdge ("1-2", "2-2");
88
        scene.addEdge ("1-2", "2-3");
89
90
        GraphLayout graphLayout = GraphLayoutFactory.createTreeGraphLayout(0, 0, 20, 20, true, true);
91
        graphLayout.setAnimated(false);
92
        GraphLayoutSupport.setTreeGraphLayoutRootNode(graphLayout, "Root");
93
94
        SceneLayout sceneLayout = LayoutFactory.createSceneGraphLayout(scene, graphLayout);
95
        sceneLayout.invokeLayout();
96
97
        BufferedImage snapshot = takeOneTimeSnapshot(scene);
98
99
        BufferedImage clean = clearRegions (snapshot, Color.WHITE,
100
                new Rectangle (48, -2, 34, 34),
101
102
                new Rectangle (-2, 48, 34, 34),
103
                new Rectangle (48, 48, 34, 34),
104
                new Rectangle (98, 48, 34, 34),
105
106
                new Rectangle (-2, 98, 34, 34),
107
                new Rectangle (48, 98, 34, 34),
108
                new Rectangle (98, 98, 34, 34)
109
        );
110
        assertCleaness (testCleaness (clean, Color.WHITE), snapshot, clean);
111
    }
112
113
    private final class TestScene extends GraphScene<String,String> {
114
        
115
        private final LayerWidget mainLayer;
116
        private final LayerWidget connLayer;
117
118
        public TestScene() {
119
            mainLayer = new LayerWidget(this);
120
            addChild(mainLayer);
121
            connLayer = new LayerWidget(this);
122
            addChild(connLayer);
123
        }
124
125
        public void addEdge (String source, String target) {
126
            String edge = source + " to " + target;
127
            addEdge (edge);
128
            setEdgeSource (edge, source);
129
            setEdgeTarget (edge, target);
130
        }
131
132
        @Override
133
        protected Widget attachNodeWidget(String node) {
134
            LabelWidget widget = new LabelWidget(this, node);
135
            widget.setCheckClipping(true);
136
            widget.setAlignment(LabelWidget.Alignment.CENTER);
137
            widget.setVerticalAlignment(LabelWidget.VerticalAlignment.CENTER);
138
            widget.setPreferredSize(new Dimension(30, 30));
139
            widget.setBorder(BorderFactory.createLineBorder());
140
            mainLayer.addChild(widget);
141
            return widget;
142
        }
143
144
        @Override
145
        protected Widget attachEdgeWidget(String edge) {
146
            ConnectionWidget conn = new ConnectionWidget(this);
147
            connLayer.addChild(conn);
148
            return conn;
149
        }
150
151
        @Override
152
        protected void attachEdgeSourceAnchor(String edge, String oldSourceNode, String sourceNode) {
153
            ConnectionWidget conn = (ConnectionWidget) findWidget (edge);
154
            Widget source = findWidget (sourceNode);
155
            conn.setSourceAnchor(source != null ? AnchorFactory.createRectangularAnchor(source) : null);
156
        }
157
158
        @Override
159
        protected void attachEdgeTargetAnchor(String edge, String oldTargetNode, String targetNode) {
160
            ConnectionWidget conn = (ConnectionWidget) findWidget (edge);
161
            Widget target = findWidget (targetNode);
162
            conn.setTargetAnchor(target != null ? AnchorFactory.createRectangularAnchor(target) : null);
163
        }
164
165
    }
166
167
}

Return to bug 178705