Search in sources :

Example 1 with Polyline

use of org.eclipse.draw2d.Polyline in project yamcs-studio by yamcs.

the class PolylineJumpConnection method drawSquare.

private void drawSquare(final Entry<Point, PointList> currentEntry, Graphics graphics) {
    PointList intersectionEdges = currentEntry.getValue();
    Point x1y1 = intersectionEdges.getFirstPoint();
    Point x2y2 = intersectionEdges.getLastPoint();
    int x3 = (int) (x1y1.x - (RATIO_30_DEGREES) * (x2y2.y - x1y1.y));
    int y3 = (int) (x1y1.y - (RATIO_30_DEGREES) * (x2y2.x - x1y1.x));
    Point squareCorner1 = new Point(x3, y3);
    // Leave margin for rounding errors
    if (Math.abs(x1y1.x - x2y2.x) < 5) {
        if (x3 > x1y1.x) {
            int length = Math.abs(x1y1.x - x3);
            x3 = x1y1.x - length;
            squareCorner1 = new Point(x3, y3);
        }
    }
    // Leave margin for rounding errors
    if (Math.abs(x1y1.y - x2y2.y) < 5) {
        if (y3 > x1y1.y) {
            int length = Math.abs(x1y1.y - y3);
            y3 = x1y1.y - length;
            squareCorner1 = new Point(x3, y3);
        }
    }
    int x4 = (int) (x2y2.x + (RATIO_30_DEGREES) * (x1y1.y - x2y2.y));
    int y4 = (int) (x2y2.y + (RATIO_30_DEGREES) * (x1y1.x - x2y2.x));
    Point squareCorner2 = new Point(x4, y4);
    // Leave margin for rounding errors
    if (Math.abs(x1y1.x - x2y2.x) < 5) {
        if (x4 > x2y2.x) {
            int length = Math.abs(x2y2.x - x4);
            x4 = x2y2.x - length;
            squareCorner2 = new Point(x4, y4);
        }
    }
    // Leave margin for rounding errors
    if (Math.abs(x1y1.y - x2y2.y) < 5) {
        if (y4 > x2y2.y) {
            int length = Math.abs(x2y2.y - y4);
            y4 = x2y2.y - length;
            squareCorner2 = new Point(x4, y4);
        }
    }
    final Polyline squareLine1 = getPolyLine(intersectionEdges.getFirstPoint(), squareCorner1);
    this.setBounds(getBounds().union(squareLine1.getBounds()));
    final Polyline squareLine2 = getPolyLine(squareCorner1, squareCorner2);
    this.setBounds(getBounds().union(squareLine2.getBounds()));
    final Polyline squareLine3 = getPolyLine(squareCorner2, intersectionEdges.getLastPoint());
    this.setBounds(getBounds().union(squareLine3.getBounds()));
    squareLine1.paint(graphics);
    squareLine2.paint(graphics);
    squareLine3.paint(graphics);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Polyline(org.eclipse.draw2d.Polyline) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 2 with Polyline

use of org.eclipse.draw2d.Polyline in project yamcs-studio by yamcs.

the class PolylineJumpConnection method getPolyLine.

private Polyline getPolyLine(Point firstPoint, Point lastPoint) {
    Polyline line = new Polyline();
    line.addPoint(firstPoint);
    line.addPoint(lastPoint);
    line.setLineWidth(getLineWidth());
    line.setLineStyle(getLineStyle());
    return line;
}
Also used : Polyline(org.eclipse.draw2d.Polyline)

Example 3 with Polyline

use of org.eclipse.draw2d.Polyline in project yamcs-studio by yamcs.

the class AbstractPolyFeedbackFactory method showSizeOnDropFeedback.

/**
 * {@inheritDoc}
 */
@Override
public final void showSizeOnDropFeedback(final CreateRequest createRequest, final IFigure feedbackFigure, final Insets insets) {
    assert createRequest != null;
    // $NON-NLS-1$
    assert feedbackFigure instanceof Polyline : "feedbackFigure instanceof Polyline";
    Polyline polyline = (Polyline) feedbackFigure;
    // the request should contain a point list, because the creation is done
    // by a special creation tool
    PointList points = ((PointList) createRequest.getExtendedData().get(PROP_POINTS)).getCopy();
    assert points != null;
    // the points are viewer relative and need to be translated to reflect
    // the zoom level, scrollbar occurence etc.
    polyline.translateToRelative(points);
    polyline.setPoints(points);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Polyline(org.eclipse.draw2d.Polyline)

Example 4 with Polyline

use of org.eclipse.draw2d.Polyline in project yamcs-studio by yamcs.

the class AbstractPolyEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    super.registerPropertyChangeHandlers();
    // points
    IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            Polyline polyline = (Polyline) refreshableFigure;
            PointList points = (PointList) newValue;
            if (points.size() != polyline.getPoints().size()) {
                anchorMap = null;
                // delete connections on deleted points
                if (points.size() < polyline.getPoints().size()) {
                    for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
                        if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                    for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
                        if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                }
            }
            // deselect the widget (this refreshes the polypoint drag
            // handles)
            int selectionState = getSelected();
            setSelected(EditPart.SELECTED_NONE);
            polyline.setPoints(points);
            doRefreshVisuals(polyline);
            // restore the selection state
            setSelected(selectionState);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
    IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) Polyline(org.eclipse.draw2d.Polyline) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with Polyline

use of org.eclipse.draw2d.Polyline in project yamcs-studio by yamcs.

the class AbstractPolyFeedbackFactory method createSizeOnDropFeedback.

/**
 * {@inheritDoc}
 */
@Override
public final Shape createSizeOnDropFeedback(final CreateRequest createRequest) {
    assert createRequest != null;
    // Polyline polyline = new Polyline();
    // the request should contain a point list, because the creation is done
    // by a special creation tool
    PointList points = (PointList) createRequest.getExtendedData().get(PROP_POINTS);
    assert points != null;
    // polyline.setPoints(points);
    Polyline feedbackFigure = createFeedbackFigure();
    feedbackFigure.setPoints(points);
    return feedbackFigure;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Polyline(org.eclipse.draw2d.Polyline)

Aggregations

Polyline (org.eclipse.draw2d.Polyline)8 PointList (org.eclipse.draw2d.geometry.PointList)7 Point (org.eclipse.draw2d.geometry.Point)4 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)3 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)2 ArrayList (java.util.ArrayList)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 IFigure (org.eclipse.draw2d.IFigure)1