Commit 460f29e5 authored by Eric Tobias's avatar Eric Tobias

Added methods to BaseWidget and SpatialPositionManager to access positions and...

Added methods to BaseWidget and SpatialPositionManager to access positions and retrieve left-most widgets based on filters
parent 7e27f9b6
......@@ -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
......
......@@ -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);
}
}
/**
......
......@@ -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 {
/**
......
......@@ -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 <code>null</code> if no object is
* present.
*/
public @Nullable BaseWidget getLeftMostWidget(List<Class<?>> 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 <code>null</code> 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.
......
......@@ -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<Integer> keys = new ArrayList<>(positions.keySet());
Collections.sort(keys, Ordering.natural());
return positions.get(keys.get(0));
}
/**
* Simple getter method for positions.
*
......
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