コード例 #1
0
  public void renderInJGraph() {
    /** the real renderer */
    ConnectionSet cs = new ConnectionSet();
    Map<Object, AttributeMap> attributes = new Hashtable<Object, AttributeMap>();
    for (DefaultEdge linkEdge : retrieveLinks()) {
      DefaultPort srcPort = (DefaultPort) linkEdge.getSource();
      DefaultPort trgtPort = (DefaultPort) linkEdge.getTarget();
      DefaultGraphCell sourceCell = (DefaultGraphCell) srcPort.getParent();
      DefaultGraphCell targetCell = (DefaultGraphCell) trgtPort.getParent();

      AttributeMap lineStyle = linkEdge.getAttributes();
      AttributeMap sourceNodeCellAttribute = null;
      if (sourceCell != null) sourceNodeCellAttribute = sourceCell.getAttributes();
      AttributeMap targetNodeCellAttribute = null;
      if (targetCell != null) targetNodeCellAttribute = targetCell.getAttributes();

      Object sourceNode = srcPort.getUserObject();
      Object targetNode = trgtPort.getUserObject();
      try {
        if (sourceNode instanceof DefaultMappableTreeNode) {
          if ((targetNode instanceof DefaultMappableTreeNode)) {
            // change target node
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) targetNode;
            adjustToNewPosition(treeNode, targetNodeCellAttribute);
          }
          // change source node
          DefaultMutableTreeNode srcNode = (DefaultMutableTreeNode) sourceNode;
          adjustToNewPosition(srcNode, sourceNodeCellAttribute);
        }
        if (sourceNodeCellAttribute != null
            && targetNodeCellAttribute
                != null) { // put in attribute if and only if it is constructed.
          attributes.put(sourceCell, sourceNodeCellAttribute);
          attributes.put(targetCell, targetNodeCellAttribute);
          attributes.put(linkEdge, lineStyle);
          // cs.connect(linkEdge, sourceCell.getChildAt(0), targetCell.getChildAt(0));
          // Log.logInfo(this, "Drew line for : " + mappingComponent.toString());
        }
      } catch (Throwable e) {
        e.printStackTrace();
        // Log.logInfo(this, "Did not draw line for : " + mappingComponent.toString(true));
      }
    } // end of for
    getGraph().getGraphLayoutCache().edit(attributes, cs, null, null);
    getGraph().getGraphLayoutCache().setSelectsAllInsertedCells(false);
  }
コード例 #2
0
ファイル: GraphEditor.java プロジェクト: gityejing/flow
  /**
   * 连接两个Port
   *
   * @param source
   * @param target
   */
  public void connect(Port source, Port target) {
    for (Iterator it = source.edges(); it.hasNext(); ) {
      Edge e = (Edge) it.next();
      if (e.getTarget() == target) {
        this.repaint();
        return;
      }
    }
    // Construct Edge with no label
    DefaultEdge edge = new DefaultEdge();
    if (graph.getModel().acceptsSource(edge, source)
        && graph.getModel().acceptsTarget(edge, target)) {

      edge.setUserObject(new FlowEdgeObject(edge));
      // Create a Map thath holds the attributes for the edge
      edge.getAttributes().applyMap(createEdgeAttributes());
      // Insert the Edge and its Attributes
      graph.getGraphLayoutCache().insertEdge(edge, source, target);

      // 添加到树结构
      // editor.strutcView.addFlowRoute(graph, edge);
    }
  }