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

The following examples show how to use org.eclipse.draw2d.IFigure#translateToAbsolute() . 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: 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 2
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Click on one of the lane size control (+,-)
 *
 * @param pLane
 * @param pLaneSizeId (see org.bonitasoft.studio.qa.util.SWTBotConstants.java)
 */
public void updateLaneSize(final String pLane, final int pLaneSizeId) {
    SWTBotGefEditPart element;
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(pLane);
    Assert.assertNotNull("Error: No Edit Part \'" + pLane + "\' found.", gep);
    element = gep.parent();
    element.select();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    final UpdateSizeLaneSelectionEditPolicy updateSizeLaneEditPolicy = (UpdateSizeLaneSelectionEditPolicy) graphicalEditPart
            .getEditPolicy(UpdateSizeLaneSelectionEditPolicy.UPDATE_LANE_SIZE_SELECTION_FEEDBACK_ROLE);
    final IFigure toolbarFigure = updateSizeLaneEditPolicy.getFigure(pLaneSizeId);

    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    gmfEditor.click(location.x, location.y);
}
 
Example 3
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convenient method to translate bounds to Absolute coordinate
 *
 * @param owner
 * @param b
 */
public static void translateToAbsolute(final IFigure owner, final Rectangle b) {
    owner.translateToAbsolute(b);
    IFigure parentFigure = owner.getParent();
    while (parentFigure != null) {
        if (parentFigure instanceof Viewport) {
            final Viewport viewport = (Viewport) parentFigure;
            b.translate(
                    viewport.getHorizontalRangeModel().getValue(),
                    viewport.getVerticalRangeModel().getValue());
            parentFigure = parentFigure.getParent();
        }
        else {
            parentFigure = parentFigure.getParent();
        }
    }
}
 
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: TableUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the union bounds for all the tabelCell in the given List.
 * 
 * @param list
 * @return
 */
public static Rectangle getUnionBounds( List list )
{

	int size = list.size( );
	if ( size == 0 )
	{
		return new Rectangle( );
	}
	IFigure figure = ( (GraphicalEditPart) list.get( 0 ) ).getFigure( );
	Rectangle retValue = figure.getBounds( ).getCopy( );

	for ( int i = 1; i < size; i++ )
	{
		GraphicalEditPart cellPart = (GraphicalEditPart) list.get( i );
		retValue.union( cellPart.getFigure( ).getBounds( ) );
	}
	retValue.shrink( 2, 2 );
	figure.translateToAbsolute( retValue );

	return retValue;
}
 
Example 6
Source File: Connection.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Point getLocation(Point reference) {
	IFigure owner = getOwner();
	Rectangle bounds = owner.getBounds().getCopy();
	owner.translateToAbsolute(bounds);
	if (reference.x < bounds.getLeft().x) {
		return bounds.getLeft();
	} else {
		return bounds.getRight();
	}
}
 
Example 7
Source File: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void increasePoolWidth(final SWTBotGefEditor editor, final String poolName) {
    final SWTBotGefEditPart poolPart = editor.getEditPart(poolName).parent();
    poolPart.select();

    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) poolPart.part();
    final UpdateSizePoolSelectionEditPolicy addPoolSizeElementEditPolicy = (UpdateSizePoolSelectionEditPolicy) graphicalEditPart
            .getEditPolicy(UpdateSizePoolSelectionEditPolicy.UPDATE_POOL_SIZE_SELECTION_FEEDBACK_ROLE);

    final IFigure toolbarFigure = addPoolSizeElementEditPolicy.getFigure(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT);
    final Point location = toolbarFigure.getBounds().getCenter().getCopy();
    toolbarFigure.translateToAbsolute(location);
    editor.click(location.x, location.y);
}
 
Example 8
Source File: RootDragTracker.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private List calculateNewSelection( )
{

	List newSelections = new ArrayList( );
	List children = getAllChildren( );

	// Calculate new selections based on which children fall
	// inside the marquee selection rectangle. Do not select
	// children who are not visible
	for ( int i = 0; i < children.size( ); i++ )
	{
		EditPart child = (EditPart) children.get( i );
		if ( !child.isSelectable( ) || isInTable( child ) )
			continue;
		IFigure figure = ( (GraphicalEditPart) child ).getFigure( );
		Rectangle r = figure.getBounds( ).getCopy( );
		figure.translateToAbsolute( r );

		if ( getMarqueeSelectionRectangle( ).contains( r.getTopLeft( ) )
				&& getMarqueeSelectionRectangle( ).contains( r.getBottomRight( ) )
				&& figure.isShowing( )
				&& child.getTargetEditPart( MARQUEE_REQUEST ) == child
				&& isFigureVisible( figure ) )
			newSelections.add( child );

	}
	return newSelections;
}
 
