KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > layout > PartnerLinkTypeContentLayout


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 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.layout;
20
21 import java.awt.Point JavaDoc;
22 import java.awt.Rectangle JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.netbeans.api.visual.layout.Layout;
26 import org.netbeans.api.visual.widget.Widget;
27
28 public class PartnerLinkTypeContentLayout implements Layout {
29
30     private int mGap = 40;
31     
32     public PartnerLinkTypeContentLayout(int gap) {
33         mGap = gap;
34     }
35     
36     public void justify(Widget widget) {
37         List JavaDoc<Widget> children = widget.getChildren();
38         
39         if (children.size() < 5) return;
40         
41         Rectangle JavaDoc parentBounds = widget.getClientArea();
42         
43         int midPoint = parentBounds.width / 2;
44         Widget roleLabel = children.get(3);
45         Widget portTypeLabel = children.get(4);
46         int rolesX = midPoint - roleLabel.getBounds().width / 2;
47         int rolesY = 10 - parentBounds.y;
48
49         int portTypesX = midPoint - portTypeLabel.getBounds().width / 2;
50         int portTypesY = 40 - parentBounds.y;
51         
52         roleLabel.resolveBounds(new Point JavaDoc(rolesX, rolesY), null);
53         portTypeLabel.resolveBounds(new Point JavaDoc(portTypesX, portTypesY), null);
54         
55     }
56
57     public void layout(Widget widget) {
58         List JavaDoc<Widget> children = widget.getChildren();
59         
60         if (children.size() < 5) return;
61         
62         Widget firstRole = children.get(0);
63         Widget secondRole = children.get(1);
64         Widget operationLayer = children.get(2);
65         Widget roleLabel = children.get(3);
66         Widget portTypeLabel = children.get(4);
67         
68         
69         Rectangle JavaDoc bounds1 = firstRole.getPreferredBounds();
70         Rectangle JavaDoc bounds2 = secondRole.getPreferredBounds();
71         Rectangle JavaDoc bounds3 = operationLayer.getPreferredBounds();
72         
73         roleLabel.resolveBounds(null, roleLabel.getPreferredBounds());
74         portTypeLabel.resolveBounds(null, portTypeLabel.getPreferredBounds());
75         
76         int width = Math.max(bounds1.width, bounds2.width);
77         int height = Math.max(bounds1.height, bounds2.height);
78         
79         int realHeight = bounds3.height + mGap;
80         
81         height = Math.max(height, realHeight);
82         
83         int totalWidth = width + bounds3.width;
84
85         Rectangle JavaDoc roleBounds = new Rectangle JavaDoc(width, realHeight);
86         firstRole.resolveBounds(new Point JavaDoc(), roleBounds);
87         secondRole.resolveBounds(new Point JavaDoc(totalWidth - width, 0), roleBounds);
88 // bounds3.height = roleBounds.height - mGap;
89
operationLayer.resolveBounds(new Point JavaDoc(width / 2 + 1, mGap), bounds3);
90     }
91
92     public boolean requiresJustification(Widget widget) {
93         return true;
94     }
95
96 }
97
Popular Tags