package de.siphalor.was.visual.canvas.layout;

import java.awt.*;

public class FulfillingLayout implements LayoutManager {
	private Component component;

	public FulfillingLayout() {
		this(null);
	}

	public FulfillingLayout(Component component) {
		this.component = component;
	}

	@Override
	public void addLayoutComponent(String name, Component comp) {
		component = comp;
	}

	@Override
	public void removeLayoutComponent(Component comp) {
		component = null;
	}

	@Override
	public Dimension preferredLayoutSize(Container parent) {
		Insets insets = parent.getInsets();
		return new Dimension(parent.getWidth() - (insets.left + insets.right), parent.getHeight() - (insets.top + insets.bottom));
	}

	@Override
	public Dimension minimumLayoutSize(Container parent) {
		Insets insets = parent.getInsets();
		return new Dimension(parent.getWidth() - (insets.left + insets.right), parent.getHeight() - (insets.top + insets.bottom));
	}

	@Override
	public void layoutContainer(Container parent) {
		if (component != null) {
			Insets insets = parent.getInsets();

			component.setBounds(insets.left, insets.top,
					parent.getWidth() - (insets.left + insets.right),
					parent.getHeight() - (insets.top + insets.bottom)
			);
		}
	}
}
