import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.event.*;

/**

The GuiController class is responsible for constructing the GUI Framework for the 2dfQSO system
Its split in a number of panes. 

There are two splitpanes 
1) splitPane - This is the pane which splits the window in two panes
	a) query pane on the left (leftPane)
	b) outputpane on the right (RightPane)
	
2) The rigthPane adds the following splitPane
   splitOutput - This splitpanes splits the pane in two sections
	a) Pane to describe the output results in table form
	b) pane to perfrom operations on the data results like Save, Vo-Plot etc

*/

class GuiController
{	
	/**
	The main function creates the GuiController object called theApp and invokes init ()
	**/
	public static void main (String[] args)
	{
		GuiController theApp = new GuiController ();
		theApp.init();
	}
	
	/**
	init creates the framework for the UI of the system as described above in the class description
	**/
	public void init()
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		window = new JFrame ("2dfQSO Database System");		
		
		Toolkit theKit = window.getToolkit();          // Get the window toolkit
		Dimension wndSize = theKit.getScreenSize();    // Get screen size

	    	window.setBounds (0,0, wndSize.width - 10, wndSize.height - 20);  // Set Size for the main Frame
		window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); 		

		//Creating the split pane for spliting the entire window in the query section and output Section
		leftPane = new JPanel (new BorderLayout());	// query Form
		rightPane = new JPanel (new BorderLayout());	// output Pane for display and tool bar
				
		// create the query module
		tdfInterface = new TdfInterface (this, (int) wndSize.width/4, wndSize.height);
				
		// add the left and right components to the panes
		leftPane.add (tdfInterface, BorderLayout.CENTER);
		
		// create the split pane for splitting the main window
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,leftPane,rightPane);
		splitPane.setDividerLocation((int)wndSize.width/4);  // sets
		splitPane.setOneTouchExpandable (true);
		
		// create panels for the output section & tool bar
		dataPane = new JPanel (new BorderLayout ());	// this outputs the query results/data
		toolBar = new JPanel (new BorderLayout ());	// this performs operations on the data		
		
		JSplitPane splitOutput = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT,true,dataPane,toolBar);
		splitOutput.setDividerLocation ((int) ((wndSize.width * 3)/5));
		splitOutput.setOneTouchExpandable (true);
		toolBar.setPreferredSize (new Dimension 
					((int) ((wndSize.width * 2)/7), wndSize.height - 50));
		
		rightPane.add (splitOutput);
		
		// set the splitpane pane position !
		int minWidth =  (3 * wndSize.width)/4;
		int minHeight = (3 * wndSize.height)/4;
		rightPane.setMinimumSize (new Dimension (minWidth,minHeight));

		// add the splitpane to the content pane !
		window.getContentPane().add(splitPane, BorderLayout.CENTER);	
		window.setVisible (true);
	}
	
	/**
	This function adds the JScrollPane which contains the query results to the main dataPane
	**/
	public void showResults (JScrollPane results)
        {
                dataPane.add (results, BorderLayout.CENTER);
                window.setVisible (true);
        }

	/**
	This function removes the previos results (if any) and clears the output pane
	**/
	public void removeComponents ()
	{
		dataPane.removeAll ();
	}
	
	/**
	*
	*/
	private GuiController theApp; 
	private JFrame window;
	private JPanel leftPane,rightPane, dataPane, toolBar;
	private TdfInterface tdfInterface;
}
