Java Code Examples for org.eclipse.draw2d.IFigure#translateToRelative()

The following examples show how to use org.eclipse.draw2d.IFigure#translateToRelative() . 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: RowDragTracker.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected Rectangle getMarqueeSelectionRectangle( )
{
	IFigure figure = ( (TableEditPart) getSourceEditPart( ) ).getFigure( );
	Insets insets = figure.getInsets( );

	int value = getLocation( ).y - getStartLocation( ).y;
	value = getTrueValueAbsolute( value );

	Point p = getStartLocation( ).getCopy( );
	figure.translateToAbsolute( p );
	figure.translateToRelative( p );
	Rectangle bounds = figure.getBounds( ).getCopy( );
	figure.translateToAbsolute( bounds );

	return new Rectangle( bounds.x + insets.left, value + p.y, bounds.width
			- ( insets.left + insets.right ), 2 );
}
 
Example 2
Source File: ColumnDragTracker.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected Rectangle getMarqueeSelectionRectangle( )
{
	IFigure figure = ( (TableEditPart) getSourceEditPart( ) ).getFigure( );
	Insets insets = figure.getInsets( );

	int value = getLocation( ).x - getStartLocation( ).x;
	value = getTrueValueAbsolute( value );

	Point p = getStartLocation( ).getCopy( );
	figure.translateToAbsolute( p );
	figure.translateToRelative( p );
	Rectangle bounds = figure.getBounds( ).getCopy( );
	figure.translateToAbsolute( bounds );

	return new Rectangle( value + p.x,
			bounds.y + insets.top,
			2,
			bounds.height - ( insets.top + insets.bottom ) );

}
 
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: CellDragoicator.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void relocate( IFigure target )
{
	IFigure reference = getReferenceFigure( );
	Rectangle targetBounds = new PrecisionRectangle( getReferenceBox( ).getResized( -1,
			-1 ) );
	reference.translateToAbsolute( targetBounds );
	target.translateToRelative( targetBounds );
	targetBounds.resize( 1, 1 );

	Dimension targetSize = getTargetSize( targetBounds.getSize( ) );

	targetBounds.x += (int) ( targetBounds.width * relativeX ) - 1;
	targetBounds.y += (int) ( targetBounds.height * relativeY );
	if (targetBounds.x < 0)
	{
		targetBounds.x = 0;
	}
	if (targetBounds.y < 0)
	{
		targetBounds.y = 0;
	}
	targetBounds.setSize( targetSize );
	target.setBounds( targetBounds );
}
 
Example 5
Source File: ListBandHandle.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void relocate( IFigure target )
{
	Rectangle bounds;
	if ( getReference( ) instanceof ListBandFigure )
	{
		ListBandFigure parent = (ListBandFigure) getReference( );
		Figure content = (Figure) parent.getContent( );
		bounds = content.getBounds( ).getCopy( );
	}
	else
	{
		bounds = getReference( ).getBounds( ).getCopy( );
	}

	getReference( ).translateToAbsolute( bounds );
	target.translateToRelative( bounds );

	bounds.translate( 1, 1 );
	bounds.resize( -1, -1 );

	target.setBounds( bounds );
}
 
Example 6
Source File: ERDiagramLayoutEditPolicy.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void showSizeOnDropFeedback(CreateRequest request) {
	Point p = new Point(request.getLocation().getCopy());

	ZoomManager zoomManager = ((ScalableFreeformRootEditPart) this
			.getHost().getRoot()).getZoomManager();
	double zoom = zoomManager.getZoom();

	IFigure feedback = getSizeOnDropFeedback(request);

	Dimension size = request.getSize().getCopy();
	feedback.translateToRelative(size);
	feedback.setBounds(new Rectangle((int) (p.x * zoom),
			(int) (p.y * zoom), size.width, size.height)
			.expand(getCreationFeedbackOffset(request)));
}
 
