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 28 public class HorizontalPanel extends CellPanel implements HasAlignment { 29 30 private HorizontalAlignmentConstant horzAlign = ALIGN_LEFT; 31 private Element tableRow; 32 private VerticalAlignmentConstant vertAlign = ALIGN_TOP; 33 34 37 public HorizontalPanel() { 38 tableRow = DOM.createTR(); 39 DOM.appendChild(getBody(), tableRow); 40 41 DOM.setElementProperty(getTable(), "cellSpacing", "0"); 42 DOM.setElementProperty(getTable(), "cellPadding", "0"); 43 } 44 45 51 public void add(Widget w) { 52 insert(w, getWidgetCount()); 53 } 54 55 public HorizontalAlignmentConstant getHorizontalAlignment() { 56 return horzAlign; 57 } 58 59 public VerticalAlignmentConstant getVerticalAlignment() { 60 return vertAlign; 61 } 62 63 72 public void insert(Widget w, int beforeIndex) { 73 Element td = DOM.createTD(); 74 beforeIndex = super.insert(w, td, beforeIndex); 75 DOM.insertChild(tableRow, td, beforeIndex); 76 77 setCellHorizontalAlignment(w, horzAlign); 78 setCellVerticalAlignment(w, vertAlign); 79 } 80 81 public boolean remove(Widget w) { 82 if (w.getParent() != this) { 83 return false; 84 } 85 86 Element td = DOM.getParent(w.getElement()); 87 DOM.removeChild(tableRow, td); 88 89 super.remove(w); 90 return true; 91 } 92 93 99 public void setHorizontalAlignment(HorizontalAlignmentConstant align) { 100 horzAlign = align; 101 } 102 103 109 public void setVerticalAlignment(VerticalAlignmentConstant align) { 110 vertAlign = align; 111 } 112 } 113 | Popular Tags |