From cd47baa406818f99c6d7e7711b7c1d16357456f6 Mon Sep 17 00:00:00 2001 From: Sven Göthel 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/jogamp/graph/ui/TreeTool.java | 64 +++++++++++++++++------ 1 file changed, 48 insertions(+), 16 deletions(-) (limited to 'src/graphui/classes/jogamp') diff --git a/src/graphui/classes/jogamp/graph/ui/TreeTool.java b/src/graphui/classes/jogamp/graph/ui/TreeTool.java index b26ec8417..c37cd53d8 100644 --- a/src/graphui/classes/jogamp/graph/ui/TreeTool.java +++ b/src/graphui/classes/jogamp/graph/ui/TreeTool.java @@ -79,18 +79,16 @@ public class TreeTool { * @return true to signal operation complete and to stop traversal, i.e. {@link Visitor1#visit(Shape)} returned true, otherwise false */ public static boolean forAll(final List shapes, final Visitor1 v) { - for(int i=0; i shapes, final PMVMatrix4f pmv, final Visitor2 v) { - for(int i=0; i sortComp, final List shapes, final PMVMatrix4f pmv, final Visitor2 v) { final Object[] shapesS = shapes.toArray(); Arrays.sort(shapesS, (Comparator)sortComp); + boolean res = false; - for(int i=0; i shapes, 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; } + public static Shape getShapeByID(final List shapes, final int id) { + final Shape[] res = { null }; + forAll(shapes, (final Shape s) -> { + if( s.getID() == id ) { + res[0] = s; + return true; + } else { + return false; + } + }); + return res[0]; + } + public static Shape getShapeByName(final List shapes, final String name) { + final Shape[] res = { null }; + forAll(shapes, (final Shape s) -> { + if( s.getName().equals(name) ) { + res[0] = s; + return true; + } else { + return false; + } + }); + return res[0]; + } } -- cgit v1.2.3