1 13 package org.eclipse.jface.layout; 14 import org.eclipse.swt.graphics.Point; 15 import org.eclipse.swt.graphics.Rectangle; 16 import org.eclipse.swt.layout.GridLayout; 17 import org.eclipse.swt.widgets.Composite; 18 19 45 public final class GridLayoutFactory { 46 47 50 private GridLayout l; 51 52 57 private GridLayoutFactory(GridLayout l) { 58 this.l = l; 59 } 60 61 67 public static GridLayoutFactory createFrom(GridLayout l) { 68 return new GridLayoutFactory(copyLayout(l)); 69 } 70 71 76 public GridLayoutFactory copy() { 77 return new GridLayoutFactory(create()); 78 } 79 80 100 public static GridLayoutFactory swtDefaults() { 101 return new GridLayoutFactory(new GridLayout()); 102 } 103 104 124 public static GridLayoutFactory fillDefaults() { 125 GridLayout layout = new GridLayout(); 126 layout.marginWidth = 0; 127 layout.marginHeight = 0; 128 Point defaultSpacing = LayoutConstants.getSpacing(); 129 layout.horizontalSpacing = defaultSpacing.x; 130 layout.verticalSpacing = defaultSpacing.y; 131 return new GridLayoutFactory(layout); 132 } 133 134 140 public GridLayoutFactory equalWidth(boolean equal) { 141 l.makeColumnsEqualWidth = equal; 142 return this; 143 } 144 145 155 public GridLayoutFactory spacing(int hSpacing, int vSpacing) { 156 l.horizontalSpacing = hSpacing; 157 l.verticalSpacing = vSpacing; 158 return this; 159 } 160 161 170 public GridLayoutFactory spacing(Point spacing) { 171 l.horizontalSpacing = spacing.x; 172 l.verticalSpacing = spacing.y; 173 return this; 174 } 175 176 185 public GridLayoutFactory margins(Point margins) { 186 l.marginWidth = margins.x; 187 l.marginHeight = margins.y; 188 return this; 189 } 190 191 206 public GridLayoutFactory margins(int width, int height) { 207 l.marginWidth = width; 208 l.marginHeight = height; 209 return this; 210 } 211 212 233 public GridLayoutFactory extendedMargins(int left, int right, int top, int bottom) { 234 l.marginLeft = left; 235 l.marginRight = right; 236 l.marginTop = top; 237 l.marginBottom = bottom; 238 return this; 239 } 240 241 268 public GridLayoutFactory extendedMargins(Rectangle differenceRect) { 269 l.marginLeft = -differenceRect.x; 270 l.marginTop = -differenceRect.y; 271 l.marginBottom = differenceRect.y + differenceRect.height; 272 l.marginRight = differenceRect.x + differenceRect.width; 273 return this; 274 } 275 276 282 public GridLayoutFactory numColumns(int numColumns) { 283 l.numColumns = numColumns; 284 return this; 285 } 286 287 293 public GridLayout create() { 294 return copyLayout(l); 295 } 296 297 306 public void applyTo(Composite c) { 307 c.setLayout(copyLayout(l)); 308 } 309 310 316 public static GridLayout copyLayout(GridLayout l) { 317 GridLayout result = new GridLayout(l.numColumns, l.makeColumnsEqualWidth); 318 result.horizontalSpacing = l.horizontalSpacing; 319 result.marginBottom = l.marginBottom; 320 result.marginHeight = l.marginHeight; 321 result.marginLeft = l.marginLeft; 322 result.marginRight = l.marginRight; 323 result.marginTop = l.marginTop; 324 result.marginWidth = l.marginWidth; 325 result.verticalSpacing = l.verticalSpacing; 326 327 return result; 328 } 329 330 374 public void generateLayout(Composite c) { 375 applyTo(c); 376 LayoutGenerator.generateLayout(c); 377 } 378 } 379 | Popular Tags |