Search in sources :

Example 1 with Point

use of org.eclipse.draw2d.geometry.Point in project cogtool by cogtool.

the class BezierPolylineConnection method generateBezierPoints.

/**
     * Generates the Bezier curve points
     * @param start the start of the curve
     * @param end the end of the curve
     */
public void generateBezierPoints(Point start, Point end) {
    PointList newPoints = new PointList();
    // the vertical space between the line start/end
    int spacing = 25;
    // and the middle two points
    Point[] bezierPoints = new Point[4];
    int position = 0;
    if ((start.x <= end.x) && (start.y > end.y)) {
        position = 1;
    } else if ((start.x > end.x) && (start.y > end.y)) {
        position = 2;
    } else if ((start.x > end.x) && (start.y <= end.y)) {
        position = 3;
    } else if ((start.x <= end.x) && (start.y <= end.y)) {
        position = 4;
    }
    // Set the start and end
    bezierPoints[0] = start;
    bezierPoints[3] = end;
    // Set the middle points
    // Diagram at: http://cogtool.hcii.cs.cmu.edu/trac/browser/docs/Design%20%26%20Architecture/bezierPoints.ppt
    // distance between the two points
    double Mh = 0;
    // x distance between the two points
    double Mx = 0;
    // y distance between the two points
    double My = 0;
    // the angle MhMx
    double Ma = 0;
    // distance between the start point and P1
    double P1h = 0;
    // x value of the point below B1 (Bezier middle point 1)
    double P1x = 0;
    // y value of the point below B1 (Bezier middle point 1)
    double P1y = 0;
    // distance between P1 and B1
    double B1h = 0;
    // x distance between P1 and B1
    double B1x = 0;
    // y distance between P1 and B1
    double B1y = 0;
    // distance between the start point and P2
    double P2h = 0;
    // x value of the point below B2 (Bezier middle point 2)
    double P2x = 0;
    // y value of the point below B2 (Bezier middle point 2)
    double P2y = 0;
    // distance between P2 and B2
    double B2h = 0;
    // x distance between P1 and B2
    double B2x = 0;
    // y distance between P1 and B2
    double B2y = 0;
    Mx = Math.abs(end.x - start.x);
    My = Math.abs(end.y - start.y);
    Mh = Math.sqrt((Math.pow(Mx, 2) + Math.pow(My, 2)));
    Ma = Math.atan((My / Mx));
    P1h = (0.25 * Mh);
    P2h = (0.75 * Mh);
    if (position == 1) {
        P1x = start.x + (Math.cos(Ma) * P1h);
        P1y = start.y - (Math.sin(Ma) * P1h);
        P2x = start.x + (Math.cos(Ma) * P2h);
        P2y = start.y - (Math.sin(Ma) * P2h);
    } else if (position == 2) {
        P1x = start.x - (Math.cos(Ma) * P1h);
        P1y = start.y - (Math.sin(Ma) * P1h);
        P2x = start.x - (Math.cos(Ma) * P2h);
        P2y = start.y - (Math.sin(Ma) * P2h);
    } else if (position == 3) {
        P1x = start.x - (Math.cos(Ma) * P1h);
        P1y = start.y + (Math.sin(Ma) * P1h);
        P2x = start.x - (Math.cos(Ma) * P2h);
        P2y = start.y + (Math.sin(Ma) * P2h);
    } else if (position == 4) {
        P1x = start.x + (Math.cos(Ma) * P1h);
        P1y = start.y + (Math.sin(Ma) * P1h);
        P2x = start.x + (Math.cos(Ma) * P2h);
        P2y = start.y + (Math.sin(Ma) * P2h);
    }
    boolean above = (connections % 2) == 0;
    B1h = spacing * (connections / 2);
    B2h = spacing * (connections / 2);
    B1x = Math.sin(Ma) * B1h;
    B1y = Math.cos(Ma) * B1h;
    B2x = Math.sin(Ma) * B2h;
    B2y = Math.cos(Ma) * B2h;
    if (position == 1) {
        if (above) {
            bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y - B1y));
            bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y - B2y));
        } else {
            bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y + B1y));
            bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y + B2y));
        }
    } else if (position == 2) {
        if (above) {
            bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y + B1y));
            bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y + B2y));
        } else {
            bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y - B1y));
            bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y - B2y));
        }
    } else if (position == 3) {
        if (above) {
            bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y + B1y));
            bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y + B2y));
        } else {
            bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y - B1y));
            bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y - B2y));
        }
    } else if (position == 4) {
        if (above) {
            bezierPoints[1] = new Point((int) (P1x + B1x), (int) (P1y - B1y));
            bezierPoints[2] = new Point((int) (P2x + B2x), (int) (P2y - B2y));
        } else {
            bezierPoints[1] = new Point((int) (P1x - B1x), (int) (P1y + B1y));
            bezierPoints[2] = new Point((int) (P2x - B2x), (int) (P2y + B2y));
        }
    }
    // Calculate the bezier curve
    double x1 = bezierPoints[0].x;
    double y1 = bezierPoints[0].y;
    double x2;
    double y2;
    double t = 0;
    double k = 0.025;
    for (t = k; t <= 1 + k; t += k) {
        // Use Berstein polynomials
        x2 = (bezierPoints[0].x + t * (-bezierPoints[0].x * 3 + t * (3 * bezierPoints[0].x - bezierPoints[0].x * t))) + t * (3 * bezierPoints[1].x + t * (-6 * bezierPoints[1].x + bezierPoints[1].x * 3 * t)) + t * t * (bezierPoints[2].x * 3 - bezierPoints[2].x * 3 * t) + bezierPoints[3].x * t * t * t;
        y2 = (bezierPoints[0].y + t * (-bezierPoints[0].y * 3 + t * (3 * bezierPoints[0].y - bezierPoints[0].y * t))) + t * (3 * bezierPoints[1].y + t * (-6 * bezierPoints[1].y + bezierPoints[1].y * 3 * t)) + t * t * (bezierPoints[2].y * 3 - bezierPoints[2].y * 3 * t) + bezierPoints[3].y * t * t * t;
        // Add the point to the curve
        newPoints.addPoint(new org.eclipse.draw2d.geometry.Point((int) x1, (int) y1));
        x1 = x2;
        y1 = y2;
    }
    // Add the end point
    newPoints.addPoint(bezierPoints[3]);
    // Update line to the new points
    setPoints(newPoints);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with Point

