1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Simplified PageBook

This commit is contained in:
Michael Scharf 2007-02-08 03:08:55 +00:00
parent d725899290
commit c0e2a60500
2 changed files with 13 additions and 97 deletions

View file

@ -1,22 +1,18 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation (org.eclipse.ui.part.PageBook)
* Michael Scharf (Wind River) - consider all children for layout and hiding
* Michael Scharf (Wind River) - simplified implementation
*******************************************************************************/
package org.eclipse.tm.terminal.internal.view;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Layout;
/**
* A pagebook is a composite control where only a single control is visible
@ -27,94 +23,14 @@ import org.eclipse.swt.widgets.Layout;
*
*/
public class PageBook extends Composite {
private Point minimumPageSize = new Point(0, 0);
/**
* Layout for the page container.
*
*/
private class PageBookLayout extends Layout {
public Point computeSize(Composite composite, int wHint, int hHint, boolean force) {
if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
return new Point(wHint, hHint);
int x = minimumPageSize.x;
int y = minimumPageSize.y;
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
Point size = children[i].computeSize(wHint, hHint, force);
x = Math.max(x, size.x);
y = Math.max(y, size.y);
}
if (wHint != SWT.DEFAULT) {
x = wHint;
}
if (hHint != SWT.DEFAULT) {
y = hHint;
}
return new Point(x, y);
}
public void layout(Composite composite, boolean force) {
Rectangle rect = composite.getClientArea();
Control[] children = composite.getChildren();
for (int i = 0; i < children.length; i++) {
children[i].setBounds(rect);
}
}
private StackLayout fLayout;
public PageBook(Composite parent, int style) {
super(parent, style);
fLayout= new StackLayout();
setLayout(fLayout);
}
public void showPage(Control page) {
fLayout.topControl= page;
layout();
}
/**
* The current control; <code>null</code> if none.
*/
private Control currentPage = null;
/**
* Creates a new empty pagebook.
*
* @param parent the parent composite
* @param style the SWT style bits (use {@link SWT#NONE})
*/
public PageBook(Composite parent, int style, int minWidth, int minHeight) {
super(parent, style);
minimumPageSize.x=minWidth;
minimumPageSize.y=minHeight;
setLayout(new PageBookLayout());
}
/**
* Shows the given page. This method has no effect if the given page is not
* contained in this pagebook.
*
* @param page the page to show
*/
public void showPage(Control page) {
if (page == currentPage) {
return;
}
if (page==null || page.getParent() != this) {
return;
}
currentPage = page;
// show new page
if (!page.isDisposed()) {
page.setVisible(true);
layout(true);
// if (fRequestFocusOnShowPage)
// page.setFocus();
}
// hide old *after* new page has been made visible in order to avoid flashing
// we have to hide all other pages, because they might be visible
// by some other means...
Control[] pages=getChildren();
for (int i = 0; i < pages.length; i++) {
if(pages[i]!=page && !pages[i].isDisposed()) {
pages[i].setVisible(false);
}
}
}
}

View file

@ -121,7 +121,7 @@ class TerminalSettingsDlg extends Dialog {
group.setText(ViewMessages.SETTINGS + ":"); //$NON-NLS-1$
group.setLayout(new GridLayout());
group.setLayoutData(new GridData(GridData.FILL_BOTH));
fPageBook=new PageBook(group,SWT.NONE,230,0);
fPageBook=new PageBook(group,SWT.NONE);
fPageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));