use of com.ait.lienzo.client.core.shape.IPrimitive in project lienzo-core by ahome-it.
the class LienzoHandlerManager method findPrimitiveForPredicate.
private final IPrimitive<?> findPrimitiveForPredicate(final INodeXYEvent event, final Predicate<IPrimitive<?>> pred) {
NFastArrayList<IPrimitive<?>> list = null;
EventPropagationMode stop = EventPropagationMode.LAST_ANCESTOR;
Node<?> node = findShapeAtPoint(event.getX(), event.getY());
while ((null != node) && (null != node.asPrimitive())) {
final IPrimitive<?> prim = node.asPrimitive();
if (pred.test(prim)) {
final EventPropagationMode mode = prim.getEventPropagationMode();
if (null == list) {
list = new NFastArrayList<>();
}
list.add(prim);
if (mode == EventPropagationMode.NO_ANCESTORS) {
return prim;
}
if (mode.getOrder() < stop.getOrder()) {
stop = mode;
break;
}
}
node = node.getParent();
}
if ((list != null) && (list.isEmpty() == false)) {
final int size = list.size();
if (stop == EventPropagationMode.FIRST_ANCESTOR) {
if (size > 1) {
return list.get(1);
}
} else {
if (size > 1) {
return list.get(size - 1);
}
}
return list.get(0);
}
return null;
}
Aggregations