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

The following examples show how to use org.eclipse.draw2d.Graphics#translate() . 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 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 2
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 3
Source File: SelectionBorder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void paintRegular( IFigure figure, Graphics graphics, Insets insets )
{
	Rectangle bounds = figure.getBounds( ).getCopy( );
	graphics.translate( bounds.getLocation( ) );

	graphics.setBackgroundColor( ReportColorConstants.SelctionFillColor );

	graphics.fillRectangle( 0, 0, bounds.width, lineWidth );
	graphics.fillRectangle( bounds.width - lineWidth,
			0,
			lineWidth,
			bounds.height );
	graphics.fillRectangle( 0,
			bounds.height - lineWidth,
			bounds.width,
			lineWidth );
	graphics.fillRectangle( 0, 0, lineWidth, bounds.height );

	graphics.translate( bounds.getLocation( ).getNegated( ) );
}
 
Example 4
Source File: StyledLabel.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void paintFigure(Graphics graphics) {
		Rectangle bounds = getBounds();
		graphics.translate(bounds.x, bounds.y);
		updateImage();

		if (image == null || ranges == null || ranges.length == 0 || isOpaque()) {
			return;
		}

		if (getIcon() != null)
			graphics.drawImage(getIcon(), getIconLocation());
//		if (!isEnabled()) {
//			graphics.translate(1, 1);
//			graphics.drawImage(image, getTextLocation());
//			graphics.translate(-1, -1);
//		}
		graphics.drawImage(image, getTextLocation());
		graphics.translate(-bounds.x, -bounds.y);
	}
 
Example 5
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 6
Source File: LinearScaleTickMarks.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected void paintClientArea(Graphics graphics) {
	graphics.translate(bounds.x, bounds.y);
	ITicksProvider ticks = scale.getTicksProvider();

	int width = getSize().width;
	int height = getSize().height;

	try {
		graphics.pushState();
		graphics.setAlpha(100);
		if (scale.isHorizontal()) {
			drawXTickMarks(graphics, ticks.getPositions(), scale.getTickLabelSide(), width, height);
		} else {
			drawYTickMarks(graphics, ticks.getPositions(), scale.getTickLabelSide(), width, height);
		}
	} finally {
		graphics.popState();
	}
}
 
Example 7
Source File: GraphicsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw vertical text.
 * 
 * @param graphics
 *            draw2D graphics.
 * @param text
 *            text to be drawn.
 * @param x
 *            the x coordinate of the text, which is the left upper corner.
 * @param y
 *            the y coordinate of the text, which is the left upper corner.
 */
public static final void drawVerticalText(Graphics graphics, String text, int x, int y, boolean upToDown) {
	try {
		if (SWT.getPlatform().startsWith("rap")) //$NON-NLS-1$
			throw new Exception();
		try {
			graphics.pushState();
			graphics.translate(x, y);
			if (upToDown) {
				graphics.rotate(90);
				graphics.drawText(text, 0, -FigureUtilities.getTextExtents(text, graphics.getFont()).height);
			} else {
				graphics.rotate(270);
				graphics.drawText(text, -FigureUtilities.getTextWidth(text, graphics.getFont()), 0);
			}
		} finally {
			graphics.popState();
		}
	} catch (Exception e) {// If rotate is not supported by the graphics.
		// final Dimension titleSize = FigureUtilities.getTextExtents(text,
		// graphics.getFont());

		// final int w = titleSize.height;
		// final int h = titleSize.width + 1;
		Image image = null;
		try {
			image = SingleSourceHelper2.createVerticalTextImage(text, graphics.getFont(),
					graphics.getForegroundColor().getRGB(), upToDown);
			graphics.drawImage(image, x, y);

		} finally {
			if (image != null)
				image.dispose();
		}
	}
}
 
Example 8
Source File: LinearScaledMarker.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {
	// use relative coordinate
	graphics.translate(bounds.x, bounds.y);
	updateTick();
	drawMarkerTick(graphics);
	super.paintClientArea(graphics);
}
 
Example 9
Source File: LinearScaleTickLabels.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {
	graphics.translate(bounds.x, bounds.y);
	graphics.setFont(getFont());
	if (scale.isHorizontal()) {
		drawXTick(graphics);
	} else {
		drawYTick(graphics);
	}

	super.paintClientArea(graphics);
}
 
Example 10
Source File: RoundScaleTickLabels.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {
	
	graphics.translate(bounds.x, bounds.y);
	drawTickLabels(graphics);
	super.paintClientArea(graphics);
}
 
