PanelPosition next;
}
private void createSlider(final Element wrapper, final Element child,
final PanelNode node, final boolean first) {
final Element sliderEl = Browser.getDocument().createSpanElement();
final String cls;
if (vertical) {
if (first) {
// Do a top-slider
cls = css.topSplit();
} else {
// Do a bottom-slider
cls = css.bottomSplit();
}
} else {
if (first) {
// Do a left-slider
cls = css.leftSplit();
} else {
// Do a right-slider
cls = css.rightSplit();
}
}
sliderEl.addClassName(cls);
wrapper.appendChild(sliderEl);
final PanelPosition self = new PanelPosition();
self.node = node;
sliderEl.setOnmousedown(new EventListener() {
@Override
public void handleEvent(Event evt) {
evt.preventDefault();
final PanelNode siblingNode = first ? getPreviousSibling(node) : node.next;
final Element sibling;
if (siblingNode == null) {
sibling = null;
} else {
self.next = new PanelPosition();
sibling = siblingNode.el;
self.next.node = siblingNode;
}
PanelPosition affected = self.next;
MouseEvent e = (MouseEvent) evt;
if (vertical) {
self.mouseStart = e.getClientY();
// We parse from the css values set (which we set before this is called),
// so we don't have to do any measuring
// or compensate for weird offsets in the client elements.
self.posStart = CssUtils.parsePixels(wrapper.getStyle().getTop());
self.sizeStart = CssUtils.parsePixels(wrapper.getStyle().getHeight());
if (sibling != null) {
affected.posStart = CssUtils.parsePixels(sibling.getStyle().getTop());
affected.sizeStart = CssUtils.parsePixels(sibling.getStyle().getHeight());
}
} else {
self.mouseStart = e.getClientX();
self.posStart = CssUtils.parsePixels(wrapper.getStyle().getLeft());
self.sizeStart = CssUtils.parsePixels(wrapper.getStyle().getWidth());
if (sibling != null) {
affected.posStart = CssUtils.parsePixels(sibling.getStyle().getLeft());
affected.sizeStart = CssUtils.parsePixels(sibling.getStyle().getWidth());
}
}
final EventRemover[] remover = new EventRemover[2];
// TODO put these event listeners over an empty iframe, to cover up any iframes on page.
remover[0] = Browser.getWindow().addEventListener("mouseup", new EventListener() {
@Override
public void handleEvent(Event evt) {
if (remover[0] != null){
remover[0].remove();
remover[1].remove();
onResizeFinished(siblingNode, self);
remover[0] = null;
}
}
}, true);
remover[1] = Browser.getWindow().addEventListener("mousemove", new EventListener() {
@Override
public void handleEvent(Event evt) {
evt.preventDefault();
final MouseEvent e = (MouseEvent) evt;
final Element el = self.next == null ? null : self.next.node.el;
assert el != wrapper;
double delta;
if (vertical) {
delta = e.getClientY() - self.mouseStart;
if (first) {
// A top drag affects top and height
wrapper.getStyle().setTop((int)(self.posStart+ delta),"px");
wrapper.getStyle().setHeight((int)(self.sizeStart - delta),"px");
if (el != null) {
// TODO implement max/min/pref values, and iterate through the
// nodes to push delta off on any neighbors
el.getStyle().setHeight((int)(self.next.sizeStart + delta),"px");
}
} else {
wrapper.getStyle().setHeight((int)(self.sizeStart + delta),"px");
if (el != null) {
el.getStyle().setTop((int)(self.next.posStart+ delta),"px");
el.getStyle().setHeight((int)(self.next.sizeStart - delta),"px");
}
}
} else {
delta = e.getClientX() - self.mouseStart;
if (first) {
// A left drag affects left and size
wrapper.getStyle().setLeft((int)(self.posStart + delta),"px");
wrapper.getStyle().setWidth((int)(self.sizeStart - delta),"px");
if (el != null) {
el.getStyle().setWidth((int)(self.next.sizeStart + delta),"px");
}
} else {
wrapper.getStyle().setWidth((int)(self.sizeStart + delta),"px");
if (el != null) {
el.getStyle().setLeft((int)(self.next.posStart + delta),"px");
el.getStyle().setWidth((int)(self.next.sizeStart - delta),"px");
}
}
}
}
}, true);