Java Code Examples for org.eclipse.swt.graphics.GC#drawPolyline()

The following examples show how to use org.eclipse.swt.graphics.GC#drawPolyline() . 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: DefaultDropPointRenderer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));

    gc.fillPolygon(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                              getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                              getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                              getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                              getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                              getBounds().y + 5 });

    gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));

    gc.drawPolyline(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                               getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                               getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                               getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                               getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                               getBounds().y + 5 });

}
 
Example 2
Source File: ImageSelector.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void drawArrows(int x, final GC gc) {
	gc.setForeground(arrowColor);

	final Rectangle clientArea = getClientArea();
	final int topY = (clientArea.height - ARROW_SIZE) / 2;
	final int width = (int) (ARROW_SIZE * .5f);

	gc.setLineWidth(hoverLeftArrow ? 3 : 1);

	gc.drawPolyline(new int[] { x + width, topY, //
			x, topY + ARROW_SIZE / 2, //
			x + width, topY + ARROW_SIZE });

	arrowLeftArea = new Rectangle(x, topY, ARROW_SIZE, ARROW_SIZE);

	x += ARROW_SIZE * 3;

	gc.setLineWidth(hoverRightArrow ? 3 : 1);
	gc.drawPolyline(new int[] { x, topY, //
			x + width, topY + ARROW_SIZE / 2, //
			x, topY + ARROW_SIZE });
	arrowRightArea = new Rectangle(x, topY, ARROW_SIZE, ARROW_SIZE);
}
 
Example 3
Source File: PolygonLineIntersection.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected AbstractControllableShape createControllableShape2(
		Canvas canvas) {
	return new AbstractControllableShape(canvas) {
		@Override
		public void createControlPoints() {
			addControlPoint(new Point(100, 100));
			addControlPoint(new Point(300, 300));
		}

		@Override
		public Line createGeometry() {
			Point[] points = getControlPoints();
			return new Line(points[0], points[1]);
		}

		@Override
		public void drawShape(GC gc) {
			Line line = createGeometry();
			gc.drawPolyline(Geometry2SWT.toSWTPointArray(line));
		}
	};
}
 
Example 4
Source File: EllipseLineIntersection.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected AbstractControllableShape createControllableShape2(
		Canvas canvas) {
	return new AbstractControllableShape(canvas) {
		@Override
		public void createControlPoints() {
			addControlPoint(new Point(100, 100));
			addControlPoint(new Point(300, 300));
		}

		@Override
		public Line createGeometry() {
			Point[] points = getControlPoints();
			return new Line(points[0], points[1]);
		}

		@Override
		public void drawShape(GC gc) {
			Line line = createGeometry();
			gc.drawPolyline(Geometry2SWT.toSWTPointArray(line));
		}
	};
}
 
Example 5
Source File: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void draw(@Nullable ITimeGraphPresentationProvider provider, GC gc) {
    RGBAColor rgba = fColorRGBA;
    int colorInt = rgba.toInt();
    Color color = getColor(colorInt);
    for (int i = 0; i < this.fSeriesPoints.size(); i++) {
        Color prev = gc.getForeground();
        int prevAlpha = gc.getAlpha();
        gc.setAlpha(rgba.getAlpha());
        gc.setForeground(color);
        List<LongPoint> series = fSeriesPoints.get(i);
        int[] points = new int[series.size() * 2];
        for (int point = 0; point < series.size(); point++) {
            LongPoint longPoint = series.get(point);
            points[point * 2] = longPoint.x;
            points[point * 2 + 1] = fBounds.height - (int) ((longPoint.y - fMin) * fScale) + fBounds.y;
        }
        gc.drawPolyline(points);
        gc.setForeground(prev);
        gc.setAlpha(prevAlpha);
    }
}
 
Example 6
Source File: DefaultDropPointRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));

    gc.fillPolygon(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                              getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                              getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                              getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                              getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                              getBounds().y + 5 });

    gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));

    gc.drawPolyline(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                               getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                               getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                               getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                               getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                               getBounds().y + 5 });

}
 
Example 7
Source File: DefaultDropPointRenderer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));

    gc.fillPolygon(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                              getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                              getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                              getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                              getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                              getBounds().y + 5 });

    gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));

    gc.drawPolyline(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                               getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                               getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                               getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                               getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                               getBounds().y + 5 });

}
 
Example 8
Source File: Oscilloscope.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < chan.length; c++) {

			if (chan[c].tailSize <= 0) {
				chan[c].stack.popNegate(0);
				continue;
			}

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0 && l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 9
Source File: Plotter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < this.chan.length; c++) {

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			PositionPolyLine(l1);
			PositionPolyLine(l2);

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(this.chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && this.chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0
					&& l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 10
Source File: RingOutlineExample.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ControllableShape[] getControllableShapes() {
	return new ControllableShape[] { new ControllableShape() {
		{
			addControlPoints(new Point(100, 100), new Point(400, 100),
					new Point(400, 200));
			addControlPoints(new Point(400, 100), new Point(400, 400),
					new Point(300, 400));
			addControlPoints(new Point(400, 400), new Point(100, 400),
					new Point(100, 300));
			addControlPoints(new Point(100, 400), new Point(100, 100),
					new Point(200, 100));
		}

		@Override
		public Ring getShape() {
			Point[] cp = getPoints();

			Polygon[] polygons = new Polygon[cp.length / 3];
			for (int i = 0; i < polygons.length; i++) {
				polygons[i] = new Polygon(cp[3 * i], cp[3 * i + 1],
						cp[3 * i + 2]);
			}

			return new Ring(polygons);
		}

		@Override
		public void onDraw(GC gc) {
			Ring ring = getShape();

			gc.setForeground(
					Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
			int lineWidth = gc.getLineWidth();
			gc.setLineWidth(1);

			for (Polyline outline : ring.getOutlines()) {
				gc.drawPolyline(Geometry2SWT.toSWTPointArray(outline));
				gc.setLineWidth(gc.getLineWidth() + 1);
			}

			gc.setLineWidth(lineWidth);
		}
	} };
}
 
Example 11
Source File: BezierApproximationExample.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ControllableShape[] getControllableShapes() {
	return new ControllableShape[] { new ControllableShape() {
		{
			/*
			 * These are the control points used to construct the
			 * BezierCurve below.
			 */
			addControlPoints(new Point(100, 200), new Point(150, 250),
					new Point(200, 150), new Point(250, 250),
					new Point(300, 150), new Point(350, 250),
					new Point(400, 200));
		}

		@Override
		public BezierCurve getShape() {
			/*
			 * Here, we construct the BezierCurve from the defined Points.
			 */
			return new BezierCurve(getPoints());
		}

		@Override
		public void onDraw(GC gc) {
			/*
			 * This is the code to display the BezierCurve via SWT.
			 */

			// Construct the Bezier curve.
			BezierCurve curve = getShape();

			// Display the BezierCurve as a Path.
			gc.drawPath(
					new org.eclipse.swt.graphics.Path(Display.getCurrent(),
							Geometry2SWT.toSWTPathData(curve.toPath())));

			// Display the connection line of its control points.
			gc.setLineStyle(SWT.LINE_DOT);
			gc.drawPolyline(Geometry2SWT
					.toSWTPointArray(new Polyline(curve.getPoints())));

		}
	} };
}
 
Example 12
Source File: MapView.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
private void renderLine(GC gc, LayerConfig conf, Feature f, LineString line) {
	int[] points = translation.translate(line);
	gc.setLineWidth(5 + zoom);
	gc.drawPolyline(points);
	gc.setLineWidth(1);
}