/** Resizes selected and sibling columns. */ protected void resize() { int position = this.currentX; int delta = position - startX; Element tr = DOM.getParent(th); int left = DOM.getAbsoluteLeft(th); int width = getElementWidth(th); Element sibling = null; int sign = 0; int thIndex = DOM.getChildIndex(tr, th); if (startX <= left + 2) { sign = 1; sibling = DOM.getChild(tr, thIndex - 1); } else if (startX >= left + width - 2) { sign = -1; sibling = DOM.getChild(tr, thIndex + 1); } int thExpectedWidth = width - sign * delta; int siblingExpectedWidth; int siblingIndex; if (sibling != null) { siblingExpectedWidth = getElementWidth(sibling) + sign * delta; siblingIndex = DOM.getChildIndex(tr, sibling); } else { siblingExpectedWidth = 0; siblingIndex = -1; } // interrupt immediately if (thExpectedWidth < 3 || siblingExpectedWidth < 3 && siblingIndex > -1) { th = null; return; } if (siblingIndex > -1) { grid.setColumnWidth(thIndex, thExpectedWidth); grid.setColumnWidth(siblingIndex, siblingExpectedWidth); } int thWidthNow = getElementWidth(th); int siblingWidthNow; if (siblingIndex > -1) siblingWidthNow = getElementWidth(sibling); else siblingWidthNow = 0; if (thWidthNow > thExpectedWidth) grid.setColumnWidth(thIndex, 2 * thExpectedWidth - thWidthNow); if (siblingWidthNow > siblingExpectedWidth && siblingIndex > -1) grid.setColumnWidth(siblingIndex, 2 * siblingExpectedWidth - siblingWidthNow); this.startX = position; }
/** * This method interrupts resiszing. * * @param event is an event. */ protected void interruptResizing(Event event) { int positionX = getPositionX(event); int positionY = getPositionY(event); Element thead = grid.getTHeadElement(); int left = DOM.getAbsoluteLeft(thead); int top = DOM.getAbsoluteTop(thead); int width = getElementWidth(thead); int height = getElementHeight(thead); if (positionX < left || positionX > left + width || positionY < top || positionY > top + height) { th = null; timer.cancel(); } }