Java Code Examples for org.eclipse.draw2d.PositionConstants#WEST

The following examples show how to use org.eclipse.draw2d.PositionConstants#WEST . 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: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given the coordinates of the connection anchor point the shape's rectangle and the
 * orientation of the first rectilinear connection segment that comes out from the anchor
 * point the method detemines on which geographic side of the rectangle the anchor point
 * is located on.
 * 
 * @param anchorPoint coordinates of the anchor point
 * @param rectangle the shape's bounding rectangle
 * @param segmentOrientation orinetation of the segment coming out from the anchor point
 * @return geographic position of the anchor point relative to the rectangle
 */
private int getAnchorLocationBasedOnSegmentOrientation(Point anchorPoint, Rectangle rectangle, int segmentOrientation) {
    if (segmentOrientation == PositionConstants.VERTICAL) {
        if (Math.abs(anchorPoint.y - rectangle.y) < Math.abs(anchorPoint.y - rectangle.y - rectangle.height)) {
            return PositionConstants.NORTH;
        } else {
            return PositionConstants.SOUTH;
        }
    } else if (segmentOrientation == PositionConstants.HORIZONTAL) {
        if (Math.abs(anchorPoint.x - rectangle.x) < Math.abs(anchorPoint.x - rectangle.x - rectangle.width)) {
            return PositionConstants.WEST;
        } else {
            return PositionConstants.EAST;
        }
    }
    return PositionConstants.NONE;
}
 
Example 2
Source File: EditorRulerComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void setRulerContainer( GraphicalViewer container, int orientation )
{
	if ( orientation == PositionConstants.NORTH )
	{
		if ( top == container )
			return;
		disposeRulerViewer( top );
		top = container;
	}
	else if ( orientation == PositionConstants.WEST )
	{
		if ( left == container )
			return;
		disposeRulerViewer( left );
		left = container;
	}
}
 
Example 3
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines the relative to rectangle geographic location of a point.
 * Example: If shape is closer to the the top edge of the rectangle location
 * would be north.
 * Method used to determine which side of shape's bounding rectangle is closer
 * to connection's anchor point.
 * All geometric quantities must be in the same coordinate system.
 * 
 * @param anchorPoint location of the anchor point
 * @param rect bounding rectangle of the shape
 * @return
 */
private int getAnchorOffRectangleDirection(Point anchorPoint, Rectangle rect) {
    int position = PositionConstants.NORTH;
    int criteriaValue = Math.abs(anchorPoint.y - rect.y);
    int tempCriteria = Math.abs(anchorPoint.y - rect.y - rect.height);
    if (tempCriteria < criteriaValue) {
        criteriaValue = tempCriteria;
        position = PositionConstants.SOUTH;
    }

    tempCriteria = Math.abs(anchorPoint.x - rect.x);
    if (tempCriteria < criteriaValue) {
        criteriaValue = tempCriteria;
        position = PositionConstants.WEST;
    }

    tempCriteria = Math.abs(anchorPoint.x - rect.x - rect.width);
    if (tempCriteria < criteriaValue) {
        criteriaValue = tempCriteria;
        position = PositionConstants.EAST;
    }

    return position;
}
 
Example 4
Source File: CustomResizeHandle.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the handle with fill color and outline color dependent on the
 * primary selection status of the owner editpart.
 * 
 * @param g
 *            The graphics used to paint the figure.
 */
public void paintFigure(Graphics g) {
	Rectangle r = getBounds() ;
	switch (cursorDirection) {
	case PositionConstants.SOUTH_EAST:
		g.drawImage(Pics.getImage("resize_SE.gif"),r.getLocation()) ;
		break;
	case PositionConstants.NORTH:
		g.drawImage(Pics.getImage("resize_N.gif"),r.getLocation().translate(0, -2)) ;
		break;
	case PositionConstants.SOUTH:
		g.drawImage(Pics.getImage("resize_S.gif"),r.getLocation().translate(0, 5)) ;
		break;
	case PositionConstants.WEST:
		g.drawImage(Pics.getImage("resize_W.gif"),r.getLocation().translate(-2, 0)) ;
		break;
	case PositionConstants.EAST:
		g.drawImage(Pics.getImage("resize_E.gif"),r.getLocation().translate(5, 0)) ;
		break;
	default:
		break;
	}


}
 
