use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class ManhattanBendpointEditPolicy method createSelectionHandles.
@Override
protected List<?> createSelectionHandles() {
List<BendpointHandle> handles = new ArrayList<>();
final PointList points = getConnection().getPoints();
if (points.size() < 4)
return handles;
for (int i = 1; i < points.size() - 2; i++) {
handles.add(new BendpointMoveHandle(getConnectionEditPart(), i - 1, new MidpointLocator(getConnection(), i)) {
@Override
protected Color getBorderColor() {
return (isPrimary()) ? ColorConstants.darkGreen : ColorConstants.white;
}
@Override
protected Color getFillColor() {
return ColorConstants.yellow;
}
});
}
return handles;
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class WidgetNodeEditPolicy method getReconnectTargetCommand.
@Override
protected Command getReconnectTargetCommand(ReconnectRequest request) {
ConnectionModel connection = (ConnectionModel) request.getConnectionEditPart().getModel();
AbstractWidgetModel newTarget = getWidgetEditPart().getWidgetModel();
ConnectionAnchor anchor = getWidgetEditPart().getTargetConnectionAnchor(request);
String newTerminal = getWidgetEditPart().getTerminalNameFromAnchor(anchor);
ConnectionReconnectCommand cmd = new ConnectionReconnectCommand(connection);
cmd.setNewTarget(newTarget);
cmd.setNewTargetTerminal(newTerminal);
// clear point list
return cmd.chain(new SetWidgetPropertyCommand(connection, ConnectionModel.PROP_POINTS, new PointList()));
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method createChangeConstraintCommand.
@Override
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
return super.createChangeConstraintCommand(request, child, constraint);
AbstractBaseEditPart part = (AbstractBaseEditPart) child;
AbstractWidgetModel widgetModel = part.getWidgetModel();
IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(widgetModel.getTypeID());
Command cmd = null;
if (feedbackFactory != null)
cmd = feedbackFactory.createChangeBoundsCommand(widgetModel, request, (Rectangle) constraint);
if (cmd == null)
cmd = new WidgetSetConstraintCommand(widgetModel, request, (Rectangle) constraint);
List<ConnectionModel> allConnections = new ArrayList<ConnectionModel>(part.getWidgetModel().getSourceConnections());
allConnections.addAll(part.getWidgetModel().getTargetConnections());
if (part.getWidgetModel() instanceof AbstractContainerModel) {
for (AbstractWidgetModel d : ((AbstractContainerModel) part.getWidgetModel()).getAllDescendants()) {
allConnections.addAll(d.getSourceConnections());
allConnections.addAll(d.getTargetConnections());
}
}
if (allConnections.size() > 0) {
CompoundCommand reRouteCmd = new CompoundCommand();
for (ConnectionModel srcConn : allConnections) {
reRouteCmd.add(new SetWidgetPropertyCommand(srcConn, ConnectionModel.PROP_POINTS, new PointList()));
}
cmd = cmd.chain(reRouteCmd);
}
if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
if (guidePos != null) {
cmd = chainGuideAttachmentCommand(request, part, cmd, true);
} else if (GuideUtil.getInstance().getGuide(widgetModel, true) != null) {
// SnapToGuides didn't provide a horizontal guide, but
// this part is attached
// to a horizontal guide. Now we check to see if the
// part is attached to
// the guide along the edge being resized. If that is
// the case, we need to
// detach the part from the guide; otherwise, we leave
// it alone.
int alignment = GuideUtil.getInstance().getGuide(widgetModel, true).getAlignment(widgetModel);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
cmd = cmd.chain(new ChangeGuideCommand(widgetModel, true));
}
}
}
if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos != null) {
cmd = chainGuideAttachmentCommand(request, part, cmd, false);
} else if (GuideUtil.getInstance().getGuide(widgetModel, false) != null) {
int alignment = GuideUtil.getInstance().getGuide(widgetModel, false).getAlignment(widgetModel);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.WEST) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
cmd = cmd.chain(new ChangeGuideCommand(widgetModel, false));
}
}
}
if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) {
cmd = chainGuideAttachmentCommand(request, part, cmd, true);
cmd = chainGuideAttachmentCommand(request, part, cmd, false);
cmd = chainGuideDetachmentCommand(request, part, cmd, true);
cmd = chainGuideDetachmentCommand(request, part, cmd, false);
}
return cmd;
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class AbstractPolyFeedbackFactory method showSizeOnDropFeedback.
/**
* {@inheritDoc}
*/
@Override
public final void showSizeOnDropFeedback(final CreateRequest createRequest, final IFigure feedbackFigure, final Insets insets) {
assert createRequest != null;
// $NON-NLS-1$
assert feedbackFigure instanceof Polyline : "feedbackFigure instanceof Polyline";
Polyline polyline = (Polyline) feedbackFigure;
// 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)).getCopy();
assert points != null;
// the points are viewer relative and need to be translated to reflect
// the zoom level, scrollbar occurence etc.
polyline.translateToRelative(points);
polyline.setPoints(points);
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class AbstractPolyFeedbackFactory method createInitialBoundsCommand.
/**
* {@inheritDoc}
*/
@Override
public final Command createInitialBoundsCommand(final AbstractWidgetModel widgetModel, final CreateRequest request, final Rectangle bounds) {
// $NON-NLS-1$
assert widgetModel instanceof AbstractPolyModel : "widgetModel instanceof AbstractPolyModel";
assert request != null;
assert bounds != null;
AbstractPolyModel abstractPolyElement = (AbstractPolyModel) widgetModel;
PointList points = (PointList) request.getExtendedData().get(PROP_POINTS);
// necessary if the call was occurred by a "Drag and Drop" action
if (points == null) {
points = (PointList) widgetModel.getProperty(AbstractPolyModel.PROP_POINTS).getPropertyValue();
}
// the points are viewer relative and need to be translated to the
// specified bounds, to reflect zoom level, scrollbar occurence etc.
PointList scaledPoints = PointListHelper.scaleTo(points, bounds);
return new ChangePolyPointsCommand(abstractPolyElement, scaledPoints);
}
Aggregations