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

The following examples show how to use org.eclipse.gef.requests.ChangeBoundsRequest#getMoveDelta() . 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: 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 2
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private int getCurrentPositionZoomed( ChangeBoundsRequest request )
{

	int newPosition;
	if ( getGuideEditPart( ).isHorizontal( ) )
	{
		newPosition = getGuideEditPart( ).getZoomedPosition( )
				+ request.getMoveDelta( ).y;
	}
	else
	{
		newPosition = getGuideEditPart( ).getZoomedPosition( )
				+ request.getMoveDelta( ).x;
	}
	return newPosition;
}
 
Example 3
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public Command getCommand( Request request )
{
	Command cmd;
	final ChangeBoundsRequest req = (ChangeBoundsRequest) request;
	if ( isDeleteRequest( req ) )
	{
		cmd = getGuideEditPart( ).getRulerProvider( )
				.getDeleteGuideCommand( getHost( ).getModel( ) );
	}
	else
	{
		int pDelta;
		if ( getGuideEditPart( ).isHorizontal( ) )
		{
			pDelta = req.getMoveDelta( ).y;
		}
		else
		{
			pDelta = req.getMoveDelta( ).x;
		}
		if ( isMoveValid( getGuideEditPart( ).getZoomedPosition( ) + pDelta ) )
		{
			ZoomManager zoomManager = getGuideEditPart( ).getZoomManager( );
			if ( zoomManager != null )
			{
				pDelta = (int) Math.round( pDelta / zoomManager.getZoom( ) );
			}
			cmd = getGuideEditPart( ).getRulerProvider( )
					.getMoveGuideCommand( getHost( ).getModel( ), pDelta );
		}
		else
		{
			cmd = UnexecutableCommand.INSTANCE;
		}
	}
	return cmd;
}
 
Example 4
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 5
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Command getCommand(Request request) {
	if (!(request instanceof ChangeBoundsRequest))
		return null;
	ChangeBoundsRequest req = (ChangeBoundsRequest) request;
	Dimension sizeDelta = req.getSizeDelta();
	if (sizeDelta.height != 0 || sizeDelta.width != 0)
		return null;
	Command commandChain = null;
	for (Object o : req.getEditParts()) {
		if (!(o instanceof ProcessPart))
			continue;
		ProcessPart part = (ProcessPart) o;
		XYLayoutCommand command = new XYLayoutCommand();
		command.setProcessNode(part.getModel());
		Rectangle bounds = (part.getModel()).figure.getBounds().getCopy();
		part.getModel().figure.translateToAbsolute(bounds);
		Rectangle moveResize = new Rectangle(req.getMoveDelta(), sizeDelta);
		bounds.resize(moveResize.getSize());
		bounds.translate(moveResize.getLocation());
		part.getModel().figure.translateToRelative(bounds);
		command.setConstraint(bounds);
		if (commandChain == null) {
			commandChain = command;
		} else {
			commandChain = commandChain.chain(command);
		}
	}
	return commandChain;
}
 
