Java Code Examples for org.eclipse.draw2d.Graphics#getClip()

The following examples show how to use org.eclipse.draw2d.Graphics#getClip() . 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: PrintERDiagramOperation.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void printPages() {
    final Graphics graphics = getFreshPrinterGraphics();
    final IFigure figure = getPrintSource();
    setupPrinterGraphicsFor(graphics, figure);
    final Rectangle bounds = figure.getBounds();
    int x = bounds.x, y = bounds.y;
    final Rectangle clipRect = new Rectangle();
    while (y < bounds.y + bounds.height) {
        while (x < bounds.x + bounds.width) {
            graphics.pushState();
            getPrinter().startPage();
            graphics.translate(-x, -y);
            graphics.getClip(clipRect);
            clipRect.setLocation(x, y);
            graphics.clipRect(clipRect);
            figure.paint(graphics);
            getPrinter().endPage();
            graphics.popState();
            x += clipRect.width;
        }
        x = bounds.x;
        y += clipRect.height;
    }
}
 
Example 2
Source File: PrintERDiagramOperation.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
protected void printPages() {
    final Graphics graphics = getFreshPrinterGraphics();
    final IFigure figure = getPrintSource();
    setupPrinterGraphicsFor(graphics, figure);
    final Rectangle bounds = figure.getBounds();
    int x = bounds.x, y = bounds.y;
    final Rectangle clipRect = new Rectangle();
    while (y < bounds.y + bounds.height) {
        while (x < bounds.x + bounds.width) {
            graphics.pushState();
            getPrinter().startPage();
            graphics.translate(-x, -y);
            graphics.getClip(clipRect);
            clipRect.setLocation(x, y);
            graphics.clipRect(clipRect);
            figure.paint(graphics);
            getPrinter().endPage();
            graphics.popState();
            x += clipRect.width;
        }
        x = bounds.x;
        y += clipRect.height;
    }
}
 
Example 3
Source File: PrintERDiagramOperation.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void printPages() {
	Graphics graphics = getFreshPrinterGraphics();
	IFigure figure = getPrintSource();
	setupPrinterGraphicsFor(graphics, figure);
	Rectangle bounds = figure.getBounds();
	int x = bounds.x, y = bounds.y;
	Rectangle clipRect = new Rectangle();
	while (y < bounds.y + bounds.height) {
		while (x < bounds.x + bounds.width) {
			graphics.pushState();
			getPrinter().startPage();
			graphics.translate(-x, -y);
			graphics.getClip(clipRect);
			clipRect.setLocation(x, y);
			graphics.clipRect(clipRect);
			figure.paint(graphics);
			getPrinter().endPage();
			graphics.popState();
			x += clipRect.width;
		}
		x = bounds.x;
		y += clipRect.height;
	}
}
 
Example 4
Source File: ReportPrintGraphicalViewerOperation.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Prints the pages based on the current print mode.
 * 
 * @see org.eclipse.draw2d.PrintOperation#printPages()
 */
protected void printPages( )
{
	Graphics graphics = getFreshGraphics( );
	IFigure figure = getPrintSource( );
	setupPrinterGraphicsFor( graphics, figure );
	Rectangle bounds = figure.getBounds( );
	int x = bounds.x, y = bounds.y;
	Rectangle clipRect = new Rectangle( );
	while ( y < bounds.y + bounds.height )
	{
		while ( x < bounds.x + bounds.width )
		{
			graphics.pushState( );
			graphics.translate( -x, -y );
			graphics.getClip( clipRect );
			clipRect.setLocation( x, y );
			graphics.clipRect( clipRect );
			figure.paint( graphics );
			graphics.popState( );
			x += clipRect.width;
			if ( x == 0 )
			{
				return;
			}
		}
		x = bounds.x;
		y += clipRect.height;
	}
}
 
Example 5
Source File: ReportElementFigure.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void paintBorder( Graphics graphics )
{
	if ( clip != null )
	{
		graphics.getClip( OLD_CLIP );
		graphics.setClip( getBounds( ).getCopy( ).intersect( clip ) );
	}

	super.paintBorder( graphics );

	if ( clip != null )
	{
		graphics.setClip( OLD_CLIP );
	}
}
 
