package vgp.curve.deCasteljau;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import jv.object.PsPanel;
import jv.object.PsUpdateIf;
import jv.project.PjProject_IP;

/**
 * Info panel allows to control the dynamic movement of faces.
 * 
 * @author		Konrad Polthier
 * @version		03.11.06, 2.00 revised (kp) Package moved to vgp.curve.deCasteljau from dev.app.deCasteljau.<br>
 *					05.10.04, 1.00 created (kp) 
 */
public class PjDeCasteljau_IP extends PjProject_IP implements ActionListener { 
	/** Parent project. */
	protected	PjDeCasteljau			m_pjDeCasteljau;
	/** Reset the project and participating geometries. */
	protected	Button					m_bReset;
	/** Panel contains all sliders of the project. */
	protected	PsPanel					m_pSlider;

	public PjDeCasteljau_IP() {
		super();
		if (getClass() == PjDeCasteljau_IP.class) {
			init();
		}
	}
	public void init() {
		super.init();
		addTitle("");

		m_pSlider = new PsPanel(new GridLayout(3, 1));
		add(m_pSlider);

		// buttons at bottom
		Panel pBottomButtons = new Panel(new FlowLayout(FlowLayout.CENTER));
		add(pBottomButtons);
		m_bReset	= new Button("Reset");
		m_bReset.addActionListener(this);
		pBottomButtons.add(m_bReset);
	}
	/**
	 * Set parent of panel which supplies the data inspected by the panel.
	 */
	public void setParent(PsUpdateIf parent) {
		super.setParent(parent);
		m_pjDeCasteljau = (PjDeCasteljau)parent;

		m_pSlider.add(m_pjDeCasteljau.m_position.getInfoPanel());
		m_pSlider.add(m_pjDeCasteljau.m_depth.getInfoPanel());
			
		validate();
	}
	/**
	 * Update the panel whenever the parent has changed somewhere else.
	 * Method is invoked from the parent or its superclasses.
	 */
	public boolean update(Object event) {
		if (m_pjDeCasteljau == event) {
			setTitle(m_pjDeCasteljau.getName());
			return true;			
		}
		return super.update(event);
	}
	/**
	 * Handle action events invoked from buttons, menu items, text fields.
	 */
	public void actionPerformed(ActionEvent event) {
		if (m_pjDeCasteljau==null)
			return;
		Object source = event.getSource();
		if (source == m_bReset) {
			m_pjDeCasteljau.init();			
			// Use event==geom to initiate an update of the geometry too
			// original control polygon may have changed.
			m_pjDeCasteljau.m_geom.update(m_pjDeCasteljau.m_geom);
			// Fit control polygon
			m_pjDeCasteljau.start();
		}
	}
}
