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

The following examples show how to use org.eclipse.draw2d.Graphics#fillPolygon() . 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: NoteFigure.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void fillShape(final Graphics graphics) {
    graphics.setAlpha(200);

    final Rectangle bounds = getBounds();

    final Point topRight1 = bounds.getTopRight().translate(0, RETURN_WIDTH);
    final Point topRight2 = bounds.getTopRight().translate(-RETURN_WIDTH, 0);

    final PointList pointList = new PointList();
    pointList.addPoint(bounds.getTopLeft());
    pointList.addPoint(bounds.getBottomLeft());
    pointList.addPoint(bounds.getBottomRight());
    pointList.addPoint(topRight1);
    pointList.addPoint(topRight2);
    pointList.addPoint(bounds.getTopLeft());

    graphics.fillPolygon(pointList);
}
 
Example 2
Source File: NoteFigure.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAlpha(200);

	Rectangle bounds = this.getBounds();

	Point topRight1 = bounds.getTopRight().translate(0, RETURN_WIDTH);
	Point topRight2 = bounds.getTopRight().translate(-RETURN_WIDTH, 0);

	PointList pointList = new PointList();
	pointList.addPoint(bounds.getTopLeft());
	pointList.addPoint(bounds.getBottomLeft());
	pointList.addPoint(bounds.getBottomRight());
	pointList.addPoint(topRight1);
	pointList.addPoint(topRight2);
	pointList.addPoint(bounds.getTopLeft());

	graphics.fillPolygon(pointList);
}
 
Example 3
Source File: ScaledSliderFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics g) {	
	g.setAntialias(SWT.ON);
	g.setClip(new Rectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height));
	g.setBackgroundColor(WHITE_COLOR);
	super.fillShape(g);
	Point leftPoint = getPoints().getPoint(0);
	Point rightPoint;
	if(horizontal) 
		rightPoint = getPoints().getPoint(4);
	else
		rightPoint = getPoints().getPoint(1);//.translate(0, -BREADTH/2);
	Pattern thumbPattern = null;
	boolean support3D = GraphicsUtil.testPatternSupported(g);
	if(effect3D && support3D) {
		thumbPattern = GraphicsUtil.createScaledPattern(g, Display.getCurrent(),
			leftPoint.x, leftPoint.y, rightPoint.x, rightPoint.y, WHITE_COLOR, 0, 
			thumbColor, 255);
		g.setBackgroundPattern(thumbPattern);		
	}else
		g.setBackgroundColor(thumbColor);
		
	g.fillPolygon(getPoints());
	
	if(effect3D && support3D)
		thumbPattern.dispose();
			
}
 
Example 4
Source File: ProgressBarFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics g) {	
	g.setAntialias(SWT.ON);
	g.setClip(new Rectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height));
	g.setBackgroundColor(WHITE_COLOR);
	super.fillShape(g);
	Point leftPoint = getPoints().getPoint(0);
	Point rightPoint;
	//if(horizontal) 
		rightPoint = getPoints().getPoint(2);
	//else
	//	rightPoint = getPoints().getPoint(1);//.translate(0, -BREADTH/2);
	Pattern thumbPattern = null;
	boolean support3D = GraphicsUtil.testPatternSupported(g);
	setOutline(effect3D && support3D);
	if(effect3D && support3D) {
		thumbPattern = GraphicsUtil.createScaledPattern(g, Display.getCurrent(),
			leftPoint.x, leftPoint.y, rightPoint.x, rightPoint.y, WHITE_COLOR, 0, 
			fillColor, 255);
		g.setBackgroundPattern(thumbPattern);		
	}else
		g.setBackgroundColor(fillColor);
		
	g.fillPolygon(getPoints());
	
	if(effect3D && support3D)
		thumbPattern.dispose();
			
}
 
Example 5
Source File: ChoiceFigure.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Shape#fillShape(org.eclipse.draw2d.Graphics)
 */
@Override
protected void fillShape(Graphics graphics) {
	graphics.pushState();
	graphics.setForegroundColor(getForegroundColor());
	graphics.setBackgroundColor(getBackgroundColor());
	PointList pl = new PointList();
	pl.addPoint(getBounds().getTop());
	pl.addPoint(getBounds().getRight());
	pl.addPoint(getBounds().getBottom());
	pl.addPoint(getBounds().getLeft());
	graphics.fillPolygon(pl);
	graphics.popState();
}
 
Example 6
Source File: WalkerNoteFigure.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
    graphics.setAlpha(200);
    final Rectangle bounds = getBounds();
    final Point topRight1 = bounds.getTopRight().translate(0, RETURN_WIDTH);
    final Point topRight2 = bounds.getTopRight().translate(-RETURN_WIDTH, 0);
    final PointList pointList = new PointList();
    pointList.addPoint(bounds.getTopLeft());
    pointList.addPoint(bounds.getBottomLeft());
    pointList.addPoint(bounds.getBottomRight());
    pointList.addPoint(topRight1);
    pointList.addPoint(topRight2);
    pointList.addPoint(bounds.getTopLeft());
    graphics.fillPolygon(pointList);
}
 
