Package org.jbpm.ui.common.figure

Source Code of org.jbpm.ui.common.figure.TerminalFigure$TerminalAnchor

package org.jbpm.ui.common.figure;

import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.EllipseAnchor;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

public abstract class TerminalFigure extends NodeFigure {

    protected final Ellipse ellipse = new Ellipse();

    @Override
    public void init(boolean bpmnNotation) {
        super.init(bpmnNotation);
        if (bpmnNotation) {
            ellipse.setSize(48, 48);
            ellipse.setVisible(false);
            add(ellipse);
        } else {
            // add 3 additional pixel around ellipse
            //((GridLayout) getLayoutManager()).marginHeight = 3;
        }
        connectionAnchor = new TerminalAnchor(ellipse);
    }
   
    @Override
    public boolean isResizeable() {
        return !bpmnNotation;
    }

    protected abstract void addEllipse();

    @Override
    protected void paintUMLFigure(Graphics g, Rectangle r) {
    }
   
    // drawing flat transitions
    private class TerminalAnchor extends EllipseAnchor {

        public TerminalAnchor(IFigure owner) {
            super(owner);
        }

        @Override
    public Point getReferencePoint() {
        Point ref = getOwner().getBounds().getCenter();
          int o = ref.x % GRID_SIZE;
           if (o != 0) {
             ref.x += (o > GRID_SIZE/2) ? GRID_SIZE-o : -o;
           }
           o = ref.y % GRID_SIZE;
           if (o != 0) {
             ref.y += (o > GRID_SIZE/2) ? GRID_SIZE-o : -o;
           }
        getOwner().translateToAbsolute(ref);
        return ref;
    }

    @Override
        public Point getLocation(Point reference) {
            Point p = super.getLocation(reference);
            if (Math.abs(p.x-reference.x) <= 3) {
              p.x = reference.x;
            }
            if (Math.abs(p.y-reference.y) <= 3) {
              p.y = reference.y;
            }
            return p;
        }
    }
}
TOP

Related Classes of org.jbpm.ui.common.figure.TerminalFigure$TerminalAnchor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.