diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cc78417223afad64a5c2219ff93a5b708a70affc..71fa89022623d1467a624086d06941acff7e6b08 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,8 @@ + Added test method for various classes. + Changed update method to return whether the underlying data structure have indeed been changed. + Added PositionChangeListener. ++ Added method for fetching the position of the lowest ID handle from the BaseWidget. ++ Added methods to filter the list of widgets returned by getLeftMostWidget. 2.1.3 diff --git a/TULIP/src/lu/list/itis/dkd/tui/adapter/TuiAdapter.java b/TULIP/src/lu/list/itis/dkd/tui/adapter/TuiAdapter.java index a4e62ec73ef7cfad2f8234376e98611b902a30d1..75a5686257b43048abfa418d7ab9f80cc96f298d 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/adapter/TuiAdapter.java +++ b/TULIP/src/lu/list/itis/dkd/tui/adapter/TuiAdapter.java @@ -17,6 +17,7 @@ package lu.list.itis.dkd.tui.adapter; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; +import lu.list.itis.dkd.dbc.annotation.Nullable; import lu.list.itis.dkd.tui.TangibleInterfaceManager; import lu.list.itis.dkd.tui.TangibleObjectManager; import lu.list.itis.dkd.tui.event.SpatialEvent; @@ -170,8 +171,10 @@ public abstract class TuiAdapter { * @param listener * The listener to add. */ - public synchronized void addListener(SpatialEventListener listener) { - spatialEventListeners.add(listener); + public synchronized void addListener(@Nullable SpatialEventListener listener) { + if (null != listener) { + spatialEventListeners.add(listener); + } } /** @@ -180,8 +183,10 @@ public abstract class TuiAdapter { * @param listener * The listener to remove. */ - public synchronized void removeListener(SpatialEventListener listener) { - spatialEventListeners.remove(listener); + public synchronized void removeListener(@Nullable SpatialEventListener listener) { + if (null != listener) { + spatialEventListeners.remove(listener); + } } /** diff --git a/TULIP/src/lu/list/itis/dkd/tui/event/PositionChangeListener.java b/TULIP/src/lu/list/itis/dkd/tui/event/PositionChangeListener.java index 77474e392c0e65fa03156120a948aa9e2bdc014c..f0835cd96c773d2a98fa87d3a275e96e3b1667a2 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/event/PositionChangeListener.java +++ b/TULIP/src/lu/list/itis/dkd/tui/event/PositionChangeListener.java @@ -16,6 +16,7 @@ */ package lu.list.itis.dkd.tui.event; +import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.tui.space.SpatialPositioningManager; import java.util.EventListener; @@ -25,6 +26,7 @@ import java.util.EventListener; * @since 2.1 * @version 2.1.4 */ +@NonNullByDefault public interface PositionChangeListener extends EventListener { /** 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 09796aeb4343548be4380f87243f3bb726a325b5..94f12ee873d3f4e7d1311cd9ed46fd9f76137bf4 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java +++ b/TULIP/src/lu/list/itis/dkd/tui/space/SpatialPositioningManager.java @@ -213,6 +213,59 @@ public class SpatialPositioningManager implements SpatialEventListener { return TangibleObjectManager.getWidget(getLeftMostObject().getObjectId()); } + /** + * The method will return the left-most widget, that is, the first widget found based based on + * its x-axis coordinate that is not an instance of any of the classes present in the filter + * list. The retrieval is based on the underlying handles. + * + * @param filter + * The {@link List} of {@link Class}es that the returned widget should not be part of. + * + * @return The widget with the smallest x-axis coordinate not in the filter list. Returns the + * first if more than one are tied. Will return null if no object is + * present. + */ + public @Nullable BaseWidget getLeftMostWidget(List> filter) { + if (getLeftMostObject() == null) { + return null; + } + + for (TangibleObject object : spatialMatrix.getHorizontal()) { + BaseWidget widget = TangibleObjectManager.getWidget(object.getObjectId()); + if (!filter.contains(widget.getClass())) { + return widget; + } + } + return null; + } + + /** + * The method will return the left-most widget, that is, the first widget found based based on + * its x-axis coordinate that is of the provided class. The retrieval is based on the underlying + * handles. + * + * @param _class + * The {@link Class} of the widget that should be returned. + * + * @return The widget with the smallest x-axis coordinate that is of the given class. Returns + * the first if more than one are tied. Will return null if no object is + * present. + */ + public @Nullable BaseWidget getLeftMostWidget(Class _class) { + if (getLeftMostObject() == null) { + return null; + } + + for (TangibleObject object : spatialMatrix.getHorizontal()) { + BaseWidget widget = TangibleObjectManager.getWidget(object.getObjectId()); + if (widget.getClass().equals(_class)) { + return widget; + } + } + + return null; + } + /** * The method will return the left-most tangible object. * @@ -222,7 +275,6 @@ public class SpatialPositioningManager implements SpatialEventListener { return spatialMatrix.getLeftMostObject(); } - /** * The method will return the right-most widget, that is, the last widget found based based on * its x-axis coordinate. The retrieval is based on the underlying handles. diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/BaseWidget.java b/TULIP/src/lu/list/itis/dkd/tui/widget/BaseWidget.java index 08039453c0eb8a2e0a01ea8b96ca48ee46a0cb3b..84ce68dddc5b2132e46d59876f5d23b7b1fb77fa 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/BaseWidget.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/BaseWidget.java @@ -26,11 +26,13 @@ import lu.list.itis.dkd.tui.widget.builder.BaseBuilder; import lu.list.itis.dkd.tui.widget.corona.Corona; import com.google.common.collect.Multimap; +import com.google.common.collect.Ordering; import java.awt.Graphics2D; import java.awt.Shape; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -217,6 +219,20 @@ public class BaseWidget { return positions.get(handleId); } + /** + * Method used for returning th {@link Point} that holds the position of the handle with the + * lowest ID. This is useful also when the widget is only represented by a single handle and one + * wants to recover the position of that handle. + * + * @return The position as a {@link Point} of the handle with the lowest ID. + */ + public Point getPosition() { + List keys = new ArrayList<>(positions.keySet()); + Collections.sort(keys, Ordering.natural()); + + return positions.get(keys.get(0)); + } + /** * Simple getter method for positions. *