Example 6
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void showSourceFeedback( Request request )
	{
		ChangeBoundsRequest req = (ChangeBoundsRequest) request;

		// add the placeholder guide figure to the ruler
		getHostFigure( ).getParent( ).add( getDummyGuideFigure( ), 0 );
		( (GraphicalEditPart) getHost( ).getParent( ) ).setLayoutConstraint(
				getHost( ), getDummyGuideFigure( ), Integer.valueOf(
						getGuideEditPart( ).getZoomedPosition( ) ) );
		getDummyGuideFigure( ).setBounds( getHostFigure( ).getBounds( ) );
		// add the invisible placeholder line figure to the primary viewer
		getGuideEditPart( ).getGuideLayer( ).add( getDummyLineFigure( ), 0 );
		getGuideEditPart( ).getGuideLayer( ).setConstraint(
				getDummyLineFigure( ),
				Boolean.valueOf( getGuideEditPart( ).isHorizontal( ) ) );
		//			getDummyLineFigure( ).setBounds(
		//					getGuideEditPart( ).getGuideLineFigure( ).getBounds( ) );
		getDummyLineFigure( ).setBounds( getDummyLineFigureBounds( req ) );
		//add the info label
		getGuideEditPart( ).getGuideLayer( ).add( getInfoLabel( ), 0 );
//		getGuideEditPart( ).getGuideLayer( ).setConstraint(
//				getInfoLabel( ),
//				Boolean.valueOf( getGuideEditPart( ).isHorizontal( ) ) );
		
		updateInfomation( getShowLable( req ) );
		
		// move the guide being dragged to the last index so that it's drawn
		// on
		// top of other guides
		List children = getHostFigure( ).getParent( ).getChildren( );
		children.remove( getHostFigure( ) );
		children.add( getHostFigure( ) );

		if ( isDeleteRequest( req ) )
		{
			getHostFigure( ).setVisible( false );
			getGuideEditPart( ).getGuideLineFigure( ).setVisible( false );
			getGuideEditPart( ).setCurrentCursor( SharedCursors.ARROW );
			eraseAttachedPartsFeedback( request );
		}
		else
		{
			int newPosition;
			if ( getGuideEditPart( ).isHorizontal( ) )
			{
				newPosition = getGuideEditPart( ).getZoomedPosition( )
						+ req.getMoveDelta( ).y;
			}
			else
			{
				newPosition = getGuideEditPart( ).getZoomedPosition( )
						+ req.getMoveDelta( ).x;
			}
			getHostFigure( ).setVisible( true );
			getGuideEditPart( ).getGuideLineFigure( ).setVisible( true );
			if ( isMoveValid( newPosition ) )
			{
				getGuideEditPart( ).setCurrentCursor( null );
				getGuideEditPart( ).updateLocationOfFigures( newPosition );
				showAttachedPartsFeedback( req );
			}
			else
			{
				getGuideEditPart( ).setCurrentCursor( SharedCursors.NO );
				getGuideEditPart( ).updateLocationOfFigures(
						getGuideEditPart( ).getZoomedPosition( ) );
				eraseAttachedPartsFeedback( request );
			}
		}
	}
 
Example 7
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private String getShowLable(ChangeBoundsRequest req)
	{
		int pDelta;
		if ( getGuideEditPart( ).isHorizontal( ) )
		{
			pDelta = req.getMoveDelta( ).y;
		}
		else
		{
			pDelta = req.getMoveDelta( ).x;
		}
		
		ZoomManager zoomManager = getGuideEditPart( ).getZoomManager( );
		if ( zoomManager != null )
		{
			pDelta = (int) Math.round( pDelta / zoomManager.getZoom( ) );
		}
		
		int marginValue = ((EditorRulerProvider)getGuideEditPart( ).getRulerProvider( )).getMarginValue( getHost( ).getModel( ), pDelta );
		
		ModuleHandle handle = SessionHandleAdapter.getInstance( )
		.getReportDesignHandle( );
//		MasterPageHandle page = SessionHandleAdapter.getInstance( )
//			.getFirstMasterPageHandle( handle );
		String unit = handle.getDefaultUnits( );


		if ( unit == null )
		{
			unit = DesignChoiceConstants.UNITS_IN;
		}
		double value = MetricUtility.pixelToPixelInch( marginValue );
		if ( value < 0.0 )
		{
			value = 0.0;
		}
		DimensionValue dim = DimensionUtil.convertTo( value,
				DesignChoiceConstants.UNITS_IN,
				unit );
		double showValue = dim.getMeasure( );
		String prefix = ((EditorRulerProvider)getGuideEditPart( ).getRulerProvider( )).getPrefixLabel( getHost( ).getModel( ) );
		return prefix + " "  + getShowValue( showValue )+ " " + getUnitDisplayName(unit)  + " (" + marginValue +" " + PIXELS_LABEL + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$;
	}