Example 7
Source File: CrosstabColumnDragTracker.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected Rectangle getMarqueeSelectionRectangle( )
{
	IFigure figure = getCrosstabTableEditPart( ).getFigure( );
	Insets insets = figure.getInsets( );

	int value = getLocation( ).x - getStartLocation( ).x;
	value = getTrueValueAbsolute( value );

	Point p = getStartLocation( ).getCopy( );
	figure.translateToAbsolute( p );
	figure.translateToRelative( p );
	Rectangle bounds = figure.getBounds( ).getCopy( );
	figure.translateToAbsolute( bounds );

	return new Rectangle( value + p.x,
			bounds.y + insets.top,
			2,
			bounds.height - ( insets.top + insets.bottom ) );
}
 
Example 8
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectTargetCommand(final ReconnectRequest reconnectrequest) {
    final ConnectionElement connection = (ConnectionElement) reconnectrequest.getConnectionEditPart().getModel();

    if (connection.getSource() == connection.getTarget()) {
        return null;
    }

    final NodeElement newTarget = (NodeElement) reconnectrequest.getTarget().getModel();
    if (connection.getTarget() != newTarget) {
        return null;
    }

    final NodeElementEditPart targetEditPart = (NodeElementEditPart) reconnectrequest.getConnectionEditPart().getTarget();

    final Point location = new Point(reconnectrequest.getLocation());

    final IFigure targetFigure = targetEditPart.getFigure();
    targetFigure.translateToRelative(location);

    int xp = -1;
    int yp = -1;

    final Rectangle bounds = targetFigure.getBounds();

    final Rectangle centerRectangle = new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

    if (!centerRectangle.contains(location)) {
        final Point point = NodeElementEditPart.getIntersectionPoint(location, targetFigure);

        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }
    final ReconnectTargetCommand command = new ReconnectTargetCommand(connection, xp, yp);

    return command;
}
 
Example 9
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private Command getCommand(ProcessPart part, ChangeBoundsRequest request) {
	IFigure figure = part.getModel().figure;
	Rectangle bounds = figure.getBounds().getCopy();
	figure.translateToAbsolute(bounds);
	Rectangle moveResize = new Rectangle(request.getMoveDelta(), request.getSizeDelta());
	bounds.resize(moveResize.getSize());
	bounds.translate(moveResize.getLocation());
	figure.translateToRelative(bounds);
	if (request.getSizeDelta().height != 0 || request.getSizeDelta().width != 0)
		return XYLayoutCommand.resize(part.getModel(), bounds);
	if (request.getMoveDelta().x != 0 || request.getMoveDelta().y != 0)
		return XYLayoutCommand.move(part.getModel(), bounds);
	return null;
}
 
Example 10
Source File: SubprocessCollapseHandle.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public void relocate(IFigure target) {
	Rectangle theBounds = getOwnerFigure().getParent().getBounds().getCopy();          
	getOwnerFigure().translateToAbsolute(theBounds);
	target.translateToRelative(theBounds);
	Point loc = theBounds.getBottom(); 
	double zoom = zoomManager.getZoom() ;
	loc.translate(Math.round((float)zoom*-5), Math.round((float)zoom*-20)) ;
	target.setLocation(loc);            
}
 
Example 11
Source File: ERDiagramLayoutEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected void showSizeOnDropFeedback(CreateRequest request) {
    final Point p = new Point(request.getLocation().getCopy());
    final ZoomManager zoomManager = ((ScalableFreeformRootEditPart) getHost().getRoot()).getZoomManager();
    final double zoom = zoomManager.getZoom();
    final IFigure feedback = getSizeOnDropFeedback(request);
    final Dimension size = request.getSize().getCopy();
    feedback.translateToRelative(size);
    feedback.setBounds(new Rectangle((int) (p.x * zoom), (int) (p.y * zoom), size.width, size.height)
            .expand(getCreationFeedbackOffset(request)));
}
 
