//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/god4j
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : god4j@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.god4j;
import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;

import org.huihoo.god4j.jgraph.XPDLJGraph;
import org.huihoo.god4j.jgraph.XPDLJGraphModel;
import org.huihoo.god4j.jgraph.XPDLJGraphRuler;
import org.huihoo.workflow.xpdl.WorkflowProcess;
/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class JGraphFrame extends JInternalFrame
{
	public final static Integer JGRAPH_FRAME_LAYER   = new Integer(1);
	
	private WorkflowProcess workflowProcess;
	private XPDLJGraph graph;

	private XPDLJGraphRuler columnRuler = null;
	private XPDLJGraphRuler rowRuler = null;
	private JScrollPane scrollPane4JGraph = null;
	

	//==========================================================================	
	public JGraphFrame(WorkflowProcess workflowProcess)
	{
		this(workflowProcess, "", false, false, false, false);
	}
	public JGraphFrame(WorkflowProcess workflowProcess, String title)
	{
		this(workflowProcess, title, false, false, false, false);
	}
	public JGraphFrame(WorkflowProcess workflowProcess, String title, boolean resizable)
	{
		this(workflowProcess, title, resizable, false, false, false);
	}
	public JGraphFrame(WorkflowProcess workflowProcess, String title, boolean resizable, boolean closable)
	{
		this(workflowProcess, title, resizable, closable, false, false);
	}
	public JGraphFrame(
		WorkflowProcess workflowProcess,
		String title,
		boolean resizable,
		boolean closable,
		boolean maximizable)
	{
		this(workflowProcess, title, resizable, closable, maximizable, false);
	}
	public JGraphFrame(
		WorkflowProcess workflowProcess,
		String title,
		boolean resizable,
		boolean closable,
		boolean maximizable,
		boolean iconifiable)
	{
		super(title, resizable, closable, maximizable, iconifiable);
		
		this.workflowProcess = workflowProcess;
		this.graph = new XPDLJGraph(this, new XPDLJGraphModel());
		
		this.columnRuler = new XPDLJGraphRuler(XPDLJGraphRuler.HORIZONTAL, false, this.graph);
		this.rowRuler = new XPDLJGraphRuler(XPDLJGraphRuler.VERTICAL, false, this.graph);
		
		this.scrollPane4JGraph = new JScrollPane(graph);
		this.scrollPane4JGraph.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		this.scrollPane4JGraph.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(scrollPane4JGraph, BorderLayout.CENTER);

		this.setDisplayGrid(GOD4JFactory.getGOD4J().getControlPanel().isGridVisible());
		this.setDisplayRuler(GOD4JFactory.getGOD4J().getControlPanel().isRulerVisible());
		
		this.addInternalFrameListener(new JGraphFrameListener(this));
	}
	//================================================================================
	
	public XPDLJGraph getJGraph()
	{
		return this.graph;
	}
	
	public void zoomNormal()
	{
		//this.setScale(1);
	}
	public void zoomOut()
	{
//		setScale(graph.getScale() - 0.25);
//		if (graph.getSelectionCell() != null)
//		{
//			graph.scrollCellToVisible(graph.getSelectionCell());
//		}
	}
	public void zoomIn()
	{
//		setScale(graph.getScale() + 0.25);
//		if (graph.getSelectionCell() != null)
//		{
//			graph.scrollCellToVisible(graph.getSelectionCell());
//		}
	}
	public void deleteCell()
	{
		graph.graphDelete();
	}
	public void setDisplayGrid(boolean display)
	{
		graph.setGridEnabled(display);
		graph.setGridVisible(display);
	}
	public void setDisplayRuler(boolean display)
	{
		if (display)
		{
			scrollPane4JGraph.setColumnHeaderView(columnRuler);
			scrollPane4JGraph.setRowHeaderView(rowRuler);
		}
		else
		{
			scrollPane4JGraph.setColumnHeaderView(null);
			scrollPane4JGraph.setRowHeaderView(null);
		}
	}

	public WorkflowProcess getWorkflowProcess()
	{
		return this.workflowProcess;
	}
}
