KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > part > PageBook


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.part;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Layout;
18
19 /**
20  * A pagebook is a composite control where only a single control is visible
21  * at a time. It is similar to a notebook, but without tabs.
22  * <p>
23  * This class may be instantiated; it is not intended to be subclassed.
24  * </p>
25  *
26  * @see PageBookView
27  */

28 public class PageBook extends Composite {
29
30     /**
31      * <p>
32      * [Issue: This class should be declared private.]
33      * </p>
34      */

35     public class PageBookLayout extends Layout {
36
37         protected Point computeSize(Composite composite, int wHint, int hHint,
38                 boolean flushCache) {
39             if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
40                 return new Point(wHint, hHint);
41             }
42
43             Point result = null;
44             if (currentPage != null) {
45                 result = currentPage.computeSize(wHint, hHint, flushCache);
46             } else {
47                 //Rectangle rect= composite.getClientArea();
48
//result= new Point(rect.width, rect.height);
49
result = new Point(0, 0);
50             }
51             if (wHint != SWT.DEFAULT) {
52                 result.x = wHint;
53             }
54             if (hHint != SWT.DEFAULT) {
55                 result.y = hHint;
56             }
57             return result;
58         }
59
60         protected void layout(Composite composite, boolean flushCache) {
61             if (currentPage != null) {
62                 currentPage.setBounds(composite.getClientArea());
63             }
64         }
65     }
66
67     /**
68      * The current control; <code>null</code> if none.
69      */

70     private Control currentPage = null;
71
72     /**
73      * Creates a new empty pagebook.
74      *
75      * @param parent the parent composite
76      * @param style the SWT style bits
77      */

78     public PageBook(Composite parent, int style) {
79         super(parent, style);
80         setLayout(new PageBookLayout());
81     }
82
83     /**
84      * Shows the given page. This method has no effect if the given page is not
85      * contained in this pagebook.
86      *
87      * @param page the page to show
88      */

89     public void showPage(Control page) {
90
91         if (page == currentPage) {
92             return;
93         }
94         if (page.getParent() != this) {
95             return;
96         }
97
98         Control oldPage = currentPage;
99         currentPage = page;
100
101         // show new page
102
if (page != null) {
103             if (!page.isDisposed()) {
104                 page.setVisible(true);
105                 layout(true);
106                 // if (fRequestFocusOnShowPage)
107
// page.setFocus();
108
}
109         }
110
111         // hide old *after* new page has been made visible in order to avoid flashing
112
if (oldPage != null && !oldPage.isDisposed()) {
113             oldPage.setVisible(false);
114         }
115     }
116 }
117
Popular Tags