Example 7
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 8
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 9
Source File: Trace.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw line with the line style and line width of the trace.
 * 
 * @param graphics
 * @param p1
 * @param p2
 */
public void drawLine(Graphics graphics, Point p1, Point p2) {
	graphics.pushState();
	graphics.setLineWidth(lineWidth);
	switch (traceType) {
	case SOLID_LINE:
		graphics.setLineStyle(SWTConstants.LINE_SOLID);
		graphics.drawLine(p1, p2);
		break;
	case BAR:
		if (use_advanced_graphics)
			graphics.setAlpha(areaAlpha);
		graphics.setLineStyle(SWTConstants.LINE_SOLID);
		graphics.drawLine(p1, p2);
		break;
	case DASH_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DASH);
		graphics.drawLine(p1, p2);
		break;
	case DASHDOT_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DASHDOT);
		graphics.drawLine(p1, p2);
		break;
	case DASHDOTDOT_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DASHDOTDOT);
		graphics.drawLine(p1, p2);
		break;
	case DOT_LINE:
		graphics.setLineStyle(SWTConstants.LINE_DOT);
		graphics.drawLine(p1, p2);
		break;
	case AREA:
	case LINE_AREA:
		if (traceType == TraceType.LINE_AREA) {
			graphics.setLineStyle(SWTConstants.LINE_SOLID);
			graphics.drawLine(p1, p2);
		}
		int basey;
		switch (baseLine) {
		case NEGATIVE_INFINITY:
			basey = yAxis.getValuePosition(yAxis.getRange().getLower(), false);
			break;
		case POSITIVE_INFINITY:
			basey = yAxis.getValuePosition(yAxis.getRange().getUpper(), false);
			break;
		default:
			basey = yAxis.getValuePosition(0, false);
			break;
		}
		if (use_advanced_graphics)
			graphics.setAlpha(areaAlpha);
		graphics.setBackgroundColor(traceColor);
		graphics.fillPolygon(new int[] { p1.x, p1.y, p1.x, basey, p2.x, basey, p2.x, p2.y });
		break;
	case STEP_HORIZONTALLY:
		graphics.setLineStyle(SWTConstants.LINE_SOLID);
		graphics.drawLine(p1.x, p1.y, p2.x, p1.y);
		graphics.drawLine(p2.x, p1.y, p2.x, p2.y);
		break;
	case STEP_VERTICALLY:
		graphics.setLineStyle(SWTConstants.LINE_SOLID);
		graphics.drawLine(p1.x, p1.y, p1.x, p2.y);
		graphics.drawLine(p1.x, p2.y, p2.x, p2.y);
		break;

	default:
		break;
	}
	graphics.popState();
}
 
Example 10
Source File: JoinXYLayoutEditPolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected EditPolicy createChildEditPolicy( EditPart child )
{
	return new ResizableEditPolicy( ) {

		protected IFigure createDragSourceFeedbackFigure( )
		{
			// Use a ghost rectangle for feedback
			Figure r = new Figure( ) {

				protected void paintFigure( Graphics graphics )
				{
					Rectangle rect = getBounds( ).getCopy( );

					graphics.setXORMode( true );
					graphics.setForegroundColor( ColorConstants.white );
					graphics.setBackgroundColor( ColorManager.getColor( 31,
							31,
							31 ) );

					graphics.translate( getLocation( ) );

					PointList outline = new PointList( );

					outline.addPoint( 0, 0 );
					outline.addPoint( rect.width, 0 );
					outline.addPoint( rect.width - 1, 0 );
					outline.addPoint( rect.width - 1, rect.height - 1 );
					outline.addPoint( 0, rect.height - 1 );

					graphics.fillPolygon( outline );

					// draw the inner outline
					PointList innerLine = new PointList( );

					innerLine.addPoint( rect.width - 0 - 1, 0 );
					innerLine.addPoint( rect.width - 0 - 1, 0 );
					innerLine.addPoint( rect.width - 1, 0 );
					innerLine.addPoint( rect.width - 0 - 1, 0 );
					innerLine.addPoint( 0, 0 );
					innerLine.addPoint( 0, rect.height - 1 );
					innerLine.addPoint( rect.width - 1, rect.height - 1 );
					innerLine.addPoint( rect.width - 1, 0 );

					graphics.drawPolygon( innerLine );

					graphics.drawLine( rect.width - 0 - 1,
							0,
							rect.width - 1,
							0 );

					graphics.translate( getLocation( ).getNegated( ) );
				}
			};

			r.setBounds( getInitialFeedbackBounds( ) );
			addFeedback( r );
			return r;
		}

	};
}
 
Example 11
Source File: ReportFigureUtilities.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Paints a triangle using given height and central point.
 * 
 * @param graphics
 * @param triangleHeight
 * @param triangleCenter
 */
public static void paintTriangle( Graphics graphics, int triangleHeight,
		Point triangleCenter )
{
	graphics.fillPolygon( getTrianglePoints( triangleHeight, triangleCenter ) );
}