/** * Constructor. * * @param edge the Edge to layout */ public ClassdiagramEdge(FigEdge edge) { currentEdge = edge; underlyingFig = new FigPoly(); underlyingFig.setLineColor(edge.getFig().getLineColor()); destFigNode = edge.getDestFigNode(); sourceFigNode = edge.getSourceFigNode(); }
/** * If the selected Fig is a FigAssociation (an edge) then convert it to a FigNodeAssociation. * * @param fig the select end Fig * @return the fig converted to a FigNode */ private FigNode convertToFigNode(Fig fig) { if (fig instanceof FigEdgePort) { fig = fig.getGroup(); } if (!(fig instanceof FigAssociation)) { return (FigNode) fig; } final FigAssociation figAssociation = (FigAssociation) fig; final int x = figAssociation.getEdgePort().getX(); final int y = figAssociation.getEdgePort().getY(); final Object association = fig.getOwner(); final FigNode originalEdgePort = figAssociation.getEdgePort(); // Detach any edges (such as comment edges) already attached // to the FigAssociation before the FigAssociation is removed. // They'll later be re-attached to the new FigNodeAssociation final Collection<FigEdge> existingEdges = originalEdgePort.getEdges(); for (FigEdge edge : existingEdges) { originalEdgePort.removeFigEdge(edge); } figAssociation.removeFromDiagram(); // Create the new FigNodeAssociation and locate it. final MutableGraphModel gm = (MutableGraphModel) editor.getGraphModel(); gm.addNode(association); final LayerPerspective lay = (LayerPerspective) editor.getLayerManager().getActiveLayer(); final List associationFigs = lay.presentationsFor(association); associationFigs.remove(figAssociation); final FigNodeAssociation figNode = (FigNodeAssociation) associationFigs.get(0); figNode.setLocation(x - figNode.getWidth() / 2, y - figNode.getHeight() / 2); editor.add(figNode); editor.getSelectionManager().deselectAll(); // Add the association ends to the graph model final Collection<Object> associationEnds = Model.getFacade().getConnections(association); for (Object associationEnd : associationEnds) { gm.addEdge(associationEnd); } // Add the edges (such as comment edges) that were on the old // FigAssociation to our new FigNodeAssociation and make sure they are // positioned correctly. for (FigEdge edge : existingEdges) { if (edge.getDestFigNode() == originalEdgePort) { edge.setDestFigNode(figNode); edge.setDestPortFig(figNode); } if (edge.getSourceFigNode() == originalEdgePort) { edge.setSourceFigNode(figNode); edge.setSourcePortFig(figNode); } } figNode.updateEdges(); return figNode; }
private void buildTree(Fig f, DefaultMutableTreeNode tn) { if (f instanceof FigGroup) { FigGroup fg = (FigGroup) f; for (int i = 0; i < fg.getFigCount(); ++i) { addNode(tn, fg.getFigAt(i)); } } else if (f instanceof FigEdge) { FigEdge fe = (FigEdge) f; Fig lineFig = fe.getFig(); addNode(tn, lineFig); addNode(tn, fe.getSourceFigNode()); addNode(tn, fe.getSourcePortFig()); addNode(tn, fe.getDestFigNode()); addNode(tn, fe.getDestPortFig()); for (Fig pathFig : (Vector<Fig>) fe.getPathItemFigs()) { addNode(tn, pathFig); } } }
protected void addEdge(Layer lay, FigEdge newEdge, Object edge) { if (newEdge == null) { throw new IllegalArgumentException( "Don't know how to create FigEdge for model type " + edge.getClass().getName()); } setPorts(lay, newEdge); assert newEdge != null : "There has been no FigEdge created"; // newEdge.setDiElement( // GraphChangeAdapter.getInstance().createElement(gm, edge)); assert newEdge != null : "There has been no FigEdge created"; assert (newEdge.getDestFigNode() != null) : "The FigEdge has no dest node"; assert (newEdge.getDestPortFig() != null) : "The FigEdge has no dest port"; assert (newEdge.getSourceFigNode() != null) : "The FigEdge has no source node"; assert (newEdge.getSourcePortFig() != null) : "The FigEdge has no source port"; lay.add(newEdge); }