Example 5
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates geographic position of a point located outside the given rectangle relative
 * to the rectangle
 * 
 * @param p point outside of rectangle
 * @param r the rectangle
 * @return geographic position of the point relative to the recatangle
 */
private int getOutisePointOffRectanglePosition(Point p, Rectangle r) {
    int position = PositionConstants.NONE;
    if (r.x > p.x) {
        position |= PositionConstants.WEST;
    } else if (r.x + r.width < p.x) {
        position |= PositionConstants.EAST;
    }
    if (r.y > p.y) {
        position |= PositionConstants.NORTH;
    } else if (r.y + r.height < p.y) {
        position |= PositionConstants.SOUTH;
    }
    return position;
}
 
Example 6
Source File: SWTBotTestUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static Point computeTargetLocation(final SWTBotGefEditor gmfEditor, final String sourceElement,
        final int position) {
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(sourceElement);
    Assert.assertNotNull("Error: No Edit Part \'" + sourceElement + "\' found.", gep);
    final SWTBotGefEditPart element = gep.parent();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();

    switch (position) {
        case PositionConstants.NORTH:
            return graphicalEditPart.getFigure().getBounds().getTop().getCopy().translate(-20, -Y_MARGIN);
        case PositionConstants.SOUTH:
            return graphicalEditPart.getFigure().getBounds().getBottom().getCopy().translate(-20, Y_MARGIN);
        case PositionConstants.WEST:
            return graphicalEditPart.getFigure().getBounds().getLeft().getCopy().translate(-X_MARGIN, 10);
        case PositionConstants.EAST:
            return graphicalEditPart.getFigure().getBounds().getRight().getCopy().translate(X_MARGIN, 10);
        case PositionConstants.NORTH_EAST:
            return graphicalEditPart.getFigure().getBounds().getTopRight().getCopy().translate(X_MARGIN, -Y_MARGIN);
        case PositionConstants.NORTH_WEST:
            return graphicalEditPart.getFigure().getBounds().getTopLeft().getCopy().translate(-X_MARGIN, Y_MARGIN);
        case PositionConstants.SOUTH_EAST:
            return graphicalEditPart.getFigure().getBounds().getBottomRight().getCopy().translate(-X_MARGIN, Y_MARGIN);
        case PositionConstants.SOUTH_WEST:
            return graphicalEditPart.getFigure().getBounds().getBottomLeft().getCopy().translate(X_MARGIN, -Y_MARGIN);
        default:
            throw new RuntimeException("Invalid position specified");
    }

}
 
Example 7
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether the rectilinear line segment coming out of the shape should be
 * horizontal or vertical based on the anchor geographic position relative to the shape
 * 
 * @param anchorRelativeLocation
 * @return
 */
private int getOffShapeDirection(int anchorRelativeLocation) {
    if (anchorRelativeLocation == PositionConstants.EAST || anchorRelativeLocation == PositionConstants.WEST) {
        return PositionConstants.HORIZONTAL;
    } else if (anchorRelativeLocation == PositionConstants.NORTH || anchorRelativeLocation == PositionConstants.SOUTH) {
        return PositionConstants.VERTICAL;
    }
    return PositionConstants.NONE;
}
 
