KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > util > EnhancedFillLayout


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.presentations.util;
12
13 import org.eclipse.jface.util.Geometry;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.graphics.Rectangle;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Layout;
19
20 /**
21  * @since 3.1
22  */

23 public class EnhancedFillLayout extends Layout {
24
25     public int xmargin = 0;
26     public int ymargin = 0;
27     
28     protected Point computeSize(Composite composite, int wHint, 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, -ymargin );
53             control.setBounds(area);
54         }
55     }
56 }
57
Popular Tags