Commits

Michael Ludwig committed 1097d41

Fix keyboard focus in windows and refactor a lot of code into JoglOnscreenSurface.

Comments (0)

Files changed (3)

src/com/ferox/renderer/impl/jogl/JoglFullscreenSurface.java

 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
 
-import javax.swing.SwingUtilities;
-
 import com.ferox.renderer.DisplayOptions;
 import com.ferox.renderer.FullscreenSurface;
-import com.ferox.renderer.RenderException;
 
 public class JoglFullscreenSurface extends JoglOnscreenSurface implements FullscreenSurface {
 	private Frame frame;
 	private GraphicsDevice gDev;
 	
 	protected JoglFullscreenSurface(JoglSurfaceFactory factory,	int id, DisplayOptions optionsRequest, int width, int height) {
-		super(factory, id, optionsRequest);
-		
-		// create the frame to use
-		try {
-			SwingUtilities.invokeAndWait(new Runnable() {
-				public void run() {
-					Frame f = new Frame();
-					f.setResizable(false);
-					f.setUndecorated(true);
-					
-					f.add(JoglFullscreenSurface.this.getGLAutoDrawable());
-					f.setVisible(true);
-					
-					JoglFullscreenSurface.this.frame = f;
-				}
-			});
-		} catch (Exception e) {
-			throw new RenderException("Error creating JoglWindowSurface", e);
-		}
-		this.frame.addWindowListener(this);
-		
+		super(factory, id, optionsRequest, 0, 0, width, height, false, true);
+	
 		// get target device parameters and set the display mode
 		this.gDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
 		this.gDev.setFullScreenWindow(this.frame);
 	public void destroySurface() {
 		if (this.gDev.getFullScreenWindow() == this.frame)
 			this.gDev.setFullScreenWindow(null);
-		try {
-			SwingUtilities.invokeAndWait(new Runnable() {
-				public void run() {
-					Frame f = JoglFullscreenSurface.this.frame;
-					
-					f.removeWindowListener(JoglFullscreenSurface.this);
-					f.setVisible(false);
-					f.dispose();
-					
-					JoglFullscreenSurface.this.frame = null;
-				}
-			});
-		} catch (Exception e) {
-			throw new RenderException("Error hiding JoglFullscreenSurface", e);
-		}
-		
 		super.destroySurface();
 	}
-
-	@Override
-	protected Frame getFrame() {
-		return this.frame;
-	}
 }

src/com/ferox/renderer/impl/jogl/JoglOnscreenSurface.java

 
 import com.ferox.renderer.DisplayOptions;
 import com.ferox.renderer.OnscreenSurface;
+import com.ferox.renderer.RenderException;
 import com.ferox.renderer.DisplayOptions.AntiAliasMode;
 import com.ferox.renderer.DisplayOptions.DepthFormat;
 import com.ferox.renderer.DisplayOptions.PixelFormat;
  *
  */
 public abstract class JoglOnscreenSurface extends JoglRenderSurface implements OnscreenSurface, WindowListener {
-	private final GLCanvas canvas;
+	protected final GLCanvas canvas;
+	protected final Frame frame;
+	
 	private final JoglStateRecord record;
 	
 	private DisplayOptions options;
 	/** The given options is used to identify the GLCapabilities for the
 	 * constructed GLCanvas.  The GLCanvas shares with the given factory's 
 	 * shadow context. */
-	protected JoglOnscreenSurface(JoglSurfaceFactory factory, int id, DisplayOptions optionsRequest) {
+	protected JoglOnscreenSurface(JoglSurfaceFactory factory, int id, DisplayOptions optionsRequest,
+								  final int x, final int y, final int width, final int height, 
+								  final boolean resizable, final  boolean undecorated) {
 		super(factory, id);
 		if (optionsRequest == null)
 			optionsRequest = new DisplayOptions();
 		this.canvas = new GLCanvas(chooseCapabilities(optionsRequest), new DefaultGLCapabilitiesChooser(), factory.getShadowContext(), null);
-		//this.canvas.setFocusable(false); // to make sure input doesn't get stolen
+		this.frame = new Frame();
+		
+		try {
+			SwingUtilities.invokeAndWait(new Runnable() {
+				public void run() {
+					frame.setResizable(resizable);
+					frame.setUndecorated(undecorated);
+					frame.setBounds(x, y, Math.max(width, 1), Math.max(height, 1));
+
+					frame.add(canvas);
+					
+					frame.setVisible(true);
+					canvas.requestFocusInWindow();
+				}
+			});
+		} catch (Exception e) {
+			throw new RenderException("Error creating JoglOnscreenSurface", e);
+		}
+		
 		this.canvas.addGLEventListener(this);
+		this.frame.addWindowListener(this);
 		
 		this.record = new JoglStateRecord(factory.getRenderer().getCapabilities());
-
 		this.options = optionsRequest;
 		
 		this.enableVsync = false;
 		this.updateVsync = true;
-		
 		this.iconified = false;
 	}
-	
-	/** Return the frame object that contains this surface's GLCanvas. */
-	protected abstract Frame getFrame();
-	
+		
 	/** Return the gl canvas that must be the sole child of the frame
 	 * returned by getFrame(). */
 	@Override
 	/** In addition, destroys the context of this surface's GLCanvas. */
 	@Override
 	public void destroySurface() {
+		this.frame.removeWindowListener(JoglOnscreenSurface.this);
+
+		try {
+			SwingUtilities.invokeAndWait(new Runnable() {
+				public void run() {
+					frame.setVisible(false);
+					frame.dispose();
+				}
+			});
+		} catch (Exception e) {
+			throw new RenderException("Error hiding JoglWindowSurface", e);
+		}
+		
 		this.canvas.getContext().destroy();
 		super.destroySurface();
 	}
 
 	@Override
 	public Object getWindowImpl() {
-		return this.getFrame();
+		return this.frame;
 	}
 	
 	@Override
 	
 	@Override
 	public String getTitle() {
-		return this.getFrame().getTitle();
+		return this.frame.getTitle();
 	}
 
 	@Override
 	public void setTitle(final String title) {
 		SwingUtilities.invokeLater(new Runnable() {
 			public void run() {
-				JoglOnscreenSurface.this.getFrame().setTitle(title == null ? "" : title);
+				JoglOnscreenSurface.this.frame.setTitle(title == null ? "" : title);
 			}
 		});
 	}

src/com/ferox/renderer/impl/jogl/JoglWindowSurface.java

 import javax.swing.SwingUtilities;
 
 import com.ferox.renderer.DisplayOptions;
-import com.ferox.renderer.RenderException;
 import com.ferox.renderer.WindowSurface;
 
 /** The Jogl implementation of a WindowSurface.  It uses a Frame that has a single
 	 * 
 	 * Makes sure that the created window is at least 1x1, wherever the window was created. */
 	protected JoglWindowSurface(JoglSurfaceFactory factory,	int id, DisplayOptions optionsRequest, 
-								final int x, final int y, final int width, final int height, 
-								final boolean resizable,final  boolean undecorated) {
-		super(factory, id, optionsRequest);
-		try {
-			SwingUtilities.invokeAndWait(new Runnable() {
-				public void run() {
-					Frame f = new Frame();
-					f.setResizable(resizable);
-					f.setUndecorated(undecorated);
-
-					f.add(JoglWindowSurface.this.getGLAutoDrawable());
-					f.setBounds(x, y, Math.max(width, 1), Math.max(height, 1));
-					f.setVisible(true);
-					
-					JoglWindowSurface.this.frame = f;
-				}
-			});
-		} catch (Exception e) {
-			throw new RenderException("Error creating JoglWindowSurface", e);
-		}
+								int x, int y, int width, int height, boolean resizable, boolean undecorated) {
+		super(factory, id, optionsRequest, x, y, width, height, resizable, undecorated);
 		
-		this.frame.addWindowListener(this);
-	}
-
-	protected Frame getFrame() {
-		return this.frame;
-	}
-	
-	@Override
-	public void destroySurface() {
-		try {
-			SwingUtilities.invokeAndWait(new Runnable() {
-				public void run() {
-					Frame f = JoglWindowSurface.this.frame;
-					
-					f.removeWindowListener(JoglWindowSurface.this);
-					f.setVisible(false);
-					f.dispose();
-					
-					JoglWindowSurface.this.frame = null;
-				}
-			});
-		} catch (Exception e) {
-			throw new RenderException("Error hiding JoglWindowSurface", e);
-		}
-		
-		super.destroySurface();
 	}
 	
 	@Override