Interface.java 1.93 KB
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

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

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());
	
	protected MusicList musicList;
	protected AnimationPlayer animPlayer;
	protected TimeLineJPanel timeLinePanel;
	protected TimeLineJList timeLineList;
	protected LightCanvasJPanel lightCanvas;
	protected JSlider timeSlider;
	protected long tick = 0;

	public Interface(MusicList musicList, final Runnable executeOnClose) {
		super("VRGNYMusicLights");
		this.musicList = musicList;
		populateWindow();
		pack();
		setMinimumSize(new Dimension(600, 500));
		setSize(new Dimension(800, 600));
		setLocationRelativeTo(null); // center window
		getContentPane().requestFocus();
        
		addWindowListener(new WindowAdapter() {
        	@Override
        	public void windowClosing(WindowEvent e) {
        		if(animPlayer != null)
        			animPlayer.stopTickClock();
        		if(executeOnClose != null)
        			executeOnClose.run();
        		dispose();
        	}
		});
	}
	
	protected void computeTick() {
		timeSlider.setValue((int) tick);
		lightCanvas.paintLights(musicList.render(tick));
		timeLineList.repaint();
		timeLinePanel.updateTick();
	}
	
	private void populateWindow() {
		JPanel mainPanel = new JPanel(new BorderLayout());
		timeLinePanel = new TimeLineJPanel(this);
		mainPanel.add(timeLinePanel, BorderLayout.CENTER);
		lightCanvas =  new LightCanvasJPanel();
		mainPanel.add(new PlayJPanel(this, lightCanvas), BorderLayout.SOUTH);
		mainPanel.add(new CommandJPanel(this), BorderLayout.EAST);
		add(mainPanel);
	}
}