Search in sources :

Example 1 with IAnimationCallback

use of com.ait.lienzo.client.core.animation.IAnimationCallback in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method layout.

void layout() {
    // Get layout information
    final Map<WiresBaseShape, Point2D> layout = layoutManager.getLayoutInformation(uiRoot);
    final Rectangle2D canvasBounds = WiresLayoutUtilities.alignLayoutInCanvas(layout);
    // Run an animation to move WiresBaseTreeNodes from their current position to the target position
    uiRoot.animate(AnimationTweener.EASE_OUT, new AnimationProperties(), ANIMATION_DURATION, new IAnimationCallback() {

        private final Map<WiresBaseShape, Pair<Point2D, Point2D>> transformations = new HashMap<WiresBaseShape, Pair<Point2D, Point2D>>();

        @Override
        public void onStart(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
            // Reposition nodes. First we store the WiresBaseTreeNode together with its current position and target position
            transformations.clear();
            for (Map.Entry<WiresBaseShape, Point2D> e : layout.entrySet()) {
                final Point2D origin = e.getKey().getLocation();
                final Point2D destination = new Point2D(e.getValue().getX(), e.getValue().getY());
                transformations.put(e.getKey(), new Pair<Point2D, Point2D>(origin, destination));
            }
            WiresLayoutUtilities.resizeViewPort(canvasBounds, canvasLayer.getViewport());
        }

        @Override
        public void onFrame(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
            // Lienzo's IAnimation.getPercent() passes values > 1.0
            final double pct = iAnimation.getPercent() > 1.0 ? 1.0 : iAnimation.getPercent();
            // Move each descendant along the line between its origin and the target destination
            for (Map.Entry<WiresBaseShape, Pair<Point2D, Point2D>> e : transformations.entrySet()) {
                final Point2D descendantOrigin = e.getValue().getK1();
                final Point2D descendantTarget = e.getValue().getK2();
                final double dx = (descendantTarget.getX() - descendantOrigin.getX()) * pct;
                final double dy = (descendantTarget.getY() - descendantOrigin.getY()) * pct;
                e.getKey().setX(descendantOrigin.getX() + dx);
                e.getKey().setY(descendantOrigin.getY() + dy);
            }
            // Without this call Lienzo doesn't update the Canvas for sub-classes of WiresBaseTreeNode
            uiRoot.getLayer().batch();
        }

        @Override
        public void onClose(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
        // Nothing to do
        }
    });
    canvasLayer.batch();
}
Also used : HashMap(java.util.HashMap) Rectangle2D(org.uberfire.ext.wires.core.trees.client.layout.treelayout.Rectangle2D) IAnimationHandle(com.ait.lienzo.client.core.animation.IAnimationHandle) WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape) AnimationProperties(com.ait.lienzo.client.core.animation.AnimationProperties) Point2D(com.ait.lienzo.client.core.types.Point2D) IAnimation(com.ait.lienzo.client.core.animation.IAnimation) IAnimationCallback(com.ait.lienzo.client.core.animation.IAnimationCallback) Pair(org.uberfire.commons.data.Pair)

Example 2 with IAnimationCallback

use of com.ait.lienzo.client.core.animation.IAnimationCallback in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method showGettingStartedHint.

private void showGettingStartedHint() {
    if (isGettingStartedHintVisible) {
        return;
    }
    if (hint == null) {
        hint = new Group();
        final Rectangle hintRectangle = new Rectangle(600, 225, 15);
        hintRectangle.setStrokeWidth(2.0);
        hintRectangle.setStrokeColor("#6495ED");
        hintRectangle.setFillColor("#AFEEEE");
        hintRectangle.setAlpha(0.75);
        final Text hintText = new Text(GuidedDecisionTreeConstants.INSTANCE.gettingStartedHint(), ShapeFactoryUtil.FONT_FAMILY_DESCRIPTION, 18);
        hintText.setTextAlign(TextAlign.CENTER);
        hintText.setTextBaseLine(TextBaseLine.MIDDLE);
        hintText.setFillColor("#6495ED");
        hintText.setX(hintRectangle.getWidth() / 2);
        hintText.setY(hintRectangle.getHeight() / 2);
        hint.setX((canvasLayer.getWidth() - hintRectangle.getWidth()) / 2);
        hint.setY((canvasLayer.getHeight() / 3) - (hintRectangle.getHeight() / 2));
        hint.add(hintRectangle);
        hint.add(hintText);
    }
    hint.animate(AnimationTweener.LINEAR, new AnimationProperties(), ANIMATION_DURATION, new IAnimationCallback() {

        @Override
        public void onStart(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
            hint.setAlpha(0.0);
            canvasLayer.add(hint);
            isGettingStartedHintVisible = true;
        }

        @Override
        public void onFrame(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
            // Lienzo's IAnimation.getPercent() passes values > 1.0
            final double pct = iAnimation.getPercent() > 1.0 ? 1.0 : iAnimation.getPercent();
            hint.setAlpha(pct);
            hint.getLayer().batch();
        }

        @Override
        public void onClose(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
        // Nothing to do
        }
    });
}
Also used : IAnimationHandle(com.ait.lienzo.client.core.animation.IAnimationHandle) Group(com.ait.lienzo.client.core.shape.Group) AnimationProperties(com.ait.lienzo.client.core.animation.AnimationProperties) IAnimation(com.ait.lienzo.client.core.animation.IAnimation) Rectangle(com.ait.lienzo.client.core.shape.Rectangle) Text(com.ait.lienzo.client.core.shape.Text) IAnimationCallback(com.ait.lienzo.client.core.animation.IAnimationCallback)

Aggregations

AnimationProperties (com.ait.lienzo.client.core.animation.AnimationProperties)2 IAnimation (com.ait.lienzo.client.core.animation.IAnimation)2 IAnimationCallback (com.ait.lienzo.client.core.animation.IAnimationCallback)2 IAnimationHandle (com.ait.lienzo.client.core.animation.IAnimationHandle)2 Group (com.ait.lienzo.client.core.shape.Group)1 Rectangle (com.ait.lienzo.client.core.shape.Rectangle)1 Text (com.ait.lienzo.client.core.shape.Text)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 HashMap (java.util.HashMap)1 Pair (org.uberfire.commons.data.Pair)1 WiresBaseShape (org.uberfire.ext.wires.core.api.shapes.WiresBaseShape)1 Rectangle2D (org.uberfire.ext.wires.core.trees.client.layout.treelayout.Rectangle2D)1