Java Code Examples for org.eclipse.swt.graphics.Path#lineTo()

The following examples show how to use org.eclipse.swt.graphics.Path#lineTo() . 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: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
void paintScale(final GC gc) {
	gc.setBackground(IGamaColors.BLACK.color());
	final int BAR_WIDTH = 1;
	final int BAR_HEIGHT = 8;
	final int x = 0;
	final int y = 0;
	final int margin = 20;
	final int width = scalebar.getBounds().width - 2 * margin;
	final int height = scalebar.getBounds().height;
	final int barStartX = x + 1 + BAR_WIDTH / 2 + margin;
	final int barStartY = y + height - BAR_HEIGHT / 2;

	final Path path = new Path(WorkbenchHelper.getDisplay());
	path.moveTo(barStartX, barStartY - BAR_HEIGHT + 2);
	path.lineTo(barStartX, barStartY + 2);
	path.moveTo(barStartX, barStartY - BAR_HEIGHT / 2 + 2);
	path.lineTo(barStartX + width, barStartY - BAR_HEIGHT / 2 + 2);
	path.moveTo(barStartX + width, barStartY - BAR_HEIGHT + 2);
	path.lineTo(barStartX + width, barStartY + 2);

	gc.setForeground(IGamaColors.WHITE.color());
	gc.setLineStyle(SWT.LINE_SOLID);
	gc.setLineWidth(BAR_WIDTH);
	gc.drawPath(path);
	gc.setFont(coord.getFont());
	drawStringCentered(gc, "0", barStartX, barStartY - 6, false);
	drawStringCentered(gc, getScaleRight(), barStartX + width, barStartY - 6, false);
	path.dispose();
}
 
Example 2
Source File: SWTGraphics2D.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 3
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 * 
 * @param shape  the shape (<code>null</code> not permitted).
 * 
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2], 
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 4
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 5
Source File: SWTGraphics2D.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 6
Source File: SWTGraphics2D.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 7
Source File: SWTGraphics2D.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 8
Source File: SWTGraphics2D.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @return The path.
 */
private Path toSwtPath(Shape shape) {
    int type;
    float[] coords = new float[6];
    Path path = new Path(this.gc.getDevice());
    PathIterator pit = shape.getPathIterator(null);
    while (!pit.isDone()) {
        type = pit.currentSegment(coords);
        switch (type) {
            case (PathIterator.SEG_MOVETO):
                path.moveTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_LINETO):
                path.lineTo(coords[0], coords[1]);
                break;
            case (PathIterator.SEG_QUADTO):
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
                break;
            case (PathIterator.SEG_CUBICTO):
                path.cubicTo(coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5]);
                break;
            case (PathIterator.SEG_CLOSE):
                path.close();
                break;
            default:
                break;
        }
        pit.next();
    }
    return path;
}
 
Example 9
Source File: StepRenderer.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void performRender ( final Graphics g, final Rectangle clientRect )
{
    final XAxis xAxis = this.seriesData.getXAxis ();
    final YAxis yAxis = this.seriesData.getYAxis ();

    final NavigableSet<DataEntry> entries = this.seriesData.getViewData ().getEntries ();
    if ( entries.isEmpty () )
    {
        return;
    }

    final Path path = g.createPath ();
    try
    {
        boolean first = true;

        final DataPoint point = new DataPoint ();
        Float previousX = null;
        Float previousY = null;

        logger.trace ( "Render steps" );

        final long now = System.currentTimeMillis ();

        for ( final DataEntry entry : entries )
        {
            final boolean hasData = translateToPoint ( clientRect, xAxis, yAxis, point, entry );

            logger.trace ( "Entry - {}, hasData: {}, point: {}", new Object[] { entry, hasData, point } );

            final boolean skip = this.noFuture && entry.getTimestamp () > now;

            if ( hasData && !skip )
            {
                if ( first )
                {
                    first = false;
                    path.moveTo ( point.x, point.y );
                }
                else
                {
                    if ( previousX != null && previousX + 1 == point.x )
                    {
                        /* is the special case were we only advance one pixel.
                         * so we can draw a direct line and allow the
                         * antialiasing to kick in */

                        path.lineTo ( point.x, point.y );
                    }
                    else
                    {
                        path.lineTo ( point.x, previousY );
                        path.lineTo ( point.x, point.y );
                    }
                }
                previousX = point.x;
                previousY = point.y;
            }
            else
            {
                first = true;
                if ( previousY != null )
                {
                    path.lineTo ( point.x, previousY );
                    previousY = null;
                }
                previousX = null;
            }
        }

        g.setAlpha ( 255 );
        g.setLineAttributes ( this.lineAttributes );
        g.setForeground ( this.lineColor );
        g.setAntialias ( true );

        g.setClipping ( clientRect );
        g.drawPath ( path );
    }
    finally
    {
        path.dispose ();
    }
}
 
