diff options
author | Sven Göthel <[email protected]> | 2024-01-07 04:48:16 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-01-07 04:48:16 +0100 |
commit | 79eba1f0e450a75f01505ca5ed5817ec481491a8 (patch) | |
tree | 34c6d8bb595966d737d8db4d4ff85bc40fd1e5d2 /src/graphui/classes/com | |
parent | 259fce6ca0fa4fe92e6dc2266d442c62723eb73c (diff) |
GraphUI Shape: Maintain multiple Activation Listener (ArrayList instead of single instance)
This allows listenting to activation of Group members, while Group is set to widget-mode.
For the latter, Group adds a forward listener to itself.
Diffstat (limited to 'src/graphui/classes/com')
3 files changed, 40 insertions, 13 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java index 9dca781b1..025213f8d 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -288,7 +288,7 @@ public class Group extends Shape implements Container { * Enabled widget behavior for a group causes * <ul> * <li>the whole group to be shown on top on (mouse over) activation of one of its elements</li> - * <li>this group's {@link #onActivation(Listener)} to handle all it's elements activation events</li> + * <li>this group's {@link #addActivationListener(Listener)} to handle all it's elements activation events</li> * <li>{@link #isActive()} of this group and its sub-groups to return true if one of its elements is active</li> * </ul> * </p> @@ -313,7 +313,7 @@ public class Group extends Shape implements Container { final Group sg = (Group)s; sg.setWidgetMode(v); } - s.onActivation(activationListener); + s.addActivationListener(activationListener); } } diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index e3a1f0e74..65a989ebd 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -195,7 +195,7 @@ public abstract class Shape { private ListenerBool onInitListener = null; private MoveListener onMoveListener = null; private Listener onToggleListener = null; - private Listener onActivationListener = null; + private ArrayList<Listener> activationListeners = new ArrayList<Listener>(); private Listener onClickedListener = null; private final Vec2f objDraggedFirst = new Vec2f(); // b/c its relative to Shape and we stick to it @@ -319,7 +319,7 @@ public abstract class Shape { onInitListener = null; onMoveListener = null; onToggleListener = null; - onActivationListener = null; + activationListeners.clear(); onClickedListener = null; markShapeDirty(); } @@ -358,13 +358,44 @@ public abstract class Shape { * </p> */ public final void onToggle(final Listener l) { onToggleListener = l; } + /** - * Set user callback to be notified when shape is activated (pointer-over and/or click) or de-activated (pointer left). + * Add user callback to be notified when shape is activated (pointer-over and/or click) or de-activated (pointer left). * <p> * Use {@link #isActive()} to retrieve the state. * </p> */ - public final void onActivation(final Listener l) { onActivationListener = l; } + public final Shape addActivationListener(final Listener l) { + if(l == null) { + return this; + } + @SuppressWarnings("unchecked") + final ArrayList<Listener> clonedListeners = (ArrayList<Listener>) activationListeners.clone(); + clonedListeners.add(l); + activationListeners = clonedListeners; + return this; + } + public final Shape removeActivationListener(final Listener l) { + if (l == null) { + return this; + } + @SuppressWarnings("unchecked") + final ArrayList<Listener> clonedListeners = (ArrayList<Listener>) activationListeners.clone(); + clonedListeners.remove(l); + activationListeners = clonedListeners; + return this; + } + /** + * Dispatch activation event event to this shape + * @return true to signal operation complete and to stop traversal, otherwise false + */ + private final void dispatchActivationEvent(final Shape s) { + final int sz = activationListeners.size(); + for(int i = 0; i < sz; i++ ) { + activationListeners.get(i).run(s); + } + } + /** * Set user callback to be notified when shape is clicked. * <p> @@ -1268,9 +1299,7 @@ public abstract class Shape { if( DEBUG ) { System.err.println("XXX "+(v?" Active":"DeActive")+" "+this); } - if( null != onActivationListener ) { - onActivationListener.run(this); - } + dispatchActivationEvent(this); return true; } else { return false; @@ -1282,9 +1311,7 @@ public abstract class Shape { protected final Listener forwardActivation = new Listener() { @Override public void run(final Shape shape) { - if( null != onActivationListener ) { - onActivationListener.run(shape); - } + dispatchActivationEvent(shape); } }; diff --git a/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java b/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java index 4ea05912b..da912fa8a 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java +++ b/src/graphui/classes/com/jogamp/graph/ui/widgets/MediaPlayer.java @@ -464,7 +464,7 @@ public class MediaPlayer extends Widget { } this.setWidgetMode(true); - this.onActivation( (final Shape s) -> { + this.addActivationListener( (final Shape s) -> { if( this.isActive() ) { this.setBorderColor(borderColorA); } else { |