From d80762bdaf79a852cde2391479bb066968ae573c Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sun, 7 Jan 2024 13:05:42 +0100 Subject: GraphUI Shape: Ease Tooltip managment via Scene: Only started Tooltip is required to tick(), drop List --- src/graphui/classes/com/jogamp/graph/ui/Scene.java | 18 +++++++++--------- src/graphui/classes/com/jogamp/graph/ui/Shape.java | 13 ++++--------- src/graphui/classes/com/jogamp/graph/ui/Tooltip.java | 6 ++---- 3 files changed, 15 insertions(+), 22 deletions(-) (limited to 'src/graphui') diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index c71060db4..e2dc96b8d 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -133,7 +133,7 @@ public final class Scene implements Container, GLEventListener { private static final boolean DEBUG = false; private final List shapes = new CopyOnWriteArrayList(); - /* pp */ final List toolTips = new CopyOnWriteArrayList(); + private final AtomicReference startedToolTip = new AtomicReference(); private final AtomicReference toolTipHUD = new AtomicReference(); private boolean doFrustumCulling = false; @@ -503,13 +503,12 @@ public final class Scene implements Container, GLEventListener { displayedOnce = true; syncDisplayedOnce.notifyAll(); } - if( null == toolTipHUD.get() ) { + final Tooltip tt = startedToolTip.get(); + if( null != tt && null == toolTipHUD.get() ) { final GraphShape[] t = { null }; - for(final Tooltip tt : toolTips ) { - if( tt.tick() && forOne(pmv, tt.tool, () -> { t[0] = tt.createTip(pmv); }) ) { - toolTipHUD.set( t[0] ); - break; // done - } + if( tt.tick() && forOne(pmv, tt.tool, () -> { t[0] = tt.createTip(pmv); }) ) { + toolTipHUD.set( t[0] ); + startedToolTip.set(null); } } } @@ -1205,7 +1204,7 @@ public final class Scene implements Container, GLEventListener { final Shape s = dispatchMouseEventPickShape(e, glWinX, glWinY); if( null != s ) { mouseOver = true; - s.startToolTip(); + startedToolTip.set( s.startToolTip() ); } else { mouseOver = false; } @@ -1243,7 +1242,8 @@ public final class Scene implements Container, GLEventListener { return true; }); } - for(final Tooltip tt : toolTips) { + final Tooltip tt = startedToolTip.getAndSet(null); + if( null != tt ) { tt.stop(); } } diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 3e22cba78..cb5a5e896 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -1300,16 +1300,12 @@ public abstract class Shape { if( isActivable() ) { this.zOffset = zOffset; setIO(IO_ACTIVE, v); - final Tooltip tt = tooltip; if( !v ) { releaseInteraction(); + final Tooltip tt = tooltip; if( null != tt ) { tt.stop(); } - } else { - if( null != tt ) { - tt.start(); - } } if( DEBUG ) { System.err.println("XXX "+(v?" Active":"DeActive")+" "+this); @@ -1344,10 +1340,8 @@ public abstract class Shape { final Tooltip newTT = new TooltipText(text, font, scaleY, this, toolTipdelayMS, scene, Region.VBAA_RENDERING_BIT); if( null != oldTT ) { oldTT.stop(); - oldTT.scene.toolTips.remove(oldTT); } tooltip = newTT; - newTT.scene.toolTips.add(newTT); return newTT; } public void removeToolTip() { @@ -1355,7 +1349,6 @@ public abstract class Shape { tooltip = null; if( null != tt ) { tt.stop(); - tt.scene.toolTips.remove(tt); } } private void stopToolTip() { @@ -1364,11 +1357,13 @@ public abstract class Shape { tt.stop(); } } - /* pp */ void startToolTip() { + /* pp */ Tooltip startToolTip() { final Tooltip tt = tooltip; if( null != tt ) { tt.start(); + return tt; } + return null; } public Tooltip getTooltip() { return tooltip; } diff --git a/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java b/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java index 6c1603800..88cfeac99 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java @@ -54,8 +54,7 @@ public abstract class Tooltip { /** Starts the timer. */ public void start() { - final long t0 = Clock.currentMillis(); - this.delayT1 = t0 + delayMS; + this.delayT1 = Clock.currentMillis() + delayMS; } /** @@ -66,8 +65,7 @@ public abstract class Tooltip { if( 0 == delayT1 ) { return false; } - final long t1 = Clock.currentMillis(); - if( t1 < delayT1 ) { + if( Clock.currentMillis() < delayT1 ) { return false; } this.delayT1 = 0; -- cgit v1.2.3