public class DivPanel extends SimplePanel {
private WidgetCollection children = new WidgetCollection(this);
public DivPanel() {
super();
}
public Widget getWidget(int index) {
return getChildren().get(index);
}
public int getWidgetCount() {
return getChildren().size();
}
public int getWidgetIndex(Widget child) {
return getChildren().indexOf(child);
}
public Iterator
return getChildren().iterator();
}
public boolean remove(int index) {
return remove(getWidget(index));
}
@Override
public boolean remove(Widget w) {
// Validate.
if (w.getParent() != this) {
return false;
}
// Orphan.
orphan(w);
// Physical detach.
Element elem = w.getElement();
DOM.removeChild(DOM.getParent(elem), elem);
// Logical detach.
getChildren().remove(w);
return true;
}
public void add(Widget child){
add(child,getElement());
}
protected void add(Widget child, Element container) {
// Detach new child.
child.removeFromParent();
// Logical attach.
getChildren().add(child);
// Physical attach.
DOM.appendChild(container, child.getElement());
// Adopt.
adopt(child);
}
protected WidgetCollection getChildren() {
return children;
}
}
public class DockDiv extends DivPanel{
public final static int NORTH = 0;
public final static int SOUTH = 1;
public final static int EAST = 2;
public final static int WEST = 3;
public final static int CENTER = 4;
private Element north = DOM.createDiv();
private Element south = DOM.createDiv();
private Element east = DOM.createDiv();
private Element west = DOM.createDiv();
private Element center = DOM.createDiv();
private Element row = DOM.createDiv();
private Element container = DOM.createDiv();
public DockDiv(){
container.appendChild(north);
container.appendChild(row);
container.appendChild(south);
row.appendChild(west);
row.appendChild(center);
row.appendChild(east);
getElement().appendChild(container);
east.getStyle().setProperty("float", "left");
west.getStyle().setProperty("float", "left");
center.getStyle().setProperty("float", "left");
}
public void add(Widget child){
add(child,center);
}
public void add(Widget child, int pos){
switch (pos) {
case NORTH:
add(child,north);
break;
case SOUTH:
add(child,south);
break;
case EAST:
add(child,east);
break;
case WEST:
add(child, west);
break;
default:
add(child, center);
break;
}
}
public Element getRegion(int region){
switch (region) {
case NORTH:
return north;
case SOUTH:
return south;
case EAST:
return east;
case WEST:
return west;
default:
return center;
}
}
@Override
public void setWidth(String width) {
super.setWidth(width);
north.getStyle().setProperty("width", width);
row.getStyle().setProperty("width", width);
south.getStyle().setProperty("width", width);
}
public void setCenterSize(String west, String center, String east){
if (west != null && !west.equals("")){
this.west.getStyle().setProperty("width", west);
}
if (center != null && !center.equals("")){
this.center.getStyle().setProperty("width", center);
}
if (east != null && !east.equals("")){
this.east.getStyle().setProperty("width", east);
}
}
}
No comments:
Post a Comment