	package lala;
	import javax.media.opengl.*;
	import javax.media.opengl.glu.GLU;
	
	import org.eclipse.swt.SWT;
	import org.eclipse.swt.custom.SashForm;
	import org.eclipse.swt.layout.FillLayout;
	import org.eclipse.swt.layout.GridLayout;
	import org.eclipse.swt.widgets.*;
	import org.eclipse.swt.events.PaintListener;
	import org.eclipse.swt.events.PaintEvent;
	import org.eclipse.swt.graphics.Rectangle;
	
	import com.jogamp.newt.opengl.GLWindow;
	import com.jogamp.newt.swt.NewtCanvasSWT;
	import com.jogamp.opengl.util.Animator;
	
	public class NewtSashTest {
		NewtCanvasSWT right;
		Canvas canvas;
		Composite loller;
	
		public NewtSashTest() {
			final Display d = new Display();
			Shell shell = new Shell(d);
			shell.setLayout(new FillLayout());
			shell.setSize(400, 200);
			SashForm sash = new SashForm(shell, SWT.BORDER | SWT.HORIZONTAL);
	
			Text left = new Text(sash, SWT.CENTER);
			left.setText(" --- Left text ----");
	
			BaseClass demo = new BaseClass();
			GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
	
			GLWindow glWindow1 = GLWindow.create(caps);
			glWindow1.addGLEventListener(demo);
	
			loller = new Composite(sash, SWT.NONE);
			
//			loller.setLayout(new FillLayout(SWT.NONE));
			loller.setLayout(new GridLayout(1, false));
			
			canvas = new Canvas(loller, SWT.NONE);
			canvas.addPaintListener(new PaintListener() {
				public void paintControl(PaintEvent e) {
					Rectangle clientArea = canvas.getClientArea();
					e.gc.setBackground(d.getSystemColor(SWT.COLOR_CYAN));
					e.gc.fillOval(0, 0, clientArea.width, clientArea.height);
				}
			});
			right = NewtCanvasSWT.create(loller, SWT.SHELL_TRIM, glWindow1);
			shell.open();
			Animator anim = new Animator(glWindow1);
			anim.start();
			while (!shell.isDisposed()) {
				if (!d.readAndDispatch()) {
					d.sleep();
				}
			}
			d.dispose();
			System.exit(0);
		}
	
		class BaseClass implements GLEventListener {
	
			int x, y;
			int w, h;
	
			protected void setup(GL2 gl2) {
				gl2.glMatrixMode(GL2.GL_PROJECTION);
				gl2.glLoadIdentity();
				GLU glu = new GLU();
				glu.gluOrtho2D(0.0f, w, 0.0f, h);
				gl2.glMatrixMode(GL2.GL_MODELVIEW);
				gl2.glLoadIdentity();
				gl2.glViewport(x, y, w, h);
	
			}
	
			protected void render(GL2 gl2) {
				gl2.glClear(GL.GL_COLOR_BUFFER_BIT);
				gl2.glLoadIdentity();
				gl2.glBegin(GL.GL_TRIANGLES);
				gl2.glColor3f(1, 0, 0);
				gl2.glVertex2f(0, 0);
				gl2.glColor3f(0, 1, 0);
				gl2.glVertex2f(w, 0);
				gl2.glColor3f(0, 0, 1);
				gl2.glVertex2f(w / 2, h);
				gl2.glEnd();
			}
	
			@Override
			public void display(GLAutoDrawable arg0) {
				render((GL2) arg0.getGL());
			}
	
			@Override
			public void dispose(GLAutoDrawable arg0) {
			}
	
			@Override
			public void init(GLAutoDrawable arg0) {
				setup((GL2) arg0.getGL());
			}
	
			@Override
			public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) {
				this.x = x;
				this.y = y;
				this.w = w;
				this.h = h;
				System.out
						.println("x: " + x + " y: " + y + " w: " + w + " h: " + h);
				setup((GL2) arg0.getGL());
			}
		}
	
		public static void main(String args[]) {
			new NewtSashTest();
		}
	
}
