Java Code Examples for org.eclipse.draw2d.geometry.Rectangle#union()

The following examples show how to use org.eclipse.draw2d.geometry.Rectangle#union() . 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: LaneFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * This is a copy of the parent method. Only change is that we call getContraintAsRectangle() instead of directly accessing the constraints member.
 */
@Override
protected Dimension calculatePreferredSize(IFigure f, int wHint, int hHint) {
	final Rectangle rect = new Rectangle();
	final ListIterator children = f.getChildren().listIterator();
	while (children.hasNext()) {
		final IFigure child = (IFigure) children.next();
		Rectangle r = getConstraintAsRectangle(child);
		if (r == null)
			continue;

		if ((r.width == -1) || (r.height == -1)) {
			final Dimension preferredSize = child.getPreferredSize(r.width, r.height);
			r = r.getCopy();
			if (r.width == -1)
				r.width = preferredSize.width;
			if (r.height == -1)
				r.height = preferredSize.height;
		}
		rect.union(r);
	}
	final Dimension d = rect.getSize();
	final Insets insets = f.getInsets();
	return new Dimension(d.width + insets.getWidth(), d.height + insets.getHeight()).union(getBorderPreferredSize(f));
}
 
Example 2
Source File: GroupStatesIntoCompositeRefactoring.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Iterates through all {@link StateEditPart}s of the current selection and
 * computes layout constraints for the composite node.
 * 
 * @param compositeStateNode
 *            node of the composite state
 */
protected void setCompositeStateLayoutConstraint(Node compositeStateNode) {

	Rectangle newbounds = null;
	
	for (GraphicalEditPart editPart : getContextObjects()) {
		Rectangle childBounds = editPart.getFigure().getBounds();
		if (newbounds == null)
			newbounds = childBounds.getCopy();
		
		newbounds.union(childBounds);
	}
	newbounds.expand(new Insets(PADDING, PADDING, PADDING, PADDING));

	Bounds bounds = NotationFactory.eINSTANCE.createBounds();
	bounds.setX(newbounds.x);
	bounds.setY(newbounds.y);
	bounds.setWidth(newbounds.width);
	bounds.setHeight(newbounds.height);
	compositeStateNode.setLayoutConstraint(bounds);
}
 
Example 3
Source File: CrosstabTableEditPart.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return select bounds
 */
public Rectangle getSelectBounds( )
{
	List list = TableUtil.getSelectionCells( this );
	int size = list.size( );
	ITableLayoutCell[] parts = new ITableLayoutCell[size];
	list.toArray( parts );

	ITableLayoutCell[] caleNumber = getMinAndMaxNumber( parts );
	ITableLayoutCell minRow = caleNumber[0];
	ITableLayoutCell maxColumn = caleNumber[3];

	Rectangle min = ( (CrosstabCellEditPart) minRow ).getBounds( )
			.getCopy( );
	Rectangle max = ( (CrosstabCellEditPart) maxColumn ).getBounds( )
			.getCopy( );

	return min.union( max );
}
 
Example 4
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 5
Source File: TableEditPart.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return select bounds
 */
public Rectangle getSelectBounds( )
{
	if ( getSelectRowAndColumnRect( ) != null )
	{
		return getSelectRowAndColumnRect( );
	}
	List list = TableUtil.getSelectionCells( this );
	int size = list.size( );
	TableCellEditPart[] parts = new TableCellEditPart[size];
	list.toArray( parts );

	TableCellEditPart[] caleNumber = getMinAndMaxNumber( parts );
	TableCellEditPart minRow = caleNumber[0];
	TableCellEditPart maxColumn = caleNumber[3];

	Rectangle min = minRow.getBounds( ).getCopy( );
	Rectangle max = maxColumn.getBounds( ).getCopy( );

	return min.union( max );
}
 
Example 6
Source File: LayoutManager.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected Dimension calculatePreferredSize(IFigure container, int hint,
		int hint2) {
	container.validate();
	List<IFigure> children = container.getChildren();
	Rectangle result = new Rectangle().setLocation(container.getClientArea().getLocation());
	for (IFigure child : children)
		result.union(child.getBounds());
	result.resize(container.getInsets().getWidth(), container.getInsets().getHeight());
	return result.getSize();
}
 
Example 7
Source File: GraphLayoutManager.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Dimension calculatePreferredSize(IFigure container, int hint,
		int hint2) {
	container.validate();
	List<?> children = container.getChildren();
	Rectangle result = new Rectangle().setLocation(container.getClientArea().getLocation());
	for (int i = 0; i < children.size(); i++) {
		result.union(((IFigure) children.get(i)).getBounds());
	}
	result.resize(container.getInsets().getWidth(), container.getInsets().getHeight());
	return result.getSize();
}
 
Example 8
Source File: DeferredGraphicalViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void reveal( EditPart part )
{
	// In some case, the editor control is not created, but get the sync selection event.
	// Fix this problem temporary.
	if(getFigureCanvas( )==null || getFigureCanvas( ).isDisposed( ))
	{
		return;
	}
	
	Viewport port = getFigureCanvas( ).getViewport( );
	IFigure target = ( (GraphicalEditPart) part ).getFigure( );

	Rectangle exposeRegion = target.getBounds( ).getCopy( );

	// Get the primary editpolicy
	EditPolicy policy = part.getEditPolicy( EditPolicy.PRIMARY_DRAG_ROLE );

	// If the policy let us access the handles, proceed, otherwise
	// default to original behaviour
	if ( !( policy instanceof ISelectionHandlesEditPolicy ) )
	{
		super.reveal( part );
		return;
	}

	// First translate exposeRegion to the root level
	target = target.getParent( );
	while ( target != null && target != port )
	{
		target.translateToParent( exposeRegion );
		target = target.getParent( );
	}

	// Merge selection handles if any to the exposeRegion
	List handles = ( (ISelectionHandlesEditPolicy) policy ).getHandles( );
	for ( Iterator iter = handles.iterator( ); iter.hasNext( ); )
	{
		AbstractHandle handle = (AbstractHandle) iter.next( );

		Locator locator = handle.getLocator( );
		locator.relocate( handle );
		exposeRegion.union( handle.getBounds( ).getCopy( ) );
	}

	exposeRegion.getExpanded( 5, 5 );

	Dimension viewportSize = port.getClientArea( ).getSize( );

	Point topLeft = exposeRegion.getTopLeft( );
	Point bottomRight = exposeRegion.getBottomRight( )
			.translate( viewportSize.getNegated( ) );
	Point finalLocation = new Point( );
	if ( viewportSize.width < exposeRegion.width )
		finalLocation.x = Math.min( bottomRight.x, Math.max( topLeft.x,
				port.getViewLocation( ).x ) );
	else
		finalLocation.x = Math.min( topLeft.x, Math.max( bottomRight.x,
				port.getViewLocation( ).x ) );

	if ( viewportSize.height < exposeRegion.height )
		finalLocation.y = Math.min( bottomRight.y, Math.max( topLeft.y,
				port.getViewLocation( ).y ) );
	else
		finalLocation.y = Math.min( topLeft.y, Math.max( bottomRight.y,
				port.getViewLocation( ).y ) );

	getFigureCanvas( ).scrollSmoothTo( finalLocation.x, finalLocation.y );
}