package j3deditor.bin.components;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.LayoutManager;

/**
 * The <code>CenterLayout</code> class is a layout manager
 * that lays out a container's component in the middle of the container.
 *
 * @author Risto Seene
 */
public class CenterLayout implements LayoutManager{

	/** vertical width of the border. */
	private int hborder = 0;
	
	/** horizontal width of the border. */
	private int vborder = 0;


	/**
	 * Creates an instance of <code>CenterLayout</code>
	 * with the given border width.
	 * 
	 * @param border
	 * 	width of the border
	 */
	public CenterLayout(int border){
		this.hborder = border;
		this.vborder = border;
	}


	/**
	 * Creates an instance of <code>CenterLayout</code>
	 * with the given border width.
	 * 
	 * @param hborder
	 * 	horizontal width of the border
	 * @param vborder
	 * 	vertical width of the border
	 */
	public CenterLayout(int hborder, int vborder){
		this.hborder = hborder;
		this.vborder = vborder;
	}


	/**
	 * Required by LayoutManager, not in use.
	 * 
	 * @param string
	 * 	doesn't do anything
	 * @param component
	 * 	doesn't do anything
	 */
	public void addLayoutComponent(String string, Component component){
	}


	/**
	 * Required by LayoutManager, not in use.
	 * 
	 * @param component
	 * 	doesn't do anything
	 */
	public void removeLayoutComponent(Component component){
	}


	/**
	 * Required by LayoutManager, not in use.
	 * 
	 * @param container
	 * 	doesn't do anything
	 * @return
	 * 	<code>null</code>
	 */
	public Dimension preferredLayoutSize(Container container){
		return null;
	}


	/**
	 * Required by LayoutManager, not in use.
	 * 
	 * @param container
	 * 	doesn't do anything
	 * @return
	 * 	<code>null</code>
	 */
	public Dimension minimumLayoutSize(Container container){
		return null;
	}


	 /**
	  * Required by LayoutManager.
	  * Lays out the components into the given container.
	  *
	  * @param container
	  *        container which components will be layd out
	  */
	public void layoutContainer(Container container){
		if(container.getComponentCount() > 0){
			container.getComponent(0).setBounds(vborder, hborder, container.getWidth()-2*vborder, container.getHeight()-2*hborder);
		}
	}

}
