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

The following examples show how to use org.eclipse.draw2d.Graphics#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: ReportFigureUtilities.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Paints double arrow on list element
 * 
 * @param graphics
 * @param height
 * @param center
 */
public static void paintDoubleArrow( Graphics graphics, int height,
		Point center )
{
	int points[] = new int[6];
	int xOff = (int) ( height * Math.tan( Math.PI / 4 ) / 2 );
	points[0] = center.x - xOff;
	points[1] = center.y - height / 2;
	points[2] = center.x;
	points[3] = center.y;
	points[4] = center.x - xOff;
	points[5] = center.y + height / 2;

	graphics.drawPolyline( points );

	incXOffset( points, 1 );
	graphics.drawPolyline( points );

	incXOffset( points, 3 );
	graphics.drawPolyline( points );

	incXOffset( points, 1 );
	graphics.drawPolyline( points );
}
 
Example 2
Source File: Trace.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw polyline with the line style and line width of the trace.
 * 
 * @param graphics
 * @param pl
 */
private void drawPolyline(Graphics graphics, PointList pl) {
	graphics.pushState();
	graphics.setLineWidth(lineWidth);
	switch (traceType) {
	case SOLID_LINE:
	case STEP_HORIZONTALLY:
	case STEP_VERTICALLY:
		graphics.setLineStyle(SWTConstants.LINE_SOLID);
		graphics.drawPolyline(pl);
		break;
	case DASH_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DASH);
		graphics.drawPolyline(pl);
		break;
	case DASHDOT_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DASHDOT);
		graphics.drawPolyline(pl);
		break;
	case DASHDOTDOT_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DASHDOTDOT);
		graphics.drawPolyline(pl);
		break;
	case DOT_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DOT);
		graphics.drawPolyline(pl);
		break;
	default:
		break;
	}
	graphics.popState();
}
 
Example 3
Source File: Legend.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawTraceLegend(Trace trace, Graphics graphics, int hPos, int vPos) {
	graphics.pushState();
	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);
	graphics.setForegroundColor(trace.getTraceColor());

	// limit size of symbol to ICON_WIDTH - INNER_GAP
	int maxSize = ((trace.getPointSize() > Math.floor((ICON_WIDTH - OUT_GAP) / 2))
			? (int) Math.floor((ICON_WIDTH - OUT_GAP))
			: trace.getPointSize());

	// draw symbol
	switch (trace.getTraceType()) {
	case BAR:
		trace.drawLine(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2 ),
				new Point(hPos + ICON_WIDTH / 2, vPos + ICON_WIDTH));
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2));
		break;
	case LINE_AREA:
		graphics.drawPolyline(new int[] { hPos, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH / 2, vPos + maxSize / 2,
				hPos + ICON_WIDTH - 1, vPos + ICON_WIDTH / 2, });
	case AREA:
		graphics.setBackgroundColor(trace.getTraceColor());
		if (Preferences.useAdvancedGraphics())
			graphics.setAlpha(trace.getAreaAlpha());
		graphics.fillPolygon(new int[] { hPos, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH / 2, vPos + maxSize / 2,
				hPos + ICON_WIDTH, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH, vPos + ICON_WIDTH, hPos,
				vPos + ICON_WIDTH });
		if (Preferences.useAdvancedGraphics())
			graphics.setAlpha(255);
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2));
		break;
	default:
		trace.drawLine(graphics, new Point(hPos, vPos + ICON_WIDTH / 2),
				new Point(hPos + ICON_WIDTH, vPos + ICON_WIDTH / 2));
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + ICON_WIDTH / 2));
		break;
	}

	// draw text
	Font previousFont = super.getFont();
	if (font != null) {
		graphics.setFont(font);
	}
	
	graphics.drawText(trace.getName(), hPos + ICON_WIDTH + INNER_GAP,
			vPos + ICON_WIDTH / 2 - FigureUtilities.getTextExtents(trace.getName(), getFont()).height / 2);
	
	graphics.setFont(previousFont);
	graphics.popState();
}
 
