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