KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > TabFolderLayout


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.ui.internal.editors.text;
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Point;
16 import org.eclipse.swt.graphics.Rectangle;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Layout;
20
21 /**
22  * This layout controls the position and size
23  * of the children of a tab folder.
24  *
25  * @since 2.1
26  */

27 class TabFolderLayout extends Layout {
28
29     /*
30      * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean)
31      */

32     protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
33         if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
34             return new Point(wHint, hHint);
35
36         Control [] children = composite.getChildren ();
37         int count = children.length;
38         int maxWidth = 0, maxHeight = 0;
39         for (int i=0; i<count; i++) {
40             Control child = children [i];
41             Point pt = child.computeSize (SWT.DEFAULT, SWT.DEFAULT, flushCache);
42             maxWidth = Math.max (maxWidth, pt.x);
43             maxHeight = Math.max (maxHeight, pt.y);
44         }
45
46         if (wHint != SWT.DEFAULT)
47             maxWidth= wHint;
48         if (hHint != SWT.DEFAULT)
49             maxHeight= hHint;
50
51         return new Point(maxWidth, maxHeight);
52
53     }
54
55     /*
56      * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, boolean)
57      */

58     protected void layout (Composite composite, boolean flushCache) {
59         Rectangle rect= composite.getClientArea();
60
61         Control[] children = composite.getChildren();
62         for (int i = 0; i < children.length; i++) {
63             children[i].setBounds(rect);
64         }
65     }
66 }
67
Popular Tags