import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import javax.media.opengl.awt.GLCanvas;
import java.awt.*;

/**
  * Short program to illustrate a JOGL bug when GLCanvas is used
  * using the SWT_AWT bridge on linux with Java 7.
  *
  * Needs swt.jar and the JOGL libraries.
  */
public class GLSWT {
  public static void main( String[] args ) {
    Display display = new Display();

    Shell shell = new Shell( display, SWT.SHELL_TRIM );
    shell.setLayout( new FillLayout() );
    shell.setText( "SWT Application" );
    shell.setSize( 640, 480 );

    Composite composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
    composite.setLayout( new FillLayout() );

    final Frame frame = SWT_AWT.new_Frame( composite );

    frame.setLayout( new BorderLayout() );

    // Regular Canvas works
    // frame.add( new Canvas(), BorderLayout.CENTER );

    // GLCanvas does not work: shows separate JavaEmbeddedFrame and sometimes enters into an infinite loop of destroying and creating a new frame.
    frame.add( new GLCanvas(), BorderLayout.CENTER );

    shell.open();
    while ( !shell.isDisposed() ) {
      if ( !display.readAndDispatch() ) {
        display.sleep();
      }
    }
    display.dispose();
    System.exit( 0 );
  }
}