Example 11
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 12
Source File: ROIFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	if(roiInfoProvider!=null && roiDataBounds!=null){
		String text = roiInfoProvider.getROIInfo(roiDataBounds.x, roiDataBounds.y, 
				roiDataBounds.width, roiDataBounds.height);
		Dimension size = TextUtilities.INSTANCE.getTextExtents(text, getFont());
		graphics.pushState();
		graphics.translate(getLocation());
		graphics.fillRectangle(roiGeoBounds.x, roiGeoBounds.y - size.height, size.width, size.height);
		graphics.drawText(text, roiGeoBounds.x, roiGeoBounds.y - size.height);
		graphics.popState();
	}
	super.paintFigure(graphics);
	
}
 
Example 13
Source File: RoundScaleTickMarks.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void paintClientArea(Graphics graphics) {
graphics.translate(bounds.x, bounds.y);
graphics.setAntialias(SWT.ON);
ArrayList<Double> tickLabelPositions = scale
            .getScaleTickLabels().getTickLabelPositions(); 
   drawTickMarks(graphics, tickLabelPositions);
 
   }
 
Example 14
Source File: JoinXYLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected EditPolicy createChildEditPolicy( EditPart child )
{
	return new ResizableEditPolicy( ) {

		protected IFigure createDragSourceFeedbackFigure( )
		{
			// Use a ghost rectangle for feedback
			Figure r = new Figure( ) {

				protected void paintFigure( Graphics graphics )
				{
					Rectangle rect = getBounds( ).getCopy( );

					graphics.setXORMode( true );
					graphics.setForegroundColor( ColorConstants.white );
					graphics.setBackgroundColor( ColorManager.getColor( 31,
							31,
							31 ) );

					graphics.translate( getLocation( ) );

					PointList outline = new PointList( );

					outline.addPoint( 0, 0 );
					outline.addPoint( rect.width, 0 );
					outline.addPoint( rect.width - 1, 0 );
					outline.addPoint( rect.width - 1, rect.height - 1 );
					outline.addPoint( 0, rect.height - 1 );

					graphics.fillPolygon( outline );

					// draw the inner outline
					PointList innerLine = new PointList( );

					innerLine.addPoint( rect.width - 0 - 1, 0 );
					innerLine.addPoint( rect.width - 0 - 1, 0 );
					innerLine.addPoint( rect.width - 1, 0 );
					innerLine.addPoint( rect.width - 0 - 1, 0 );
					innerLine.addPoint( 0, 0 );
					innerLine.addPoint( 0, rect.height - 1 );
					innerLine.addPoint( rect.width - 1, rect.height - 1 );
					innerLine.addPoint( rect.width - 1, 0 );

					graphics.drawPolygon( innerLine );

					graphics.drawLine( rect.width - 0 - 1,
							0,
							rect.width - 1,
							0 );

					graphics.translate( getLocation( ).getNegated( ) );
				}
			};

			r.setBounds( getInitialFeedbackBounds( ) );
			addFeedback( r );
			return r;
		}

	};
}
 
Example 15
Source File: SelectionBorder.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void paintGradient( IFigure figure, Graphics graphics, Insets insets )
{
	Rectangle bounds = figure.getBounds( ).getCopy( );
	graphics.translate( bounds.getLocation( ) );

	int halfW = bounds.width / 2 + 1;

	setGradientColor( graphics, false );

	graphics.fillGradient( 0, 0, halfW, lineWidth, false );
	graphics.fillGradient( bounds.width, 0, -halfW, lineWidth, false );

	graphics.fillGradient( 0,
			bounds.height - lineWidth,
			halfW,
			lineWidth,
			false );
	graphics.fillGradient( bounds.width,
			bounds.height - lineWidth,
			-halfW,
			lineWidth,
			false );

	int halfH = bounds.height / 2 + 1;

	graphics.fillGradient( 0, 0, lineWidth, halfH, true );
	graphics.fillGradient( 0, bounds.height, lineWidth, -halfH, true );

	graphics.fillGradient( bounds.width - lineWidth,
			0,
			lineWidth,
			halfH,
			true );
	graphics.fillGradient( bounds.width - lineWidth,
			bounds.height,
			lineWidth,
			-halfH,
			true );

	graphics.translate( bounds.getLocation( ).getNegated( ) );

}
 
