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

The following examples show how to use org.eclipse.draw2d.geometry.Rectangle#getTopLeft() . 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: MasterPageLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private Rectangle convertRectangle( Rectangle bounds, Rectangle clientArea )
{
	Rectangle b = bounds.getCopy( );

	b.width = clientArea.width;

	if ( b.x == 0 )
	{
		b.x = clientArea.getTopLeft( ).x;
		b.y = clientArea.getTopLeft( ).y;
	}
	else
	{
		b.x = clientArea.getBottomLeft( ).x;
		b.y = clientArea.getBottomLeft( ).y
				- ( ( b.height < 0 ) ? MasterPageLayout.MINIMUM_HEIGHT
						: b.height );
	}
	return b;

}
 
Example 2
Source File: CollapsableEventSubprocessFigure.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	if(useGradient){
		Rectangle r = getBounds().getCopy();
		Point topLeft = r.getTopLeft();
		Point bottomRight = r.getBottomRight();
		Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x +2,
				topLeft.y+2 , bottomRight.x-2, bottomRight.y-2,gradientColor,255,getBackgroundColor(),90);
		graphics.setBackgroundPattern(pattern);
		graphics.fillRectangle(r.crop(new Insets(2,2,2,2)));
		graphics.setBackgroundPattern(null);
		pattern.dispose();
	}else{
		super.fillShape(graphics) ;
	}

}
 
Example 3
Source File: AbstractSwitchLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param zoom 
 * 
 */
private void showSelectionForAddTop(double zoom) {
	if (!isOnTop()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp));
		f.setParent(getHostFigure());
		f.setSize(20, 20);



		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}


		Point location = new Point(bounds.getTopLeft().x+20,bounds.getTopLeft().y-20) ;

		f.setLocation(location);
		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP));
		getLayer(LayerConstants.HANDLE_LAYER).add(f);
		figures.add(f);
	}
}
 
Example 4
Source File: DropDownMenuEventFigure.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void createSubMenuFigure() {
	subMenuFigure = new RoundedRectangle();
	subMenuFigure.setAlpha(50);
	subMenuFigure.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
	subMenuFigure.setSize(new Dimension(4*20,figureList.size()*20));
	Rectangle parentBounds = parent.getBounds();
	Point newPointLocation = new Point(parentBounds.getTopLeft().x,parentBounds.getTopLeft().y+40);
	subMenuFigure.setLocation(newPointLocation);
	subMenuFigure.setVisible(false);
	parent.add(subMenuFigure);
}
 
Example 5
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 );
}
 
Example 6
Source File: SelectionFeedbackEditPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public SelectionFeedbackEditPolicy(final EClass eClass) {

	feedBackFigure = new RoundedRectangle(){
		protected void fillShape(Graphics graphics) {
			Rectangle r = getBounds() ;

			Point topLeft = r.getTopLeft();
			Point bottomRight = r.getBottomRight();
			Color backGroundColor = null ;
			if(useSelectionColor){
				backGroundColor = ColorRegistry.getInstance().getColor(selectionColor) ;
			}else{
				backGroundColor=FiguresHelper.getFeedbackColor(eClass) ;
			}


			Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
					topLeft.y, bottomRight.x, bottomRight.y,
					backGroundColor,30, backGroundColor,60);

			graphics.setBackgroundPattern(pattern);
			graphics.fillRoundRectangle(r, 20, 20) ;
			graphics.setAlpha(0) ;
			graphics.setBackgroundPattern(null);	
			pattern.dispose();

		};
	} ;


	figureListener = new FigureListener() {

		public void figureMoved(IFigure source) {
			hideFeedback();
			List<?> selectedEditPart = getHost().getViewer().getSelectedEditParts() ;
			if(selectedEditPart.contains(getHost())){

				if(!figureIsDisplayed()){
					showFeedback(zoomManager.getZoom());
				}
			}
		}
	};

}
 
Example 7
Source File: CustomFeedbackXYLayoutPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override to compute position of Subprocess event children when changing parent
 */
@Override
protected Command createAddCommand(final EditPart child, final Object constraint) {
    if (child instanceof CustomSubProcessEvent2EditPart && constraint instanceof Rectangle) {
        final Rectangle rect = (Rectangle) constraint;

        final CompoundCommand cmds = new CompoundCommand("Move Subprocesss Event");

        ICommand boundsCommand = new SetBoundsCommand(((ShapeEditPart) child).getEditingDomain(),
                DiagramUIMessages.SetLocationCommand_Label_Resize,
                new EObjectAdapter((View) child.getModel()),
                rect.getTopLeft());

        cmds.add(new ICommandProxy(boundsCommand));

        ShapeCompartmentEditPart compartment = null;
        for (final Object c : child.getChildren()) {
            if (c instanceof ShapeCompartmentEditPart) {
                compartment = (ShapeCompartmentEditPart) c;
            }
        }

        final Location origin = (Location) ((Node) child.getModel()).getLayoutConstraint();
        for (final Object ep : compartment.getChildren()) {
            if (ep instanceof IGraphicalEditPart) {
                final Node view = (Node) ((IGraphicalEditPart) ep).getModel();
                final Location loc = (Location) view.getLayoutConstraint();
                final Point delta = new Point(loc.getX() - origin.getX(), loc.getY() - origin.getY());

                final Point newLoc = new Point(rect.getTopLeft().x + delta.x, rect.getTopLeft().y + delta.y);

                boundsCommand = new SetBoundsCommand(((IGraphicalEditPart) ep).getEditingDomain(),
                        DiagramUIMessages.SetLocationCommand_Label_Resize,
                        new EObjectAdapter((View) ((IGraphicalEditPart) ep).getModel()),
                        newLoc);

                cmds.add(new ICommandProxy(boundsCommand));
            }
        }

        return cmds.unwrap();
    } else {
        return super.createAddCommand(child, constraint);
    }

}