Search in sources :

Example 21 with PointList

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;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) MidpointLocator(org.eclipse.draw2d.MidpointLocator) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) BendpointHandle(org.eclipse.gef.handles.BendpointHandle) BendpointMoveHandle(org.eclipse.gef.handles.BendpointMoveHandle) Point(org.eclipse.draw2d.geometry.Point)

Example 22 with PointList

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()));
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) PointList(org.eclipse.draw2d.geometry.PointList) ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ConnectionReconnectCommand(org.csstudio.opibuilder.commands.ConnectionReconnectCommand)

Example 23 with 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;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ArrayList(java.util.ArrayList) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) CloneCommand(org.csstudio.opibuilder.commands.CloneCommand) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand)

Example 24 with PointList

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);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Polyline(org.eclipse.draw2d.Polyline)

Example 25 with PointList

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);
}
Also used : AbstractPolyModel(org.csstudio.opibuilder.widgets.model.AbstractPolyModel) PointList(org.eclipse.draw2d.geometry.PointList)

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