use of org.eclipse.draw2d.geometry.Point in project cogtool by cogtool.

the class ChoiceWireRenderer method setSize.

@Override
public void setSize(int width, int height) {
    super.setSize(width, height);
    int labelX;
    int labelY;
    int labelWidth;
    int labelHeight;
    if (height < width) {
        choiceWidth = height - 2;
        choiceHeight = height - 2;
        labelX = height + MARGIN;
        labelY = 1;
        labelWidth = width - labelX - 1;
        labelHeight = height - 2;
    } else {
        choiceWidth = width - 2;
        choiceHeight = width - 2;
        labelX = 1;
        labelY = width + MARGIN;
        labelWidth = width - 2;
        labelHeight = height - labelY - 1;
    }
    if (choiceWidth < 0) {
        choiceWidth = 1;
    }
    if (choiceHeight < 0) {
        choiceHeight = 1;
    }
    if (labelWidth < 0) {
        labelWidth = 1;
    }
    if (labelHeight < 0) {
        labelHeight = 1;
    }
    choiceLabel.setLocation(new Point(labelX, labelY));
    choiceLabel.setSize(labelWidth, labelHeight);
}
Also used : Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 3 with Point

use of org.eclipse.draw2d.geometry.Point in project cogtool by cogtool.

the class DesignEditorTransition method repaintSelection.

public void repaintSelection(InteractionDrawingEditor editor) {
    if (isSelected()) {
        double zoom = editor.getZoomSetting();
        Point pt = getStart();
        sourceHandle.centerAt(PrecisionUtilities.round(pt.x * zoom), PrecisionUtilities.round(pt.y * zoom));
        pt = getEnd();
        targetHandle.centerAt(PrecisionUtilities.round(pt.x * zoom), PrecisionUtilities.round(pt.y * zoom));
        sourceHandle.repaint();
        targetHandle.repaint();
    }
}
Also used : Point(org.eclipse.draw2d.geometry.Point)

Example 4 with Point

use of org.eclipse.draw2d.geometry.Point in project cogtool by cogtool.

the class ImageRenderer method setSize.

/**
     * Sets the size of the area to draw the widget in.
     * This depends on the renderedArea variable.
     *
     * If there is text associated with this widget, that text will always
     * be drawn in the non-square area of the widget; ie, if the rendered area
     * is a square the text will be drawn next to (or below or above) the actual
     * rendered area, but if the rendered area is full or a fill around a square
     * the text will be drawn on top of the rendered area.
     */
