1 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 28 public class PageBook extends Composite { 29 30 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 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 70 private Control currentPage = null; 71 72 78 public PageBook(Composite parent, int style) { 79 super(parent, style); 80 setLayout(new PageBookLayout()); 81 } 82 83 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 if (page != null) { 103 if (!page.isDisposed()) { 104 page.setVisible(true); 105 layout(true); 106 } 109 } 110 111 if (oldPage != null && !oldPage.isDisposed()) { 113 oldPage.setVisible(false); 114 } 115 } 116 } 117 | Popular Tags |