1 19 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.layout; 20 21 import java.awt.Point ; 22 import java.awt.Rectangle ; 23 import java.util.List ; 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 <Widget> children = widget.getChildren(); 38 39 if (children.size() < 5) return; 40 41 Rectangle 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 (rolesX, rolesY), null); 53 portTypeLabel.resolveBounds(new Point (portTypesX, portTypesY), null); 54 55 } 56 57 public void layout(Widget widget) { 58 List <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 bounds1 = firstRole.getPreferredBounds(); 70 Rectangle bounds2 = secondRole.getPreferredBounds(); 71 Rectangle 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 roleBounds = new Rectangle (width, realHeight); 86 firstRole.resolveBounds(new Point (), roleBounds); 87 secondRole.resolveBounds(new Point (totalWidth - width, 0), roleBounds); 88 operationLayer.resolveBounds(new Point (width / 2 + 1, mGap), bounds3); 90 } 91 92 public boolean requiresJustification(Widget widget) { 93 return true; 94 } 95 96 } 97 | Popular Tags |