From cd47baa406818f99c6d7e7711b7c1d16357456f6 Mon Sep 17 00:00:00 2001
From: Sven Göthel <sgothel@jausoft.com>
Date: Sat, 20 Jan 2024 05:04:15 +0100
Subject: GraphUI Graph/Scene: Reuse TreeTool for contains(), getShapeByID()
 and getShapeByName(), also adding full traversion (instead of a flat lookup)

---
 src/graphui/classes/com/jogamp/graph/ui/Group.java | 27 +++-------------------
 src/graphui/classes/com/jogamp/graph/ui/Scene.java | 16 +++----------
 2 files changed, 6 insertions(+), 37 deletions(-)

(limited to 'src/graphui/classes/com/jogamp/graph/ui')

diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java
index d1156120a..fc6f91980 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Group.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java
@@ -564,19 +564,8 @@ public class Group extends Shape implements Container {
 
     @Override
     public boolean contains(final Shape s) {
-        if( shapes.contains(s) ) {
-            return true;
-        }
-        for(final Shape shape : shapes) {
-            if( shape instanceof Container ) {
-                if( ((Container)shape).contains(s) ) {
-                    return true;
-                }
-            }
-        }
-        return false;
+        return TreeTool.contains(shapes, s);
     }
-
     @Override
     public Shape getShapeByIdx(final int id) {
         if( 0 > id ) {
@@ -586,21 +575,11 @@ public class Group extends Shape implements Container {
     }
     @Override
     public Shape getShapeByID(final int id) {
-        for(final Shape b : shapes) {
-            if(b.getID() == id ) {
-                return b;
-            }
-        }
-        return null;
+        return TreeTool.getShapeByID(shapes, id);
     }
     @Override
     public Shape getShapeByName(final String name) {
-        for(final Shape b : shapes) {
-            if( b.getName().equals(name) ) {
-                return b;
-            }
-        }
-        return null;
+        return TreeTool.getShapeByName(shapes, name);
     }
 
     @Override
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
index 03cc29097..fa11f2675 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
@@ -332,7 +332,7 @@ public final class Scene implements Container, GLEventListener {
 
     @Override
     public boolean contains(final Shape s) {
-        return false;
+        return TreeTool.contains(shapes, s);
     }
     @Override
     public Shape getShapeByIdx(final int id) {
@@ -343,21 +343,11 @@ public final class Scene implements Container, GLEventListener {
     }
     @Override
     public Shape getShapeByID(final int id) {
-        for(final Shape b : shapes) {
-            if(b.getID() == id ) {
-                return b;
-            }
-        }
-        return null;
+        return TreeTool.getShapeByID(shapes, id);
     }
     @Override
     public Shape getShapeByName(final String name) {
-        for(final Shape b : shapes) {
-            if( b.getName().equals(name) ) {
-                return b;
-            }
-        }
-        return null;
+        return TreeTool.getShapeByName(shapes, name);
     }
 
     /** Returns {@link RegionRenderer#getSampleCount()}. */
-- 
cgit v1.2.3