Example 9
Source File: CopyPasteTests.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testCopyPaste() {
    SWTBotTestUtil.createNewDiagram(bot);
    final SWTBotGefEditor editor1 = bot.gefEditor(bot.activeEditor().getTitle());
    SWTBotGefEditPart part = editor1.getEditPart("Step1").parent();
    part.select();
    bot.viewById(SWTBotTestUtil.VIEWS_PROPERTIES_PROCESS_GENERAL).show();
    bot.viewById(SWTBotTestUtil.VIEWS_PROPERTIES_PROCESS_GENERAL).setFocus();
    SWTBotTestUtil.selectTabbedPropertyView(bot, "General");
    final NextElementEditPolicy policy = (NextElementEditPolicy) part.part()
            .getEditPolicy(NextElementEditPolicy.NEXT_ELEMENT_ROLE);
    final IFigure textAnnotationFigure = policy.getTextAnnotationFigure();
    final Point location = textAnnotationFigure.getBounds().getCenter().getCopy();
    textAnnotationFigure.translateToAbsolute(location);
    editor1.drag(location.x, location.y, 200, 200);
    part.select();
    editor1.clickContextMenu("Copy");
    SWTBotTestUtil.createNewDiagram(bot);
    SWTBotGefEditor editor2 = bot.gefEditor(bot.activeEditor().getTitle());
    editor2.click(200, 200);
    editor2.clickContextMenu("Paste");
    final MainProcess diagram1 = getLabelFromEditor(editor1);
    final MainProcess diagram2 = getLabelFromEditor(editor2);
    editor2.saveAndClose();
    waitForcloseAction(editor1);
    editor1.saveAndClose();
    waitForcloseAction(editor2);

    final BotOpenDiagramDialog botOpenDiagramDialog = new BotApplicationWorkbenchWindow(bot).open();
    botOpenDiagramDialog.selectDiagram(diagram1.getName(), diagram1.getVersion()).delete()
            .selectDiagram(diagram2.getName(), diagram2.getVersion()).open();
    editor2 = bot.gefEditor(bot.activeEditor().getTitle());
    part = editor2.getEditPart("Step1").parent();
    editor2.drag(part, 100, 100);
    bot.activeEditor().save();
    waitForSaveAction(editor2);
}
 
Example 10
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void routeInResponseToBoxDrag(ChangeBoundsRequest request) {
	if (connectionStart) {
		IFigure figure = getHostFigure();
		originalBounds = getHostFigure().getBounds().getCopy();
		figure.translateToAbsolute(originalBounds);
		originalBounds.translate(request.getMoveDelta().getNegated()).resize(request.getSizeDelta().getNegated());
		router.initBoxDrag(originalBounds, getSourceConnections(request), getTargetConnections(request));
		connectionStart = false;
	}
	router.updateBoxDrag(request.getTransformedRectangle(originalBounds));
}
 
Example 11
Source File: TreeLayoutEditPolicy.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Calculates FeedbackfigurePoint in absolute coordinates
 * 
 * @param childFigure
 * @param siblingList
 * @param lowerIndex
 * @param upperIndex
 * @return
 */
private Point getFeedBackFigurePoint(IFigure childFigure,
		List<IGraphicalEditPart> siblingList, int lowerIndex, int upperIndex) {
	final Point point = new Point();

	IFigure topFigure;
	IFigure bottomFigure;

	if (lowerIndex == siblingList.size()) {
		topFigure = siblingList.get(lowerIndex - 1).getFigure();
		bottomFigure = siblingList.get(upperIndex - 1).getFigure();
	} else {
		topFigure = siblingList.get(lowerIndex).getFigure();
		bottomFigure = siblingList.get(upperIndex).getFigure();
	}

	final Rectangle absTopFigBounds = topFigure.getBounds().getCopy();
	topFigure.translateToAbsolute(absTopFigBounds);

	final Rectangle absBottomFigBounds = bottomFigure.getBounds().getCopy();
	bottomFigure.translateToAbsolute(absBottomFigBounds);

	final Rectangle feedbackFigBounds = getFeedbackFigureBounds();
	topFigure.translateToAbsolute(feedbackFigBounds);

	point.x = absTopFigBounds.x
			- (feedbackFigBounds.width - absTopFigBounds.width) / 2;

	if (lowerIndex == 0 && upperIndex == 0) {
		// Top end
		point.y = absTopFigBounds.y
				+ (absBottomFigBounds.y - absTopFigBounds.y) / 2 - 5;
	} else if (lowerIndex == siblingList.size()
			&& upperIndex == siblingList.size()) {
		// bottom end
		point.y = absTopFigBounds.y
				+ (absBottomFigBounds.y - absTopFigBounds.y) / 2
				+ absBottomFigBounds.height + 5;
	} else {
		point.y = absTopFigBounds.y
				+ (absBottomFigBounds.y - absTopFigBounds.y) / 2
				+ absBottomFigBounds.height / 2;
	}
	return point;
}
 
