diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index ea36f70..a7e527e 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -18,6 +18,7 @@ import java.util.Map.Entry; import javax.swing.JFrame; +import javax.swing.JPanel; import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DirectedWeightedPseudograph; @@ -63,7 +64,7 @@ //BUG: edge drawing order. -> parent //BUG: methodExecution drawing order. -> parent //BUG: ObjectVertex position when Resize ObjectVertex. O -public class DeltaViewer { +public class DeltaViewer extends JPanel { private static Dimension DEFAULT_SIZE = new Dimension(1300, 700); private static String WINDOW_TITLE = "Delta Viewer"; @@ -74,7 +75,6 @@ private Map methodExecToVertexMap = new LinkedHashMap<>(); private Map edgeMap = new HashMap<>(); - private JFrame frame; private DeltaGraphAdapter mxgraph; // No clue what this does but it is needed. private mxICell mxDefaultParent; @@ -97,35 +97,21 @@ public mxInteractiveCanvas createCanvas() { return new CurvedCanvas(this); } - }; + }; deltaAnimation = new DeltaAnimation(mxgraph, mxgraphComponent); + mxgraphComponent.setPreferredSize(DEFAULT_SIZE); + add(mxgraphComponent, BorderLayout.CENTER); } - public DeltaViewer(ExtractedStructure extractedStructure, DeltaAliasCollector deltaAliasCollector) { - this(); + public void init(ExtractedStructure extractedStructure, DeltaAliasCollector deltaAliasCollector) { this.eStructure = extractedStructure; this.deltaAliasCollector = deltaAliasCollector; // init(); } /** Initialize JFrame, make vertex object and edge object. */ - public void init() { + public void initAnimation() { // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. - if(eStructure != null) { - List srcSide = eStructure.getDelta().getSrcSide(); - List dstSide = eStructure.getDelta().getDstSide(); - if (srcSide.size() >= 1 && dstSide.size() >= 1) { - WINDOW_TITLE = "extract delta of:" + eStructure.getDelta().getSrcSide().get(0).getDstClassName() + "(" + eStructure.getDelta().getSrcSide().get(0).getDstObjectId() + ")" + " -> " + eStructure.getDelta().getDstSide().get(0).getDstClassName() + "(" + eStructure.getDelta().getDstSide().get(0).getDstObjectId() + ")"; - } - } - - frame = new JFrame(WINDOW_TITLE); - frame.setSize(DEFAULT_SIZE); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - frame.add(mxgraphComponent, BorderLayout.CENTER); - frame.setVisible(true); - createObjectVertices(eStructure); createEdgeToObject(deltaAliasCollector.getAliasList(), deltaAliasCollector.getAliasPairList()); @@ -150,7 +136,6 @@ // scale = 1.5; view.setScale(scale); deltaAnimation.setScale(scale); - update(); } @@ -1321,7 +1306,7 @@ if (methodSignature.contains(" ")) { System.out.println(methodSignature); - methodSignature = formatMethodSignature(methodSignature); + methodSignature = formatMethodSignature(methodSignature, methodExec.getThisClassName()); } // Add a vertex to the graph in a transactional fashion. The vertex is actually a 'cell' in jgraphx terminology. @@ -1700,6 +1685,9 @@ // deltaAnimation.setExpandEdgeAnimation(new mxPoint(absolutPointSourceVertexCell.getX() + (sourceVertexCell.getGeometry().getWidth() / 2), absolutPointSourceVertexCell.getY() + sourceVertexCell.getGeometry().getHeight()), new mxPoint(absolutPointTargetVertexCell.getX() + (targetVertexCell.getGeometry().getWidth() / 2), absolutPointTargetVertexCell.getY())); // deltaAnimation.startExpandEdgeAnimation(); Object edge = mxgraph.insertDeltaEdge(mxDefaultParent, methodSignature, null, sourceVertexCell, targetVertexCell); + ((mxCell)edge).getParent().remove(((mxCell)edge)); + ((mxCell)edge).setParent(mxDefaultParent); + mxgraph.orderCells(false, new Object[] {edge}); ((mxCell)edge).setStyle("exitX=0.5;exitY=1;exitPerimeter=1;entryX=0.5;entryY=0;entryPerimeter=1;"); mxgraph.removeCells(new Object[]{cloneTargetVertexCell}); edgeMap.put(methodSignature, new Edge(methodSignature, TypeName.Call, edge)); @@ -1743,14 +1731,24 @@ return names; } - private String formatMethodSignature(String methodSignature) { + private String formatMethodSignature(String methodSignature, String thisClassName) { // Step1 : split "(" String[] methodSignatures = methodSignature.split("\\("); methodSignature = methodSignatures[0]; // Step2 : split " " methodSignatures = methodSignature.split(" "); + String tmpMethodSignature = methodSignatures[methodSignatures.length-1]; + // Step2 : split "." + String[] thisClassNames = thisClassName.split("\\."); + methodSignatures = tmpMethodSignature.split("\\."); StringBuffer sb = new StringBuffer(); - sb.append(methodSignatures[methodSignatures.length-1]); + for (int i = 0; i < methodSignatures.length; i++) { + if ((thisClassNames.length > i && !methodSignatures[i].equals(thisClassNames[i])) || thisClassNames.length <= i) { + sb.append(methodSignatures[i]); + if (methodSignatures.length - i > 1) sb.append("."); + } + } +// sb.append(tmpMethodSignature); sb.append("()"); return sb.toString(); } @@ -1799,7 +1797,7 @@ } System.out.println("\nEdge"); for (Edge e: edgeMap.values()) { - System.out.println(e.getLabel()); + System.out.println(e.getLabel() + "(" + ((mxICell)e.getCell()).getId() + ")"); if (((mxICell)e.getCell()).getParent() != null) { System.out.println(" " + ((mxICell)e.getCell()).getParent().getId()); }