Commit 7b304a28 authored by Eric Tobias's avatar Eric Tobias

Added fucntionality

parent 460f29e5
...@@ -40,6 +40,7 @@ import java.util.Set; ...@@ -40,6 +40,7 @@ import java.util.Set;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
/** /**
* Singleton class managing the relative positioning of all tangible objects. The manger listens to * Singleton class managing the relative positioning of all tangible objects. The manger listens to
...@@ -244,6 +245,8 @@ public class SpatialPositioningManager implements SpatialEventListener { ...@@ -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 * its x-axis coordinate that is of the provided class. The retrieval is based on the underlying
* handles. * handles.
* *
* @param <T>
*
* @param _class * @param _class
* The {@link Class} of the widget that should be returned. * The {@link Class} of the widget that should be returned.
* *
...@@ -251,7 +254,8 @@ public class SpatialPositioningManager implements SpatialEventListener { ...@@ -251,7 +254,8 @@ public class SpatialPositioningManager implements SpatialEventListener {
* the first if more than one are tied. Will return <code>null</code> if no object is * the first if more than one are tied. Will return <code>null</code> if no object is
* present. * present.
*/ */
public @Nullable BaseWidget getLeftMostWidget(Class<?> _class) { @SuppressWarnings("unchecked")
public @Nullable <T> T getLeftMostWidget(Class<T> _class) {
if (getLeftMostObject() == null) { if (getLeftMostObject() == null) {
return null; return null;
} }
...@@ -259,7 +263,7 @@ public class SpatialPositioningManager implements SpatialEventListener { ...@@ -259,7 +263,7 @@ public class SpatialPositioningManager implements SpatialEventListener {
for (TangibleObject object : spatialMatrix.getHorizontal()) { for (TangibleObject object : spatialMatrix.getHorizontal()) {
BaseWidget widget = TangibleObjectManager.getWidget(object.getObjectId()); BaseWidget widget = TangibleObjectManager.getWidget(object.getObjectId());
if (widget.getClass().equals(_class)) { if (widget.getClass().equals(_class)) {
return widget; return (T) widget;
} }
} }
...@@ -393,6 +397,31 @@ public class SpatialPositioningManager implements SpatialEventListener { ...@@ -393,6 +397,31 @@ public class SpatialPositioningManager implements SpatialEventListener {
return widgets; 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 <T extends BaseWidget> List<T> getWidgetsToRightOf(BaseWidget widget, boolean aligned, Class<T> _class) {
List<BaseWidget> 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<T>) widgets;
}
/** /**
* Method for returning a list of widgets that are above of a given widget. The method either * 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 * returns all objects no matter their alignment with this widget, or only returns vertically
...@@ -448,7 +477,7 @@ public class SpatialPositioningManager implements SpatialEventListener { ...@@ -448,7 +477,7 @@ public class SpatialPositioningManager implements SpatialEventListener {
* widget's handle centre y coordinates lies within the inclusive bounds defined by the * 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. * returned widgets defining shape's max and minimum y-axis coordinates.
*/ */
private Set<BaseWidget> getAlignedWidgets(ArrayList<BaseWidget> widgets, BaseWidget widget, SpatialAlignment alignment) { private Set<BaseWidget> getAlignedWidgets(List<BaseWidget> widgets, BaseWidget widget, SpatialAlignment alignment) {
Collection<Point> centres = widget.getPositions().values(); Collection<Point> centres = widget.getPositions().values();
Set<BaseWidget> alignedWidgets = new HashSet<>(); Set<BaseWidget> alignedWidgets = new HashSet<>();
for (BaseWidget _widget : widgets) { for (BaseWidget _widget : widgets) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment