Java Code Examples for org.eclipse.gef.requests.ChangeBoundsRequest#getTransformedRectangle()

The following examples show how to use org.eclipse.gef.requests.ChangeBoundsRequest#getTransformedRectangle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiveFeedbackNonResizableEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
	// If REQ_DROP is delivered 2 times in a row it is a "real" drop and not only a
	// hover over existing elements in the same region
	if (RequestConstants.REQ_DROP.equals(request.getType()) && RequestConstants.REQ_DROP.equals(lastRequest)) {
		Rectangle rect = getOriginalBounds();
		getHostFigure().getParent().translateToRelative(rect);
		getHostFigure().setBounds(rect);
		super.showChangeBoundsFeedback(request);
		lastRequest = (String) request.getType();
		return;
	}
	super.eraseChangeBoundsFeedback(request);
	 enforceConstraintForMove(request);
	if (connectionStart) {
		updateOriginalBounds();
		connectionStart = false;
	}
	Rectangle bounds = request.getTransformedRectangle(getOriginalBounds());
	getHostFigure().getParent().translateToRelative(bounds);
	getHostFigure().setBounds(bounds);
	getHostFigure().getParent().setConstraint(getHostFigure(), bounds);
	lastRequest = (String) request.getType();
}
 
Example 2
Source File: BarResizeEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected ResizeTracker getResizeTracker(int direction) {

	return new ResizeTracker((GraphicalEditPart) getHost(), direction) {
		@Override
		protected void enforceConstraintsForResize(ChangeBoundsRequest request) {
			Rectangle locationAndSize = getOriginalBounds();
			
			final Rectangle origRequestedBounds = request.getTransformedRectangle(locationAndSize);
			final Rectangle modified = origRequestedBounds.getCopy();
			checkAndPrepareConstraint(request, modified);
			Dimension newDelta = new Dimension(modified.width - locationAndSize.width,
					modified.height - locationAndSize.height);
			request.setSizeDelta(newDelta);
			final Point moveDelta = request.getMoveDelta();
			request.setMoveDelta(new Point(moveDelta.x - origRequestedBounds.x + modified.x,
					moveDelta.y - origRequestedBounds.y + modified.y));
		}
	};
}
 