Example 16
Source File: TableDragGuideTracker.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	Rectangle bounds = getBounds( ).getCopy( );
	graphics.translate( getLocation( ) );

	graphics.setXORMode( true );
	graphics.setForegroundColor( ColorConstants.white );
	graphics.setBackgroundColor( ColorConstants.black );

	graphics.setLineStyle( Graphics.LINE_DOT );

	int[] points = new int[6];

	points[0] = 0 + offset;
	points[1] = 0;
	points[2] = bounds.width - 1;
	points[3] = 0;
	points[4] = bounds.width - 1;
	points[5] = bounds.height - 1;

	graphics.drawPolyline( points );

	points[0] = 0;
	points[1] = 0 + offset;
	points[2] = 0;
	points[3] = bounds.height - 1;
	points[4] = bounds.width - 1;
	points[5] = bounds.height - 1;

	graphics.drawPolyline( points );

	graphics.translate( getLocation( ).getNegated( ) );

	if ( schedulePaint )
	{
		Display.getCurrent( ).timerExec( DELAY, new Runnable( ) {

			public void run( )
			{
				offset++;
				if ( offset > 5 )
					offset = 0;

				schedulePaint = true;
				repaint( );
			}
		} );
	}

	schedulePaint = false;
}
 
Example 17
Source File: CellDragTracker.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	Rectangle bounds = getBounds( ).getCopy( );
	graphics.translate( getLocation( ) );

	graphics.setXORMode( true );
	graphics.setForegroundColor( ColorConstants.white );
	graphics.setBackgroundColor( ColorConstants.black );

	graphics.setLineStyle( Graphics.LINE_DOT );

	int[] points = new int[6];

	points[0] = 0 + offset;
	points[1] = 0;
	points[2] = bounds.width - 1;
	points[3] = 0;
	points[4] = bounds.width - 1;
	points[5] = bounds.height - 1;

	graphics.drawPolyline( points );

	points[0] = 0;
	points[1] = 0 + offset;
	points[2] = 0;
	points[3] = bounds.height - 1;
	points[4] = bounds.width - 1;
	points[5] = bounds.height - 1;

	graphics.drawPolyline( points );

	graphics.translate( getLocation( ).getNegated( ) );

	if ( schedulePaint )
	{
		Display.getCurrent( ).timerExec( DELAY, new Runnable( ) {

			public void run( )
			{
				offset++;
				if ( offset > 5 )
					offset = 0;

				schedulePaint = true;
				repaint( );
			}
		} );
	}

	schedulePaint = false;
}
 
Example 18
Source File: RootDragTracker.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
 */
protected void paintFigure( Graphics graphics )
{
	Rectangle bounds = getBounds( ).getCopy( );
	graphics.translate( getLocation( ) );

	graphics.setXORMode( true );
	graphics.setForegroundColor( ColorConstants.white );
	graphics.setBackgroundColor( ColorConstants.black );

	graphics.setLineStyle( Graphics.LINE_DOT );

	int[] points = new int[6];

	points[0] = 0 + offset;
	points[1] = 0;
	points[2] = bounds.width - 1;
	points[3] = 0;
	points[4] = bounds.width - 1;
	points[5] = bounds.height - 1;

	graphics.drawPolyline( points );

	points[0] = 0;
	points[1] = 0 + offset;
	points[2] = 0;
	points[3] = bounds.height - 1;
	points[4] = bounds.width - 1;
	points[5] = bounds.height - 1;

	graphics.drawPolyline( points );

	graphics.translate( getLocation( ).getNegated( ) );

	if ( schedulePaint )
	{
		Display.getCurrent( ).timerExec( DELAY, new Runnable( ) {

			public void run( )
			{
				offset++;
				if ( offset > 5 )
					offset = 0;

				schedulePaint = true;
				repaint( );
			}
		} );
	}

	schedulePaint = false;
}
 
Example 19
Source File: CustomRubberbandDragTracker.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
 */
protected void paintFigure(Graphics graphics) {	
	Rectangle bounds1 = getBounds().getCopy();
	graphics.translate(getLocation());

	graphics.setXORMode(false);
	graphics.setForegroundColor(ColorConstants.black);
	graphics.setBackgroundColor(ColorConstants.black);

	//graphics.drawRectangle(bounds1) ;

	graphics.setLineStyle(Graphics.LINE_DOT);

	int[] points = new int[6];

	points[0] = 0 + offset;
	points[1] = 0;
	points[2] = bounds1.width - 1;
	points[3] = 0;
	points[4] = bounds1.width - 1;
	points[5] = bounds1.height - 1;

	graphics.drawPolyline(points);

	points[0] = 0;
	points[1] = 0 + offset;
	points[2] = 0;
	points[3] = bounds1.height - 1;
	points[4] = bounds1.width - 1;
	points[5] = bounds1.height - 1;

	graphics.drawPolyline(points);

	graphics.translate(getLocation().getNegated());

	if (schedulePaint) {
		Display.getCurrent().timerExec(DELAY, new Runnable() {
			public void run() {
				offset++;
				if (offset > 5)
					offset = 0;	

				schedulePaint = true;
				repaint();
			}
		});
	}

	schedulePaint = false;
}