Search in sources :

Example 1 with EventPropagationMode

use of com.ait.lienzo.shared.core.types.EventPropagationMode 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;
}
Also used : IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) TouchPoint(com.ait.lienzo.client.core.event.TouchPoint)

Aggregations

TouchPoint (com.ait.lienzo.client.core.event.TouchPoint)1 IPrimitive (com.ait.lienzo.client.core.shape.IPrimitive)1 EventPropagationMode (com.ait.lienzo.shared.core.types.EventPropagationMode)1