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 33 public class DeckPanel extends ComplexPanel { 34 35 private Widget visibleWidget; 36 37 40 public DeckPanel() { 41 setElement(DOM.createDiv()); 42 } 43 44 49 public void add(Widget w) { 50 insert(w, getWidgetCount()); 51 } 52 53 58 public int getVisibleWidget() { 59 return getWidgetIndex(visibleWidget); 60 } 61 62 70 public void insert(Widget w, int beforeIndex) { 71 super.insert(w, getElement(), beforeIndex); 72 73 Element child = w.getElement(); 74 DOM.setStyleAttribute(child, "width", "100%"); 75 DOM.setStyleAttribute(child, "height", "100%"); 76 w.setVisible(false); 77 } 78 79 public boolean remove(Widget w) { 80 if (!super.remove(w)) { 81 return false; 82 } 83 84 if (visibleWidget == w) { 85 visibleWidget = null; 86 } 87 88 return true; 89 } 90 91 97 public void showWidget(int index) { 98 checkIndex(index); 99 100 if (visibleWidget != null) { 101 visibleWidget.setVisible(false); 102 } 103 visibleWidget = getWidget(index); 104 visibleWidget.setVisible(true); 105 } 106 107 116 protected void disown(Widget w) { 117 super.disown(w); 118 DOM.setStyleAttribute(w.getElement(), "width", ""); 119 DOM.setStyleAttribute(w.getElement(), "height", ""); 120 w.setVisible(true); 121 } 122 123 private void checkIndex(int index) { 124 if ((index < 0) || (index >= getWidgetCount())) { 125 throw new IndexOutOfBoundsException (); 126 } 127 } 128 } 129 | Popular Tags |