Example 4
Source File: Trace.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawPoint(Graphics graphics, Point pos, ISample sample) {
	Color renderColor = traceColor;
	PointStyle renderPointStyle = pointStyle;
	int renderPointSize = pointSize;
	try {
		if ((fPointStyleProvider != null) && (sample != null)) {
			renderColor = fPointStyleProvider.getPointColor(sample, this);
			renderPointStyle = fPointStyleProvider.getPointStyle(sample, this);
			renderPointSize = fPointStyleProvider.getPointSize(sample, this);
		}
	} catch (Exception ex) {
		// Draw anyway and log error
		System.err.println(ex.getMessage());
		renderColor = traceColor;
		renderPointStyle = pointStyle;
		renderPointSize = pointSize;
	}
	// Shortcut when no point requested
	if (renderPointStyle == PointStyle.NONE) {
		return;
	}
	graphics.pushState();
	graphics.setBackgroundColor(renderColor);
	graphics.setForegroundColor(renderColor); // Otherwise redraw does not
												// affect lines
	graphics.setLineWidth(1);
	graphics.setLineStyle(SWTConstants.LINE_SOLID);
	int halfSize = renderPointSize / 2;
	switch (renderPointStyle) {
	case POINT:
		graphics.fillOval(new Rectangle(pos.x - halfSize, pos.y - halfSize, renderPointSize, renderPointSize));
		break;
	case CIRCLE:
		graphics.drawOval(new Rectangle(pos.x - halfSize, pos.y - halfSize, renderPointSize, renderPointSize));
		break;
	case FILLED_CIRCLE:
		graphics.fillOval(new Rectangle(pos.x - halfSize, pos.y - halfSize, renderPointSize, renderPointSize));
		break;
	case TRIANGLE:
		graphics.drawPolygon(new int[] { pos.x - halfSize, pos.y + halfSize, pos.x, pos.y - halfSize,
				pos.x + halfSize, pos.y + halfSize });
		break;
	case FILLED_TRIANGLE:
		graphics.fillPolygon(new int[] { pos.x - halfSize, pos.y + halfSize, pos.x, pos.y - halfSize,
				pos.x + halfSize, pos.y + halfSize });
		break;
	case SQUARE:
		graphics.drawRectangle(new Rectangle(pos.x - halfSize, pos.y - halfSize, renderPointSize, renderPointSize));
		break;
	case FILLED_SQUARE:
		graphics.fillRectangle(new Rectangle(pos.x - halfSize, pos.y - halfSize, renderPointSize, renderPointSize));
		break;
	case BAR:
		graphics.drawLine(pos.x, pos.y - halfSize, pos.x, pos.y + halfSize);
		break;
	case CROSS:
		graphics.drawLine(pos.x, pos.y - halfSize, pos.x, pos.y + halfSize);
		graphics.drawLine(pos.x - halfSize, pos.y, pos.x + halfSize, pos.y);
		break;
	case XCROSS:
		graphics.drawLine(pos.x - halfSize, pos.y - halfSize, pos.x + halfSize, pos.y + halfSize);
		graphics.drawLine(pos.x + halfSize, pos.y - halfSize, pos.x - halfSize, pos.y + halfSize);
		break;
	case DIAMOND:
		graphics.drawPolyline(new int[] { pos.x, pos.y - halfSize, pos.x - halfSize, pos.y,
				pos.x, pos.y + halfSize, pos.x + halfSize, pos.y, pos.x, pos.y - halfSize });
		break;
	case FILLED_DIAMOND:
		graphics.fillPolygon(new int[] { pos.x, pos.y - halfSize, pos.x - halfSize, pos.y,
				pos.x, pos.y + halfSize, pos.x + halfSize, pos.y });
		break;
	default:
		break;
	}
	graphics.popState();
}
 
Example 5
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 6
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 7
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 8
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;
}
 
Example 9
Source File: CursorTimingsLayer.java    From nebula with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Use calculated points list. The original implementation directly accesses the points member.
 *
 * @see #getPoints()
 */
@Override
protected void outlineShape(Graphics g) {
	g.drawPolyline(getPoints());
}