Example #1
0
  NodePresenter(VGraphExplorer parent, NodeProxy model) {
    this.parent = parent;
    this.model = model;
    graph = parent.getGraph();

    view.setTitle(model.getId());
    Style style = view.getElement().getStyle();
    style.setLeft(model.getX(), Unit.PX);
    style.setTop(model.getY(), Unit.PX);

    view.addDomHandler(this, MouseDownEvent.getType());
    view.addDomHandler(this, MouseMoveEvent.getType());
    view.addDomHandler(this, MouseUpEvent.getType());

    parent.add(view);
  }
Example #2
0
  private void limitToBoundingBox() {
    Element element = view.getElement();
    Style style = element.getStyle();

    int width = element.getOffsetWidth();
    model.setWidth(width);
    int xRadius = width / 2;
    int leftEdge = model.getX() - xRadius;
    leftEdge = limit(0, leftEdge, parent.getOffsetWidth() - width);
    model.setX(leftEdge + xRadius);
    style.setLeft(leftEdge, Unit.PX);

    int height = element.getOffsetHeight();
    model.setHeight(height);
    int yRadius = height / 2;
    int topEdge = model.getY() - yRadius;
    topEdge = limit(0, topEdge, parent.getOffsetHeight() - height);
    model.setY(topEdge + yRadius);
    style.setTop(topEdge, Unit.PX);
  }
Example #3
0
 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();
 }
Example #4
0
 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();
 }