public void onMouseMove(MouseMoveEvent event) { if (isMouseDown()) { setDragging(true); updateCSS(); model.setX(event.getX() + model.getX() - dragStartX); model.setY(event.getY() + model.getY() - dragStartY); onUpdateInModel(); int clientX = event.getClientX(); int clientY = event.getClientY(); boolean outsideWindow = clientX < 0 || clientY < 0 || clientX > Window.getClientWidth() || clientY > Window.getClientHeight(); if (outsideWindow) { parent.save(model, true); setDragging(false); } } event.preventDefault(); }
public void onMouseUp(MouseUpEvent event) { Element element = view.getElement(); if (!isDragging()) { updateCSS(); limitToBoundingBox(); if (NodeProxy.EXPANDED.equals(model.getState())) { model.setState(NodeProxy.COLLAPSED); for (NodeProxy neighbor : graph.getNeighbors(model)) { boolean collapsed = NodeProxy.COLLAPSED.equals(neighbor.getState()); boolean leafNode = graph.degree(neighbor) == 1; if (collapsed && leafNode) { graph.removeNode(neighbor); } } } parent.toggle(model); } else { parent.save(model, true); setDragging(false); } setMouseDown(false); DOM.releaseCapture(element); event.preventDefault(); }