Example 8
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Point computeTargetLocation(final String pSourceElement, final int pOrientation) {
    final SWTBotGefEditPart gep = gmfEditor.getEditPart(pSourceElement);
    Assert.assertNotNull("Error: No Edit Part \'" + pSourceElement + "\' found.", gep);
    final SWTBotGefEditPart element = gep.parent();
    final IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) element.part();
    switch (pOrientation) {
        case PositionConstants.NORTH:
            return graphicalEditPart.getFigure().getBounds().getTop().getCopy().translate(-30, -70);
        case PositionConstants.SOUTH:
            return graphicalEditPart.getFigure().getBounds().getBottom().getCopy().translate(-30, 70);
        case PositionConstants.WEST:
            return graphicalEditPart.getFigure().getBounds().getTopLeft().getCopy().translate(-140, 0);
        case PositionConstants.EAST:
            return graphicalEditPart.getFigure().getBounds().getTopRight().getCopy().translate(80, 0);
        case PositionConstants.NORTH_EAST:
            return graphicalEditPart.getFigure().getBounds().getTopRight().getCopy().translate(80, -70);
        case PositionConstants.NORTH_WEST:
            return graphicalEditPart.getFigure().getBounds().getTopLeft().getCopy().translate(-80, 70);
        case PositionConstants.SOUTH_EAST:
            return graphicalEditPart.getFigure().getBounds().getBottomRight().getCopy().translate(-80, 70);
        case PositionConstants.SOUTH_WEST:
            return graphicalEditPart.getFigure().getBounds().getBottomLeft().getCopy().translate(80, -70);
        default:
            throw new RuntimeException("Invalid position specified");
    }

}
 
Example 9
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a translation dimension for the anchor point. Translation dimension
 * translates the anchor point off the shape. The off shape direction
 * is specified by the relative to the shape geographic position of the anchor
 * 
 * @param position relative to the shape geographic position of the anchor
 * @param xFactorValue translation value along x-axis
 * @param yFactorValue translation value along y-axis
 * @return
 */
private Dimension getTranslationValue(int position, int xFactorValue, int yFactorValue) {
    Dimension translationDimension = new Dimension();
    if (position == PositionConstants.EAST) {
        translationDimension.width = xFactorValue;
    } else if (position == PositionConstants.SOUTH) {
        translationDimension.height = yFactorValue;
    } else if (position == PositionConstants.WEST) {
        translationDimension.width = -xFactorValue;
    } else if (position == PositionConstants.NORTH) {
        translationDimension.height = -yFactorValue;
    }
    return translationDimension;
}
 
Example 10
Source File: ReportFlowLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param request
 * @param child
 * @param constraintFor
 * @return
 */
protected Command createChangeConstraintCommand(
		ChangeBoundsRequest request, GraphicalEditPart child,
		Object constraintFor )
{

	ReportItemHandle handle = (ReportItemHandle) child.getModel( );

	SetConstraintCommand command = new SetConstraintCommand( );

	command.setModel( handle );

	int direction = request.getResizeDirection( );
	Dimension size = new Dimension( ( (Rectangle) constraintFor ).getSize( ) );

	if ( direction == PositionConstants.EAST
			|| direction == PositionConstants.WEST )
	{
		size.height = -1;
	}
	else if ( direction == PositionConstants.SOUTH
			|| direction == PositionConstants.NORTH )
	{
		size.width = -1;
	}

	command.setSize( size );

	return command;
}
 
Example 11
Source File: ReportElementResizablePolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles()
 */