Example 10
Source File: LinearRenderer.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void performRender ( final Graphics g, final Rectangle clientRect )
{

    final Path path = g.createPath ();

    try
    {
        // eval min/max
        final XAxis xAxis = this.seriesData.getXAxis ();
        final YAxis yAxis = this.seriesData.getYAxis ();

        final SortedSet<DataEntry> entries = this.seriesData.getViewData ().getEntries ();
        if ( entries.isEmpty () )
        {
            return;
        }

        boolean first = true;

        final DataPoint point = new DataPoint ();

        for ( final DataEntry entry : entries )
        {
            final boolean hasData = translateToPoint ( clientRect, xAxis, yAxis, point, entry );
            if ( hasData )
            {
                if ( first )
                {
                    first = false;
                    path.moveTo ( point.x, point.y );
                }
                else
                {
                    path.lineTo ( point.x, point.y );
                }
            }
            else
            {
                first = true;
            }
        }
        g.setAlpha ( 255 );
        g.setLineAttributes ( this.lineAttributes );
        g.setForeground ( this.lineColor );

        g.setClipping ( clientRect );
        g.drawPath ( path );
    }
    finally
    {
        path.dispose ();
    }
}
 
Example 11
Source File: LoginDialog.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create a default image. It is a port of the image used by the Login Box
 * in the project SwingX
 *
 * @param w width
 * @param h height
 * @return a default image (blue wave)
 */
private Image createDefaultImage(final int w, final int h) {
	final Display display = Display.getCurrent();
	final Color backgroundColor = new Color(display, 49, 121, 242);
	final Color gradientColor1 = new Color(display, 155, 185, 245);
	final Color gradientColor2 = new Color(display, 53, 123, 242);

	final Image img = new Image(display, w, h);
	final GC gc = new GC(img);
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setBackground(backgroundColor);
	gc.fillRectangle(0, 0, w, h);

	final Path curveShape = new Path(display);
	curveShape.moveTo(0, h * .6f);
	curveShape.cubicTo(w * .167f, h * 1.2f, w * .667f, h * -.5f, w, h * .75f);
	curveShape.lineTo(w, h);
	curveShape.lineTo(0, h);
	curveShape.lineTo(0, h * .8f);
	curveShape.close();

	final Pattern pattern = new Pattern(display, 0, 0, 1, h * 1.2f, gradientColor1, gradientColor2);
	gc.setBackgroundPattern(pattern);
	gc.fillPath(curveShape);

	final Font font = new Font(display, "Arial Bold", 30, SWT.NONE);
	gc.setFont(font);
	gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
	final Point textSize = gc.stringExtent(ResourceManager.getLabel(ResourceManager.LOGIN));
	gc.drawString(ResourceManager.getLabel(ResourceManager.LOGIN), (int) (w * .05f), (h - textSize.y) / 2, true);

	font.dispose();
	curveShape.dispose();
	pattern.dispose();
	backgroundColor.dispose();
	gradientColor1.dispose();
	gradientColor2.dispose();
	gc.dispose();
	return img;
}
 
