Search in sources :

Example 26 with PointList

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

the class AbstractPolyFeedbackFactory method createChangeBoundsCommand.

/**
 * {@inheritDoc}
 */
@Override
public final Command createChangeBoundsCommand(final AbstractWidgetModel model, final ChangeBoundsRequest request, final Rectangle targetBounds) {
    // $NON-NLS-1$
    assert model instanceof AbstractPolyModel : "model instanceof AbstractPolyModel";
    Rectangle correctedBounds = targetBounds;
    // if (model instanceof PolyLineModel) {
    // PolyLineModel polyline = (PolyLineModel) model;
    // int correctedX = targetBounds.x + (polyline.getLineWidth() / 2);
    // int correctedY = targetBounds.y + (polyline.getLineWidth() / 2);
    // correctedBounds = new Rectangle(correctedX, correctedY, targetBounds.width, targetBounds.height);
    // }
    AbstractPolyModel abstractPolyElement = (AbstractPolyModel) model;
    // 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();
    }
    assert points != null;
    // the points are viewer relative and need to be translated to the
    // specified bounds, to reflect zoom level, scrollbar occurence etc.
    points = PointListHelper.scaleTo(points, correctedBounds);
    return new ChangePolyPointsCommand(abstractPolyElement, points);
}
Also used : AbstractPolyModel(org.csstudio.opibuilder.widgets.model.AbstractPolyModel) PointList(org.eclipse.draw2d.geometry.PointList) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 27 with PointList

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

the class PointListCreationTool method createTargetRequest.

/**
 * {@inheritDoc}
 */
@Override
protected Request createTargetRequest() {
    _points = new PointList();
    CreateRequest request = new CreateRequest();
    request.setFactory(getFactory());
    return request;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) CreateRequest(org.eclipse.gef.requests.CreateRequest)

Example 28 with PointList

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

the class PointListHelper method scaleToLocation.

/**
 * Moves the origin (0,0) of the coordinate system of all the points in the
 * specified point list to the Point (x,y).
 *
 * @param points
 *            the point list
 * @param x
 *            the x coordinate
 * @param y
 *            the y coordinate
 * @return a point list copy, which has been scaled to the new location
 */
public static PointList scaleToLocation(final PointList points, final int x, final int y) {
    int oldX = points.getBounds().x;
    int oldY = points.getBounds().y;
    PointList result = points.getCopy();
    result.translate(x - oldX, y - oldY);
    return result;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point)

Example 29 with PointList

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

the class PolyPointDragTracker method updateSourceRequest.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected void updateSourceRequest() {
    super.updateSourceRequest();
    ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
    PrecisionPoint location = new PrecisionPoint(getLocation().x, getLocation().y);
    if (_snapToHelper != null) {
        _snapToHelper.snapPoint(request, PositionConstants.NORTH_WEST, new PrecisionPoint(getLocation().x, getLocation().y), location);
    }
    _owner.getFigure().translateToRelative(location);
    PointList oldPoints = ((PointList) request.getExtendedData().get(EXT_DATA_POINTS)).getCopy();
    PointList newPoints = oldPoints.getCopy();
    newPoints.setPoint(location.getCopy(), _pointIndex);
    // calculate difference
    Rectangle oldBounds = _oldPoints.getBounds();
    Rectangle newBounds = newPoints.getBounds();
    request.setLocation(getLocation());
    Dimension locationDiff = newBounds.getLocation().getDifference(oldBounds.getLocation());
    _owner.getFigure().translateToAbsolute(locationDiff);
    Dimension sizeDiff = newBounds.getSize().getDifference(oldBounds.getSize());
    _owner.getFigure().translateToAbsolute(sizeDiff);
    request.setMoveDelta(new Point(locationDiff.width, locationDiff.height));
    request.setSizeDelta(sizeDiff);
    request.getExtendedData().put(EXT_DATA_POINTS, newPoints);
    request.getExtendedData().put(EXT_DATA_POINT_INDEX, _pointIndex);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) PointList(org.eclipse.draw2d.geometry.PointList) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 30 with PointList

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

the class PolyPointDragTracker method createSourceRequest.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected Request createSourceRequest() {
    ChangeBoundsRequest request = new ChangeBoundsRequest();
    // TODO: swende: ugly
    request.setEditParts(getTargetEditPart());
    PointList points = ((AbstractPolyModel) _owner.getModel()).getPoints();
    request.getExtendedData().put(AbstractPolyFeedbackFactory.PROP_POINTS, points.getCopy());
    request.setType(RequestConstants.REQ_RESIZE);
    _oldPoints = points.getCopy();
    return request;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) PointList(org.eclipse.draw2d.geometry.PointList) AbstractPolyModel(org.csstudio.opibuilder.widgets.model.AbstractPolyModel)

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