From b2d450179d1b595ff837896ff3d5ee70faa085cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rie=20Maquil?= Date: Wed, 4 Nov 2015 17:02:36 +0100 Subject: [PATCH] added method for rightmostWidget of a certain class --- .../tui/space/SpatialPositioningManager.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java b/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java index 02539b9..d8df817 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java +++ b/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java @@ -294,6 +294,37 @@ public class SpatialPositioningManager implements SpatialEventListener { return TangibleObjectManager.getWidget(getRightMostObject().getObjectId()); } + /** + * The method will return the right-most widget, that is, the last widget found based based on + * its x-axis coordinate that is of the provided class. The retrieval is based on the underlying + * handles. + * + * @param + * + * @param _class + * The {@link Class} of the widget that should be returned. + * + * @return The widget with the largest x-axis coordinate that is of the given class. Returns the + * last if more than one are tied. Will return null if no object is + * present. + */ + @SuppressWarnings("unchecked") + public @Nullable T getRightMostWidget(Class _class) { + if (getRightMostObject() == null) { + return null; + } + + for (int i = spatialMatrix.getHorizontal().size() - 1; i >= 0; i--) { + TangibleObject object = spatialMatrix.getHorizontal().get(i); + BaseWidget widget = TangibleObjectManager.getWidget(object.getObjectId()); + if (widget.getClass().equals(_class)) { + return (T) widget; + } + } + + return null; + } + /** * The method will return the right-most tangible object. * -- GitLab