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

The following examples show how to use org.eclipse.swt.graphics.Path#dispose() . 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: SWTGraphics2D.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
 
Example 2
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 3
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** 
 * Fills the specified shape using the current paint.
 * 
 * @param shape  the shape (<code>null</code> not permitted).
 * 
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is 
    // necessary to switch temporarily the foreground and background 
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
 
Example 4
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void setClip(Shape clip) {
    if (clip == null) 
        return;
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
 
Example 5
Source File: SWTGraphics2D.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fills the specified shape using the current paint.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is
    // necessary to switch temporarily the foreground and background
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
 
Example 6
Source File: SWTGraphics2D.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
 
Example 7
Source File: SWTGraphics2D.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fills the specified shape using the current paint.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is
    // necessary to switch temporarily the foreground and background
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
 
Example 8
Source File: SWTGraphics2D.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
 
Example 9
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 10
Source File: SWTGraphics2D.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the specified clip.
 *
 * @param s  the shape for the clip.
 */
public void clip(Shape s) {
    Path path = toSwtPath(s);
    this.gc.setClipping(path);
    path.dispose();
}
 
Example 11
Source File: SWTGraphics2D.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Applies the specified clip.
 *
 * @param s  the shape for the clip.
 */
public void clip(Shape s) {
    Path path = toSwtPath(s);
    this.gc.setClipping(path);
    path.dispose();
}
 
Example 12
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 13
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 14
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void clip(Shape s) {
    Path path = toSwtPath(s);
    this.gc.setClipping(path);
    path.dispose();
}
 
Example 15
Source File: SWTGraphics2D.java    From ECG-Viewer with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Draws the outline of the specified shape using the current stroke and
 * paint settings.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #getStroke()
 * @see #fill(Shape)
 */
public void draw(Shape shape) {
    Path path = toSwtPath(shape);
    this.gc.drawPath(path);
    path.dispose();
}
 
Example 16
Source File: SWTGraphics2D.java    From buffer_bci with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Draws the outline of the specified shape using the current stroke and
 * paint settings.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #getStroke()
 * @see #fill(Shape)
 */
public void draw(Shape shape) {
    Path path = toSwtPath(shape);
    this.gc.drawPath(path);
    path.dispose();
}
 
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();

}
 
Example 18
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Draws the outline of the specified shape using the current stroke and
 * paint settings.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #getStroke()
 * @see #fill(Shape)
 */
public void draw(Shape shape) {
    Path path = toSwtPath(shape);
    this.gc.drawPath(path);
    path.dispose();
}
 
Example 19
Source File: SWTGraphics2D.java    From SIMVA-SoS with Apache License 2.0 2 votes vote down vote up
/**
 * Draws the outline of the specified shape using the current stroke and
 * paint settings.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #getStroke()
 * @see #fill(Shape)
 */
public void draw(Shape shape) {
    Path path = toSwtPath(shape);
    this.gc.drawPath(path);
    path.dispose();
}
 
Example 20
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Draws the outline of the specified shape using the current stroke and
 * paint settings.
 * 
 * @param shape  the shape (<code>null</code> not permitted).
 * 
 * @see #getPaint()
 * @see #getStroke()
 * @see #fill(Shape)
 */
public void draw(Shape shape) {
    Path path = toSwtPath(shape);
    this.gc.drawPath(path);
    path.dispose();
}