Skip to content

Instantly share code, notes, and snippets.

@ulmangt
Created August 24, 2014 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulmangt/e5aa014c1eb8c75328cd to your computer and use it in GitHub Desktop.
Save ulmangt/e5aa014c1eb8c75328cd to your computer and use it in GitHub Desktop.
Runnable SWT / JOGL class demonstrating inability to create SWT Menu over NewtCanvasSWT
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.newt.swt.NewtCanvasSWT;
public class NewtSwtPopupExample
{
public static void main( String[] args )
{
GLProfile glProfile = GLProfile.getMaxFixedFunc( true );
GLCapabilities glCapabilities = new GLCapabilities( glProfile );
final Display display = new Display( );
final Shell shell = new Shell( display );
shell.setLayout( new FillLayout( ) );
GLWindow glWindow = GLWindow.create( glCapabilities );
new NewtCanvasSWT( shell, SWT.NO_BACKGROUND, glWindow );
shell.setSize( 800, 800 );
shell.setLocation( 0, 0 );
shell.open( );
shell.moveAbove( null );
final Menu menu = new Menu( shell, SWT.NONE );
MenuItem m1 = new MenuItem( menu, SWT.PUSH );
MenuItem m2 = new MenuItem( menu, SWT.PUSH );
MenuItem m3 = new MenuItem( menu, SWT.PUSH );
m1.setText( "Option 1" );
m2.setText( "Option 2" );
m3.setText( "Option 3" );
glWindow.addMouseListener( new MouseAdapter( )
{
@Override
public void mousePressed( MouseEvent e )
{
System.out.println( "pre mousePressed " + e.getX( ) + " " + e.getY( ) + " Menu Visible " + menu.isVisible( ) );
// map canvas coordinate system to Display coordinate system to place menu in proper location
Point point = display.map( shell, null, new Point( e.getX( ), e.getY( ) ) );
menu.setLocation( point );
menu.setVisible( true );
System.out.println( "post mousePressed " + point.x + " " + point.y + " Menu Visible " + menu.isVisible( ) );
}
} );
while ( !shell.isDisposed( ) )
if ( !display.readAndDispatch( ) ) display.sleep( );
return;
}
}
v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment