use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class PointsUtil method scalePointsBySize.
/**
*Scale the bound size of a point list.
* @param points the points to be scaled.
* @param width the new width.
* @param height the new height
* @return the points after scaled. If no scale is needed, return the input points.
*/
public static PointList scalePointsBySize(final PointList points, final int width, final int height) {
int targetW = Math.max(1, width);
int targetH = Math.max(1, height);
double oldW = points.getBounds().width;
double oldH = points.getBounds().height;
double topLeftX = points.getBounds().x;
double topLeftY = points.getBounds().y;
if (oldW != targetW || oldH != targetH) {
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 * targetW);
double newY = topLeftY + (oldRelY * targetH);
int roundedX = (int) Math.round(newX);
int roundedY = (int) Math.round(newY);
newPoint = new Point(roundedX, roundedY);
}
newPoints.addPoint(newPoint);
}
return newPoints;
}
return points;
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class PointsUtil method rotatePoints.
/**
* Rotates all points.
*
* @param points The PoinList, which points should be rotated
* @param angle
* The angle to rotate
* @return The rotated PointList
*/
public static final PointList rotatePoints(final PointList points, final double angle) {
Rectangle pointBounds = points.getBounds();
Point rotationPoint = pointBounds.getCenter();
PointList newPoints = rotatePoints(points, angle, rotationPoint);
Rectangle newPointBounds = newPoints.getBounds();
if (!rotationPoint.equals(newPointBounds.getCenter())) {
Dimension difference = rotationPoint.getCopy().getDifference(newPointBounds.getCenter());
newPoints.translate(difference.width, difference.height);
}
return newPoints;
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class WidgetCreateCommand method execute.
@Override
public void execute() {
oldBounds = newWidget.getBounds();
generateNewWUID(newWidget);
// If the new created widget has connections on it, remove their points.
for (ConnectionModel conn : newWidget.getSourceConnections()) {
conn.setPoints(new PointList());
}
redo();
}
use of org.eclipse.draw2d.geometry.PointList 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);
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class GeometryUtil method getChildrenRange.
/**
*Get the range of children widgets.
* @param container editpart of the container widget.
* @return the range (minX, minY, maxX-minX, maxY-minY) relative to the container.
*/
public static Rectangle getChildrenRange(AbstractContainerEditpart container) {
PointList pointList = new PointList(container.getChildren().size());
for (Object child : container.getChildren()) {
AbstractWidgetModel childModel = ((AbstractBaseEditPart) child).getWidgetModel();
pointList.addPoint(childModel.getLocation());
pointList.addPoint(childModel.getX() + childModel.getWidth(), childModel.getY() + childModel.getHeight());
}
return pointList.getBounds();
}
Aggregations