1 19 20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.layout; 21 22 import java.awt.Point ; 23 import java.awt.Rectangle ; 24 import org.netbeans.api.visual.layout.Layout; 25 import org.netbeans.api.visual.widget.Widget; 26 27 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 b1 = w1.getPreferredBounds(); 52 Rectangle 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 (x1, y1), b1); 66 w2.resolveBounds(new Point (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 bounds = widget.getClientArea(); 80 81 Rectangle b1 = w1.getBounds(); 82 Rectangle 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 (x1, y1), b1); 94 w2.resolveBounds(new Point (x2, y2), b2); 95 } 96 } 97 | Popular Tags |