@Override
public void setSize(int width, int height) {
    super.setSize(width, height);
    int labelX = 0;
    int labelY = 0;
    int labelWidth = width;
    int labelHeight = height;
    if (renderedArea == RENDER_FULL) {
        widgetBounds.setSize(width, height);
        if (label != null) {
            labelX = MARGIN;
            labelWidth = width - 2 * (MARGIN + 1);
            labelHeight = height;
        }
    } else if (renderedArea == RENDER_LEFT_SQUARE) {
        if (height < width) {
            widgetBounds.setSize(height, height);
            if (label != null) {
                labelX = height + MARGIN;
                labelWidth = width - labelX - MARGIN;
                labelHeight = height;
            }
        } else {
            widgetBounds.setSize(width, width);
            if (label != null) {
                labelX = MARGIN;
                labelY = width;
                labelWidth = width - MARGIN;
                labelHeight = height - labelY;
            }
        }
    } else if (renderedArea == RENDER_RIGHT_SQUARE) {
        if (height < width) {
            widgetBounds.setLocation(0, width - height);
            widgetBounds.setSize(height, height);
            if (label != null) {
                labelX = MARGIN;
                labelWidth = width - height - MARGIN;
                labelHeight = height;
            }
        } else {
            widgetBounds.setLocation(height - width, 0);
            widgetBounds.setSize(width, width);
            if (label != null) {
                labelX = MARGIN;
                labelWidth = width - MARGIN;
                labelHeight = height - width;
            }
        }
    } else if (renderedArea == RENDER_LEFT_FILL) {
        if (height < width) {
            widgetBounds.setSize(width - height, height);
            if (label != null) {
                labelX = MARGIN;
                labelWidth = width - height - MARGIN;
                labelHeight = height;
            }
        } else {
            widgetBounds.setSize(width, height - width);
            if (label != null) {
                labelX = MARGIN;
                labelWidth = width - MARGIN;
                labelHeight = height - width;
            }
        }
    } else if (renderedArea == RENDER_RIGHT_FILL) {
        if (height < width) {
            widgetBounds.setLocation(0, height);
            widgetBounds.setSize(width - height, height);
            if (label != null) {
                labelX = height + MARGIN;
                labelWidth = width - labelX - MARGIN;
                labelHeight = height;
            }
        } else {
            widgetBounds.setLocation(width, 0);
            widgetBounds.setSize(width, height - width);
            if (label != null) {
                labelX = MARGIN;
                labelY = width;
                labelWidth = width - MARGIN;
                labelHeight = height - labelY;
            }
        }
    }
    if (label != null) {
        if (labelWidth < 0) {
            labelWidth = 1;
        }
        if (labelHeight < 0) {
            labelHeight = 1;
        }
        label.setLocation(new Point(labelX, labelY));
        label.setSize(labelWidth, labelHeight);
    }
}
Also used : Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 5 with Point

use of org.eclipse.draw2d.geometry.Point in project cogtool by cogtool.

the class FrameEditorUI method moveWidgetGroup.

// moveFrameElementGroup
/**
     * Assumes gw's model is a traversable widget but not a child widget.
     */
public void moveWidgetGroup(double offsetX, double offsetY, GraphicalTraversableWidget<?> gw) {
    // No easier way to do this (hard to make getTopHeader call generic)
    TraversableWidget groupWidget = null;
    if (gw instanceof GraphicalMenuWidget<?>) {
        groupWidget = ((AMenuWidget) gw.getModel()).getTopHeader();
    } else if ((gw instanceof GraphicalListItem) || (gw instanceof GraphicalGridButton)) {
        groupWidget = (TraversableWidget) gw.getModel();
    } else {
        return;
    }
    SimpleWidgetGroup headerGroup = groupWidget.getParentGroup();
    // Ensure top-left header doesn't scroll off-screen
    groupWidget = (TraversableWidget) headerGroup.get(0);
    DoublePoint p = groupWidget.getShape().getOrigin();
    // Prevent the ability to move a widget to an origin less than 0,0
    if (offsetX + p.x < 0.0) {
        offsetX = -p.x;
    }
    if (offsetY + p.y < 0.0) {
        offsetY = -p.y;
    }
    Point newOrigin = new Point(0, 0);
    int index = 1;
    int headerCount = headerGroup.size();
    do {
        newOrigin.setLocation(PrecisionUtilities.round(p.x + offsetX), PrecisionUtilities.round(p.y + offsetY));
        frameUI.getWidgetFigure(groupWidget).setLocation(newOrigin);
        // Stop when we've moved the last header!
        if (index >= headerCount) {
            break;
        }
        groupWidget = (TraversableWidget) headerGroup.get(index++);
        p = groupWidget.getShape().getOrigin();
    } while (true);
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalMenuWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)661 Rectangle (org.eclipse.draw2d.geometry.Rectangle)178 PointList (org.eclipse.draw2d.geometry.PointList)97 Dimension (org.eclipse.draw2d.geometry.Dimension)86 IFigure (org.eclipse.draw2d.IFigure)68 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)63 ArrayList (java.util.ArrayList)50 List (java.util.List)46 Path (org.eclipse.swt.graphics.Path)28 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)27 EditPart (org.eclipse.gef.EditPart)23 Node (org.talend.designer.core.ui.editor.nodes.Node)19 Viewport (org.eclipse.draw2d.Viewport)15 Bendpoint (org.eclipse.draw2d.Bendpoint)14 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)13 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)13 INode (org.talend.core.model.process.INode)13 PolylineConnection (org.eclipse.draw2d.PolylineConnection)12 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)11 INodeFigure (org.whole.lang.ui.figures.INodeFigure)11