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

The following examples show how to use org.eclipse.swt.graphics.Path#close() . 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
/**
 * 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 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: 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();

}