01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.presentations.util;
11:
12: import org.eclipse.jface.util.Geometry;
13: import org.eclipse.swt.graphics.Point;
14: import org.eclipse.swt.graphics.Rectangle;
15: import org.eclipse.swt.widgets.Composite;
16: import org.eclipse.swt.widgets.Control;
17: import org.eclipse.swt.widgets.Layout;
18:
19: /**
20: * @since 3.1
21: */
22: public class EnhancedFillLayout extends Layout {
23:
24: public int xmargin = 0;
25: public int ymargin = 0;
26:
27: protected Point computeSize(Composite composite, int wHint,
28: int hHint, boolean flushCache) {
29: int resultX = 1;
30: int resultY = 1;
31:
32: Control[] children = composite.getChildren();
33:
34: for (int i = 0; i < children.length; i++) {
35: Control control = children[i];
36:
37: Point sz = control.computeSize(wHint, hHint, flushCache);
38:
39: resultX = Math.max(resultX, sz.x + 2 * xmargin);
40: resultY = Math.max(resultY, sz.y + 2 * ymargin);
41: }
42:
43: return new Point(resultX, resultY);
44: }
45:
46: protected void layout(Composite composite, boolean flushCache) {
47: Control[] children = composite.getChildren();
48:
49: for (int i = 0; i < children.length; i++) {
50: Control control = children[i];
51: Rectangle area = composite.getClientArea();
52: Geometry.expand(area, -xmargin, -xmargin, -ymargin,
53: -ymargin);
54: control.setBounds(area);
55: }
56: }
57: }
|