001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.part;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.graphics.Point;
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.swt.widgets.Control;
016: import org.eclipse.swt.widgets.Layout;
017:
018: /**
019: * A pagebook is a composite control where only a single control is visible
020: * at a time. It is similar to a notebook, but without tabs.
021: * <p>
022: * This class may be instantiated; it is not intended to be subclassed.
023: * </p>
024: *
025: * @see PageBookView
026: */
027: public class PageBook extends Composite {
028:
029: /**
030: * <p>
031: * [Issue: This class should be declared private.]
032: * </p>
033: */
034: public class PageBookLayout extends Layout {
035:
036: protected Point computeSize(Composite composite, int wHint,
037: int hHint, boolean flushCache) {
038: if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
039: return new Point(wHint, hHint);
040: }
041:
042: Point result = null;
043: if (currentPage != null) {
044: result = currentPage.computeSize(wHint, hHint,
045: flushCache);
046: } else {
047: //Rectangle rect= composite.getClientArea();
048: //result= new Point(rect.width, rect.height);
049: result = new Point(0, 0);
050: }
051: if (wHint != SWT.DEFAULT) {
052: result.x = wHint;
053: }
054: if (hHint != SWT.DEFAULT) {
055: result.y = hHint;
056: }
057: return result;
058: }
059:
060: protected void layout(Composite composite, boolean flushCache) {
061: if (currentPage != null) {
062: currentPage.setBounds(composite.getClientArea());
063: }
064: }
065: }
066:
067: /**
068: * The current control; <code>null</code> if none.
069: */
070: private Control currentPage = null;
071:
072: /**
073: * Creates a new empty pagebook.
074: *
075: * @param parent the parent composite
076: * @param style the SWT style bits
077: */
078: public PageBook(Composite parent, int style) {
079: super (parent, style);
080: setLayout(new PageBookLayout());
081: }
082:
083: /**
084: * Shows the given page. This method has no effect if the given page is not
085: * contained in this pagebook.
086: *
087: * @param page the page to show
088: */
089: public void showPage(Control page) {
090:
091: if (page == currentPage) {
092: return;
093: }
094: if (page.getParent() != this ) {
095: return;
096: }
097:
098: Control oldPage = currentPage;
099: 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: }
|