Example 12
Source File: TreeLayoutUtil.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Calculates the new tree node list index based on the given location.
 * Currently works only with horizontal tree node alignment!
 * 
 * @param location
 * @param siblings
 * @return
 */
public static int getNewTreeNodePosition(Point location,
		List<IGraphicalEditPart> siblings) {

	int position = -1;

	if (siblings.isEmpty()) {
		return 0;
	}

	if (location != null) {
		int minPosDelta = Integer.MAX_VALUE;
		int minNegDelta = Integer.MIN_VALUE;
		int upperIndex = siblings.size() - 1;
		int lowerIndex = 0;
		for (int i = 0; i < siblings.size(); i++) {

			// convert to absolute coordinates to consider zoom level.
			final IFigure figure = siblings.get(i).getFigure();
			final Rectangle absoluteBounds = figure.getBounds().getCopy();
			figure.translateToAbsolute(absoluteBounds);

			// TODO: Look for Layout settings. Maybe layout is vertical
			// aligned.
			final int deltaY = location.y - absoluteBounds.y;

			if (deltaY > 0 && deltaY < minPosDelta) {
				if (siblings.size() == 1) {
					lowerIndex = 1;
					upperIndex = 1;
				} else {
					minPosDelta = deltaY;
					lowerIndex = i;
				}
			} else if (deltaY < 0 && deltaY > minNegDelta) {
				if (siblings.size() == 1) {
					lowerIndex = 0;
					upperIndex = 0;
				} else {
					minNegDelta = deltaY;
					upperIndex = i;
				}
			}
		}

		if (lowerIndex == 0 && upperIndex == 0) {
			position = 0;
		} else if (lowerIndex < upperIndex
				|| (siblings.size() == 1 && lowerIndex == 1 && upperIndex == 1)) {
			position = upperIndex;
		} else if (lowerIndex == siblings.size() - 1
				&& upperIndex == siblings.size() - 1) {
			position = upperIndex + 1;
		}
	}
	return position;
}
 
Example 13
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getNorthWestLocation(IFigure owner){
	Point topLeft = owner.getBounds().getTopLeft();
	Point p = new PrecisionPoint(topLeft.x+X_OFFSET, topLeft.y);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 14
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getNorthLocation(IFigure owner){
	Point top = owner.getBounds().getTop();
	Point p = new PrecisionPoint(top.x, top.y);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 15
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getGateNorthWestLocation(IFigure owner){
	Point topLeft = owner.getBounds().getTopLeft();
	Point p = new PrecisionPoint(topLeft.x+X_GATE_OFFSET, topLeft.y+Y_GATE_OFFSET);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 16
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getWestSouthLocation(IFigure owner){
	Point bottomLeft = owner.getBounds().getBottomLeft();
	Point p = new PrecisionPoint(bottomLeft.x , bottomLeft.y - Y_OFFSET);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 17
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getGateEastLocation(IFigure owner){
	Point right = owner.getBounds().getRight();
	Point p = new PrecisionPoint(right.x, right.y+1);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 18
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getGateNorthLocation(IFigure owner){
	Point top = owner.getBounds().getTop();
	Point p = new PrecisionPoint(top.x+1, top.y);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 19
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getGateSouthEastLocation(IFigure owner) {
	Point bottom = owner.getBounds().getBottomRight();
	Point p = new PrecisionPoint(bottom.x-X_GATE_OFFSET, bottom.y-Y_GATE_OFFSET);
	owner.translateToAbsolute(p);
	return p ;
}
 
Example 20
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static Point getSouthLocation(IFigure owner){
	Point bottom = owner.getBounds().getBottom();
	Point p = new PrecisionPoint(bottom.x, bottom.y);
	owner.translateToAbsolute(p);
	return p ;
}