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.layout.LayoutFactory.SerialAlignment; 27 import org.netbeans.api.visual.widget.Widget; 28 import org.netbeans.modules.visual.layout.SerialLayout; 29 30 public class OneSideJustifiedLayout implements Layout { 31 32 int gap = 0; 33 int otherGap = 0; 34 boolean isRightSided = false; 35 36 SerialLayout layout; 37 38 50 public OneSideJustifiedLayout(boolean isRightSided, int gap, int heightIncrease) { 51 this.isRightSided = isRightSided; 52 this.gap = gap; 53 this.otherGap = heightIncrease; 54 layout = new SerialLayout(false, SerialAlignment.JUSTIFY, gap); 55 } 56 57 58 67 public OneSideJustifiedLayout(boolean isRightSided, int heightIncrease) { 68 this(isRightSided, 0, heightIncrease); 69 } 70 71 77 public OneSideJustifiedLayout(boolean isRightSided) { 78 this(isRightSided, 0, 0); 79 } 80 81 82 public void justify(Widget widget) { 83 84 List <Widget> children = widget.getChildren(); 85 assert children.size() == 2 : "this layout cannot take more than 2 child widgets"; 86 87 layout.justify(widget); 88 89 Widget first = children.get(0); 90 Widget second = children.get(1); 91 92 Rectangle parentBounds = widget.getClientArea(); 93 95 Rectangle firstBounds = first.getBounds(); 96 Point firstLocation = first.getLocation(); 97 98 Rectangle secondBounds = second.getBounds(); 99 Point secondLocation = second.getLocation(); 100 101 int width = parentBounds.width - secondBounds.width; 102 103 104 firstBounds.width = width; 105 106 if (isRightSided) { 107 secondLocation.x = width - secondBounds.x; 108 first.resolveBounds(firstLocation, firstBounds); 109 second.resolveBounds(secondLocation, secondBounds); 110 } else { 111 secondLocation.x = secondBounds.width - secondBounds.x; 112 firstLocation.x += secondBounds.x; 113 first.resolveBounds(secondLocation, firstBounds); 114 second.resolveBounds(firstLocation, secondBounds); 115 } 116 117 } 118 119 public void layout(Widget widget) { 120 layout.layout(widget); 121 } 122 123 public boolean requiresJustification(Widget widget) { 124 return true; 125 } 126 127 } 128 | Popular Tags |