1 11 package org.eclipse.ui.forms.widgets; 12 import java.util.Hashtable ; 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.layout.GridLayout; 16 import org.eclipse.swt.widgets.*; 17 import org.eclipse.ui.internal.forms.widgets.WrappedPageBook; 18 25 public class ScrolledPageBook extends SharedScrolledComposite { 26 private WrappedPageBook pageBook; 27 private Hashtable pages; 28 private Composite emptyPage; 29 private Control currentPage; 30 35 public ScrolledPageBook(Composite parent) { 36 this(parent, SWT.H_SCROLL | SWT.V_SCROLL); 37 } 38 47 public ScrolledPageBook(Composite parent, int style) { 48 super(parent, style); 49 pageBook = new WrappedPageBook(this, SWT.NULL); 50 setContent(pageBook); 51 pages = new Hashtable (); 52 setExpandHorizontal(true); 53 setExpandVertical(true); 54 this.addListener(SWT.Traverse, new Listener() { 55 public void handleEvent(Event e) { 56 switch (e.detail) { 57 case SWT.TRAVERSE_ESCAPE : 58 case SWT.TRAVERSE_RETURN : 59 case SWT.TRAVERSE_TAB_NEXT : 60 case SWT.TRAVERSE_TAB_PREVIOUS : 61 e.doit = true; 62 break; 63 } 64 } 65 }); 66 } 67 78 public Point computeSize(int wHint, int hHint, boolean changed) { 79 Rectangle trim = computeTrim(0, 0, 10, 10); 80 return new Point(trim.width, trim.height); 81 } 82 90 public boolean hasPage(Object key) { 91 return pages.containsKey(key); 92 } 93 101 public Composite createPage(Object key) { 102 Composite page = createPage(); 103 pages.put(key, page); 104 return page; 105 } 106 111 public Composite getContainer() { 112 return pageBook; 113 } 114 125 public void registerPage(Object key, Control page) { 126 pages.put(key, page); 127 } 128 135 public void removePage(Object key) { 136 removePage(key, true); 137 } 138 148 public void removePage(Object key, boolean showEmptyPage) { 149 Control page = (Control) pages.get(key); 150 if (page != null) { 151 pages.remove(key); 152 page.dispose(); 153 if (showEmptyPage) 154 showEmptyPage(); 155 } 156 } 157 164 public void showPage(Object key) { 165 Control page = (Control) pages.get(key); 166 if (page != null) { 167 pageBook.showPage(page); 168 if (currentPage != null && currentPage != page) { 169 if (page instanceof Composite) 171 ((Composite) page).layout(false); 172 } 173 currentPage = page; 174 } else { 175 showEmptyPage(); 176 } 177 reflow(true); 178 } 179 183 public void showEmptyPage() { 184 if (emptyPage == null) { 185 emptyPage = createPage(); 186 emptyPage.setLayout(new GridLayout()); 187 } 188 pageBook.showPage(emptyPage); 189 currentPage = emptyPage; 190 reflow(true); 191 } 192 195 public boolean setFocus() { 196 if (currentPage != null) 197 return currentPage.setFocus(); 198 return super.setFocus(); 199 } 200 205 public Control getCurrentPage() { 206 return currentPage; 207 } 208 private Composite createPage() { 209 Composite page = new LayoutComposite(pageBook, SWT.NULL); 210 page.setBackground(getBackground()); 211 page.setForeground(getForeground()); 212 page.setMenu(pageBook.getMenu()); 213 return page; 214 } 215 } 216 | Popular Tags |