1 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 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 49 public int computeMaximumWidth(Composite parent, boolean changed) { 50 return computeSize(parent, SWT.DEFAULT, SWT.DEFAULT, changed).x; 51 } 52 58 public int computeMinimumWidth(Composite parent, boolean changed) { 59 return computeSize(parent, 0, SWT.DEFAULT, changed).x; 60 } 61 } 62 65 private Control currentPage = null; 66 74 public WrappedPageBook(Composite parent, int style) { 75 super(parent, style); 76 setLayout(new PageBookLayout()); 77 } 78 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 if (page != null) { 94 if (!page.isDisposed()) { 95 layout(true); 97 page.setVisible(true); 98 } 99 } 100 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 |