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 java.util.List ; 25 import org.netbeans.api.visual.layout.Layout; 26 import org.netbeans.api.visual.widget.Widget; 27 28 32 public class TableLayout implements Layout { 33 34 private int columnCount; 35 private int hgap; 36 private int vgap; 37 private int minColumnWidth; 38 39 public TableLayout(int columnCount, int hgap, int vgap, 40 int minColumnWidth) 41 { 42 this.minColumnWidth = minColumnWidth; 43 this.columnCount = columnCount; 44 this.hgap = hgap; 45 this.vgap = vgap; 46 } 47 48 49 public void layout(Widget widget) { 50 List <Widget> children = widget.getChildren(); 51 52 int width = (minColumnWidth + hgap) * columnCount - hgap;; 53 int y = 0; 54 55 for (int i = 0; i < children.size(); i += columnCount) { 56 57 int rowHeight = 0; 58 59 for (int j = 0; j < columnCount; j++) { 60 Widget w = children.get(i + j); 61 Rectangle b = w.getPreferredBounds(); 62 rowHeight = Math.max(rowHeight, b.height); 63 } 64 65 int x = 0; 66 67 for (int j = 0; j < columnCount; j++) { 68 Widget w = children.get(i + j); 69 Rectangle b = w.getPreferredBounds(); 70 b.height = rowHeight; 71 b.width = minColumnWidth; 72 w.resolveBounds(new Point (x - b.x, y - b.y), b); 73 74 x += minColumnWidth + hgap; 75 } 76 77 y += rowHeight + vgap; 78 } 79 } 80 81 public boolean requiresJustification(Widget widget) { 82 return true; 83 } 84 85 public void justify(Widget widget) { 86 Rectangle bounds = widget.getClientArea(); 87 88 int y0 = bounds.y; 89 90 List <Widget> children = widget.getChildren(); 91 92 for (int i = 0; i < children.size(); i += columnCount) { 93 int rowHeight = 0; 94 95 for (int j = 0; j < columnCount; j++) { 96 Widget w = children.get(i + j); 97 Rectangle b = w.getBounds(); 98 rowHeight = Math.max(rowHeight, b.height); 99 } 100 101 int x0 = bounds.x; 102 int width = bounds.width; 103 104 for (int j = 0; j < columnCount; j++) { 105 Widget w = children.get(i + j); 106 Rectangle b = w.getBounds(); 107 108 int columnWidth = (width - hgap * (columnCount - 1 - j)) 109 / (columnCount - j); 110 111 b.width = columnWidth; 112 b.height = rowHeight; 113 114 w.resolveBounds(new Point (x0 - b.x, y0 - b.y), b); 115 116 width -= columnWidth + hgap; 117 x0 += columnWidth + hgap; 118 } 119 120 y0 += rowHeight + vgap; 121 } 122 } 123 } 124 | Popular Tags |