Example 3
Source File: ReportFlowLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Generates a draw2d constraint object derived from the specified child
 * EditPart using the provided Request. The returned constraint will be
 * translated to the application's model later using
 * {@link #translateToModelConstraint(Object)}.
 * 
 * @param request
 *            the ChangeBoundsRequest
 * @param child
 *            the child EditPart for which the constraint should be
 *            generated
 * @return the draw2d constraint
 */
protected Object getConstraintFor( ChangeBoundsRequest request,
		GraphicalEditPart child )
{
	IFigure figure = child.getFigure( );
	Rectangle rect = new PrecisionRectangle(figure.getBounds());
	figure.translateToAbsolute(rect);
	rect = request.getTransformedRectangle( rect );
	
	figure.translateToRelative(rect);
	rect.translate( getLayoutOrigin( ).getNegated( ) );
	if (figure instanceof IOutsideBorder)
	{
		Border border = ((IOutsideBorder)figure).getOutsideBorder( );
		if (border !=  null)
		{
			Insets insets = border.getInsets( figure );
			rect.shrink( insets.right, insets.bottom );
		}
	}

	return getConstraintFor( rect );
}
 
Example 4
Source File: LiveFeedbackResizableEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void enforceConstraintForMove(ChangeBoundsRequest request) {
	Rectangle relativeBounds = getOriginalBounds();
	PrecisionRectangle manipulatedConstraint = new PrecisionRectangle(
			 request.getTransformedRectangle(relativeBounds));
	getHostFigure().translateToRelative(manipulatedConstraint);
	
	manipulatedConstraint.setX(Math.max(0, manipulatedConstraint.x));
	manipulatedConstraint.setY(Math.max(0, manipulatedConstraint.y));
	
	getHostFigure().translateToAbsolute(manipulatedConstraint);
	
	Dimension difference = manipulatedConstraint.getLocation().getDifference(originalBounds.getLocation());
	request.setMoveDelta(new Point(difference.width, difference.height));
}
 
Example 5
Source File: LiveFeedbackResizableEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void enforceConstraintsForResize(ChangeBoundsRequest request) {
	super.enforceConstraintsForResize(request);
	final IFigure figure = getHostFigure();
	Dimension prefSize = figure.getPreferredSize().getCopy();
	figure.translateToAbsolute(prefSize);
	Rectangle bounds = getOriginalBounds();
	bounds = request.getTransformedRectangle(bounds);
	if (bounds.width < prefSize.width) {
		request.getSizeDelta().width = request.getSizeDelta().width + (prefSize.width - bounds.width);
	}
	if (bounds.height < prefSize.height) {
		request.getSizeDelta().height = request.getSizeDelta().height + (prefSize.height - bounds.height);
	}
	request.setSizeDelta(request.getSizeDelta());
}
 
Example 6
Source File: ResizeTracker.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Ensures size constraints (by default minimum and maximum) are respected
 * by the given request. May be overwritten by clients to enforce additional
 * constraints.
 * 
 * @param changeBoundsRequest
 *            The request to validate
 * @since 3.7
 */
protected void enforceConstraintsForResize(
		ChangeBoundsRequest changeBoundsRequest) {
	// adjust request, so that minimum and maximum size constraints are
	// respected
	if (owner != null) {
		PrecisionRectangle originalConstraint = new PrecisionRectangle(
				getOriginalBounds());
		owner.getFigure().translateToAbsolute(originalConstraint);
		PrecisionRectangle manipulatedConstraint = new PrecisionRectangle(
				changeBoundsRequest
						.getTransformedRectangle(originalConstraint));
		owner.getFigure().translateToRelative(manipulatedConstraint);
		// validate constraint (maximum and minimum size are regarded to be
		// 'normalized', i.e. relative to this figure's bounds coordinates).
		manipulatedConstraint.setSize(Dimension.max(
				manipulatedConstraint.getSize(),
				getMinimumSizeFor(changeBoundsRequest)));
		manipulatedConstraint.setSize(Dimension.min(
				manipulatedConstraint.getSize(),
				getMaximumSizeFor(changeBoundsRequest)));
		// translate back to absolute
		owner.getFigure().translateToAbsolute(manipulatedConstraint);
		Dimension newSizeDelta = manipulatedConstraint.getSize()
				.getShrinked(originalConstraint.getSize());
		changeBoundsRequest.setSizeDelta(newSizeDelta);
	}
}
 
Example 7
Source File: CustomResizableEditPolicyEx.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected boolean checkSubprocessEventCanReduce(final ChangeBoundsRequest request) {
    for (final Object c : getHost().getChildren()) {
        if (c instanceof CustomSubprocessEventCompartmentEditPart) {
            final View view = ((org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart) c).getNotationView();
            if (view != null) {
                final DrawerStyle style = (DrawerStyle) view.getStyle(NotationPackage.eINSTANCE.getDrawerStyle());
                if (style != null) {
                    if (!style.isCollapsed()
                            && !((Container) ((CustomSubprocessEventCompartmentEditPart) c).resolveSemanticElement()).getElements().isEmpty()) {
                        final Rectangle bounds = request.getTransformedRectangle(getHostFigure().getBounds());
                        for (final Object child : ((CustomSubprocessEventCompartmentEditPart) c).getChildren()) {
                            final int x = ((IGraphicalEditPart) child).getFigure().getBounds().x;
                            final int width = ((IGraphicalEditPart) child).getFigure().getBounds().width;
                            final int y = ((IGraphicalEditPart) child).getFigure().getBounds().y;
                            final int height = ((IGraphicalEditPart) child).getFigure().getBounds().height;

                            if ((request.getSizeDelta().height < 0 || request.getSizeDelta().width < 0)
                                    && (bounds.width + bounds.x - 20 <= x + width || bounds.height + bounds.y - 30 <= y + height)) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}