Search in sources :

Example 61 with PointList

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

the class AbstractPolyFeedbackFactory method showChangeBoundsFeedback.

/**
 * {@inheritDoc}
 */
@Override
public final void showChangeBoundsFeedback(final AbstractWidgetModel model, final PrecisionRectangle bounds, final IFigure feedbackFigure, final ChangeBoundsRequest request) {
    assert model != null;
    // $NON-NLS-1$
    assert model instanceof AbstractPolyModel : "model instanceof AbstractPolyModel";
    assert bounds != null;
    assert feedbackFigure != null;
    // $NON-NLS-1$
    assert feedbackFigure instanceof PolyFeedbackFigureWithRectangle : "feedbackFigure instanceof AbstractPolyFeedbackFigure";
    assert request != null;
    PolyFeedbackFigureWithRectangle figure = (PolyFeedbackFigureWithRectangle) feedbackFigure;
    figure.translateToRelative(bounds);
    // try to get a point list from the request (this happens only, when
    // poly point handles are dragged arround)
    PointList points = (PointList) request.getExtendedData().get(PROP_POINTS);
    // otherwise take the points from the model
    if (points == null) {
        points = ((AbstractPolyModel) model).getPoints();
    }
    // scale the points to the specified bounds
    PointList scaledPoints = PointListHelper.scaleTo(points.getCopy(), bounds);
    // apply the scaled points
    figure.setPoints(scaledPoints);
}
Also used : AbstractPolyModel(org.csstudio.opibuilder.widgets.model.AbstractPolyModel) PointList(org.eclipse.draw2d.geometry.PointList)

Example 62 with PointList

use of org.eclipse.draw2d.geometry.PointList 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)

Example 63 with PointList

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

the class AbstractPolyFeedbackFactory method createDragSourceFeedbackFigure.

/**
 * {@inheritDoc}
 */
@Override
public final IFigure createDragSourceFeedbackFigure(final AbstractWidgetModel model, final Rectangle initalBounds) {
    assert model != null;
    // $NON-NLS-1$
    assert model instanceof AbstractPolyModel : "model instanceof AbstractPolyModel";
    assert initalBounds != null;
    // get the points from the model
    AbstractPolyModel abstractPolyElement = (AbstractPolyModel) model;
    PointList points = abstractPolyElement.getPoints();
    // create feedbackfigure
    // RectangleWithPolyLineFigure r = new
    // RectangleWithPolyLineFigure(points);
    PolyFeedbackFigureWithRectangle feedbackFigure = new PolyFeedbackFigureWithRectangle(createFeedbackFigure(), points);
    return feedbackFigure;
}
Also used : AbstractPolyModel(org.csstudio.opibuilder.widgets.model.AbstractPolyModel) PointList(org.eclipse.draw2d.geometry.PointList)

Example 64 with PointList

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

the class PointListHelper method scaleToSize.

/**
 * Transforms the points in the specified point list to fit the given size.
 * All point coordinates are transformed relatively to the new size.
 *
 * @param points
 *            the point list
 * @param width
 *            the new width
 * @param height
 *            the new height
 * @return a point list copy, which has been scaled to the new size
 */
public static PointList scaleToSize(final PointList points, final int width, final int height) {
    // assert points != null;
    if (width <= 0 || height <= 0) {
        return points;
    // throw new IllegalArgumentException(
    // "Illegal dimensions. Width and height must be > 0."); //$NON-NLS-1$
    }
    double oldW = points.getBounds().width;
    double oldH = points.getBounds().height;
    double topLeftX = points.getBounds().x;
    double topLeftY = points.getBounds().y;
    PointList newPoints = new PointList();
    for (int i = 0; i < points.size(); i++) {
        int x = points.getPoint(i).x;
        int y = points.getPoint(i).y;
        Point newPoint = new Point(x, y);
        if (oldW != 0 && oldH != 0) {
            double oldRelX = (x - topLeftX) / oldW;
            double oldRelY = (y - topLeftY) / oldH;
            double newX = topLeftX + (oldRelX * width);
            double newY = topLeftY + (oldRelY * height);
            newPoint = new Point((int) newX, (int) newY);
        }
        newPoints.addPoint(newPoint);
    }
    return newPoints;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 65 with PointList

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

the class PointListHelper method scaleTo.

/**
 * Scales the point list to the new bounds.
 *
 * @param points the point list
 * @param targetBounds the target bounds
 * @return a point list copy, which has been scaled to the new bounds
 */
public static PointList scaleTo(final PointList points, final Rectangle targetBounds) {
    PointList result = scaleToLocation(points, targetBounds.x, targetBounds.y);
    result = scaleToSize(result, targetBounds.width, targetBounds.height);
    return result;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList)

Aggregations

PointList (org.eclipse.draw2d.geometry.PointList)80 Point (org.eclipse.draw2d.geometry.Point)49 Rectangle (org.eclipse.draw2d.geometry.Rectangle)15 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)10 ArrayList (java.util.ArrayList)9 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)8 Polyline (org.eclipse.draw2d.Polyline)7 List (java.util.List)6 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)6 AbstractPolyModel (org.csstudio.opibuilder.widgets.model.AbstractPolyModel)5 Dimension (org.eclipse.draw2d.geometry.Dimension)5 Bendpoint (org.eclipse.draw2d.Bendpoint)4 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)4 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)3 PolarPoint (org.csstudio.swt.widgets.figureparts.PolarPoint)3 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ConnectionReconnectCommand (org.csstudio.opibuilder.commands.ConnectionReconnectCommand)2