import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Interface extends JFrame{
	private static final long serialVersionUID = 1L;
	private static final Font titleFont = new Font(new JLabel().getFont().getName(), Font.BOLD, 14);
	private static final Font defaultFont = new Font(new JLabel().getFont().getName(), Font.PLAIN, new JLabel().getFont().getSize());

	public Interface(final Runnable executeOnClose) {
		super("VRGNYMusicLights");
		//this.actionList = actionList;
		setResizable(false);
		populateWindow();
		pack();
		setLocationRelativeTo(null); // center window
        
		addWindowListener(new WindowAdapter() {
        	@Override
        	public void windowClosing(WindowEvent e) {
        		if(executeOnClose != null)
        			executeOnClose.run();
        		dispose();
        	}
		});
	}
	
	private void populateWindow() {
		JPanel mainPanel = new JPanel(new BorderLayout());
		addPlayPanel(mainPanel);
		add(mainPanel);
	}
	
	private void addPlayPanel(JPanel parent) {
		JPanel playPanel = new JPanel(new BorderLayout());
		
		// title
		JLabel title = new JLabel("Player :");
		title.setFont(titleFont);
		playPanel.add(title, BorderLayout.NORTH);
		
		// lights
		playPanel.add(new LightCanvasJPanel(), BorderLayout.CENTER);
		
		// controls
		AnimationPlayer animPlayer = new AnimationPlayer();
		animPlayer.setAlignmentX(CENTER_ALIGNMENT);
		playPanel.add(animPlayer, BorderLayout.SOUTH);
		
		parent.add(playPanel, BorderLayout.SOUTH);
	}
}
