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 94f12ee873d3f4e7d1311cd9ed46fd9f76137bf4..02539b9843bf1e314bba91c659bf182f37573dba 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java +++ b/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java @@ -40,6 +40,7 @@ import java.util.Set; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; /** * Singleton class managing the relative positioning of all tangible objects. The manger listens to @@ -244,6 +245,8 @@ public class SpatialPositioningManager implements SpatialEventListener { * 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. * @@ -251,7 +254,8 @@ public class SpatialPositioningManager implements SpatialEventListener { * the first if more than one are tied. Will return null if no object is * present. */ - public @Nullable BaseWidget getLeftMostWidget(Class _class) { + @SuppressWarnings("unchecked") + public @Nullable T getLeftMostWidget(Class _class) { if (getLeftMostObject() == null) { return null; } @@ -259,7 +263,7 @@ public class SpatialPositioningManager implements SpatialEventListener { for (TangibleObject object : spatialMatrix.getHorizontal()) { BaseWidget widget = TangibleObjectManager.getWidget(object.getObjectId()); if (widget.getClass().equals(_class)) { - return widget; + return (T) widget; } } @@ -393,6 +397,31 @@ public class SpatialPositioningManager implements SpatialEventListener { return widgets; } + /** + * Method for returning a list of widgets that are to the right of a given widget. The method + * either returns all objects no matter their alignment with this widget, or only returns + * horizontally aligned widgets, that is, more or less on the same horizontal plane as the given + * widget. The alignment is determined by the shape of the widget. + * + * @param widget + * The widget to retrieve all other aligned or non-aligned widgets to the right. + * @param aligned + * Whether all widgets (to the left) are retrieved or only those that are horizontally + * aligned. + * @param _class + * @return A list of widgets that are to the left, either all or only those that are aligned. + */ + @SuppressWarnings("unchecked") + public List getWidgetsToRightOf(BaseWidget widget, boolean aligned, Class _class) { + List widgets = objectsToWidgets(spatialMatrix.rightOf(TangibleObjectManager.getIdentifier(widget))); + + widgets = widgets.stream().filter(_widget -> _widget.getClass().equals(_class)).collect(Collectors.toList()); + if (aligned) { + widgets.retainAll(getAlignedWidgets(widgets, widget, SpatialAlignment.HORIZONTAL)); + } + return (List) widgets; + } + /** * Method for returning a list of widgets that are above of a given widget. The method either * returns all objects no matter their alignment with this widget, or only returns vertically @@ -448,7 +477,7 @@ public class SpatialPositioningManager implements SpatialEventListener { * widget's handle centre y coordinates lies within the inclusive bounds defined by the * returned widgets defining shape's max and minimum y-axis coordinates. */ - private Set getAlignedWidgets(ArrayList widgets, BaseWidget widget, SpatialAlignment alignment) { + private Set getAlignedWidgets(List widgets, BaseWidget widget, SpatialAlignment alignment) { Collection centres = widget.getPositions().values(); Set alignedWidgets = new HashSet<>(); for (BaseWidget _widget : widgets) {