1 16 package com.google.gwt.user.client.ui; 17 18 import com.google.gwt.user.client.DOM; 19 import com.google.gwt.user.client.Element; 20 21 import java.util.Iterator ; 22 23 27 public abstract class Panel extends Widget implements HasWidgets { 28 29 public void add(Widget w) { 30 throw new UnsupportedOperationException ("This panel does not support no-arg add()"); 31 } 32 33 public void clear() { 34 Iterator it = iterator(); 35 while (it.hasNext()) { 36 it.next(); 37 it.remove(); 38 } 39 } 40 41 51 protected void adopt(Widget w, Element container) { 52 w.removeFromParent(); 54 55 if (container != null) { 57 DOM.appendChild(container, w.getElement()); 58 } 59 w.setParent(this); 60 } 61 62 68 protected void disown(Widget w) { 69 if (w.getParent() != this) { 71 throw new IllegalArgumentException ("w is not a child of this panel"); 72 } 73 74 Element elem = w.getElement(); 76 w.setParent(null); 77 DOM.removeChild(DOM.getParent(elem), elem); 78 } 79 80 protected void onAttach() { 81 super.onAttach(); 82 83 for (Iterator it = iterator(); it.hasNext();) { 85 Widget child = (Widget) it.next(); 86 child.onAttach(); 87 } 88 } 89 90 protected void onDetach() { 91 super.onDetach(); 92 93 for (Iterator it = iterator(); it.hasNext();) { 95 Widget child = (Widget) it.next(); 96 child.onDetach(); 97 } 98 } 99 } 100 | Popular Tags |