Example 12
Source File: DiagramWalkerGraphicalNodeEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected Command getReconnectTargetCommand(ReconnectRequest reconnectrequest) {
    final WalkerConnection connection = (WalkerConnection) reconnectrequest.getConnectionEditPart().getModel();
    if (!(connection instanceof Relationship)) {
        return null;
    }
    final Relationship relation = (Relationship) connection;
    if (relation.getSourceWalker() == relation.getTargetWalker()) {
        return null;
    }
    final DiagramWalker newTarget = ((DiagramWalker) reconnectrequest.getTarget().getModel()).toMaterialize();
    if (!relation.getTargetWalker().equals(newTarget)) {
        return null;
    }
    final DiagramWalkerEditPart targetEditPart = (DiagramWalkerEditPart) reconnectrequest.getConnectionEditPart().getTarget();
    final Point location = new Point(reconnectrequest.getLocation());
    final IFigure targetFigure = targetEditPart.getFigure();
    targetFigure.translateToRelative(location);
    int xp = -1;
    int yp = -1;
    final Rectangle bounds = targetFigure.getBounds();
    final Rectangle centerRectangle =
            new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);
    if (!centerRectangle.contains(location)) {
        final Point point = ERTableEditPart.getIntersectionPoint(location, targetFigure);
        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }
    final ReconnectTargetCommand command = new ReconnectTargetCommand(relation, xp, yp);
    return command;
}
 
Example 13
Source File: DiagramWalkerGraphicalNodeEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected Command getReconnectSourceCommand(ReconnectRequest reconnectrequest) {
    final WalkerConnection connection = (WalkerConnection) reconnectrequest.getConnectionEditPart().getModel();
    if (!(connection instanceof Relationship)) {
        return null;
    }
    final Relationship relation = (Relationship) connection;
    if (relation.getSourceWalker() == relation.getTargetWalker()) {
        return null;
    }
    final DiagramWalker newSource = ((DiagramWalker) reconnectrequest.getTarget().getModel()).toMaterialize();
    if (!relation.getSourceWalker().equals(newSource)) {
        return null;
    }
    final DiagramWalkerEditPart sourceEditPart = (DiagramWalkerEditPart) reconnectrequest.getConnectionEditPart().getSource();
    final Point location = new Point(reconnectrequest.getLocation());
    final IFigure sourceFigure = sourceEditPart.getFigure();
    sourceFigure.translateToRelative(location);
    int xp = -1;
    int yp = -1;
    final Rectangle bounds = sourceFigure.getBounds();
    final Rectangle centerRectangle =
            new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);
    if (!centerRectangle.contains(location)) {
        final Point point = ERTableEditPart.getIntersectionPoint(location, sourceFigure);
        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }
    final ReconnectSourceCommand command = new ReconnectSourceCommand(relation, xp, yp);
    return command;
}
 
Example 14
Source File: EnlargeContainerEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void showContainerFeedback(ChangeBoundsRequest request) {
	for (IGraphicalEditPart containerEditPart : containerHierachy) {
		IFigure containerFigure = containerEditPart.getFigure();
		Rectangle feedbackBounds = getOriginalBounds(containerFigure);
		containerFigure.getParent().translateToAbsolute(feedbackBounds);
		feedbackBounds = calculateFeedbackBounds(request, feedbackBounds, containerFigure);
		containerFigure.translateToRelative(feedbackBounds);
		setBounds(containerFigure, feedbackBounds);
		EditPolicy editPolicy = containerEditPart.getEditPolicy(FixedBendpointEditPolicy.ROLE);
		if (editPolicy != null) {
			editPolicy.showSourceFeedback(request);
		}
	}
}
 
Example 15
Source File: DirectEditManagerEx.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void placeBorder() {
	if (showingFeedback) {
		IFigure shadow = getCellEditorFrame();
		Rectangle rect = new Rectangle(getCellEditor().getControl()
				.getBounds());
		rect.expand(shadow.getInsets());
		shadow.translateToRelative(rect);
		shadow.setBounds(rect);
	}
}
 
Example 16
Source File: ERDiagramLayoutEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void showSizeOnDropFeedback(final CreateRequest request) {
    final Point p = new Point(request.getLocation().getCopy());

    final ZoomManager zoomManager = ((ScalableFreeformRootEditPart) getHost().getRoot()).getZoomManager();
    final double zoom = zoomManager.getZoom();

    final IFigure feedback = getSizeOnDropFeedback(request);

    final Dimension size = request.getSize().getCopy();
    feedback.translateToRelative(size);
    feedback.setBounds(new Rectangle((int) (p.x * zoom), (int) (p.y * zoom), size.width, size.height).expand(getCreationFeedbackOffset(request)));
}
 