Example 12
Source File: SwtRendererImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void fillRectangle( RectangleRenderEvent rre ) throws ChartException
{
	iv.modifyEvent( rre  );
	final Fill flBackground = validateMultipleFill( rre.getBackground( ) );

	if ( isFullTransparent( flBackground ) )
	{
		return;
	}

	final Bounds bo = normalizeBounds( rre.getBounds( ) );
	final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ),
			(int) ( ( bo.getTop( ) + dTranslateY ) * dScale ),
			(int) Math.ceil( bo.getWidth( ) * dScale ),
			(int) Math.ceil( bo.getHeight( ) * dScale ) );

	final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) );
	pt.moveTo( r.x, r.y );
	pt.lineTo( r.x, r.y + r.height );
	pt.lineTo( r.x + r.width, r.y + r.height );
	pt.lineTo( r.x + r.width, r.y );

	try
	{
		if ( flBackground instanceof ColorDefinition )
		{				
			fillPathColor( pt, (ColorDefinition) flBackground );
		}
		if ( flBackground instanceof Gradient )
		{
			fillPathGradient( pt, (Gradient) flBackground, r );
		}
		else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image )
		{
			fillPathImage( pt,
					(org.eclipse.birt.chart.model.attribute.Image) flBackground );
		}
	}
	finally
	{
		pt.dispose( );
	}
	

}
 
Example 13
Source File: SwtRendererImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void fillPolygon( PolygonRenderEvent pre ) throws ChartException
{
	iv.modifyEvent( pre );
	
	// DUE TO RESTRICTIVE SWT API, WE SET A CLIPPED POLYGON REGION
	// AND RENDER THE POLYGON BY RENDERING A CONTAINING RECTANGLE WHERE
	// THE RECTANGLE BOUNDS CORRESPOND TO THE POLYGON BOUNDS
	// NOTE: SOME INCOMPLETE PAINTING ERRORS SEEM TO EXIST FOR GRADIENT POLY
	// FILLS

	final Fill flBackground = validateMultipleFill( pre.getBackground( ) );

	if ( isFullTransparent( flBackground ) )
	{
		return;
	}

	final Bounds bo = normalizeBounds( pre.getBounds( ) );
	final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ),
			(int) ( ( bo.getTop( ) + dTranslateY ) * dScale ),
			(int) Math.ceil( bo.getWidth( ) * dScale ),
			(int) Math.ceil( bo.getHeight( ) * dScale ) );
	
	float[] points = convertDoubleToFloat( getDoubleCoordinatesAsInts( pre.getPoints( ),
			TRUNCATE,
			dTranslateX,
			dTranslateY,
			dScale ) );
	if ( points.length < 1 )
	{
		return;
	}
	final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) );
	pt.moveTo( points[0], points[1] );
	for ( int i = 1; i < points.length / 2; i++ )
	{
		pt.lineTo( points[2 * i], points[2 * i + 1] );
	}
	
	try
	{
		if ( flBackground instanceof ColorDefinition )
		{
			fillPathColor( pt, (ColorDefinition) flBackground );
		}
		else if ( flBackground instanceof Gradient )
		{
			fillPathGradient( pt, (Gradient) flBackground, r );
		}
		else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image )
		{
			fillPathImage( pt,
					(org.eclipse.birt.chart.model.attribute.Image) flBackground );
		}
	}
	finally
	{
		pt.dispose( );
	}
	

}
 
