//----------------------------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.editor.panels;
import java.awt.Component;

import javax.swing.JTabbedPane;

import org.huihoo.god4j.editor.XPDLComponent;
/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class JavaTabbedPanel extends JavaPanel
{
	private JTabbedPane tabbed;
	public JavaTabbedPanel(XPDLComponent xpdlComp, JavaPanel[] panels)
	{
		super(xpdlComp, 1, "", JavaPanel.BOX_LAYOUT, true, false);

		tabbed = new JTabbedPane(JTabbedPane.TOP);
		tabbed.setAlignmentX(Component.LEFT_ALIGNMENT);
		tabbed.setAlignmentY(Component.TOP_ALIGNMENT);
		for (int i = 0; i < panels.length; i++)
		{
			if (panels[i].getTitle() != null && panels[i].getTitle().length() > 0)
			{
				tabbed.addTab(panels[i].getTitle(), panels[i]);
			}
			else
			{
				tabbed.addTab(panels[i].getXPDLComponent().getLabel(), panels[i]);
			}
		}
		add(tabbed);
	}
	public JavaPanel getTabbedPanel(int no)
	{
		if (no >= tabbed.getTabCount())
		{
			return null;
		}
		return (JavaPanel) tabbed.getComponentAt(no);
	}
	public boolean checkRequired()
	{
		boolean isOK = true;
		for (int i = 0; i < tabbed.getComponentCount(); i++)
		{
			Component c = tabbed.getComponent(i);
			if (c instanceof JavaPanel)
			{
				isOK = isOK && ((JavaPanel) c).checkRequired();
			}
		}
		return isOK;
	}

	public void applyChanges()
	{
		for (int i = 0; i < tabbed.getComponentCount(); i++)
		{
			Component c = tabbed.getComponent(i);
			if (c instanceof JavaPanel)
			{
				((JavaPanel) c).applyChanges();
			}
		}
	}
}