Newer
Older
MagnetRON / src / org / ntlab / deltaViewer / CollaborationViewer.java
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<Alias> 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) {
	}
	

}