protected List createSelectionHandles( )
{
	List list = new ArrayList( );

	if ( this.getResizeDirections( ) != -1 )
	{
		ReportResizableHandleKit.addMoveHandle( (GraphicalEditPart) getHost( ), list );
		if ( ( this.getResizeDirections( ) & PositionConstants.EAST ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.EAST );
		if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH_EAST ) == PositionConstants.SOUTH_EAST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.SOUTH_EAST );
		if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.SOUTH );
		if ( ( this.getResizeDirections( ) & PositionConstants.SOUTH_WEST ) == PositionConstants.SOUTH_WEST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.SOUTH_WEST );
		if ( ( this.getResizeDirections( ) & PositionConstants.WEST ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.WEST );
		if ( ( this.getResizeDirections( ) & PositionConstants.NORTH_WEST ) == PositionConstants.NORTH_WEST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.NORTH_WEST );
		if ( ( this.getResizeDirections( ) & PositionConstants.NORTH ) != 0 )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.NORTH );
		if ( ( this.getResizeDirections( ) & PositionConstants.NORTH_EAST ) == PositionConstants.NORTH_EAST )
			ReportResizableHandleKit.addHandle( (GraphicalEditPart) getHost( ),
					list,
					PositionConstants.NORTH_EAST );
	}
	else
		ReportResizableHandleKit.addHandles( (GraphicalEditPart) getHost( ), list );

	return list;
}
 
Example 12
Source File: CustomResizeHandle.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected DragTracker createDragTracker() {
	return new ResizeTracker(getOwner(), cursorDirection){
		@Override
		protected void updateSourceRequest() {
			ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
			Dimension d = getDragMoveDelta();

			Point location = new Point(getLocation());
			Point moveDelta = new Point(0, 0);
			Dimension resizeDelta = new Dimension(0, 0);

			if (getOwner() != null) {

				if(isContrained){
					request.setConstrainedResize(true);
					int origHeight = getOwner().getFigure().getBounds().height;
					int origWidth = getOwner().getFigure().getBounds().width;
					float ratio = 1;

					if (origWidth != 0 && origHeight != 0)
						ratio = ((float) origHeight / (float) origWidth);

					if (getResizeDirection() == PositionConstants.SOUTH_EAST) {
						if (d.height > (d.width * ratio))
							d.width = (int) (d.height / ratio);
						else
							d.height = (int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.NORTH_WEST) {
						if (d.height < (d.width * ratio))
							d.width = (int) (d.height / ratio);
						else
							d.height = (int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.NORTH_EAST) {
						if (-(d.height) > (d.width * ratio))
							d.width = -(int) (d.height / ratio);
						else
							d.height = -(int) (d.width * ratio);
					} else if (getResizeDirection() == PositionConstants.SOUTH_WEST) {
						if (-(d.height) < (d.width * ratio))
							d.width = -(int) (d.height / ratio);
						else
							d.height = -(int) (d.width * ratio);
					}
				}
			}else{
				request.setConstrainedResize(false);
			}

			request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1));

			if ((getResizeDirection() & PositionConstants.NORTH) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					resizeDelta.height -= d.height;
				}
				moveDelta.y += d.height;
				resizeDelta.height -= d.height;
			}
			if ((getResizeDirection() & PositionConstants.SOUTH) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					moveDelta.y -= d.height;
					resizeDelta.height += d.height;
				}
				resizeDelta.height += d.height;
			}
			if ((getResizeDirection() & PositionConstants.WEST) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					resizeDelta.width -= d.width;
				}
				moveDelta.x += d.width;
				resizeDelta.width -= d.width;
			}
			if ((getResizeDirection() & PositionConstants.EAST) != 0) {
				if (getCurrentInput().isControlKeyDown()) {
					moveDelta.x -= d.width;
					resizeDelta.width += d.width;
				}
				resizeDelta.width += d.width;
			}

			request.setMoveDelta(moveDelta);
			request.setSizeDelta(resizeDelta);
			request.setLocation(location);
			request.setEditParts(getOperationSet());

			request.getExtendedData().clear();
		}

		@Override
		protected List<IGraphicalEditPart> createOperationSet() {
			ArrayList<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>();
			for (Object selection : getCurrentViewer().getSelectedEditParts()) {
				if (isResizable((IGraphicalEditPart)selection)) {
					res.add((IGraphicalEditPart)selection);
				}
			}
			return res;
		}
	};
}
 
