package j3deditor.bin.editor.util;

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


/**
 * The <code>GELayout</code> class is a layout manager
 * for <code>GeometryEditor</code>.
 *
 * @author Risto Seene
 * 
 * @see j3deditor.bin.editor.GeometryEditor
 */
public class GELayout implements LayoutManager{

	/** width of the most left and right column components */
	private int width;

	/** height of the top and bottom row components */
	private int height;

	/** vertical space between components */
	private int vspace;

	/** horizontal space between components */
	private int hspace;


	/**
	 * Creates an instance of <code>GELayout</code>.
	 * 
	 * @param width
	 * 	width of the most left and right column components
	 * @param height
	 * 	height of the top and bottom row components
	 */
	public GELayout(int width, int height){
		this.width = width;
		this.height = height;
		vspace = 0;
		hspace = 0;
	}

	/**
	 * Creates an instance of <code>GELayout</code>.
	 * 
	 * @param width
	 * 	width of the most left and right column components
	 * @param height
	 * 	height of the top and bottom row components
	 * @param vspace
	 * 	vertical space between components
	 * @param hspace
	 * 	horizontal space between components
	 */
	public GELayout(int width, int height, int vspace, int hspace){
		this(width, height);
		this.vspace = vspace;
		this.hspace = hspace;
	}

	/**
	 * Required by LayoutManager.
	 * @param name
	 * 	doesn't do anything
	 * @param comp
	 * 	doesn't do anything
	 */
	public void addLayoutComponent(String name, Component comp){
	}

	/**
	 * Required by LayoutManager.
	 * 
	 * @param comp
	 * 	doesn't do anything
	 */
	public void removeLayoutComponent(Component comp){
	}

	/**
	 * Required by LayoutManager.
	 * 
	 * @param parent
	 * 	doesn't do anything
	 * @return (0, 0)
	 */
	public Dimension preferredLayoutSize(Container parent){
		return new Dimension(0, 0);
	}

	/**
	 * Required by LayoutManager.
	 * 
	 * @param parent
	 * 	doesn't do anything
	 * @return (0, 0)
	 */
	public Dimension minimumLayoutSize(Container parent){
		return new Dimension(0, 0);
	}

	/**
	 * Required by LayoutManager.
	 * Lays out the component into the given container.
	 *
	 * @param parent
	 *	container which components will be layd out
	 */
	public void layoutContainer(Container parent){
		int maxWidth = parent.getWidth();
		int maxHeight = parent.getHeight();

		int sceneWidth = (int)(maxWidth / 2) - width - 2 * vspace -(int)(vspace/2);
		int sceneHeight = (int)(maxHeight / 2) - height - 2 * hspace -(int)(hspace/2);

		try{
			parent.getComponent(0).setBounds(vspace, hspace, width, height);
			parent.getComponent(1).setBounds(width + 2 * vspace, hspace, 2*(sceneWidth+vspace), height);
			parent.getComponent(2).setBounds(maxWidth - width - vspace, hspace, width, height);

			parent.getComponent(3).setBounds(vspace, height + 2 * hspace, width, sceneHeight);
			parent.getComponent(4).setBounds(width + 2 * vspace, height + 2 * hspace, sceneWidth, sceneHeight);
			parent.getComponent(5).setBounds(maxWidth - sceneWidth - width - 2 * vspace, height + 2 * hspace, sceneWidth, sceneHeight);
			parent.getComponent(6).setBounds(maxWidth - width - vspace, height + 2 * hspace, width, sceneHeight);

			parent.getComponent(7).setBounds(vspace, maxHeight - height - sceneHeight - 2 * hspace, width, sceneHeight);
			parent.getComponent(8).setBounds(width + 2 * vspace, maxHeight - height - sceneHeight - 2 * hspace, sceneWidth, sceneHeight);
			parent.getComponent(9).setBounds(maxWidth - sceneWidth - width - 2 * vspace, maxHeight - height - sceneHeight - 2 * hspace, sceneWidth, sceneHeight);
			parent.getComponent(10).setBounds(maxWidth - width - vspace, maxHeight - height - sceneHeight - 2 * hspace, width, sceneHeight);

			parent.getComponent(11).setBounds(vspace, maxHeight - height - hspace, width, height);
			parent.getComponent(12).setBounds(width + 2 * vspace, maxHeight - height - hspace, 2*(sceneWidth+vspace), height);
			parent.getComponent(13).setBounds(maxWidth - width - vspace, maxHeight - height - hspace, width, height);
		} catch(Throwable t){
		}

	}
}

