KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > forms > widgets > WrappedPageBook


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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.forms.widgets;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.graphics.Point;
14 import org.eclipse.swt.widgets.*;
15 import org.eclipse.ui.forms.widgets.ILayoutExtension;
16
17 /**
18  * A pagebook is a composite control where only a single control is visible at
19  * a time. It is similar to a notebook, but without tabs.
20  * <p>
21  * This class may be instantiated; it is not intended to be subclassed.
22  * </p>
23  */

24 public class WrappedPageBook extends Composite {
25     class PageBookLayout extends Layout implements ILayoutExtension {
26         protected Point computeSize(Composite composite, int wHint, int hHint,
27                 boolean flushCache) {
28             if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
29                 return new Point(wHint, hHint);
30             Point result = null;
31             if (currentPage != null) {
32                 result = currentPage.computeSize(wHint, hHint, flushCache);
33             } else {
34                 result = new Point(0, 0);
35             }
36             return result;
37         }
38         protected void layout(Composite composite, boolean flushCache) {
39             if (currentPage != null) {
40                 currentPage.setBounds(composite.getClientArea());
41             }
42         }
43         /*
44          * (non-Javadoc)
45          *
46          * @see org.eclipse.ui.forms.widgets.ILayoutExtension#computeMaximumWidth(org.eclipse.swt.widgets.Composite,
47          * boolean)
48          */

49         public int computeMaximumWidth(Composite parent, boolean changed) {
50             return computeSize(parent, SWT.DEFAULT, SWT.DEFAULT, changed).x;
51         }
52         /*
53          * (non-Javadoc)
54          *
55          * @see org.eclipse.ui.forms.widgets.ILayoutExtension#computeMinimumWidth(org.eclipse.swt.widgets.Composite,
56          * boolean)
57          */

58         public int computeMinimumWidth(Composite parent, boolean changed) {
59             return computeSize(parent, 0, SWT.DEFAULT, changed).x;
60         }
61     }
62     /**
63      * The current control; <code>null</code> if none.
64      */

65     private Control currentPage = null;
66     /**
67      * Creates a new empty pagebook.
68      *
69      * @param parent
70      * the parent composite
71      * @param style
72      * the SWT style bits
73      */

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

85     public void showPage(Control page) {
86         if (page == currentPage)
87             return;
88         if (page.getParent() != this)
89             return;
90         Control oldPage = currentPage;
91         currentPage = page;
92         // show new page
93
if (page != null) {
94             if (!page.isDisposed()) {
95                 //page.setVisible(true);
96
layout(true);
97                 page.setVisible(true);
98             }
99         }
100         // hide old *after* new page has been made visible in order to avoid
101
// flashing
102
if (oldPage != null && !oldPage.isDisposed())
103             oldPage.setVisible(false);
104     }
105     public Point computeSize(int wHint, int hHint, boolean changed) {
106         return ((PageBookLayout) getLayout()).computeSize(this, wHint, hHint,
107                 changed);
108     }
109 }
110
Popular Tags