Example 13
Source File: ImageFigure.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	if ( isOpaque( ) )
	{
		if ( getBorder( ) instanceof BaseBorder )
		{
			graphics.fillRectangle( getBounds( ).getCopy( )
					.crop( ( (BaseBorder) getBorder( ) ).getBorderInsets( ) ) );
		}
		else
		{
			graphics.fillRectangle( getBounds( ) );
		}
	}

	if ( getImage( ) == null || getImage( ).isDisposed( ) )
	{
		return;
	}

	if ( stretch )
	{
		paintStretched( graphics );

		return;
	}

	int x, y;
	Rectangle area = getClientArea( );
	switch ( alignment & PositionConstants.NORTH_SOUTH )
	{
		case PositionConstants.NORTH :
			y = area.y;
			break;
		case PositionConstants.SOUTH :
			y = area.y + area.height - size.height;
			break;
		default :
			y = ( area.height - size.height ) / 2 + area.y;
			break;
	}
	switch ( alignment & PositionConstants.EAST_WEST )
	{
		case PositionConstants.EAST :
			x = area.x + area.width - size.width;
			break;
		case PositionConstants.WEST :
			x = area.x;
			break;
		default :
			x = ( area.width - size.width ) / 2 + area.x;
			break;
	}
	graphics.drawImage( getImage( ), x, y );
}
 
Example 14
Source File: ReportElementFigure.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	if ( isOpaque( ) )
	{
		if ( getBorder( ) instanceof BaseBorder )
		{
			graphics.fillRectangle( getBounds( ).getCopy().crop( ( (BaseBorder) getBorder( ) ).getBorderInsets( ) ) );
		}
		else
		{
			graphics.fillRectangle( getBounds( ) );
		}
	}

	Image image = getImage( );
	if ( image == null )
	{
		return;
	}

	int x, y;
	Rectangle area = getBounds( );

	graphics.getClip( PRIVATE_RECT );
	//graphics.setClip( area );

	// Calculates X
	if ( position != null && position.x != -1 )
	{
		x = area.x + position.x;
	}
	else
	{
		switch ( alignment & PositionConstants.EAST_WEST )
		{
			case PositionConstants.EAST :
				x = area.x + area.width - size.width;
				break;
			case PositionConstants.WEST :
				x = area.x;
				break;
			default :
				x = ( area.width - size.width ) / 2 + area.x;
				break;
		}
	}

	// Calculates Y
	if ( position != null && position.y != -1 )
	{
		y = area.y + position.y;
	}
	else
	{
		switch ( alignment & PositionConstants.NORTH_SOUTH )
		{
			case PositionConstants.NORTH :
				y = area.y;
				break;
			case PositionConstants.SOUTH :
				y = area.y + area.height - size.height;
				break;
			default :
				y = ( area.height - size.height ) / 2 + area.y;
				break;
		}
	}

	ArrayList xyList = createImageList( x, y );

	Iterator iter = xyList.iterator( );
	Dimension imageSize = new Rectangle( image.getBounds( ) ).getSize( );
	while ( iter.hasNext( ) )
	{
		Point point = (Point) iter.next( );
		graphics.drawImage( image, 0, 0, imageSize.width, imageSize.height,  point.x, point.y, size.width, size.height);
	}
	xyList.clear( );

	graphics.setClip( PRIVATE_RECT );
}
 
