aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui/Shape.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-12-24 16:09:38 +0100
committerSven Gothel <[email protected]>2023-12-24 16:09:38 +0100
commita782f343aeecbfdb640198bcc73794a90f63730d (patch)
tree259eed17c8b2806d00984795b760b84bc1cf55b8 /src/graphui/classes/com/jogamp/graph/ui/Shape.java
parentfeb3d34be097bcbef5ebc40342b405a832ac581f (diff)
GraphUI Scene/Shape: Add KeyListener for activeShape
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui/Shape.java')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Shape.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
index 99b9cd9b7..ee7f946c2 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
@@ -47,6 +47,8 @@ import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
import com.jogamp.newt.event.GestureHandler.GestureEvent;
import com.jogamp.newt.event.GestureHandler.GestureListener;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.NEWTEvent;
import com.jogamp.newt.event.PinchToZoomGesture;
@@ -188,6 +190,7 @@ public abstract class Shape {
private Padding padding = null;
private final Vec4f borderColor = new Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
private ArrayList<MouseGestureListener> mouseListeners = new ArrayList<MouseGestureListener>();
+ private ArrayList<KeyListener> keyListeners = new ArrayList<KeyListener>();
private ListenerBool onInitListener = null;
private MoveListener onMoveListener = null;
@@ -312,6 +315,7 @@ public abstract class Shape {
scale.set(1f, 1f, 1f);
box.reset();
mouseListeners.clear();
+ keyListeners.clear();
onInitListener = null;
onMoveListener = null;
onToggleListener = null;
@@ -1412,6 +1416,28 @@ public abstract class Shape {
return this;
}
+ public final Shape addKeyListener(final KeyListener l) {
+ if(l == null) {
+ return this;
+ }
+ @SuppressWarnings("unchecked")
+ final ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
+ clonedListeners.add(l);
+ keyListeners = clonedListeners;
+ return this;
+ }
+
+ public final Shape removeKeyListener(final KeyListener l) {
+ if (l == null) {
+ return this;
+ }
+ @SuppressWarnings("unchecked")
+ final ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
+ clonedListeners.remove(l);
+ keyListeners = clonedListeners;
+ return this;
+ }
+
/**
* Combining {@link MouseListener} and {@link GestureListener}
*/
@@ -1690,6 +1716,34 @@ public abstract class Shape {
}
}
+ /**
+ * Dispatch given NEWT key event to this shape
+ * @param e original Newt {@link KeyEvent}
+ * @return true to signal operation complete and to stop traversal, otherwise false
+ */
+ /* pp */ final boolean dispatchKeyEvent(final KeyEvent e) {
+ /**
+ * Checked at caller!
+ if( !isInteractive() ) {
+ return false;
+ } */
+ final short eventType = e.getEventType();
+ for(int i = 0; !e.isConsumed() && i < keyListeners.size(); i++ ) {
+ final KeyListener l = keyListeners.get(i);
+ switch( eventType ) {
+ case KeyEvent.EVENT_KEY_PRESSED:
+ l.keyPressed(e);
+ break;
+ case KeyEvent.EVENT_KEY_RELEASED:
+ l.keyReleased(e);
+ break;
+ default:
+ throw new NativeWindowException("Unexpected key event type " + e.getEventType());
+ }
+ }
+ return e.isConsumed(); // end signal traversal if consumed
+ }
+
//
//
//