Search in sources :

Example 61 with Rectangle

use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.

the class NodeLabelEditPart method refreshVisuals.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
     */
@Override
protected void refreshVisuals() {
    Node node = ((NodeLabel) getModel()).getNode();
    // Node node = ((NodeContainer) ((NodeContainerPart) getParent()).getModel()).getNode();
    String text = ((NodeLabel) getModel()).getLabelText();
    SimpleHtmlFigure htmlFig = (SimpleHtmlFigure) this.getFigure();
    htmlFig.setText(text);
    Point loc = node.getLocation().getCopy();
    Point offset = ((NodeLabel) getModel()).getOffset();
    Point textOffset = new Point();
    Dimension size = htmlFig.getPreferredSize();
    textOffset.y = node.getSize().height;
    textOffset.x = (node.getSize().width - size.width) / 2;
    ((NodeLabel) getModel()).setTextOffset(textOffset);
    loc.translate(textOffset.x + offset.x, textOffset.y + offset.y);
    Rectangle rectangle = new Rectangle(loc, size);
    ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), rectangle);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) SimpleHtmlFigure(org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure)

Example 62 with Rectangle

use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.

the class NodeAnchor method getDirectionPosition.

private Point getDirectionPosition(IConnection connection, Point figCenter, boolean isSource) {
    if (!DesignerPlugin.getDefault().getPreferenceStore().getBoolean(TalendDesignerPrefConstants.EDITOR_LINESTYLE)) {
        return null;
    }
    Dimension nodeSize = null;
    if (isSource) {
        nodeSize = this.source.getSize();
    } else {
        nodeSize = this.target.getSize();
    }
    EConnectionCategory category = null;
    EConnectionType lineStyle = null;
    if (connection != null) {
        lineStyle = connection.getLineStyle();
        category = lineStyle.getCategory();
    } else {
        lineStyle = ConnectionManager.getNewConnectionType();
        category = lineStyle.getCategory();
    }
    Point result = new Point(figCenter);
    if (category == EConnectionCategory.MAIN && lineStyle != EConnectionType.FLOW_REF) {
        if (isSource) {
            result.x = figCenter.x + nodeSize.width / 2;
        } else {
            result.x = figCenter.x - nodeSize.width / 2;
        }
        return result;
    } else if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.FLOW_REF || lineStyle == EConnectionType.TABLE_REF)) {
        Rectangle sourceBounds = new Rectangle(this.source.getLocation(), this.source.getSize());
        Rectangle targetBounds = new Rectangle(this.target.getLocation(), this.target.getSize());
        if (isSource) {
            int sourceY = this.source.getPosY();
            int targetY = this.target.getPosY();
            if (sourceY <= targetY) {
                if ((targetBounds.getTopRight().y == sourceBounds.getBottomLeft().y)) {
                    result.y = figCenter.y - nodeSize.height / 2;
                } else {
                    result.y = figCenter.y + nodeSize.height / 2;
                }
            } else {
                if (targetBounds.getBottomLeft().y == sourceBounds.getTopRight().y) {
                    result.y = figCenter.y + nodeSize.height / 2;
                } else {
                    result.y = figCenter.y - nodeSize.height / 2;
                }
            }
            return result;
        }
        int sourceY = this.source.getPosY();
        int targetY = this.target.getPosY();
        if (sourceY < targetY) {
            result.y = figCenter.y - nodeSize.height / 2;
        } else {
            result.y = figCenter.y + nodeSize.height / 2;
        }
        return result;
    }
    return null;
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) EConnectionCategory(org.talend.core.model.process.EConnectionCategory) Dimension(org.eclipse.draw2d.geometry.Dimension) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 63 with Rectangle

use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.

the class NodeAnchor method getLocationForMultipleConnections.

public Point getLocationForMultipleConnections(int connectionId) {
    if ((sourceLocation.y >= targetLocation.y) && ((sourceLocation.y + sourceRect.height) <= (targetLocation.y + targetRect.height))) {
        targetRect = new Rectangle(new Point(targetLocation.x, sourceLocation.y), new Dimension(targetRect.width, sourceRect.height));
    } else if ((sourceLocation.x >= targetLocation.x) && ((sourceLocation.x + sourceRect.width) <= (targetLocation.x + targetRect.width))) {
        targetRect = new Rectangle(new Point(sourceLocation.x, targetLocation.y), new Dimension(sourceRect.width, sourceRect.height));
    }
    // will calculate the numerator and denominator for the function to place the points.
    // example: 1/2; 3/4; 1/4; 5/8; 3/8; 7/8; 1/8; 9/16; 7/16; 11/16; 5/16; 13/16; 3/16...
    int num = 1;
    int numPair = 1;
    int numImpair = 1;
    int denom = 2;
    for (int i = 1; i < connectionId + 1; i++) {
        if ((i % 2) == 0) {
            // pair
            if ((numPair + 2) > denom) {
                denom = denom * 2;
                numPair = (denom / 2) + 1;
                numImpair = numPair;
            } else {
                numPair += 2;
            }
            num = numPair;
        } else {
            // impair
            numImpair -= 2;
            if (numImpair > 0) {
                num = numImpair;
            }
        }
    }
    LineSeg lineSource, lineTarget;
    if ((sourceLocation.x < targetRect.getCenter().x) && (targetRect.getCenter().x < (sourceLocation.x + sourceRect.width))) {
        lineSource = new LineSeg(sourceRect.getLeft(), sourceRect.getRight());
        lineTarget = new LineSeg(targetRect.getLeft(), targetRect.getRight());
    } else {
        lineSource = new LineSeg(sourceRect.getTop(), sourceRect.getBottom());
        lineTarget = new LineSeg(targetRect.getTop(), targetRect.getBottom());
    }
    Double length = (lineSource.length() * num / denom);
    Point pointSource = new Point();
    lineSource.pointOn(length.longValue(), KeyPoint.ORIGIN, pointSource);
    length = (lineTarget.length() * num / denom);
    Point pointTarget = new Point();
    lineTarget.pointOn(length.longValue(), KeyPoint.ORIGIN, pointTarget);
    if ((sourceLocation.y < pointTarget.y) && (pointTarget.y < (sourceLocation.y + sourceRect.height))) {
        // contains
        pointSource.y = pointTarget.y;
    }
    if ((sourceLocation.x < pointTarget.x) && (pointTarget.x < (sourceLocation.x + sourceRect.width))) {
        // contains
        pointSource.x = pointTarget.x;
    }
    return calculateLocationFromRef(pointSource, pointTarget);
}
Also used : LineSeg(org.talend.commons.ui.gmf.draw2d.LineSeg) Rectangle(org.eclipse.draw2d.geometry.Rectangle) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point)

