public static SVGPrimitive getPrimitive(final Collection<SVGPrimitive<?>> primitives, final String id) { return primitives.stream() .map(p -> getPrimitive(p, id)) .filter(Objects::nonNull) .findFirst() .orElse(null); }
public static SVGPrimitive getPrimitive(final SVGPrimitive<?> primitive, final String id) { if (primitive instanceof SVGContainer) { return getPrimitive((SVGContainer) primitive, id); } return id.equals(primitive.getPrimitiveId()) ? primitive : null; } }
public static SVGPrimitive getPrimitive(final SVGContainer container, final String id) { return getPrimitive(container.getChildren(), id); }
public static Optional<SVGPrimitive> getPrimitive(final SVGShapeView<?> view, final String id) { return Optional.ofNullable(getPrimitive(view.getChildren(), id)); }
public static void switchVisibility(final SVGShapeView<?> view, final String visibleId, final String nonVisibleId) { getPrimitive(view, visibleId) .ifPresent(prim -> prim.get().setAlpha(1)); getPrimitive(view, nonVisibleId) .ifPresent(prim -> prim.get().setAlpha(0)); }
@Test public void testGetPrimitive() { Optional<SVGPrimitive> r1 = SVGViewUtils.getPrimitive(svgShape, "p1"); assertTrue(r1.isPresent()); assertEquals(primitive1, r1.get()); assertEquals(p1, r1.get().get()); Optional<SVGPrimitive> r2 = SVGViewUtils.getPrimitive(svgShape, "p2"); assertTrue(r2.isPresent()); assertEquals(primitive2, r2.get()); assertEquals(p2, r2.get().get()); }
@Override public void handle(final ServiceTask bean, final SVGShapeView<?> view) { // Obtain the work item's icon data url. final String itemIconData = workItemDefinitionRegistry .get() .get(bean.getName()) .getIconDefinition() .getIconData(); final String iconData = null != itemIconData ? itemIconData : WorkItemDefinitionClientUtils.getDefaultIconData(); // Obtain the image element from the svg shape view. final SVGPrimitive svgPrimitive = SVGViewUtils.getPrimitive(view, WID_ICON_ID).get(); // Load the icon data. final Picture icon = (Picture) svgPrimitive.get(); if (hasDataChanged(iconData, icon.getURL())) { forceLoad(icon, iconData, () -> scaleViewIcon(view, icon)); } if (Objects.equals(bean.getDimensionsSet().getHeight().getValue(), 0d) && Objects.equals(bean.getDimensionsSet().getWidth().getValue(), 0d)) { bean.getDimensionsSet().getHeight().setValue(view.getPrimitive().get().getAttributes().getHeight()); bean.getDimensionsSet().getWidth().setValue(view.getPrimitive().get().getAttributes().getWidth()); } }
@Override public void handle(final BaseCatchingIntermediateEvent bean, final SVGShapeView<?> view) { Boolean isCancelActivity = null; if (bean instanceof IntermediateSignalEventCatching) { isCancelActivity = ((IntermediateSignalEventCatching) bean).getExecutionSet().getCancelActivity().getValue(); } else if (bean instanceof IntermediateTimerEvent) { isCancelActivity = ((IntermediateTimerEvent) bean).getExecutionSet().getCancelActivity().getValue(); } else if (bean instanceof IntermediateMessageEventCatching) { isCancelActivity = ((IntermediateMessageEventCatching) bean).getExecutionSet().getCancelActivity().getValue(); } else if (bean instanceof IntermediateConditionalEvent) { isCancelActivity = ((IntermediateConditionalEvent) bean).getExecutionSet().getCancelActivity().getValue(); } else if (bean instanceof IntermediateEscalationEvent) { isCancelActivity = ((IntermediateEscalationEvent) bean).getExecutionSet().getCancelActivity().getValue(); } if (null != isCancelActivity) { // Cancel -> Normal // NO Cancel -> dash final double fillAlpha = isCancelActivity ? 1 : 0; final double strokeAlpha = isCancelActivity ? 0 : 1; SVGViewUtils.getPrimitive(view, ID_INTERMEDIATE) .ifPresent(p -> p.get().setFillAlpha(fillAlpha).setStrokeAlpha(strokeAlpha)); } } }
@Override public void handle(final BaseStartEvent bean, final SVGShapeView<?> view) { Boolean isInterrupting = null; if (bean instanceof StartMessageEvent) { isInterrupting = ((StartMessageEvent) bean).getExecutionSet().getIsInterrupting().getValue(); } else if (bean instanceof StartTimerEvent) { isInterrupting = ((StartTimerEvent) bean).getExecutionSet().getIsInterrupting().getValue(); } else if (bean instanceof StartSignalEvent) { isInterrupting = ((StartSignalEvent) bean).getExecutionSet().getIsInterrupting().getValue(); } else if (bean instanceof StartConditionalEvent) { isInterrupting = ((StartConditionalEvent) bean).getExecutionSet().getIsInterrupting().getValue(); } else if (bean instanceof StartEscalationEvent) { isInterrupting = ((StartEscalationEvent) bean).getExecutionSet().getIsInterrupting().getValue(); } if (null != isInterrupting) { // Interrupting -> Normal // NO Interrupting -> dash final double fillAlpha = isInterrupting ? 1 : 0; final double strokeAlpha = isInterrupting ? 0 : 1; SVGViewUtils.getPrimitive(view, ID_START) .ifPresent(p -> p.get().setFillAlpha(fillAlpha).setStrokeAlpha(strokeAlpha)); } } }