package testApp;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.media.opengl.DebugGL2;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.UIManager;

/**
 */
public final class TestApp implements GLEventListener
{
	private final javax.media.opengl.awt.GLCanvas glCanvas = new javax.media.opengl.awt.GLCanvas(new GLCapabilities(GLProfile.getMaxFixedFunc()));

	private final JFrame frame = new JFrame();

	// Constructors:

	/**
	 * Initializes an instance.
	 */
	private TestApp()
	{
		this.glCanvas.addGLEventListener(TestApp.this);
		this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Prepare frame's single child.
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		splitPane.setDividerLocation(100);
		splitPane.setAlignmentX(JSplitPane.CENTER_ALIGNMENT);
		splitPane.setResizeWeight(0.5);
		splitPane.setDividerSize(2);
		this.frame.add(splitPane);

		JTree tree = new JTree(new Object[]
		{ "First node", "Second node", "Third node", "Fourth node", "Fifth node" });
		tree.setRootVisible(true);
		// tree.setUI(new BasicTreeUI());
		// tree.setShowsRootHandles(true);
		splitPane.setLeftComponent(tree);
		splitPane.setRightComponent(this.glCanvas);

		// We are done.
		// this.frame.validate();
	}

	// Methods:

	/**
	 * Program main entry point.
	 * @param inArguments Command line arguments.
	 */
	public static void main(final String[] inArguments)
	{
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

			TestApp app = new TestApp();

			// Give frame a reasonable initial size.
			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			app.frame.setSize(screenSize.width / 2, screenSize.height / 4);
			app.frame.setVisible(true);
		}
		catch (Throwable inT)
		{
			System.exit(0);
		}
	}

	@Override
	public void display(GLAutoDrawable arg0)
	{
		GL2 gl = arg0.getGL().getGL2();

		gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
	}

	@Override
	public void dispose(GLAutoDrawable arg0)
	{
	}

	@Override
	public void init(GLAutoDrawable arg0)
	{
		arg0.setGL(new DebugGL2(arg0.getGL().getGL2()));
	}

	@Override
	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4)
	{
	}
}