diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java new file mode 100644 index 0000000..16e1d4f --- /dev/null +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -0,0 +1,106 @@ +package org.ntlab.deltaViewer; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.geom.Path2D; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.swing.JPanel; + +import org.jgrapht.graph.DefaultEdge; +import org.jgrapht.graph.DirectedWeightedPseudograph; +import org.ntlab.deltaExtractor.Alias; +import org.ntlab.deltaExtractor.ExtractedStructure; + +import com.mxgraph.canvas.mxGraphics2DCanvas; +import com.mxgraph.model.mxCell; +import com.mxgraph.shape.mxConnectorShape; +import com.mxgraph.shape.mxIShape; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxInteractiveCanvas; +import com.mxgraph.util.mxConstants; +import com.mxgraph.util.mxPoint; +import com.mxgraph.util.mxUtils; +import com.mxgraph.view.mxCellState; +import com.mxgraph.view.mxGraphView; + +public class CollaborationViewer extends MagnetRONViewer { + private IObjectCallGraph objectCallGraph; + private DeltaAliasCollector deltaAliasCollector; + + private static Dimension VERTEX_OBJECT_SIZE = new Dimension(70, 70); + private static Dimension VERTEX_METHOD_EXECUTION_SIZE = new Dimension(55, 20); + + private double scale = 1; + + public CollaborationViewer() { + super(); + } + + public void init(IObjectCallGraph objectCallGraph, DeltaAliasCollector deltaAliasCollector) { + this.objectCallGraph = objectCallGraph; + this.deltaAliasCollector = deltaAliasCollector; + } + + /** Initialize JFrame, make vertex object and edge object. */ + public void initAnimation() { + // Build a frame, create a graph, and add the graph to the frame so you can actually see the graph. + createObjectVertices(objectCallGraph); + createEdgeToObject(deltaAliasCollector.getAliasList()); + + // Fit graph size in visible JFrame. + mxGraphView view = mxgraphComponent.getGraph().getView(); + int componentWidth = mxgraphComponent.getWidth() - 25; + double viewWidth = (double) view.getGraphBounds().getWidth(); + +// Object component = mxgraph.insertDeltaVertex(mxDefaultParent, "component", "component", "fillColor=white"); //creates a white vertex. +// ((mxICell)component).getGeometry().setX(mxgraphComponent.getWidth() - 30); +// ((mxICell)component).getGeometry().setY(10); +// Object vertex = mxgraph.insertDeltaVertex(mxDefaultParent, "view", "view", "fillColor=white"); //creates a white vertex. +// ((mxICell)vertex).getGeometry().setX(view.getGraphBounds().getWidth()); +// ((mxICell)vertex).getGeometry().setY(10); + +// scale = (double)componentWidth/viewWidth; + System.out.println(", " + scale); +// scale = 1.5; + view.setScale(scale); + deltaAnimation.setScale(scale); + update(); + } + + private void createObjectVertices(IObjectCallGraph objectCallGraph) { + // TODO Auto-generated method stub + + } + + private void createEdgeToObject(List aliasList) { + // TODO Auto-generated method stub + + } + + /** + * Step to animation of specified alias. + * + * @param alias Alias type and occurrence point etc. + */ + public void stepToAnimation(Alias alias) { + try { + stepToAnimation(deltaAliasCollector.getAliasList().indexOf(alias)); + } catch (IndexOutOfBoundsException e) { + stepToAnimation(-1); + } + } + + /** + * Parent : Step to animation of specified numFrame. + * + * @param numFrame Current animation frame. + */ + public void stepToAnimation(int numFrame) { + } + + +} diff --git a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java index 90ab9dd..6abcb99 100644 --- a/src/org/ntlab/deltaViewer/DeltaAliasCollector.java +++ b/src/org/ntlab/deltaViewer/DeltaAliasCollector.java @@ -3,9 +3,9 @@ import java.util.List; import org.ntlab.deltaExtractor.Alias; -import org.ntlab.deltaExtractor.IAliasCollector; +import org.ntlab.deltaExtractor.IAliasTracker; -public class DeltaAliasCollector implements IAliasCollector { +public class DeltaAliasCollector implements IAliasTracker { @Override public void addAlias(Alias alias) { @@ -19,4 +19,13 @@ return null; } + /* + * �R�R�ɂ͉��������Ȃ� + */ + @Override + public void changeTrackingObject(String from, String to, boolean isSrcSide) { + // TODO Auto-generated method stub + + } + } diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index 3a46671..75dc438 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -10,9 +10,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -64,49 +62,23 @@ //BUG: edge drawing order. -> parent //BUG: methodExecution drawing order. -> parent //BUG: ObjectVertex position when Resize ObjectVertex. O -public class DeltaViewer extends JPanel { - private static Dimension DEFAULT_SIZE = new Dimension(1300, 700); - private static String WINDOW_TITLE = "Delta Viewer"; - +public class DeltaViewer extends MagnetRONViewer { private ExtractedStructure eStructure; private DeltaAliasTracker deltaAliasCollector; - private Map objectToVertexMap = new HashMap<>(); - private Map methodExecToVertexMap = new LinkedHashMap<>(); - private Map edgeMap = new HashMap<>(); - - private DeltaGraphAdapter mxgraph; - // No clue what this does but it is needed. - private mxICell mxDefaultParent; - - private mxGraphComponent mxgraphComponent; - - private int curFrame = 0; private static Dimension VERTEX_OBJECT_SIZE = new Dimension(70, 70); private static Dimension VERTEX_METHOD_EXECUTION_SIZE = new Dimension(55, 20); private mxPoint coordinatorPoint = new mxPoint(0, 100); - private DeltaAnimation deltaAnimation; - private double scale = 1; public DeltaViewer() { - mxgraph = new DeltaGraphAdapter(new DirectedWeightedPseudograph(DefaultEdge.class)); - mxDefaultParent = (mxCell)mxgraph.getDefaultParent(); - mxgraphComponent = new mxGraphComponent(mxgraph) { - public mxInteractiveCanvas createCanvas() { - return new CurvedCanvas(this); - } - }; - deltaAnimation = new DeltaAnimation(mxgraph, mxgraphComponent); - mxgraphComponent.setPreferredSize(DEFAULT_SIZE); - add(mxgraphComponent, BorderLayout.CENTER); + super(); } public void init(ExtractedStructure extractedStructure, DeltaAliasTracker deltaAliasCollector) { this.eStructure = extractedStructure; this.deltaAliasCollector = deltaAliasCollector; -// init(); } /** Initialize JFrame, make vertex object and edge object. */ @@ -139,17 +111,6 @@ update(); } - /** Update graph on JFrame and set Cell style. */ - public void update() { - setCellsStyle(); - mxgraphComponent.refresh(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - public void setExtractedStructure(ExtractedStructure extractedStructure) { this.eStructure = extractedStructure; } @@ -158,103 +119,99 @@ this.deltaAliasCollector = deltaAliasCollector; } - public void setFrameSize(int width, int height) { - DEFAULT_SIZE.setSize(width, height); - } - public void setCoordinatorPoint(double x, double y) { coordinatorPoint.setX(x); coordinatorPoint.setY(y); } /** Set style of All cells. */ - private void setCellsStyle() { - List vertexObject = new ArrayList<>(); - List staticVertexObject = new ArrayList<>(); - List alignMiddleVertex = new ArrayList<>(); - List alignTopVertex = new ArrayList<>(); - List edgeObject = new ArrayList<>(); - List edgeObjectCreate = new ArrayList<>(); - List edgeMethodExec = new ArrayList<>(); - List roundEdge = new ArrayList<>(); - - for (Entry objectToVertexEntry: objectToVertexMap.entrySet()) { - String key = objectToVertexEntry.getKey(); - ObjectVertex objectVertex = objectToVertexEntry.getValue(); - if (key.matches("0")) { - staticVertexObject.add(objectVertex.getCell()); - } else { - vertexObject.add(objectVertex.getCell()); - } - if(objectVertex.getVertexMethodExecutions().size() == 0) { - alignMiddleVertex.add(objectVertex.getCell()); - } else { - alignTopVertex.add(objectVertex.getCell()); - } - } - - List vertexMethodExecList = new ArrayList<>(methodExecToVertexMap.values()); - Collections.reverse(vertexMethodExecList); - for (int i = 0; i < vertexMethodExecList.size(); i++) { - switch(i) { - case 0: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff7fbf"); - break; - case 1: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff99cc"); - break; - case 2: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffb2d8"); - break; - case 3: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffcce5"); - break; - case 4: - ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffe0ef"); - break; - default: - break; - } - } - - for (Edge edge: edgeMap.values()) { - roundEdge.add(edge.getCell()); - switch(edge.getTypeName()) { - case Reference: - edgeObject.add(edge.getCell()); - break; - case Create: - edgeObject.add(edge.getCell()); - edgeObjectCreate.add(edge.getCell()); - break; - case Call: - edgeMethodExec.add(edge.getCell()); - break; - default: - break; - } - } - - /*Given a cell, we can change it's style attributes, for example the color. NOTE that you have to call the graphComponent.refresh() function, otherwise you won't see the difference! */ - mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, vertexObject.toArray(new Object[vertexObject.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMiddleVertex.toArray(new Object[alignMiddleVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopVertex.toArray(new Object[alignTopVertex.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, edgeObject.toArray(new Object[edgeObject.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeObjectCreate.toArray(new Object[edgeObjectCreate.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION, edgeObject.toArray(new Object[edgeObject.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeObject.toArray(new Object[edgeObject.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdge.toArray(new Object[roundEdge.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdge.toArray(new Object[roundEdge.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdge.toArray(new Object[roundEdge.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.SHAPE_CURVE, edgeObject.toArray(new Object[edgeObject.size()])); - mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); - mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); -// mxgraph.setCellStyleFlags(mxConstants.STYLE_AUTOSIZE, 1, true, vertexObject.toArray(new Object[vertexObject.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); -// mxgraph.setCellStyles(mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); - } +// private void setCellsStyle() { +// List vertexObject = new ArrayList<>(); +// List staticVertexObject = new ArrayList<>(); +// List alignMiddleVertex = new ArrayList<>(); +// List alignTopVertex = new ArrayList<>(); +// List edgeObject = new ArrayList<>(); +// List edgeObjectCreate = new ArrayList<>(); +// List edgeMethodExec = new ArrayList<>(); +// List roundEdge = new ArrayList<>(); +// +// for (Entry objectToVertexEntry: objectToVertexMap.entrySet()) { +// String key = objectToVertexEntry.getKey(); +// ObjectVertex objectVertex = objectToVertexEntry.getValue(); +// if (key.matches("0")) { +// staticVertexObject.add(objectVertex.getCell()); +// } else { +// vertexObject.add(objectVertex.getCell()); +// } +// if(objectVertex.getVertexMethodExecutions().size() == 0) { +// alignMiddleVertex.add(objectVertex.getCell()); +// } else { +// alignTopVertex.add(objectVertex.getCell()); +// } +// } +// +// List vertexMethodExecList = new ArrayList<>(methodExecToVertexMap.values()); +// Collections.reverse(vertexMethodExecList); +// for (int i = 0; i < vertexMethodExecList.size(); i++) { +// switch(i) { +// case 0: +// ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff7fbf"); +// break; +// case 1: +// ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff99cc"); +// break; +// case 2: +// ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffb2d8"); +// break; +// case 3: +// ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffcce5"); +// break; +// case 4: +// ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffe0ef"); +// break; +// default: +// break; +// } +// } +// +// for (Edge edge: edgeMap.values()) { +// roundEdge.add(edge.getCell()); +// switch(edge.getTypeName()) { +// case Reference: +// edgeObject.add(edge.getCell()); +// break; +// case Create: +// edgeObject.add(edge.getCell()); +// edgeObjectCreate.add(edge.getCell()); +// break; +// case Call: +// edgeMethodExec.add(edge.getCell()); +// break; +// default: +// break; +// } +// } +// +// /*Given a cell, we can change it's style attributes, for example the color. NOTE that you have to call the graphComponent.refresh() function, otherwise you won't see the difference! */ +// mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); +// mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, vertexObject.toArray(new Object[vertexObject.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMiddleVertex.toArray(new Object[alignMiddleVertex.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopVertex.toArray(new Object[alignTopVertex.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, edgeObject.toArray(new Object[edgeObject.size()])); +// mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeObjectCreate.toArray(new Object[edgeObjectCreate.size()])); +//// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION, edgeObject.toArray(new Object[edgeObject.size()])); +//// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeObject.toArray(new Object[edgeObject.size()])); +// mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdge.toArray(new Object[roundEdge.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdge.toArray(new Object[roundEdge.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdge.toArray(new Object[roundEdge.size()])); +//// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.SHAPE_CURVE, edgeObject.toArray(new Object[edgeObject.size()])); +// mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); +// mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); +//// mxgraph.setCellStyleFlags(mxConstants.STYLE_AUTOSIZE, 1, true, vertexObject.toArray(new Object[vertexObject.size()])); +//// mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); +//// mxgraph.setCellStyles(mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); +// } // private double getXForCell(String id) { // double res = -1; @@ -283,34 +240,6 @@ // } /** - * Whether sourceCell parents contain targetCell - * @param sourceCell - * @param targetCell - * @return - */ - private boolean isParent(mxICell sourceCell, mxICell targetCell) { - mxICell sourceParentCell = sourceCell.getParent(); - if (sourceParentCell == null || sourceParentCell.getValue() == null) { - return false; - } - if (sourceParentCell == targetCell) { - return true; - } - System.out.println(sourceCell.getId() + ", " + sourceParentCell.getId()); - return isParent(sourceParentCell, targetCell); - } - - private Point getAbsolutePointforCell(mxICell cell) { - Point p1 = cell.getGeometry().getPoint(); - if(cell.getParent().getValue() == null || cell == cell.getParent()) { - return p1; - } - System.out.println(cell.getId() + ", " + cell.getParent().getId()); - Point p2 = getAbsolutePointforCell(cell.getParent()); - return new Point((int) (p1.getX() + p2.getX()), (int) (p1.getY() + p2.getY())); - } - - /** * Step to animation of specified alias. * * @param alias Alias type and occurrence point etc. @@ -1803,102 +1732,5 @@ } } } - - private class CurvedCanvas extends mxInteractiveCanvas { - mxIShape shape = new CurvedConnector(); - - public CurvedCanvas(mxGraphComponent mxGraphComponent) { - super(mxGraphComponent); - } - - public Object drawCell(mxCellState state) { - if (!(state.getCell() instanceof mxCell) || !((mxCell)state.getCell()).isEdge() || state.getAbsolutePointCount() == 2) { - return super.drawCell(state); - } - Map style = state.getStyle(); - - if (g != null) { - // Creates a temporary graphics instance for drawing this shape - float opacity = mxUtils.getFloat(style, mxConstants.STYLE_OPACITY, 100); - Graphics2D previousGraphics = g; - g = createTemporaryGraphics(style, opacity, state); - shape.paintShape(this, state); - g.dispose(); - g = previousGraphics; - } - - return shape; - } - } - - private class CurvedConnector extends mxConnectorShape { - public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) { - if (state.getAbsolutePointCount() > 1 - && configureGraphics(canvas, state, false)) { - List pts = new ArrayList( - state.getAbsolutePoints()); - Map style = state.getStyle(); - - // Paints the markers and updates the points - // Switch off any dash pattern for markers - boolean dashed = mxUtils.isTrue(style, mxConstants.STYLE_DASHED); - Object dashedValue = style.get(mxConstants.STYLE_DASHED); - - if (dashed) { - style.remove(mxConstants.STYLE_DASHED); - canvas.getGraphics().setStroke(canvas.createStroke(style)); - } - - translatePoint(pts, 0, - paintMarker(canvas, state, true)); - translatePoint( - pts, - pts.size() - 1, - paintMarker(canvas, state, false)); - - if (dashed) { - // Replace the dash pattern - style.put(mxConstants.STYLE_DASHED, dashedValue); - canvas.getGraphics().setStroke(canvas.createStroke(style)); - } - - // Paints the shape and restores the graphics object - if (state.getAbsolutePointCount() == 4) { - double sx = state.getAbsolutePoint(0).getX(); - double sy = state.getAbsolutePoint(0).getY(); - double tx1 = state.getAbsolutePoint(1).getX(); - double ty1 = state.getAbsolutePoint(1).getY(); - double tx2 = state.getAbsolutePoint(2).getX(); - double ty2 = state.getAbsolutePoint(2).getY(); - double ex = state.getAbsolutePoint(3).getX(); - double ey = state.getAbsolutePoint(3).getY(); - Path2D.Double p = new Path2D.Double(); - p.moveTo((int) sx, (int) sy); - p.quadTo((int) tx2, (int) ty2, (int) ex, (int) ey); -// p.curveTo((int) tx1, (int) ty1, (int) tx2, (int) ty2, (int) ex, (int) ey); - canvas.getGraphics().draw(p); - } else if (state.getAbsolutePointCount() == 3) { - double sx = state.getAbsolutePoint(0).getX(); - double sy = state.getAbsolutePoint(0).getY(); - double tx = state.getAbsolutePoint(1).getX(); - double ty = state.getAbsolutePoint(1).getY(); - double ex = state.getAbsolutePoint(2).getX(); - double ey = state.getAbsolutePoint(2).getY(); - Path2D.Double p = new Path2D.Double(); - p.moveTo((int) sx, (int) sy); - p.quadTo((int) tx, (int) ty, (int) ex, (int) ey); - canvas.getGraphics().draw(p); - } - } - } - - private void translatePoint(List points, int index, mxPoint offset) { - if (offset != null) { - mxPoint pt = (mxPoint) points.get(index).clone(); - pt.setX(pt.getX() + offset.getX()); - pt.setY(pt.getY() + offset.getY()); - points.set(index, pt); - } - } - } + } diff --git a/src/org/ntlab/deltaViewer/IObjectCallGraph.java b/src/org/ntlab/deltaViewer/IObjectCallGraph.java new file mode 100644 index 0000000..8093c6e --- /dev/null +++ b/src/org/ntlab/deltaViewer/IObjectCallGraph.java @@ -0,0 +1,16 @@ +package org.ntlab.deltaViewer; + +import java.util.List; + +import org.ntlab.trace.MethodExecution; +import org.ntlab.trace.Reference; + +public interface IObjectCallGraph { + + List getReferences(); + + /* + * �N�_�ƂȂ郁�\�b�h���s(����2�‚̋N�_�ɂ��g���\��) + */ + List getStartPoints(); +} diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java new file mode 100644 index 0000000..23a8122 --- /dev/null +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -0,0 +1,309 @@ +package org.ntlab.deltaViewer; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.geom.Path2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.JPanel; + +import org.jgrapht.graph.DefaultEdge; +import org.jgrapht.graph.DirectedWeightedPseudograph; +import org.ntlab.deltaExtractor.Alias; +import org.ntlab.trace.MethodExecution; + +import com.mxgraph.canvas.mxGraphics2DCanvas; +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxICell; +import com.mxgraph.shape.mxConnectorShape; +import com.mxgraph.shape.mxIShape; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxInteractiveCanvas; +import com.mxgraph.util.mxConstants; +import com.mxgraph.util.mxPoint; +import com.mxgraph.util.mxUtils; +import com.mxgraph.view.mxCellState; + +abstract public class MagnetRONViewer extends JPanel { + + protected static Dimension DEFAULT_SIZE = new Dimension(1300, 700); + protected static String WINDOW_TITLE = "Delta Viewer"; + + protected Map objectToVertexMap = new HashMap<>(); + protected Map methodExecToVertexMap = new LinkedHashMap<>(); + protected Map edgeMap = new HashMap<>(); + + protected DeltaGraphAdapter mxgraph; + protected mxICell mxDefaultParent; + protected mxGraphComponent mxgraphComponent; + + protected DeltaAnimation deltaAnimation; + protected int curFrame = 0; + + public MagnetRONViewer() { + mxgraph = new DeltaGraphAdapter(new DirectedWeightedPseudograph(DefaultEdge.class)); + mxDefaultParent = (mxCell)mxgraph.getDefaultParent(); + mxgraphComponent = new mxGraphComponent(mxgraph) { + public mxInteractiveCanvas createCanvas() { + return new CurvedCanvas(this); + } + }; + deltaAnimation = new DeltaAnimation(mxgraph, mxgraphComponent); + mxgraphComponent.setPreferredSize(DEFAULT_SIZE); + add(mxgraphComponent, BorderLayout.CENTER); + } + + /** Set style of All cells. */ + protected void setCellsStyle() { + List vertexObject = new ArrayList<>(); + List staticVertexObject = new ArrayList<>(); + List alignMiddleVertex = new ArrayList<>(); + List alignTopVertex = new ArrayList<>(); + List edgeObject = new ArrayList<>(); + List edgeObjectCreate = new ArrayList<>(); + List edgeMethodExec = new ArrayList<>(); + List roundEdge = new ArrayList<>(); + + for (Entry objectToVertexEntry: objectToVertexMap.entrySet()) { + String key = objectToVertexEntry.getKey(); + ObjectVertex objectVertex = objectToVertexEntry.getValue(); + if (key.matches("0")) { + staticVertexObject.add(objectVertex.getCell()); + } else { + vertexObject.add(objectVertex.getCell()); + } + if(objectVertex.getVertexMethodExecutions().size() == 0) { + alignMiddleVertex.add(objectVertex.getCell()); + } else { + alignTopVertex.add(objectVertex.getCell()); + } + } + + List vertexMethodExecList = new ArrayList<>(methodExecToVertexMap.values()); + Collections.reverse(vertexMethodExecList); + for (int i = 0; i < vertexMethodExecList.size(); i++) { + switch(i) { + case 0: + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff7fbf"); + break; + case 1: + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ff99cc"); + break; + case 2: + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffb2d8"); + break; + case 3: + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffcce5"); + break; + case 4: + ((mxICell)vertexMethodExecList.get(i).getCell()).setStyle("fillColor=#ffe0ef"); + break; + default: + break; + } + } + + for (Edge edge: edgeMap.values()) { + roundEdge.add(edge.getCell()); + switch(edge.getTypeName()) { + case Reference: + edgeObject.add(edge.getCell()); + break; + case Create: + edgeObject.add(edge.getCell()); + edgeObjectCreate.add(edge.getCell()); + break; + case Call: + edgeMethodExec.add(edge.getCell()); + break; + default: + break; + } + } + + /*Given a cell, we can change it's style attributes, for example the color. NOTE that you have to call the graphComponent.refresh() function, otherwise you won't see the difference! */ + mxgraph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE, vertexObject.toArray(new Object[vertexObject.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_UNDERLINE, true, vertexObject.toArray(new Object[vertexObject.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE, alignMiddleVertex.toArray(new Object[alignMiddleVertex.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, alignTopVertex.toArray(new Object[alignTopVertex.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_TOPTOBOTTOM, edgeObject.toArray(new Object[edgeObject.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeObjectCreate.toArray(new Object[edgeObjectCreate.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION, edgeObject.toArray(new Object[edgeObject.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeObject.toArray(new Object[edgeObject.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_ROUNDED, 1, true, roundEdge.toArray(new Object[roundEdge.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_TOP, roundEdge.toArray(new Object[roundEdge.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_BOTTOM, roundEdge.toArray(new Object[roundEdge.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.SHAPE_CURVE, edgeObject.toArray(new Object[edgeObject.size()])); + mxgraph.setCellStyles(mxConstants.STYLE_STROKECOLOR, "#008000", edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + mxgraph.setCellStyleFlags(mxConstants.STYLE_DASHED, 1, true, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + // mxgraph.setCellStyleFlags(mxConstants.STYLE_AUTOSIZE, 1, true, vertexObject.toArray(new Object[vertexObject.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + // mxgraph.setCellStyles(mxConstants.STYLE_ELBOW, mxConstants.ELBOW_VERTICAL, edgeMethodExec.toArray(new Object[edgeMethodExec.size()])); + } + + abstract public void initAnimation(); + + /** + * Step to animation of specified alias. + * + * @param alias Alias type and occurrence point etc. + */ + abstract public void stepToAnimation(Alias alias); + + /** + * Parent : Step to animation of specified numFrame. + * + * @param numFrame Current animation frame. + */ + abstract public void stepToAnimation(int numFrame); + + /** Update graph on JFrame and set Cell style. */ + protected void update() { + setCellsStyle(); + mxgraphComponent.refresh(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + protected void setFrameSize(int width, int height) { + DEFAULT_SIZE.setSize(width, height); + } + + /** + * Whether sourceCell parents contain targetCell + * @param sourceCell + * @param targetCell + * @return + */ + protected boolean isParent(mxICell sourceCell, mxICell targetCell) { + mxICell sourceParentCell = sourceCell.getParent(); + if (sourceParentCell == null || sourceParentCell.getValue() == null) { + return false; + } + if (sourceParentCell == targetCell) { + return true; + } + System.out.println(sourceCell.getId() + ", " + sourceParentCell.getId()); + return isParent(sourceParentCell, targetCell); + } + + protected Point getAbsolutePointforCell(mxICell cell) { + Point p1 = cell.getGeometry().getPoint(); + if(cell.getParent().getValue() == null || cell == cell.getParent()) { + return p1; + } + System.out.println(cell.getId() + ", " + cell.getParent().getId()); + Point p2 = getAbsolutePointforCell(cell.getParent()); + return new Point((int) (p1.getX() + p2.getX()), (int) (p1.getY() + p2.getY())); + } + + protected class CurvedCanvas extends mxInteractiveCanvas { + mxIShape shape = new CurvedConnector(); + + public CurvedCanvas(mxGraphComponent mxGraphComponent) { + super(mxGraphComponent); + } + + public Object drawCell(mxCellState state) { + if (!(state.getCell() instanceof mxCell) || !((mxCell)state.getCell()).isEdge() || state.getAbsolutePointCount() == 2) { + return super.drawCell(state); + } + Map style = state.getStyle(); + + if (g != null) { + // Creates a temporary graphics instance for drawing this shape + float opacity = mxUtils.getFloat(style, mxConstants.STYLE_OPACITY, 100); + Graphics2D previousGraphics = g; + g = createTemporaryGraphics(style, opacity, state); + shape.paintShape(this, state); + g.dispose(); + g = previousGraphics; + } + + return shape; + } + } + + protected class CurvedConnector extends mxConnectorShape { + public void paintShape(mxGraphics2DCanvas canvas, mxCellState state) { + if (state.getAbsolutePointCount() > 1 + && configureGraphics(canvas, state, false)) { + List pts = new ArrayList( + state.getAbsolutePoints()); + Map style = state.getStyle(); + + // Paints the markers and updates the points + // Switch off any dash pattern for markers + boolean dashed = mxUtils.isTrue(style, mxConstants.STYLE_DASHED); + Object dashedValue = style.get(mxConstants.STYLE_DASHED); + + if (dashed) { + style.remove(mxConstants.STYLE_DASHED); + canvas.getGraphics().setStroke(canvas.createStroke(style)); + } + + translatePoint(pts, 0, + paintMarker(canvas, state, true)); + translatePoint( + pts, + pts.size() - 1, + paintMarker(canvas, state, false)); + + if (dashed) { + // Replace the dash pattern + style.put(mxConstants.STYLE_DASHED, dashedValue); + canvas.getGraphics().setStroke(canvas.createStroke(style)); + } + + // Paints the shape and restores the graphics object + if (state.getAbsolutePointCount() == 4) { + double sx = state.getAbsolutePoint(0).getX(); + double sy = state.getAbsolutePoint(0).getY(); + double tx1 = state.getAbsolutePoint(1).getX(); + double ty1 = state.getAbsolutePoint(1).getY(); + double tx2 = state.getAbsolutePoint(2).getX(); + double ty2 = state.getAbsolutePoint(2).getY(); + double ex = state.getAbsolutePoint(3).getX(); + double ey = state.getAbsolutePoint(3).getY(); + Path2D.Double p = new Path2D.Double(); + p.moveTo((int) sx, (int) sy); + p.quadTo((int) tx2, (int) ty2, (int) ex, (int) ey); +// p.curveTo((int) tx1, (int) ty1, (int) tx2, (int) ty2, (int) ex, (int) ey); + canvas.getGraphics().draw(p); + } else if (state.getAbsolutePointCount() == 3) { + double sx = state.getAbsolutePoint(0).getX(); + double sy = state.getAbsolutePoint(0).getY(); + double tx = state.getAbsolutePoint(1).getX(); + double ty = state.getAbsolutePoint(1).getY(); + double ex = state.getAbsolutePoint(2).getX(); + double ey = state.getAbsolutePoint(2).getY(); + Path2D.Double p = new Path2D.Double(); + p.moveTo((int) sx, (int) sy); + p.quadTo((int) tx, (int) ty, (int) ex, (int) ey); + canvas.getGraphics().draw(p); + } + } + } + + private void translatePoint(List points, int index, mxPoint offset) { + if (offset != null) { + mxPoint pt = (mxPoint) points.get(index).clone(); + pt.setX(pt.getX() + offset.getX()); + pt.setY(pt.getY() + offset.getY()); + points.set(index, pt); + } + } + } +}