Example 15
Source File: TableFigure.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	if ( isOpaque( ) )
	{
		if ( getBorder( ) instanceof BaseBorder )
		{
			graphics.fillRectangle( getBounds( ).getCopy( )
					.crop( ( (BaseBorder) getBorder( ) ).getBorderInsets( ) ) );
		}
		else
		{
			graphics.fillRectangle( getBounds( ) );
		}
	}

	Image image = getImage( );
	if ( image == null )
	{
		return;
	}

	int x, y;
	Rectangle area = getBounds( );

	// Calculates X
	if ( position != null && position.x != -1 )
	{
		x = area.x + position.x;
	}
	else
	{
		switch ( alignment & PositionConstants.EAST_WEST )
		{
			case PositionConstants.EAST :
				x = area.x + area.width - size.width;
				break;
			case PositionConstants.WEST :
				x = area.x;
				break;
			default :
				x = ( area.width - size.width ) / 2 + area.x;
				break;
		}
	}

	// Calculates Y
	if ( position != null && position.y != -1 )
	{
		y = area.y + position.y;
	}
	else
	{
		switch ( alignment & PositionConstants.NORTH_SOUTH )
		{
			case PositionConstants.NORTH :
				y = area.y;
				break;
			case PositionConstants.SOUTH :
				y = area.y + area.height - size.height;
				break;
			default :
				y = ( area.height - size.height ) / 2 + area.y;
				break;
		}
	}

	ArrayList xyList = createImageList( x, y );

	Iterator iter = xyList.iterator( );
	while ( iter.hasNext( ) )
	{
		Point point = (Point) iter.next( );
		graphics.drawImage( image, point );
	}
	xyList.clear( );
}
 
Example 16
Source File: Helper.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public static int convertPosition ( final String position, final int defaultValue )
{
    if ( "CENTER".equals ( position ) )
    {
        return PositionConstants.CENTER;
    }
    else if ( "LEFT".equals ( position ) )
    {
        return PositionConstants.LEFT;
    }
    else if ( "RIGHT".equals ( position ) )
    {
        return PositionConstants.RIGHT;
    }
    else if ( "TOP".equals ( position ) )
    {
        return PositionConstants.TOP;
    }
    else if ( "BOTTOM".equals ( position ) )
    {
        return PositionConstants.BOTTOM;
    }
    else if ( "EAST".equals ( position ) )
    {
        return PositionConstants.EAST;
    }
    else if ( "WEST".equals ( position ) )
    {
        return PositionConstants.WEST;
    }
    else if ( "NORTH".equals ( position ) )
    {
        return PositionConstants.NORTH;
    }
    else if ( "SOUTH".equals ( position ) )
    {
        return PositionConstants.SOUTH;
    }

    return defaultValue;
}
 
Example 17
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;
}
 
Example 18
Source File: TableCellKeyDelegate.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Finds the next Table Cell according to the direction.
 * 
 * @param siblings
 * @param pStart
 * @param direction
 * @param exclude
 * @return
 */
protected GraphicalEditPart findTableCellSibling( List siblings,
		Point pStart, int direction, EditPart exclude )
{
	AbstractCellEditPart start = (AbstractCellEditPart) exclude;

	int nRow = start.getRowNumber( );
	int nCol = start.getColumnNumber( );

	//TODO Consider isSelectable.

	switch ( direction )
	{
		case PositionConstants.NORTH :
			nRow -= 1;
			break;
		case PositionConstants.SOUTH :
			nRow += start.getRowSpan( );
			break;
		case PositionConstants.WEST :
			nCol -= 1;
			break;
		case PositionConstants.EAST :
			nCol += start.getColSpan( );
			break;
		default :
			break;
	}

	AbstractTableEditPart parent = (AbstractTableEditPart) start.getParent( );

	if ( nRow < 1 )
	{
		nRow = 1;
	}

	if ( nRow > parent.getRowCount( ) )
	{
		nRow = parent.getRowCount( );
	}

	if ( nCol < 1 )
	{
		nCol = 1;
	}

	if ( nCol > parent.getColumnCount( ) )
	{
		nCol = parent.getColumnCount( );
	}

	return parent.getCell( nRow, nCol );
}
 