Example 14
Source File: SwtRendererImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void drawArea( AreaRenderEvent are ) throws ChartException
{
	iv.modifyEvent( are );
	
	// CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
	final LineAttributes lia = are.getOutline( );
	if ( !validateLineAttributes( are.getSource( ), lia ) )
	{
		return;
	}

	// SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL)
	final Color cFG = (Color) validateEdgeColor( lia.getColor( ),
			are.getBackground( ),
			_ids );
	if ( cFG == null ) // IF UNDEFINED, EXIT
	{
		return;
	}

	// BUILD THE GENERAL PATH STRUCTURE
	final Path gp = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) );
	PrimitiveRenderEvent pre;
	for ( int i = 0; i < are.getElementCount( ); i++ )
	{
		pre = are.getElement( i );
		if ( pre instanceof ArcRenderEvent )
		{
			final ArcRenderEvent acre = (ArcRenderEvent) pre;

			gp.addArc( (float) acre.getTopLeft( ).getX( ),
					(float) acre.getTopLeft( ).getY( ),
					(float) acre.getWidth( ),
					(float) acre.getHeight( ),
					(float) acre.getStartAngle( ),
					(float) acre.getAngleExtent( ) );
		}
		else if ( pre instanceof LineRenderEvent )
		{
			final LineRenderEvent lre = (LineRenderEvent) pre;
			gp.moveTo( (float) lre.getStart( ).getX( ),
					(float) lre.getStart( ).getY( ) );
			gp.lineTo( (float) lre.getEnd( ).getX( ), (float) lre.getEnd( )
					.getY( ) );
		}
	}

	// DRAW THE PATH
	final int iOldLineStyle = _gc.getLineStyle( );
	final int iOldLineWidth = _gc.getLineWidth( );
	int iLineStyle = SWT.LINE_SOLID;
	switch ( lia.getStyle( ).getValue( ) )
	{
		case ( LineStyle.DOTTED                                                                                                                                                                                                                                                                  ) :
			iLineStyle = SWT.LINE_DOT;
			break;
		case ( LineStyle.DASH_DOTTED                                                                                                                                                                                                                                                                  ) :
			iLineStyle = SWT.LINE_DASHDOT;
			break;
		case ( LineStyle.DASHED                                                                                                                                                                                                                                                                  ) :
			iLineStyle = SWT.LINE_DASH;
			break;
	}
	_gc.setLineStyle( iLineStyle );
	_gc.setLineWidth( lia.getThickness( ) );
	_gc.setForeground( cFG );

	R31Enhance.setAlpha( _gc, lia.getColor( ) );

	_gc.drawPath( gp );

	// Restore state
	_gc.setLineStyle( iOldLineStyle );
	_gc.setLineWidth( iOldLineWidth );

	// Free resource
	gp.dispose( );
	cFG.dispose( );

}
 
Example 15
Source File: SwtRendererImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void fillArea( AreaRenderEvent are ) throws ChartException
{
	iv.modifyEvent( are );
	
	Fill flBackground = validateMultipleFill( are.getBackground( ) );

	if ( isFullTransparent( flBackground ) )
	{
		return;
	}

	// BUILD THE GENERAL PATH STRUCTURE
	final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) );
	PrimitiveRenderEvent pre;
	for ( int i = 0; i < are.getElementCount( ); i++ )
	{
		pre = are.getElement( i );
		if ( pre instanceof ArcRenderEvent )
		{
			final ArcRenderEvent acre = (ArcRenderEvent) pre;

			pt.addArc( (float) acre.getTopLeft( ).getX( ),
					(float) acre.getTopLeft( ).getY( ),
					(float) acre.getWidth( ),
					(float) acre.getHeight( ),
					(float) acre.getStartAngle( ),
					(float) acre.getAngleExtent( ) );
		}
		else if ( pre instanceof LineRenderEvent )
		{
			final LineRenderEvent lre = (LineRenderEvent) pre;
			if ( i == 0 )
			{
				pt.moveTo( (float) lre.getStart( ).getX( ),
						(float) lre.getStart( ).getY( ) );
			}
			pt.lineTo( (float) lre.getEnd( ).getX( ), (float) lre.getEnd( )
					.getY( ) );
		}
	}

	try
	{
		if ( flBackground instanceof ColorDefinition )
		{
			fillPathColor( pt, (ColorDefinition) flBackground );
		}
		else if ( flBackground instanceof Gradient )
		{
			final Bounds bo = are.getBounds( );
			final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ),
					(int) ( ( bo.getTop( ) + dTranslateY ) * dScale ),
					(int) ( bo.getWidth( ) * dScale ),
					(int) ( bo.getHeight( ) * dScale ) );
			fillPathGradient( pt, (Gradient) flBackground, r );
		}
		else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image )
		{
			fillPathImage( pt,
					(org.eclipse.birt.chart.model.attribute.Image) flBackground );
		}
	}
	finally
	{
		pt.dispose( );
	}
	

}
 
