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 org.ntlab.deltaExtractor.IAliasCollector;

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 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();
	}
	
	/**
	 * Set objectCallGraph and aliasCollector, create vertex object and edge object.
	 * @param objectCallGraph
	 * @param aliasCollector
	 */
	public void init(IObjectCallGraph objectCallGraph, IAliasCollector aliasCollector, IObjectLayout layout) {
		this.objectCallGraph = objectCallGraph;
		this.aliasCollector = aliasCollector;
		// Build a frame, create a graph, and add the graph to the frame so you can actually see the graph.
		createObjectVertices(this.objectCallGraph);
		createEdgeToObject(this.aliasCollector.getAliasList());
		layout.execute(mxgraph, objectCallGraph, aliasCollector);
		reflectCoordinates(mxgraph); // objectVertexにmxGraphの座標を反映させる
	}
		
	/**
	 * Initialize animation. 再生ボタンを押すとき
	 */
	public void initAnimation() {
//		reflectCoordinates(mxgraph); // objectVertexにmxGraphの座標を反映させる(ユーザが指定した座標位置を反映)

		// 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(aliasCollector.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) {
	}

}