Example 17
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectSourceCommand(final ReconnectRequest reconnectrequest) {
    final ConnectionElement connection = (ConnectionElement) reconnectrequest.getConnectionEditPart().getModel();

    if (connection.getSource() == connection.getTarget()) {
        return null;
    }

    final NodeElement newSource = (NodeElement) reconnectrequest.getTarget().getModel();
    if (connection.getSource() != newSource) {
        return null;
    }

    final NodeElementEditPart sourceEditPart = (NodeElementEditPart) reconnectrequest.getConnectionEditPart().getSource();

    final Point location = new Point(reconnectrequest.getLocation());

    final IFigure sourceFigure = sourceEditPart.getFigure();
    sourceFigure.translateToRelative(location);

    int xp = -1;
    int yp = -1;

    final Rectangle bounds = sourceFigure.getBounds();

    final Rectangle centerRectangle = new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

    if (!centerRectangle.contains(location)) {
        final Point point = NodeElementEditPart.getIntersectionPoint(location, sourceFigure);
        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }

    final ReconnectSourceCommand command = new ReconnectSourceCommand(connection, xp, yp);

    return command;
}
 
Example 18
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static void translateToRelative(final IFigure owner, final Rectangle b) {
    owner.translateToRelative(b);
}
 
Example 19
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectSourceCommand(
		ReconnectRequest reconnectrequest) {
	ConnectionElement connection = (ConnectionElement) reconnectrequest
			.getConnectionEditPart().getModel();

	if (!(connection instanceof Relation)) {
		return null;
	}

	Relation relation = (Relation) connection;

	if (relation.getSource() == relation.getTarget()) {
		return null;
	}

	NodeElement newSource = (NodeElement) reconnectrequest.getTarget().getModel();
	if (!relation.getSource().equals(newSource)) {
		return null;
	}

	NodeElementEditPart sourceEditPart = (NodeElementEditPart) reconnectrequest
			.getConnectionEditPart().getSource();

	Point location = new Point(reconnectrequest.getLocation());

	IFigure sourceFigure = sourceEditPart.getFigure();
	sourceFigure.translateToRelative(location);

	int xp = -1;
	int yp = -1;

	Rectangle bounds = sourceFigure.getBounds();

	Rectangle centerRectangle = new Rectangle(
			bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4),
			bounds.width / 2, bounds.height / 2);

	if (!centerRectangle.contains(location)) {
		Point point = ERTableEditPart.getIntersectionPoint(location,
				sourceFigure);
		xp = 100 * (point.x - bounds.x) / bounds.width;
		yp = 100 * (point.y - bounds.y) / bounds.height;
	}

	ReconnectSourceCommand command = new ReconnectSourceCommand(relation,
			xp, yp);

	return command;
}
 
Example 20
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectTargetCommand(
		ReconnectRequest reconnectrequest) {
	ConnectionElement connection = (ConnectionElement) reconnectrequest
			.getConnectionEditPart().getModel();

	if (!(connection instanceof Relation)) {
		return null;
	}

	Relation relation = (Relation) connection;

	if (relation.getSource() == relation.getTarget()) {
		return null;
	}

	NodeElement newTarget = (NodeElement) reconnectrequest.getTarget()
			.getModel();
	if (!relation.getTarget().equals(newTarget)) {
		return null;
	}

	NodeElementEditPart targetEditPart = (NodeElementEditPart) reconnectrequest
			.getConnectionEditPart().getTarget();

	Point location = new Point(reconnectrequest.getLocation());

	IFigure targetFigure = targetEditPart.getFigure();
	targetFigure.translateToRelative(location);

	int xp = -1;
	int yp = -1;

	Rectangle bounds = targetFigure.getBounds();

	Rectangle centerRectangle = new Rectangle(
			bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4),
			bounds.width / 2, bounds.height / 2);

	if (!centerRectangle.contains(location)) {
		Point point = ERTableEditPart.getIntersectionPoint(location,
				targetFigure);

		xp = 100 * (point.x - bounds.x) / bounds.width;
		yp = 100 * (point.y - bounds.y) / bounds.height;
	}
	ReconnectTargetCommand command = new ReconnectTargetCommand(relation,
			xp, yp);

	return command;
}