Example 6
Source File: TableGridLayer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void drawRows( Graphics g )
{
	Rectangle clip = g.getClip( Rectangle.SINGLETON );
	List rows = getRows( );
	int size = rows.size( );
	int height = 0;
	for ( int i = 0; i < size; i++ )
	{
		int rowHeight = getRowHeight( rows.get( i ) );

		// if ( height < clip.y + clip.height )
		{
			// g.fillRectangle( clip.x, height, clip.x + clip.width, height
			// );
			drawBackgroud( rows.get( i ), g, clip.x, height, clip.x
					+ clip.width, rowHeight );

			drawBackgroudImage( (DesignElementHandle) rows.get( i ),
					g,
					clip.x,
					height,
					clip.x + clip.width,
					rowHeight );
		}
		height = height + rowHeight;
	}

}
 
Example 7
Source File: TableGridLayer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void drawColumns( Graphics g )
{
	g.setBackgroundColor( ReportColorConstants.greyFillColor );
	Rectangle clip = g.getClip( Rectangle.SINGLETON );
	List columns = getColumns( );
	int size = columns.size( );
	int width = 0;
	for ( int i = 0; i < size; i++ )
	{
		int columnWidth = getColumnWidth( i + 1, columns.get( i ) );

		// if ( width < clip.x + clip.width )
		{
			// g.fillRectangle( width, clip.y, width, clip.y + clip.height
			// );
			drawBackgroud( columns.get( i ),
					g,
					width,
					clip.y,
					columnWidth,
					clip.y + clip.height );

			drawBackgroudImage( (DesignElementHandle) columns.get( i ),
					g,
					width,
					clip.y,
					columnWidth,
					clip.y + clip.height );
		}
		width = width + columnWidth;
	}

}
 
Example 8
Source File: PagableFreeformRootEditPart.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void paintGrid(final Graphics g) {
    super.paintGrid(g);

    final Rectangle clip = g.getClip(Rectangle.SINGLETON);

    final PageSetting pageSetting = diagram.getPageSetting();

    final int width = pageSetting.getWidth();
    final int height = pageSetting.getHeight();

    final Rectangle rect = clip;

    final Color color = g.getForegroundColor();
    g.setForegroundColor(ColorConstants.lightGray);

    int startX = rect.x;
    if (startX > 0) {
        startX = 0;
    }
    int startY = rect.y;
    if (startY > 0) {
        startY = 0;
    }

    for (int i = startX; i < rect.x + rect.width; i += width) {
        g.drawLine(i, rect.y, i, rect.y + rect.height);
    }

    for (int i = startY; i < rect.y + rect.height; i += height) {
        g.drawLine(rect.x, i, rect.x + rect.width, i);
    }

    g.setForegroundColor(color);

    i++;
    if (i > 0) {
        i = -1;
        repaint();
    }
}
 
Example 9
Source File: PagableFreeformRootEditPart.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
protected void paintGrid(Graphics g) {
    super.paintGrid(g);

    Rectangle clip = g.getClip(Rectangle.SINGLETON);

    PageSettings pageSetting = diagram.getPageSetting();

    int width = pageSetting.getWidth();
    int height = pageSetting.getHeight();

    Rectangle rect = clip;

    Color color = g.getForegroundColor();
    g.setForegroundColor(ColorConstants.lightGray);

    int startX = rect.x;
    if (startX > 0) {
        startX = 0;
    }
    int startY = rect.y;
    if (startY > 0) {
        startY = 0;
    }

    for (int i = startX; i < rect.x + rect.width; i += width) {
        g.drawLine(i, rect.y, i, rect.y + rect.height);
    }

    for (int i = startY; i < rect.y + rect.height; i += height) {
        g.drawLine(rect.x, i, rect.x + rect.width, i);
    }

    g.setForegroundColor(color);

    i++;
    if (i > 0) {
        i = -1;
        repaint();
    }
}
 
Example 10
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 11
Source File: PagableFreeformRootEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void paintGrid(Graphics g) {
	super.paintGrid(g);

	Rectangle clip = g.getClip(Rectangle.SINGLETON);

	PageSetting pageSetting = diagram.getPageSetting();

	int width = pageSetting.getWidth();
	int height = pageSetting.getHeight();

	Rectangle rect = clip;

	Color color = g.getForegroundColor();
	g.setForegroundColor(ColorConstants.lightGray);

	int startX = rect.x;
	if (startX > 0) {
		startX = 0;
	}
	int startY = rect.y;
	if (startY > 0) {
		startY = 0;
	}

	for (int i = startX; i < rect.x + rect.width; i += width) {
		g.drawLine(i, rect.y, i, rect.y + rect.height);
	}

	for (int i = startY; i < rect.y + rect.height; i += height) {
		g.drawLine(rect.x, i, rect.x + rect.width, i);
	}

	g.setForegroundColor(color);

	i++;
	if (i > 0) {
		i = -1;
		repaint();
	}
}