package org.flexdock.demos.raw.border;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.flexdock.demos.util.DemoUtility;
import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.defaults.DefaultDockingPort;

public class BorderDemo extends JFrame implements DockingConstants {
	
	public BorderDemo() {
		super("Border Docking Demo");
		setContentPane(createContentPane());
	}
	
	private JPanel createContentPane() {
		JPanel p = new JPanel(new BorderLayout(5, 5));
		p.add(buildDockingPort("North"), BorderLayout.NORTH);
		p.add(buildDockingPort("South"), BorderLayout.SOUTH);
		p.add(buildDockingPort("East"), BorderLayout.EAST);
		p.add(buildDockingPort("West"), BorderLayout.WEST);
		p.add(createDockingPort(), BorderLayout.CENTER);
		return p;
	}
	
	private DefaultDockingPort buildDockingPort(String desc) {
		// create the DockingPort
		DefaultDockingPort port = createDockingPort();

		// create the Dockable panel
		DockablePanel panel = new DockablePanel(desc);

		// dock the panel and return the DockingPort
		port.dock(panel.getDockable(), CENTER_REGION);
		return port;
	}
	
	private DefaultDockingPort createDockingPort() {
		DefaultDockingPort port = new DefaultDockingPort();
		port.setPreferredSize(new Dimension(100, 100));
		port.setBorderManager(new DemoBorderManager());
		return port;
	}

	public static void main(String[] args) {
		JFrame f = new BorderDemo();
		f.setSize(600, 400);
        DemoUtility.setCloseOperation(f);
		f.setVisible(true);
	}
}
