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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations