package gui;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;

import visualization.VisualPanel;

public class MyTabbedPane extends JTabbedPane {
	private static final long serialVersionUID = -1712570648984475827L;

	public GUIFactory gui;
	public JPanel inputPanel;
	public JPanel IOPanel;
	public JToolBar toolBar;
	public VisualPanel vizPanel;
	public JPanel settings;

	public JScrollPane inputText;
	public JScrollPane highlighted;

	
	public JPanel tab1;
	public JPanel tab2;
	public JPanel tab3;
	public JPanel tab4;
	
	public MyTabbedPane(JPanel iP, JScrollPane iT, JScrollPane h, JPanel IOP, JToolBar tB, VisualPanel vP, JPanel s, GUIFactory g) {
		inputPanel = iP;		
		inputText = iT;
		highlighted = h;
		IOPanel = IOP;
		toolBar = tB;
		vizPanel = vP;
		settings = s;
		gui = g;
		gui.setTabs(this);

		tab1 = new JPanel();
        tab2 = new JPanel();
        tab3 = new JPanel();
        tab4 = new JPanel();
        
        tab1.setLayout(new BorderLayout());
        tab2.setLayout(new BorderLayout());
        tab3.setLayout(new BorderLayout());
        tab4.setLayout(new BorderLayout());
		
		resetTabs(false);
		this.setSelectedIndex(0);
	} 
	
	public void resetTabs(boolean blocked) {				
		int i = this.getSelectedIndex();
		this.removeAll();
		if (!blocked) {
			addTab(gui.guiText.getTabName("mixed"), tab1);
			addTab(gui.guiText.getTabName("visual"), tab2);
			addTab(gui.guiText.getTabName("code"), tab3);                          
			addTab(gui.guiText.getTabName("settings"), tab4);        
			this.setSelectedIndex(i);
		} else {
			addTab(gui.guiText.getTabName("visual"), tab2);
			setTab2();
		}
	}		

	@Override
	public void setSelectedIndex(int i) {
		switch (i) {
			case 0: {setTab1(); break;}
			case 1: {setTab2(); break;}
			case 2: {setTab3(); break;}
			case 3: {setTab4(); break;}
		}
		
		super.setSelectedIndex(i);
	}

	public void setTab1() {		
	    inputPanel.add(inputText, "North");
	    inputPanel.add(highlighted, "South");	 	   
		
		tab1.add(vizPanel, "Center");
		tab1.add(inputPanel, "East");
		tab1.add(IOPanel, "South");
		tab1.add(toolBar, "North");		
	}	
	
	public void setTab2() {		
		tab2.add(vizPanel, "Center");		
		tab2.add(IOPanel, "South");
		tab2.add(toolBar, "North");		
	}
	
	
	public void setTab3() {				
		tab3.add(inputText, "Center");
		tab3.add(highlighted, "East");
		tab3.add(toolBar, "North");		
	}

	public void setTab4() {
		tab4.add(settings, "Center");
		tab4.add(toolBar, "North");
	}

	
}
