Java Code Examples for org.eclipse.draw2d.Viewport#getClientArea()

The following examples show how to use org.eclipse.draw2d.Viewport#getClientArea() . 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: ReportRootEditPart.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given point is inside the
 * viewport, but near its edge.
 * 
 * @see org.eclipse.gef.AutoexposeHelper#detect(org.eclipse.draw2d.geometry.Point)
 */
public boolean detect( Point where )
{
	lastStepTime = 0;
	Viewport port = findViewport( owner );
	Rectangle rect = Rectangle.SINGLETON;
	port.getClientArea( rect );
	port.translateToParent( rect );
	port.translateToAbsolute( rect );
	return rect.contains( where )
			&& !rect.crop( threshold ).contains( where );
}
 
Example 2
Source File: ReportRootEditPart.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns <code>true</code> if the given point is outside the
 * viewport or near its edge. Scrolls the viewport by a calculated (time
 * based) amount in the current direction.
 * 
 * todo: investigate if we should allow auto expose when the pointer is
 * outside the viewport
 * 
 * @see org.eclipse.gef.AutoexposeHelper#step(org.eclipse.draw2d.geometry.Point)
 */
public boolean step( Point where )
{
	Viewport port = findViewport( owner );

	Rectangle rect = Rectangle.SINGLETON;
	port.getClientArea( rect );
	port.translateToParent( rect );
	port.translateToAbsolute( rect );
	if ( !rect.contains( where )
			|| rect.crop( threshold ).contains( where ) )
		return false;

	// set scroll offset (speed factor)
	int scrollOffset = 0;

	// calculate time based scroll offset
	if ( lastStepTime == 0 )
		lastStepTime = System.currentTimeMillis( );

	DeferredGraphicalViewer.OriginStepData stepData = ( (DeferredGraphicalViewer) owner.getViewer( ) ).getOriginStepData( );
	long difference = System.currentTimeMillis( ) - lastStepTime;

	if ( difference > 0 )
	{
		scrollOffset = ( (int) difference / 3 );
		lastStepTime = System.currentTimeMillis( );
	}

	if ( scrollOffset == 0 )
		return true;

	rect.crop( threshold );

	int region = rect.getPosition( where );
	Point loc = port.getViewLocation( );

	if ( ( region & PositionConstants.SOUTH ) != 0 )
		loc.y += scrollOffset;
	else if ( ( region & PositionConstants.NORTH ) != 0 )
		loc.y -= scrollOffset;

	if ( ( region & PositionConstants.EAST ) != 0 )
		loc.x += scrollOffset;
	else if ( ( region & PositionConstants.WEST ) != 0 )
		loc.x -= scrollOffset;

	if ( stepData.minX > loc.x )
		loc.x = port.getHorizontalRangeModel( ).getValue( );
	if ( stepData.maxX - stepData.extendX < loc.x )
		loc.x = port.getHorizontalRangeModel( ).getValue( );
	if ( stepData.minY > loc.y )
		loc.y = port.getVerticalRangeModel( ).getValue( );
	if ( stepData.maxY - stepData.extendY < loc.y )
		loc.y = port.getVerticalRangeModel( ).getValue( );
	port.setViewLocation( loc );

	return true;
}