KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > custom > CTabFolderLayout


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 package org.eclipse.swt.custom;
12
13 import org.eclipse.swt.*;
14 import org.eclipse.swt.graphics.*;
15 import org.eclipse.swt.widgets.*;
16
17 /**
18  * This class provides the layout for CTabFolder
19  *
20  * @see CTabFolder
21  */

22 class CTabFolderLayout extends Layout {
23 protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
24     CTabFolder folder = (CTabFolder)composite;
25     CTabItem[] items = folder.items;
26     // preferred width of tab area to show all tabs
27
int tabW = 0;
28     GC gc = new GC(folder);
29     for (int i = 0; i < items.length; i++) {
30         if (folder.single) {
31             tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false));
32         } else {
33             tabW += items[i].preferredWidth(gc, i == folder.selectedIndex, false);
34         }
35     }
36     gc.dispose();
37     tabW += 3;
38     if (folder.showMax) tabW += CTabFolder.BUTTON_SIZE;
39     if (folder.showMin) tabW += CTabFolder.BUTTON_SIZE;
40     if (folder.single) tabW += 3*CTabFolder.BUTTON_SIZE/2; //chevron
41
if (folder.topRight != null) {
42         Point pt = folder.topRight.computeSize(SWT.DEFAULT, folder.tabHeight, flushCache);
43         tabW += 3 + pt.x;
44     }
45     if (!folder.single && !folder.simple) tabW += folder.curveWidth - 2*folder.curveIndent;
46     
47     int controlW = 0;
48     int controlH = 0;
49     // preferred size of controls in tab items
50
for (int i = 0; i < items.length; i++) {
51         Control control = items[i].getControl();
52         if (control != null && !control.isDisposed()){
53             Point size = control.computeSize (wHint, hHint, flushCache);
54             controlW = Math.max (controlW, size.x);
55             controlH = Math.max (controlH, size.y);
56         }
57     }
58
59     int minWidth = Math.max(tabW, controlW);
60     int minHeight = (folder.minimized) ? 0 : controlH;
61     if (minWidth == 0) minWidth = CTabFolder.DEFAULT_WIDTH;
62     if (minHeight == 0) minHeight = CTabFolder.DEFAULT_HEIGHT;
63     
64     if (wHint != SWT.DEFAULT) minWidth = wHint;
65     if (hHint != SWT.DEFAULT) minHeight = hHint;
66     
67     return new Point (minWidth, minHeight);
68 }
69 protected boolean flushCache(Control control) {
70     return true;
71 }
72 protected void layout(Composite composite, boolean flushCache) {
73     CTabFolder folder = (CTabFolder)composite;
74     // resize content
75
if (folder.selectedIndex != -1) {
76         Control control = folder.items[folder.selectedIndex].getControl();
77         if (control != null && !control.isDisposed()) {
78             control.setBounds(folder.getClientArea());
79         }
80     }
81 }
82 }
83
Popular Tags