Example 19
Source File: DiagramWalkerSelectionEditPolicy.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected List<Object> createSelectionHandles() {
    final List<Object> selectedEditParts = getHost().getViewer().getSelectedEditParts();
    if (selectedEditParts.size() == 1) {
        final ViewableModel currentElement = (ViewableModel) getHost().getModel();
        if (!(currentElement instanceof Category) && !(currentElement instanceof ModelProperties)) {
            // #for_erflute maybe unneeded, already linkage between main and virtual by jflute
            //final ERDiagram diagram = ERModelUtil.getDiagram(getHost().getRoot().getContents());
            //ViewableModel targetElement = currentElement;
            //if (currentElement instanceof ERVirtualTable) {
            //    targetElement = ((ERVirtualTable) currentElement).getRawTable();
            //}
            //final List<NodeElement> nodeElementList = diagram.getDiagramContents().getContents().getNodeElementList();
            //nodeElementList.remove(targetElement);
            //nodeElementList.add((NodeElement) targetElement);
            getHost().getRoot().getContents().refresh();
        }
    }

    final List<Object> list = new ArrayList<>();
    final int directions = getResizeDirections();
    if (directions == 0) {
        // #willanalyze what is this? by jflute
        //NonResizableHandleKit.addHandles((GraphicalEditPart) getHost(), list);
    } else if (directions != -1) {
        // 0
        list.add(new ERDiagramMoveHandle((GraphicalEditPart) getHost()));

        // 1
        if ((directions & PositionConstants.EAST) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.EAST);
        }

        // 2
        if ((directions & PositionConstants.SOUTH_EAST) == PositionConstants.SOUTH_EAST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_EAST);
        }

        // 3
        if ((directions & PositionConstants.SOUTH) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH);
        }

        // 4
        if ((directions & PositionConstants.SOUTH_WEST) == PositionConstants.SOUTH_WEST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_WEST);
        }

        // 5
        if ((directions & PositionConstants.WEST) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.WEST);
        }

        // 6
        if ((directions & PositionConstants.NORTH_WEST) == PositionConstants.NORTH_WEST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_WEST);
        }

        // 7
        if ((directions & PositionConstants.NORTH) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH);
        }

        // 8
        if ((directions & PositionConstants.NORTH_EAST) == PositionConstants.NORTH_EAST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_EAST);
        }
    } else {
        addHandles((GraphicalEditPart) getHost(), list);
    }
    return list;
}
 
Example 20
Source File: NodeElementSelectionEditPolicy.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected List createSelectionHandles() {
    final List selectedEditParts = getHost().getViewer().getSelectedEditParts();
    if (selectedEditParts.size() == 1) {
        if (!(getHost().getModel() instanceof Category)) {
            final NodeElementEditPart editPart = (NodeElementEditPart) getHost();
            editPart.reorder();
        }
    }

    final List list = new ArrayList();

    final int directions = getResizeDirections();

    if (directions == 0) {
        // NonResizableHandleKit.addHandles((GraphicalEditPart) getHost(),
        // list);

    } else if (directions != -1) {
        // 0
        list.add(new ERDiagramMoveHandle((GraphicalEditPart) getHost()));

        // 1
        if ((directions & PositionConstants.EAST) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.EAST);
        }

        // 2
        if ((directions & PositionConstants.SOUTH_EAST) == PositionConstants.SOUTH_EAST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_EAST);
        }

        // 3
        if ((directions & PositionConstants.SOUTH) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH);
        }

        // 4
        if ((directions & PositionConstants.SOUTH_WEST) == PositionConstants.SOUTH_WEST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.SOUTH_WEST);
        }

        // 5
        if ((directions & PositionConstants.WEST) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.WEST);
        }

        // 6
        if ((directions & PositionConstants.NORTH_WEST) == PositionConstants.NORTH_WEST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_WEST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_WEST);
        }

        // 7
        if ((directions & PositionConstants.NORTH) != 0) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH);
        }

        // 8
        if ((directions & PositionConstants.NORTH_EAST) == PositionConstants.NORTH_EAST) {
            ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_EAST);
        } else {
            NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list, PositionConstants.NORTH_EAST);
        }

    } else {
        addHandles((GraphicalEditPart) getHost(), list);
    }

    return list;
}