Example 16
Source File: ProgressCircle.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void paintControl(final PaintEvent e) {
	firstDisplay = false;
	final GC gc = e.gc;
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);

	// Draw the selected part
	final Path pathHighlight = new Path(getDisplay());
	float ratio = 1.0f * value / (maximum - minimum);
	if (minimum < 0 && maximum < 0) {
		ratio = -1.0f * (minimum - value) / (maximum - minimum);
	}

	float angle = ratio * 360f;
	if (minimum < 0 && maximum > 0) {
		angle += 180;
	}

	pathHighlight.addArc(MARGIN, MARGIN, circleSize, circleSize, 90, -angle);
	pathHighlight.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2);
	pathHighlight.close();

	gc.setBackground(getHighlightColor());
	gc.fillPath(pathHighlight);
	pathHighlight.dispose();

	// Draw the unselected part
	final Path path = new Path(getDisplay());
	final float unselectedAngle = 360f - angle;

	path.addArc(MARGIN, MARGIN, circleSize, circleSize, 90 - angle, -unselectedAngle);
	path.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2);
	path.close();

	gc.setBackground(getForeground());
	gc.fillPath(path);
	pathHighlight.dispose();

	// Draw the hole
	gc.setBackground(getBackground());
	gc.fillOval(MARGIN + thickness, MARGIN + thickness, circleSize - thickness * 2, circleSize - thickness * 2);

	if (showText) {
		gc.setForeground(getHighlightColor());
		final String text;
		if (isTimer) {
			final LocalTime time = LocalTime.ofSecondOfDay(value);
			if (time.getHour() == 0) {
				if (time.getMinute() == 0) {
					// Seconds only
					text = String.format("%02d", time.getSecond());
				} else {
					// Minutes+secondes
					text = String.format("%02d:%02d", time.getMinute(), time.getSecond());
				}
			} else {
				// Hour/Min/sec
				text = String.format("%02d:%02d:%02d", time.getHour(), time.getMinute(), time.getSecond());
			}
		} else {
			text = String.format(textPattern, value);
		}
		final Point textSize = gc.stringExtent(text);
		final int x = MARGIN + (circleSize - textSize.x) / 2;
		final int y = (circleSize - textSize.y) / 2;
		gc.drawText(text, x, y, true);
	}
}
 
Example 17
Source File: PieUtils.java    From BiglyBT with GNU General Public License v2.0 2 votes vote down vote up
public static void
drawPie(
	GC gc,Image image, int x, int y,int width,int height,int percent, boolean draw_border )
{
	Rectangle image_size = image.getBounds();

	int	width_pad 	= ( width - image_size.width  )/2;
	int	height_pad 	= ( height - image_size.height  )/2;

    int angle = (percent * 360) / 100;
    if(angle<4){
    	angle = 0; // workaround fillArc rendering bug
    }

	Region old_clipping = new Region();

	gc.getClipping(old_clipping);

	Path path_done = new Path(gc.getDevice());

	path_done.addArc(x,y,width,height,90,-angle);
	path_done.lineTo( x+width/2, y+height/2);
	path_done.close();

	gc.setClipping( path_done );

	gc.drawImage(image, x+width_pad, y+height_pad+1);

	Path path_undone = new Path(gc.getDevice());

	path_undone.addArc(x,y,width,height,90-angle,angle-360);
	path_undone.lineTo( x+width/2, y+height/2);
	path_undone.close();

	gc.setClipping( path_undone );

	gc.setAlpha( 75 );
	gc.drawImage(image, x+width_pad, y+height_pad+1);
	gc.setAlpha( 255 );

	gc.setClipping( old_clipping );

	if ( draw_border ){

		gc.setForeground(Colors.blue);

		if ( percent == 100 ){

			gc.drawOval(x , y , width-1, height-1);

		}else{

			if ( angle > 0 ){

				gc.drawPath( path_done );
			}
		}
	}

	path_done.dispose();
	path_undone.dispose();
	old_clipping.dispose();

}