import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.Point;
 
public class ContentPane extends JPanel
{
	/************************
	 ** Instance Variables **
	 ************************/

	private DefaultListModel nodeList;
	private ArrayList<Integer> indexList;
	private JList nodeListDisplay;
	private JPanel listPane;
	private NetworkPane networkPane;
	private NodeDataPane nodeDataPane;
	private JButton listButton;
	private JButton dataButton;



	/**********************
	 ** Main Constructor **
	 **********************/

	public ContentPane(BeliefListener beliefListener)
	{
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();

		nodeList = new DefaultListModel();
		indexList = new ArrayList<Integer>();
		nodeListDisplay = new JList(nodeList);
		nodeListDisplay.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		nodeListDisplay.setSelectedIndex(0);
		nodeListDisplay.addListSelectionListener(beliefListener);

		JScrollPane listScrollPane = new JScrollPane(nodeListDisplay);

		listPane = new JPanel(new BorderLayout());
		listPane.setPreferredSize(new Dimension(0, this.getHeight()));
		listPane.setMinimumSize(new Dimension(0, this.getHeight()));
		listPane.add(listScrollPane, BorderLayout.CENTER);
		c.gridx = 0;
		c.gridy = 0;
		c.gridwidth = 1;
		c.gridheight = 1;
		c.fill = GridBagConstraints.BOTH;
		this.add(listPane, c);

		listButton = new JButton();
		listButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		listButton.setPreferredSize(new Dimension(10, this.getHeight()));
		listButton.setMinimumSize(new Dimension(10, this.getHeight()));
		listButton.addActionListener(beliefListener);
		c.gridx = 1;
		c.gridy = 0;
		c.gridwidth = 1;
		c.gridheight = 1;
		c.fill = GridBagConstraints.BOTH;
		this.add(listButton, c);

		networkPane = new NetworkPane(beliefListener);
		networkPane.setPreferredSize(new Dimension(10000, 10000));
		JScrollPane networkScrollPane = new JScrollPane(networkPane);
		networkScrollPane.getVerticalScrollBar().setUnitIncrement(25);
		networkScrollPane.getHorizontalScrollBar().setUnitIncrement(25);
		JPanel editPane = new JPanel(new BorderLayout());
		editPane.add(networkScrollPane, BorderLayout.CENTER);
		c.gridx = 2;
		c.gridy = 0;
		c.gridwidth = 1;
		c.gridheight = 1;
		c.weightx = 1.0;
		c.weighty = 1.0;
		c.fill = GridBagConstraints.BOTH;
		this.add(editPane, c);

		dataButton = new JButton();
		dataButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		dataButton.setPreferredSize(new Dimension(this.getWidth(), 10));
		dataButton.setMinimumSize(new Dimension(this.getWidth(), 10));
		dataButton.addActionListener(beliefListener);
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 3;
		c.gridheight = 1;
		c.weightx = 1.0;
		c.weighty = 0.0;
		c.fill = GridBagConstraints.BOTH;
		this.add(dataButton, c);

		nodeDataPane = new NodeDataPane(beliefListener);
		nodeDataPane.setPreferredSize(new Dimension(this.getWidth(), 0));
		nodeDataPane.setMinimumSize(new Dimension(this.getWidth(), 0));
		c.gridx = 0;
		c.gridy = 2;
		c.gridwidth = 3;
		c.gridheight = 1;
		c.weightx = 1.0;
		c.weighty = 0.0;
		c.fill = GridBagConstraints.BOTH;
		this.add(nodeDataPane, c);
	}



	/***************
	 ** Accessors **
	 ***************/

	/* Get the node list of this ContentPane */
	public DefaultListModel getNodeList()
	{
		return this.nodeList;
	}

	/* Get the key list of this ContentPane */
	public ArrayList<Integer> getIndexList()
	{
		return this.indexList;
	}

	/* Get the JList that displays the node list in this ContentPane */
	public JList getNodeListDisplay()
	{
		return this.nodeListDisplay;
	}

	/* Get this ContentPane's listPane */
	public JPanel getListPane()
	{
		return this.listPane;
	}

	/* Get this ContentPane's DisplayPane */
	public NetworkPane getNetworkPane()
	{
		return this.networkPane;
	}

	/* Get this ContentPane's NodeDataPane */
	public NodeDataPane getNodeDataPane()
	{
		return this.nodeDataPane;
	}

	public JButton getListButton()
	{
		return this.listButton;
	}

	public JButton getDataButton()
	{
		return this.dataButton;
	}



	/**************
	 ** Mutators **
	 **************/

	/* Set the node list of this ContentPane */
	public void setNodeList(DefaultListModel newNodeList)
	{
		this.nodeList = newNodeList;
	}

	/* Set the key list of this ContentPane */
	public void setIndexList(ArrayList<Integer> newIndexList)
	{
		this.indexList = newIndexList;
	}
}