Example 64 with Rectangle

use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.

the class NodeAnchor method getLocation.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.draw2d.ChopboxAnchor#getLocation(org.eclipse.draw2d.geometry.Point)
     */
@Override
public Point getLocation(Point reference) {
    if (target != null && !target.equals(source)) {
        sourceLocation = new Point(source.getLocation());
        targetLocation = new Point(target.getLocation());
        Point diff = new Point(0, 0);
        if (!isTargetAnchor) {
            if (((reference.y - (target.getSize().height / 2)) != targetLocation.y) || ((reference.x - (target.getSize().width / 2)) != targetLocation.x)) {
                FreeformViewport viewport = getViewport();
                if (viewport != null) {
                    int y = viewport.getVerticalRangeModel().getValue();
                    int x = viewport.getHorizontalRangeModel().getValue();
                    diff = new Point(-x, -y);
                }
            }
        } else {
            if (((reference.y - (source.getSize().height / 2)) != sourceLocation.y) || ((reference.x - (source.getSize().width / 2)) != sourceLocation.x)) {
                FreeformViewport viewport = getViewport();
                if (viewport != null) {
                    int y = viewport.getVerticalRangeModel().getValue();
                    int x = viewport.getHorizontalRangeModel().getValue();
                    diff = new Point(-x, -y);
                }
            }
        }
        ScalableFreeformLayeredPane pane = getScalableFreeform();
        sourceRect = new Rectangle(sourceLocation, source.getSize());
        targetRect = new Rectangle(targetLocation, target.getSize());
        if (pane != null) {
            double scale = pane.getScale();
            sourceLocation.performScale(scale);
            targetLocation.performScale(scale);
            sourceRect.performScale(scale);
            targetRect.performScale(scale);
        }
        sourceLocation = sourceLocation.getTranslated(diff);
        targetLocation = targetLocation.getTranslated(diff);
        sourceRect = sourceRect.getTranslated(diff);
        targetRect = targetRect.getTranslated(diff);
        int nb = 0;
        int connectionId = 0;
        for (Connection connection : (List<Connection>) source.getOutgoingConnections()) {
            if (connection.getTarget().equals(target)) {
                nb++;
                if (connection.equals(this.connection)) {
                    connectionId = nb;
                }
            }
        }
        if (nb <= 1) {
            return getLocationForSimpleConnection(reference);
        } else {
            return getLocationForMultipleConnections(connectionId);
        }
    }
    return super.getLocation(reference);
}
Also used : ScalableFreeformLayeredPane(org.eclipse.draw2d.ScalableFreeformLayeredPane) FreeformViewport(org.eclipse.draw2d.FreeformViewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) List(java.util.List) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point)

Example 65 with Rectangle

use of org.eclipse.draw2d.geometry.Rectangle in project tdi-studio-se by Talend.

the class NodeContainerLayoutEditPolicy method createChangeConstraintCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart,
     * java.lang.Object)
     */
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
    if (child instanceof NodeLabelEditPart) {
        boolean nodeSelected;
        // if (((NodeLabelEditPart) child).getNodePart().getSelected() != 0) {
        // nodeSelected = true;
        // } else {
        nodeSelected = false;
        // }
        MoveNodeLabelCommand locationCommand = new MoveNodeLabelCommand((NodeLabel) child.getModel(), ((Rectangle) constraint).getLocation(), nodeSelected);
        return locationCommand;
    } else if (child instanceof NodePart) {
        if (((Node) child.getModel()).isReadOnly() && !((Node) child.getModel()).isForceReadOnly()) {
            return null;
        }
        MoveNodeCommand locationCommand = new MoveNodeCommand((Node) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    } else {
        return null;
    }
}
Also used : MoveNodeLabelCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeLabelCommand) MoveNodeCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeCommand) Node(org.talend.designer.core.ui.editor.nodes.Node) Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart)

Aggregations

Rectangle (org.eclipse.draw2d.geometry.Rectangle)347 Point (org.eclipse.draw2d.geometry.Point)107 Dimension (org.eclipse.draw2d.geometry.Dimension)80 IFigure (org.eclipse.draw2d.IFigure)43 List (java.util.List)24 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)18 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)17 PointList (org.eclipse.draw2d.geometry.PointList)16 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)15 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 ArrayList (java.util.ArrayList)11 Iterator (java.util.Iterator)11 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)11 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)11 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)10 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)10 TableFigure (com.cubrid.common.ui.er.figures.TableFigure)8 Viewport (org.eclipse.draw2d.Viewport)8 Node (org.talend.designer.core.ui.editor.nodes.Node)8 Image (org.eclipse.swt.graphics.Image)7