KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.xml.wsdl.ui.view.grapheditor.layout;
21
22 import java.awt.Point JavaDoc;
23 import java.awt.Rectangle JavaDoc;
24 import org.netbeans.api.visual.layout.Layout;
25 import org.netbeans.api.visual.widget.Widget;
26
27 /**
28  *
29  * @author anjeleevich
30  */

31 public class LeftRightLayout implements Layout {
32         
33     private int hgap;
34     private int maxLeftWidth;
35     
36     public LeftRightLayout(int hgap) {
37         this(hgap, 100000);
38     }
39     
40     
41     public LeftRightLayout(int hgap, int maxLeftWidth) {
42         this.hgap = hgap;
43         this.maxLeftWidth = maxLeftWidth;
44     }
45
46     
47     public void layout(Widget widget) {
48         Widget w1 = widget.getChildren().get(0);
49         Widget w2 = widget.getChildren().get(1);
50
51         Rectangle JavaDoc b1 = w1.getPreferredBounds();
52         Rectangle JavaDoc b2 = w2.getPreferredBounds();
53         
54         b1.width = Math.min(b1.width, maxLeftWidth);
55
56         int height = Math.max(b1.height, b2.height);
57         int width = b1.width + hgap + b2.width;
58
59         int x1 = -b1.x;
60         int x2 = width - b2.width - b2.x;
61
62         int y1 = (height - b1.height) / 2 - b1.y;
63         int y2 = (height - b2.height) / 2 - b2.y;
64
65         w1.resolveBounds(new Point JavaDoc(x1, y1), b1);
66         w2.resolveBounds(new Point JavaDoc(x2, y2), b2);
67     }
68
69     
70     public boolean requiresJustification(Widget widget) {
71         return true;
72     }
73     
74
75     public void justify(Widget widget) {
76         Widget w1 = widget.getChildren().get(0);
77         Widget w2 = widget.getChildren().get(1);
78
79         Rectangle JavaDoc bounds = widget.getClientArea();
80
81         Rectangle JavaDoc b1 = w1.getBounds();
82         Rectangle JavaDoc b2 = w2.getBounds();
83
84         int width = bounds.width;
85         int height = bounds.height;
86
87         int x1 = bounds.x - b1.x;
88         int x2 = bounds.x + width - b2.width - b2.x;
89
90         int y1 = bounds.y + (height - b1.height) / 2 - b1.y;
91         int y2 = bounds.y + (height - b2.height) / 2 - b2.y;
92
93         w1.resolveBounds(new Point JavaDoc(x1, y1), b1);
94         w2.resolveBounds(new Point JavaDoc(x2, y2), b2);
95     }
96 }
97
Popular Tags