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 import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant; 21 import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant; 22 23 28 public abstract class CellPanel extends ComplexPanel { 29 30 private int spacing; 31 private Element table, body; 32 33 public CellPanel() { 34 table = DOM.createTable(); 35 body = DOM.createTBody(); 36 DOM.appendChild(table, body); 37 setElement(table); 38 } 39 40 45 public int getSpacing() { 46 return spacing; 47 } 48 49 56 public void setBorderWidth(int width) { 57 DOM.setElementProperty(table, "border", "" + width); 58 } 59 60 67 public void setCellHeight(Widget w, String height) { 68 Element td = DOM.getParent(w.getElement()); 69 DOM.setElementProperty(td, "height", height); 70 } 71 72 79 public void setCellHorizontalAlignment(Widget w, 80 HorizontalAlignmentConstant align) { 81 Element td = getWidgetTd(w); 82 if (td != null) { 83 DOM.setElementProperty(td, "align", align.getTextAlignString()); 84 } 85 } 86 87 94 public void setCellVerticalAlignment(Widget w, VerticalAlignmentConstant align) { 95 Element td = getWidgetTd(w); 96 if (td != null) { 97 DOM.setStyleAttribute(td, "verticalAlign", align.getVerticalAlignString()); 98 } 99 } 100 101 108 public void setCellWidth(Widget w, String width) { 109 Element td = DOM.getParent(w.getElement()); 110 DOM.setElementProperty(td, "width", width); 111 } 112 113 118 public void setSpacing(int spacing) { 119 this.spacing = spacing; 120 DOM.setElementPropertyInt(table, "cellSpacing", spacing); 121 } 122 123 protected Element getBody() { 124 return body; 125 } 126 127 protected Element getTable() { 128 return table; 129 } 130 131 private Element getWidgetTd(Widget w) { 132 if (w.getParent() != this) { 133 return null; 134 } 135 return DOM.getParent(w.getElement()); 136 } 137 } 138 | Popular Tags |