/**
 * The content of this file is subject to the caAdapter Software License (the "License").  
 * A copy of the License is available at:
 * [caAdapter CVS home directory]\etc\license\caAdapter_license.txt. or at:
 * http://ncicb.nci.nih.gov/infrastructure/cacore_overview/caadapter/indexContent
 * /docs/caAdapter_License
 */
package gov.nih.nci.cbiit.cmps.ui.mapping;

import org.jgraph.graph.GraphModel;

import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelGraphModel;
import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelJGraph;
import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelJGraphController;
import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelJGraphScrollAdjustmentAdapter;
import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelJGraphViewFactory;
import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelScrollAdjustmentCoordinator;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
import javax.swing.ScrollPaneConstants;

import java.awt.Graphics;
import java.awt.BorderLayout;
import java.awt.Dimension;

/**
 * The panel is used to render graphical respresentation of the mapping relations between
 * source and target tree panel.
 *
 * @author Chunqing Lin
 * @author LAST UPDATE $Author: wangeug $
 * @since     CMPS v1.0
 * @version    $Revision: 1.4 $
 * @date       $Date: 2009-11-03 18:32:26 $
 *
 */
public class MappingMiddlePanel extends JPanel //implements ActionListener
{
	private MiddlePanelScrollAdjustmentCoordinator adjustmentCoordinator = null;
	private MiddlePanelJGraph graph = null;

	private MiddlePanelJGraphScrollAdjustmentAdapter graphAdjustmentAdapter = null;

	private MiddlePanelJGraphController graphController = null;
	private CmpsMappingPanel mappingPanel = null;
	private JScrollPane graphScrollPane = new JScrollPane();
	/**
	 * @return the graphScrollPane
	 */
	public JScrollPane getGraphScrollPane() {
		return graphScrollPane;
	}
	/**
	 * @param graphScrollPane the graphScrollPane to set
	 */
	public void setGraphScrollPane(JScrollPane graphScrollPane) {
		this.graphScrollPane = graphScrollPane;
	}
	public MappingMiddlePanel(CmpsMappingPanel mappingPane)
	{
		mappingPanel = mappingPane;
		setBorder(BorderFactory.createRaisedBevelBorder());
		setLayout(new BorderLayout());
		// initialize graph
		GraphModel model = new MiddlePanelGraphModel();
		graph = new MiddlePanelJGraph(model);
		MiddlePanelJGraphViewFactory	graphViewFactory = new MiddlePanelJGraphViewFactory();
		graph.getGraphLayoutCache().setFactory(graphViewFactory);

				 
		graphScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		graphScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		graphScrollPane.getViewport().setView(graph);
		MappingPanelAdjustmentHandler listener=new MappingPanelAdjustmentHandler();
		graphScrollPane.getVerticalScrollBar().addAdjustmentListener(listener);
		add(graphScrollPane, BorderLayout.CENTER);
		adjustmentCoordinator = new MiddlePanelScrollAdjustmentCoordinator(this, graphScrollPane);
		graphAdjustmentAdapter = new MiddlePanelJGraphScrollAdjustmentAdapter(mappingPanel);
		
    }
	/**
	 * @param graphController the graphController to set
	 */
	public void setGraphController(MiddlePanelJGraphController graphController) {
		this.graphController = graphController;
	}
	public MiddlePanelScrollAdjustmentCoordinator getAdjustmentCoordinator()
	{
		return adjustmentCoordinator;
	}

    public Object getFunctionBoxSelection()
	{
    	return null;
		//return mappingPanel.getFunctionPane().getFunctionSelection();
	}

	/**
	 * @return the graph
	 */
	public MiddlePanelJGraph getGraph() {
		return graph;
	}

	public MiddlePanelJGraphScrollAdjustmentAdapter getGraphAdjustmentAdapter()
	{
		return graphAdjustmentAdapter;
	}

	public MiddlePanelJGraphController getGraphController(){
        return graphController;
    }

	public CmpsMappingPanel getMappingPanel()
	{
		return mappingPanel;
	}

	@Override
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		graphController.renderInJGraph(g);
	}


	/**
	 * @param graph the graph to set
	 */
	public void setGraph(MiddlePanelJGraph jGraph) {
		graph = jGraph;
	}

}
/**
 * HISTORY: $Log: not supported by cvs2svn $
 * HISTORY: Revision 1.3  2009/10/30 14:45:09  wangeug
 * HISTORY: simplify code: only respond to link highter
 * HISTORY:
 * HISTORY: Revision 1.2  2008/12/04 21:34:20  linc
 * HISTORY: Drap and Drop support with new Swing.
 * HISTORY:
 * HISTORY: Revision 1.1  2008/10/30 16:02:14  linc
 * HISTORY: updated.
 * HISTORY:
 */

@@ -1018,35 +1018,8 @@
 out;
-%0Aimport java.awt.Dimension;
 %0A%0A/*
@@ -1264,17 +1264,17 @@
 sion: 1.
-4
+5
  $%0A * @d
@@ -1303,18 +1303,18 @@
 11-0
-3 18:32:26
+4 19:11:59
  $%0A 
@@ -1369,36 +1369,8 @@
 anel
- //implements ActionListener
 %0A%7B%0A%09
@@ -4191,16 +4191,170 @@
 s2svn $%0A
+ * HISTORY: Revision 1.4  2009/11/03 18:32:26  wangeug%0A * HISTORY: clean codes: keep MiddlePanelJGraphController only with MiddleMappingPanel%0A * HISTORY:%0A
  * HISTO

clean codes