aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-06 12:51:45 +0200
committerSven Gothel <[email protected]>2014-06-06 12:51:45 +0200
commitebe980ad6ac40148bc84913d1ba1f7adf6200490 (patch)
tree75227f5cbfd131ddb4dd2c9e0d3a8b4318a0cde9 /src/newt
parent026cade97eab6fbd04e8bc902f24a2b61723acb8 (diff)
Bug 741 HiDPI: Add new NativeSurfaceHolder interface to GLDrawable and NativeWindow; [AWT|SWT]NewtEventFactory use NativeSurfaceHolder as source, fixes pixel unit conversion
- Add new NativeSurfaceHolder interface to GLDrawable and NativeWindow, allowing NativeSurface access (pixel unit conversion) A NativeSurfaceHolder is e.g.: - NativeWindow (is-a) - NEWT [GL]Window - GLDrawable (has-a) - [AWT|SWT]GLCanvas - [AWT|SWT]NewtEventFactory use NativeSurfaceHolder as source, fixes pixel unit conversion
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java26
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java68
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java10
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java22
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java23
-rw-r--r--src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java3
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java3
-rw-r--r--src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java46
-rw-r--r--src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java99
9 files changed, 192 insertions, 108 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index f6b2bab1f..37e9f9813 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -104,7 +104,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
private boolean newtChildAttached = false;
private boolean isOnscreen = true;
private WindowClosingMode newtChildCloseOp;
- private final AWTParentWindowAdapter awtAdapter;
+ private final AWTParentWindowAdapter awtWinAdapter;
private final AWTAdapter awtMouseAdapter;
private final AWTAdapter awtKeyAdapter;
@@ -140,8 +140,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
super();
awtMouseAdapter = new AWTMouseAdapter().addTo(this);
awtKeyAdapter = new AWTKeyAdapter().addTo(this);
- awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
- awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
+ awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
+ awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
}
/**
@@ -151,8 +151,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
super(gc);
awtMouseAdapter = new AWTMouseAdapter().addTo(this);
awtKeyAdapter = new AWTKeyAdapter().addTo(this);
- awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
- awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
+ awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
+ awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
}
/**
@@ -162,8 +162,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
super();
awtMouseAdapter = new AWTMouseAdapter().addTo(this);
awtKeyAdapter = new AWTKeyAdapter().addTo(this);
- awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
- awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
+ awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
+ awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
setNEWTChild(child);
}
@@ -174,8 +174,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
super(gc);
awtMouseAdapter = new AWTMouseAdapter().addTo(this);
awtKeyAdapter = new AWTKeyAdapter().addTo(this);
- awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
- awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
+ awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this);
+ awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction!
setNEWTChild(child);
}
@@ -779,11 +779,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
private final void configureNewtChild(boolean attach) {
- awtAdapter.clear();
+ awtWinAdapter.clear();
+ awtKeyAdapter.clear();
awtMouseAdapter.clear();
- awtKeyAdapter.setConsumeAWTEvent(false);
- awtMouseAdapter.clear();
- awtKeyAdapter.setConsumeAWTEvent(false);
if(null != keyboardFocusManager) {
keyboardFocusManager.removePropertyChangeListener("focusOwner", focusPropertyChangeListener);
@@ -797,7 +795,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
throw new InternalError("XXX");
}
isOnscreen = jawtWindow.getGraphicsConfiguration().getChosenCapabilities().isOnscreen();
- awtAdapter.setDownstream(jawtWindow, newtChild);
+ awtWinAdapter.setDownstream(jawtWindow, newtChild);
newtChild.addWindowListener(clearAWTMenusOnNewtFocus);
newtChild.setFocusAction(focusAction); // enable AWT focus traversal
newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingMode.DO_NOTHING_ON_CLOSE);
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
index cf533eb9e..9b1348288 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
@@ -28,6 +28,8 @@
package com.jogamp.newt.event.awt;
+import javax.media.nativewindow.NativeSurfaceHolder;
+
import jogamp.newt.Debug;
/**
@@ -117,37 +119,44 @@ public abstract class AWTAdapter implements java.util.EventListener
com.jogamp.newt.event.NEWTEventListener newtListener;
com.jogamp.newt.Window newtWindow;
+ NativeSurfaceHolder nsHolder;
boolean consumeAWTEvent;
protected boolean isSetup;
/**
- * Simply wrap aroung a NEWT EventListener, exposed as an AWT EventListener.<br>
+ * Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener,<br>
+ * where the given {@link NativeSurfaceHolder} impersonates the event's source.
* The NEWT EventListener will be called when an event happens.<br>
*/
- protected AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener) {
+ protected AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener, NativeSurfaceHolder nsProxy) {
if(null==newtListener) {
- throw new RuntimeException("Argument newtListener is null");
+ throw new IllegalArgumentException("Argument newtListener is null");
+ }
+ if(null==nsProxy) {
+ throw new IllegalArgumentException("Argument nwProxy is null");
}
this.newtListener = newtListener;
this.newtWindow = null;
+ this.nsHolder = nsProxy;
this.consumeAWTEvent = false;
this.isSetup = true;
}
/**
- * Wrap aroung a NEWT EventListener, exposed as an AWT EventListener,<br>
- * where the given NEWT Window impersonates as the event's source.
+ * Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener,<br>
+ * where the given {@link com.jogamp.newt.Window NEWT Window}, a {@link NativeSurfaceHolder}, impersonates the event's source.
* The NEWT EventListener will be called when an event happens.<br>
*/
protected AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener, com.jogamp.newt.Window newtProxy) {
if(null==newtListener) {
- throw new RuntimeException("Argument newtListener is null");
+ throw new IllegalArgumentException("Argument newtListener is null");
}
if(null==newtProxy) {
- throw new RuntimeException("Argument newtProxy is null");
+ throw new IllegalArgumentException("Argument newtProxy is null");
}
this.newtListener = newtListener;
this.newtWindow = newtProxy;
+ this.nsHolder = newtProxy;
this.consumeAWTEvent = false;
this.isSetup = true;
}
@@ -156,8 +165,9 @@ public abstract class AWTAdapter implements java.util.EventListener
* Create a pipeline adapter, AWT EventListener.<br>
* Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.<br>
* This is only supported with EDT enabled!
+ * @throws IllegalStateException if EDT is not enabled
*/
- protected AWTAdapter(com.jogamp.newt.Window downstream) {
+ protected AWTAdapter(com.jogamp.newt.Window downstream) throws IllegalStateException {
this();
setDownstream(downstream);
}
@@ -171,26 +181,34 @@ public abstract class AWTAdapter implements java.util.EventListener
* Setup a pipeline adapter, AWT EventListener.<br>
* Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.<br>
* This is only supported with EDT enabled!
+ * @throws IllegalStateException if EDT is not enabled
*/
- public synchronized AWTAdapter setDownstream(com.jogamp.newt.Window downstream) {
+ public synchronized AWTAdapter setDownstream(com.jogamp.newt.Window downstream) throws IllegalStateException {
if(null==downstream) {
throw new RuntimeException("Argument downstream is null");
}
this.newtListener = null;
this.newtWindow = downstream;
- this.consumeAWTEvent = false;
+ this.nsHolder = downstream;
if( null == newtWindow.getScreen().getDisplay().getEDTUtil() ) {
- throw new RuntimeException("EDT not enabled");
+ throw new IllegalStateException("EDT not enabled");
}
this.isSetup = true;
return this;
}
- /** Removes all references, downstream and NEWT-EventListener. */
+ /**
+ * Removes all references, downstream and NEWT-EventListener.
+ * <p>
+ * Also sets the internal <code>setup</code> flag and {@link #setConsumeAWTEvent(boolean)} to <code>false</code>.
+ * </p>
+ */
public synchronized AWTAdapter clear() {
this.newtListener = null;
this.newtWindow = null;
+ this.nsHolder = null;
this.isSetup = false;
+ this.consumeAWTEvent = false;
return this;
}
@@ -198,10 +216,36 @@ public abstract class AWTAdapter implements java.util.EventListener
this.consumeAWTEvent = v;
}
+ /**
+ * Returns the {@link NativeSurfaceHolder} acting {@link #AWTAdapter(com.jogamp.newt.Window) as downstream},
+ * {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, com.jogamp.newt.Window) NEWT window proxy}
+ * or as an {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, NativeSurfaceHolder) NativeSurfaceHolder proxy}.
+ * <p>
+ * Returned value is never null.
+ * </p>
+ */
+ public final synchronized NativeSurfaceHolder getNativeSurfaceHolder() {
+ return nsHolder;
+ }
+
+ /**
+ * Returns the {@link com.jogamp.newt.Window NEWT Window} acting {@link #AWTAdapter(com.jogamp.newt.Window) as downstream}
+ * or as a {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, com.jogamp.newt.Window) NEWT window proxy}.
+ * <p>
+ * Returned value maybe null if instance is used to be a
+ * {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, NativeSurfaceHolder) NativeSurfaceHolder proxy}.
+ * </p>
+ */
public final synchronized com.jogamp.newt.Window getNewtWindow() {
return newtWindow;
}
+ /**
+ * Returns the {@link com.jogamp.newt.event.NEWTEventListener NEWT event-listener} if instance
+ * is used as an {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, NativeSurfaceHolder) NativeSurfaceHolder proxy}
+ * or {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, com.jogamp.newt.Window) NEWT window proxy},
+ * otherwise method returns <code>null</code>.
+ */
public final synchronized com.jogamp.newt.event.NEWTEventListener getNewtEventListener() {
return newtListener;
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
index ddbeb6e42..5ea36bac8 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
@@ -28,6 +28,8 @@
package com.jogamp.newt.event.awt;
+import javax.media.nativewindow.NativeSurfaceHolder;
+
import jogamp.newt.awt.event.AWTNewtEventFactory;
/**
@@ -37,8 +39,8 @@ import jogamp.newt.awt.event.AWTNewtEventFactory;
*/
public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListener
{
- public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener) {
- super(newtListener);
+ public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, NativeSurfaceHolder nsProxy) {
+ super(newtListener, nsProxy);
}
public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, com.jogamp.newt.Window newtProxy) {
@@ -68,7 +70,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
@Override
public synchronized void keyPressed(java.awt.event.KeyEvent e) {
if( !isSetup ) { return; }
- final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED, e, newtWindow);
+ final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED, e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -80,7 +82,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
@Override
public synchronized void keyReleased(java.awt.event.KeyEvent e) {
if( !isSetup ) { return; }
- final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, e, newtWindow);
+ final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
index d0f73ef33..53fe70bf7 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
@@ -28,14 +28,16 @@
package com.jogamp.newt.event.awt;
+import javax.media.nativewindow.NativeSurfaceHolder;
+
import jogamp.newt.awt.event.AWTNewtEventFactory;
public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseListener,
java.awt.event.MouseMotionListener,
java.awt.event.MouseWheelListener
{
- public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener) {
- super(newtListener);
+ public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, NativeSurfaceHolder nsProxy) {
+ super(newtListener, nsProxy);
}
public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, com.jogamp.newt.Window newtProxy) {
@@ -69,7 +71,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseClicked(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -81,7 +83,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseEntered(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -93,7 +95,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseExited(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -105,7 +107,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mousePressed(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -117,7 +119,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseReleased(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -129,7 +131,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseDragged(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -141,7 +143,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseMoved(java.awt.event.MouseEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
@@ -153,7 +155,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
@Override
public synchronized void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow);
+ com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder);
if( consumeAWTEvent ) {
e.consume();
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
index 43a28b3b3..698fe86f4 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
@@ -30,6 +30,8 @@ package com.jogamp.newt.event.awt;
import java.awt.Dimension;
+import javax.media.nativewindow.NativeSurfaceHolder;
+
import jogamp.newt.awt.event.AWTNewtEventFactory;
public class AWTWindowAdapter
@@ -38,8 +40,8 @@ public class AWTWindowAdapter
{
WindowClosingListener windowClosingListener;
- public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener) {
- super(newtListener);
+ public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, NativeSurfaceHolder nsProxy) {
+ super(newtListener, nsProxy);
}
public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, com.jogamp.newt.Window newtProxy) {
@@ -49,6 +51,7 @@ public class AWTWindowAdapter
public AWTWindowAdapter(com.jogamp.newt.Window downstream) {
super(downstream);
}
+
public AWTWindowAdapter() {
super();
}
@@ -100,7 +103,7 @@ public class AWTWindowAdapter
@Override
public synchronized void focusGained(java.awt.event.FocusEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWT: focusGained: "+e+" -> "+event);
}
@@ -112,7 +115,7 @@ public class AWTWindowAdapter
@Override
public synchronized void focusLost(java.awt.event.FocusEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWT: focusLost: "+e+" -> "+event);
}
@@ -124,7 +127,7 @@ public class AWTWindowAdapter
@Override
public synchronized void componentResized(java.awt.event.ComponentEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if(DEBUG_IMPLEMENTATION) {
final java.awt.Component c = e.getComponent();
final java.awt.Dimension sz = c.getSize();
@@ -148,7 +151,7 @@ public class AWTWindowAdapter
@Override
public synchronized void componentMoved(java.awt.event.ComponentEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWT: componentMoved: "+e+" -> "+event);
}
@@ -198,7 +201,7 @@ public class AWTWindowAdapter
@Override
public synchronized void windowActivated(java.awt.event.WindowEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
}
@@ -213,7 +216,7 @@ public class AWTWindowAdapter
@Override
public synchronized void windowDeactivated(java.awt.event.WindowEvent e) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if( EventProcRes.DISPATCH == processEvent(false, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
}
@@ -233,7 +236,7 @@ public class AWTWindowAdapter
public void windowClosing(java.awt.event.WindowEvent e) {
synchronized( AWTWindowAdapter.this ) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if( EventProcRes.DISPATCH == processEvent(true, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event);
}
@@ -243,7 +246,7 @@ public class AWTWindowAdapter
public void windowClosed(java.awt.event.WindowEvent e) {
synchronized( AWTWindowAdapter.this ) {
if( !isSetup ) { return; }
- com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder);
if( EventProcRes.DISPATCH == processEvent(true, event) ) {
((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyed(event);
}
diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
index 93ecc8bb2..674d467f9 100644
--- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
+++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
@@ -548,6 +548,9 @@ public class NewtCanvasSWT extends Canvas implements WindowClosingProtocol {
}
@Override
+ public final NativeSurface getNativeSurface() { return this; }
+
+ @Override
public AbstractGraphicsConfiguration getGraphicsConfiguration() {
return config;
}
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 2411f6595..5288bfcc5 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -854,6 +854,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// public final void destroy() - see below
@Override
+ public final NativeSurface getNativeSurface() { return this; }
+
+ @Override
public final NativeWindow getParent() {
return parentWindow;
}
diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
index 709143b82..b04fd98f4 100644
--- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
@@ -28,6 +28,9 @@
package jogamp.newt.awt.event;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeSurfaceHolder;
+
import com.jogamp.newt.event.MouseEvent;
/**
@@ -590,31 +593,31 @@ public class AWTNewtEventFactory {
return defAwtKeyCode;
}
- public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.WindowEvent createWindowEvent(final java.awt.event.WindowEvent event, final NativeSurfaceHolder sourceHolder) {
final short newtType = eventTypeAWT2NEWT(event.getID());
if( (short)0 != newtType ) {
- return new com.jogamp.newt.event.WindowEvent(newtType, ((null==newtSource)?(Object)event.getComponent():(Object)newtSource), System.currentTimeMillis());
+ return new com.jogamp.newt.event.WindowEvent(newtType, sourceHolder, System.currentTimeMillis());
}
return null; // no mapping ..
}
- public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.ComponentEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.WindowEvent createWindowEvent(final java.awt.event.ComponentEvent event, final NativeSurfaceHolder sourceHolder) {
final short newtType = eventTypeAWT2NEWT(event.getID());
if( (short)0 != newtType ) {
- return new com.jogamp.newt.event.WindowEvent(newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis());
+ return new com.jogamp.newt.event.WindowEvent(newtType, sourceHolder, System.currentTimeMillis());
}
return null; // no mapping ..
}
- public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.FocusEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.WindowEvent createWindowEvent(final java.awt.event.FocusEvent event, final NativeSurfaceHolder sourceHolder) {
final short newtType = eventTypeAWT2NEWT(event.getID());
if( (short)0 != newtType ) {
- return new com.jogamp.newt.event.WindowEvent(newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis());
+ return new com.jogamp.newt.event.WindowEvent(newtType, sourceHolder, System.currentTimeMillis());
}
return null; // no mapping ..
}
- public static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.MouseEvent createMouseEvent(final java.awt.event.MouseEvent event, final NativeSurfaceHolder sourceHolder) {
final short newtType = eventTypeAWT2NEWT(event.getID());
if( (short)0 != newtType ) {
float rotation = 0;
@@ -626,35 +629,40 @@ public class AWTNewtEventFactory {
final short newtButton = awtButton2Newt(event.getButton());
int mods = awtModifiers2Newt(event.getModifiers(), event.getModifiersEx());
mods |= com.jogamp.newt.event.InputEvent.getButtonMask(newtButton); // always include NEWT BUTTON_MASK
+ final NativeSurface source = sourceHolder.getNativeSurface();
final int[] pixelPos;
- if(null!=newtSource) {
- if(newtSource.isPointerConfined()) {
- mods |= com.jogamp.newt.event.InputEvent.CONFINED_MASK;
- }
- if(!newtSource.isPointerVisible()) {
- mods |= com.jogamp.newt.event.InputEvent.INVISIBLE_MASK;
+ if( null != source ) {
+ if( source instanceof com.jogamp.newt.Window ) {
+ final com.jogamp.newt.Window newtSource = (com.jogamp.newt.Window) source;
+ if(newtSource.isPointerConfined()) {
+ mods |= com.jogamp.newt.event.InputEvent.CONFINED_MASK;
+ }
+ if(!newtSource.isPointerVisible()) {
+ mods |= com.jogamp.newt.event.InputEvent.INVISIBLE_MASK;
+ }
}
- pixelPos = newtSource.convertToPixelUnits(new int[] { event.getX(), event.getY() });
+ pixelPos = source.convertToPixelUnits(new int[] { event.getX(), event.getY() });
} else {
pixelPos = new int[] { event.getX(), event.getY() };
}
+
return new com.jogamp.newt.event.MouseEvent(
- newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(),
+ newtType, sourceHolder, event.getWhen(),
mods, pixelPos[0], pixelPos[1], (short)event.getClickCount(),
newtButton, MouseEvent.getRotationXYZ(rotation, mods), 1f);
}
return null; // no mapping ..
}
- public static final com.jogamp.newt.event.KeyEvent createKeyEvent(java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) {
- return createKeyEvent(eventTypeAWT2NEWT(event.getID()), event, newtSource);
+ public static final com.jogamp.newt.event.KeyEvent createKeyEvent(final java.awt.event.KeyEvent event, final NativeSurfaceHolder sourceHolder) {
+ return createKeyEvent(eventTypeAWT2NEWT(event.getID()), event, sourceHolder);
}
- public static final com.jogamp.newt.event.KeyEvent createKeyEvent(short newtType, java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) {
+ public static final com.jogamp.newt.event.KeyEvent createKeyEvent(final short newtType, final java.awt.event.KeyEvent event, final NativeSurfaceHolder sourceHolder) {
if( (short)0 != newtType ) {
final short newtKeyCode = awtKeyCode2NewtKeyCode( event.getKeyCode() );
return com.jogamp.newt.event.KeyEvent.create(
- newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(),
+ newtType, sourceHolder, event.getWhen(),
awtModifiers2Newt(event.getModifiers(), event.getModifiersEx()),
newtKeyCode, newtKeyCode, event.getKeyChar());
}
diff --git a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
index b5c45c1aa..386149b22 100644
--- a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
@@ -28,6 +28,9 @@
package jogamp.newt.swt.event;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeSurfaceHolder;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
@@ -134,7 +137,7 @@ public class SWTNewtEventFactory {
}
public static int newtKeyCode2SWTKeyCode(final short newtKeyCode) {
- final int defSWTKeyCode = 0xFFFF & (int)newtKeyCode;
+ final int defSWTKeyCode = 0xFFFF & newtKeyCode;
switch (newtKeyCode) {
case com.jogamp.newt.event.KeyEvent.VK_HOME : return SWT.HOME;
case com.jogamp.newt.event.KeyEvent.VK_END : return SWT.END;
@@ -199,15 +202,15 @@ public class SWTNewtEventFactory {
}
- public static final com.jogamp.newt.event.InputEvent createInputEvent(org.eclipse.swt.widgets.Event event, Object source) {
- com.jogamp.newt.event.InputEvent res = createMouseEvent(event, source);
+ public static final com.jogamp.newt.event.InputEvent createInputEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder) {
+ com.jogamp.newt.event.InputEvent res = createMouseEvent(event, sourceHolder);
if(null == res) {
- res = createKeyEvent(event, source);
+ res = createKeyEvent(event, sourceHolder);
}
return res;
}
- public static final com.jogamp.newt.event.MouseEvent createMouseEvent(org.eclipse.swt.widgets.Event event, Object source) {
+ public static final com.jogamp.newt.event.MouseEvent createMouseEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder) {
switch(event.type) {
case SWT.MouseDown:
case SWT.MouseUp:
@@ -230,24 +233,31 @@ public class SWTNewtEventFactory {
int mods = swtModifiers2Newt(event.stateMask, true);
- if( source instanceof com.jogamp.newt.Window) {
- final com.jogamp.newt.Window newtSource = (com.jogamp.newt.Window)source;
- if(newtSource.isPointerConfined()) {
- mods |= InputEvent.CONFINED_MASK;
- }
- if(!newtSource.isPointerVisible()) {
- mods |= InputEvent.INVISIBLE_MASK;
+ final NativeSurface source = sourceHolder.getNativeSurface();
+ final int[] pixelPos;
+ if( null != source ) {
+ if( source instanceof com.jogamp.newt.Window) {
+ final com.jogamp.newt.Window newtSource = (com.jogamp.newt.Window)source;
+ if(newtSource.isPointerConfined()) {
+ mods |= InputEvent.CONFINED_MASK;
+ }
+ if(!newtSource.isPointerVisible()) {
+ mods |= InputEvent.INVISIBLE_MASK;
+ }
}
+ pixelPos = source.convertToPixelUnits(new int[] { event.x, event.y });
+ } else {
+ pixelPos = new int[] { event.x, event.y };
}
return new com.jogamp.newt.event.MouseEvent(
- type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time),
- mods, event.x, event.y, (short)event.count, (short)event.button, MouseEvent.getRotationXYZ(rotation, mods), 1f);
+ type, sourceHolder, (0xFFFFFFFFL & event.time),
+ mods, pixelPos[0], pixelPos[1], (short)event.count, (short)event.button, MouseEvent.getRotationXYZ(rotation, mods), 1f);
}
return null; // no mapping ..
}
- public static final com.jogamp.newt.event.KeyEvent createKeyEvent(org.eclipse.swt.widgets.Event event, Object source) {
+ public static final com.jogamp.newt.event.KeyEvent createKeyEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder) {
switch(event.type) {
case SWT.KeyDown:
case SWT.KeyUp:
@@ -259,7 +269,7 @@ public class SWTNewtEventFactory {
if( (short)0 != type ) {
final short newtKeyCode = swtKeyCode2NewtKeyCode( event.keyCode );
return com.jogamp.newt.event.KeyEvent.create(
- type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time),
+ type, sourceHolder, (0xFFFFFFFFL & event.time),
swtModifiers2Newt(event.stateMask, false),
newtKeyCode, newtKeyCode, event.character);
}
@@ -280,8 +290,8 @@ public class SWTNewtEventFactory {
dragButtonDown = 0;
}
- public final boolean dispatchMouseEvent(org.eclipse.swt.widgets.Event event, Object source, com.jogamp.newt.event.MouseListener l) {
- com.jogamp.newt.event.MouseEvent res = createMouseEvent(event, source);
+ public final boolean dispatchMouseEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder, com.jogamp.newt.event.MouseListener l) {
+ com.jogamp.newt.event.MouseEvent res = createMouseEvent(event, sourceHolder);
if(null != res) {
if(null != l) {
switch(event.type) {
@@ -331,8 +341,8 @@ public class SWTNewtEventFactory {
return false;
}
- public final boolean dispatchKeyEvent(org.eclipse.swt.widgets.Event event, Object source, com.jogamp.newt.event.KeyListener l) {
- com.jogamp.newt.event.KeyEvent res = createKeyEvent(event, source);
+ public final boolean dispatchKeyEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder, com.jogamp.newt.event.KeyListener l) {
+ com.jogamp.newt.event.KeyEvent res = createKeyEvent(event, sourceHolder);
if(null != res) {
if(null != l) {
switch(event.type) {
@@ -349,27 +359,38 @@ public class SWTNewtEventFactory {
return false;
}
- public final void attachDispatchListener(final org.eclipse.swt.widgets.Control ctrl, final Object source,
+ public final void attachDispatchListener(final org.eclipse.swt.widgets.Control ctrl, final NativeSurfaceHolder sourceHolder,
final com.jogamp.newt.event.MouseListener ml,
final com.jogamp.newt.event.KeyListener kl) {
- final Listener listener = new Listener () {
- @Override
- public void handleEvent (Event event) {
- if( dispatchMouseEvent( event, source, ml ) ) {
- return;
- }
- if( dispatchKeyEvent( event, source, kl ) ) {
- return;
- }
- } };
- ctrl.addListener(SWT.MouseDown, listener);
- ctrl.addListener(SWT.MouseUp, listener);
- ctrl.addListener(SWT.MouseMove, listener);
- ctrl.addListener(SWT.MouseEnter, listener);
- ctrl.addListener(SWT.MouseExit, listener);
- ctrl.addListener(SWT.MouseVerticalWheel, listener);
- ctrl.addListener(SWT.KeyDown, listener);
- ctrl.addListener(SWT.KeyUp, listener);
+ if(null==ctrl) {
+ throw new IllegalArgumentException("Argument ctrl is null");
+ }
+ if(null==sourceHolder) {
+ throw new IllegalArgumentException("Argument source is null");
+ }
+
+ if( null != ml ) {
+ final Listener listener = new Listener () {
+ @Override
+ public void handleEvent (Event event) {
+ dispatchMouseEvent( event, sourceHolder, ml );
+ } };
+ ctrl.addListener(SWT.MouseDown, listener);
+ ctrl.addListener(SWT.MouseUp, listener);
+ ctrl.addListener(SWT.MouseMove, listener);
+ ctrl.addListener(SWT.MouseEnter, listener);
+ ctrl.addListener(SWT.MouseExit, listener);
+ ctrl.addListener(SWT.MouseVerticalWheel, listener);
+ }
+ if( null != kl ) {
+ final Listener listener = new Listener () {
+ @Override
+ public void handleEvent (Event event) {
+ dispatchKeyEvent( event, sourceHolder, kl );
+ } };
+ ctrl.addListener(SWT.KeyDown, listener);
+ ctrl.addListener(SWT.KeyUp, listener);
+ }
}
}