示例#1
0
 public void startLinkingFrom(final VNode node) {
   VConsole.log("onlink");
   onLink = true;
   linkNode = node;
   startX = node.getX();
   startY = node.getY();
 }
 public void startRecord(String type) {
   VNode vnode = new VNode();
   vnode.parseStatus = 1;
   vnode.VName = type;
   vNodeList.add(vnode);
   nodeListPos = vNodeList.size() - 1;
   curVNode = vNodeList.get(nodeListPos);
 }
示例#3
0
 public void constructLinkTo(final VNode node2) {
   VConsole.log("linked");
   final String name =
       linkNode.getName() + "_to_" + node2.getName() + "_" + new Random().nextInt(1000);
   final VEdge edge = VEdge.createAnEdge(null, this, graph, name, linkNode, node2, style);
   client.updateVariable(
       paintableId, "edgeCreated", new String[] {linkNode.getName(), node2.getName(), name}, true);
   graph.addEdge(edge);
 }
示例#4
0
 @Override
 public void onDoubleClick(final DoubleClickEvent event) {
   VConsole.log("onDoubleClick");
   final int x = event.getX();
   final int y = event.getY();
   final VNode node = VNode.createANode(x, y, this, graph, style);
   graph.addNode(node);
   client.updateVariable(paintableId, "createdANode", new Object[] {node.getName(), x, y}, true);
 }
 public void endRecord() {
   VNode endNode = vNodeList.get(nodeListPos);
   endNode.parseStatus = 0;
   while (nodeListPos > 0) {
     nodeListPos--;
     if ((vNodeList.get(nodeListPos)).parseStatus == 1) break;
   }
   curVNode = vNodeList.get(nodeListPos);
 }
示例#6
0
 public void nodeOrEdgeSelectionChanged() {
   final String[] edges = new String[graph.getSelectedEdges().size()];
   final String[] nodes = new String[graph.getSelectedShapes().size()];
   int i = 0;
   for (final VEdge vedge : graph.getSelectedEdges()) {
     edges[i] = vedge.toString();
     ++i;
   }
   i = 0;
   for (final VNode vnode : graph.getSelectedShapes()) {
     nodes[i] = vnode.toString();
     ++i;
   }
   client.updateVariable(paintableId, "selectedEdges", edges, false);
   client.updateVariable(paintableId, "selectedNodes", nodes, true);
 }
示例#7
0
  private void zoom(final double factor) {
    if (factor < 1) {
      zoomFactor--;
    } else {
      zoomFactor++;
    }
    for (final VNode n : graph.getPaintedShapes()) {
      n.setX((float) ((n.getX() - centerX) * factor) + centerX);
      n.setY((float) ((n.getY() - centerY) * factor) + centerY);

      if (n.getView() instanceof Circle) {
        if (factor > 1) {
          ((Circle) n.getView()).setRadius((((Circle) n.getView()).getRadius() + 1));
        } else {
          ((Circle) n.getView()).setRadius((((Circle) n.getView()).getRadius() - 1));
        }
      }
      graph.updateEdges(n, false);
    }
    client.updateVariable(paintableId, "zoomFactor", zoomFactor, true);
  }
示例#8
0
 private void selectNodesAndEdgesInTheBox(
     final int startX, final int startY, final int endX, final int endY) {
   for (final VNode node : graph.getSelectedShapes()) {
     graph.setNodeSelected(node, false);
   }
   for (final VEdge edge : graph.getSelectedEdges()) {
     graph.setEdgeSelected(edge, false);
   }
   for (final VNode node : graph.getPaintedShapes()) {
     if (isInArea(node.getX(), node.getY(), startX, startY, endX, endY)) {
       graph.setNodeSelected(node, true);
     }
   }
   for (final VEdge edge : graph.getSelectedEdges()) {
     if (graph.getSelectedShapes().contains(edge.getFirstNode())
         && graph.getSelectedShapes().contains(edge.getSecondNode())) {
       graph.setEdgeSelected(edge, true);
     }
   }
   nodeOrEdgeSelectionChanged();
 }
示例#9
0
  @Override
  public void onMouseMove(final MouseMoveEvent event) {
    final int currentX = event.getX();
    final int currentY = event.getY();

    if (selectionBox.isSelectionBoxVisible()) {
      selectionBox.drawSelectionBox(canvas, currentX, currentY);
    } else if (graph.getMovedShape() != null) {
      final VNode moved = graph.getMovedShape();
      moved.moveNode(currentX, currentY);
    } else if (onLink) {
      if (linkLine != null) {
        canvas.remove(linkLine);
      }
      linkLine = getLinkLine(currentX, currentY);
      canvas.add(linkLine);
    } else if (onMove && event.getSource().equals(canvas)) {
      graph.moveGraph(startX - currentX, startY - currentY);
      startX = currentX;
      startY = currentY;
    }
  }
示例#10
0
 private void rotate(final double delta) {
   for (final VNode n : graph.getPaintedShapes()) {
     final float newX =
         (float) ((n.getX() - centerX) * Math.cos(delta) - (n.getY() - centerY) * Math.sin(delta))
             + centerX;
     final float newY =
         (float) ((n.getX() - centerX) * Math.sin(delta) + (n.getY() - centerY) * Math.cos(delta))
             + centerY;
     n.setX(newX);
     n.setY(newY);
     graph.updateEdges(n, false);
   }
   angle += delta;
 }
示例#11
0
 public void deleteNode(final VNode node, final boolean immediate) {
   client.updateVariable(paintableId, "removedNode", node.getName(), immediate);
   graph.removeNode(node);
 }
 private String safeVisit(VNode operand) {
   if (operand == null) {
     return "null";
   }
   return operand.visit(this);
 }