1 11 package org.eclipse.swt.custom; 12 13 14 import org.eclipse.swt.*; 15 import org.eclipse.swt.graphics.*; 16 import org.eclipse.swt.widgets.*; 17 18 64 65 public class StackLayout extends Layout { 66 67 73 public int marginWidth = 0; 74 80 public int marginHeight = 0; 81 82 86 public Control topControl; 87 88 protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { 89 Control children[] = composite.getChildren(); 90 int maxWidth = 0; 91 int maxHeight = 0; 92 for (int i = 0; i < children.length; i++) { 93 Point size = children[i].computeSize(wHint, hHint, flushCache); 94 maxWidth = Math.max(size.x, maxWidth); 95 maxHeight = Math.max(size.y, maxHeight); 96 } 97 int width = maxWidth + 2 * marginWidth; 98 int height = maxHeight + 2 * marginHeight; 99 if (wHint != SWT.DEFAULT) width = wHint; 100 if (hHint != SWT.DEFAULT) height = hHint; 101 return new Point(width, height); 102 } 103 104 protected boolean flushCache(Control control) { 105 return true; 106 } 107 108 protected void layout(Composite composite, boolean flushCache) { 109 Control children[] = composite.getChildren(); 110 Rectangle rect = composite.getClientArea(); 111 rect.x += marginWidth; 112 rect.y += marginHeight; 113 rect.width -= 2 * marginWidth; 114 rect.height -= 2 * marginHeight; 115 for (int i = 0; i < children.length; i++) { 116 children[i].setBounds(rect); 117 children[i].setVisible(children[i] == topControl); 118 119 } 120 } 121 122 String getName () { 123 String string = getClass ().getName (); 124 int index = string.lastIndexOf ('.'); 125 if (index == -1) return string; 126 return string.substring (index + 1, string.length ()); 127 } 128 129 135 public String toString () { 136 String string = getName ()+" {"; 137 if (marginWidth != 0) string += "marginWidth="+marginWidth+" "; 138 if (marginHeight != 0) string += "marginHeight="+marginHeight+" "; 139 if (topControl != null) string += "topControl="+topControl+" "; 140 string = string.trim(); 141 string += "}"; 142 return string; 143 } 144 } 145 | Popular Tags |