1 16 package com.google.gwt.user.client.ui; 17 18 import com.google.gwt.user.client.Element; 19 20 import java.util.Iterator ; 21 22 25 public abstract class ComplexPanel extends Panel implements IndexedPanel { 26 27 private WidgetCollection children = new WidgetCollection(this); 28 29 public Widget getWidget(int index) { 30 return getChildren().get(index); 31 } 32 33 public int getWidgetCount() { 34 return getChildren().size(); 35 } 36 37 public int getWidgetIndex(Widget child) { 38 return getChildren().indexOf(child); 39 } 40 41 public Iterator iterator() { 42 return getChildren().iterator(); 43 } 44 45 public boolean remove(int index) { 46 return remove(getWidget(index)); 47 } 48 49 public boolean remove(Widget w) { 50 if (!getChildren().contains(w)) { 52 return false; 53 } 54 55 disown(w); 57 58 getChildren().remove(w); 59 return true; 60 } 61 62 69 protected int add(Widget w, Element container) { 70 return insert(w, container, getChildren().size()); 71 } 72 73 78 protected WidgetCollection getChildren() { 79 return children; 80 } 81 82 90 protected int insert(Widget w, Element container, int beforeIndex) { 91 if ((beforeIndex < 0) || (beforeIndex > getWidgetCount())) { 92 throw new IndexOutOfBoundsException (); 93 } 94 int idx = getWidgetIndex(w); 97 if (idx == -1) { 98 w.removeFromParent(); 99 } else { 100 remove(w); 101 if (idx < beforeIndex) { 104 beforeIndex--; 105 } 106 } 107 adopt(w, container); 108 getChildren().insert(w, beforeIndex); 109 return beforeIndex; 110 } 111 } 112 | Popular Tags |