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

The following examples show how to use org.eclipse.draw2d.Graphics#popState() . 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: ChoiceFigure.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Shape#outlineShape(org.eclipse.draw2d.Graphics)
 */
@Override
protected void outlineShape(Graphics graphics) {
	graphics.pushState();
	graphics.setForegroundColor(getForegroundColor());
	graphics.setBackgroundColor(getBackgroundColor());
	Rectangle f = Rectangle.SINGLETON;
	Rectangle r = getBounds();
	f.x = r.x + getLineWidth() / 2;
	f.y = r.y + getLineWidth() / 2;
	f.width = r.width - getLineWidth() - 1;
	f.height = r.height - getLineWidth() - 1;

	PointList pl = new PointList();
	pl.addPoint(f.getTop());
	pl.addPoint(f.getRight());
	pl.addPoint(f.getBottom());
	pl.addPoint(f.getLeft());

	graphics.drawPolygon(pl);
	graphics.popState();
}
 
Example 2
Source File: ShallowHistoryFigure.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.eclipse.draw2d.Ellipse#outlineShape(org.eclipse.draw2d.Graphics)
 */
@Override
protected void outlineShape(Graphics graphics) {
	graphics.pushState();
	graphics.setForegroundColor(getBackgroundColor());
	super.outlineShape(graphics);
	// draw the 'H' letter
	graphics.setForegroundColor(getForegroundColor());
	graphics.setBackgroundColor(getBackgroundColor());
	graphics.drawLine(
			bounds.getCenter().getTranslated((int) (-bounds.width * WIDTH_RATIO), (int) (-bounds.height * HEIGHT_RATIO)), bounds
					.getCenter().getTranslated((int) (-bounds.width * WIDTH_RATIO), (int) (bounds.height * HEIGHT_RATIO)));
	graphics.drawLine(bounds.getCenter().getTranslated((int) (bounds.width * WIDTH_RATIO), (int) (-bounds.height * HEIGHT_RATIO)),
			bounds.getCenter().getTranslated((int) (bounds.width * WIDTH_RATIO), (int) (bounds.height * HEIGHT_RATIO)));
	graphics.drawLine(bounds.getCenter().getTranslated((int) (-bounds.width * WIDTH_RATIO), 0), bounds.getCenter()
			.getTranslated((int) (bounds.width * WIDTH_RATIO), 0));
	graphics.popState();
}
 
Example 3
Source File: PrintERDiagramOperation.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void printPages() {
    final Graphics graphics = getFreshPrinterGraphics();
    final IFigure figure = getPrintSource();
    setupPrinterGraphicsFor(graphics, figure);
    final Rectangle bounds = figure.getBounds();
    int x = bounds.x, y = bounds.y;
    final Rectangle clipRect = new Rectangle();
    while (y < bounds.y + bounds.height) {
        while (x < bounds.x + bounds.width) {
            graphics.pushState();
            getPrinter().startPage();
            graphics.translate(-x, -y);
            graphics.getClip(clipRect);
            clipRect.setLocation(x, y);
            graphics.clipRect(clipRect);
            figure.paint(graphics);
            getPrinter().endPage();
            graphics.popState();
            x += clipRect.width;
        }
        x = bounds.x;
        y += clipRect.height;
    }
}
 
Example 4
Source File: FirstLevelHandleDataItemFigure.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void paintTriangle( Graphics graphics )
{
	graphics.pushState( );

	Rectangle rect = super.getClientArea();
	//int x = bounds.x + ( bounds.width - rect.width ) / 2;
	// int y = bounds.y + ( bounds.height - rect.height ) / 2;
	Point center = getCenterPoint( rect );
	graphics.setBackgroundColor( Display.getCurrent( )
			.getSystemColor( SWT.COLOR_BLACK ) );


	ReportFigureUtilities.paintTriangle( graphics,
			TRIANGLE_HEIGHT,
			center );
	graphics.popState( );
}
 
Example 5
Source File: CustomTextAnnotation2EditPart.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void paintGradient(Graphics graphics) {                     
 Rectangle rect = getClientArea();
 if (rect == null)
	 return;

 graphics.pushState();
 Color from = ColorConstants.white;
 Color to = getBackgroundColor();

 graphics.setForegroundColor(from);
 graphics.setBackgroundColor(to);

 graphics.fillGradient(rect, false);

 graphics.popState();
 //now drawing the outline shape
 super.outlineShape(graphics);
}
 
Example 6
Source File: ProcessFigure.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics g) {
	g.pushState();
	g.setBackgroundColor(ColorConstants.white);
	g.fillRectangle(new Rectangle(getLocation(), getSize()));
	paintTop(g);
	if (!node.isMinimized() || Animation.isRunning())
		paintTable(g);
	g.popState();
	super.paintFigure(g);
}
 
Example 7
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 8
Source File: StatisticFigure.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics graphics) {
	super.paint(graphics);
	graphics.pushState();
	paintParameterLabels();
	paintChartFrame(graphics);
	Point boxSize = calcBoxSize();
	paintBoxes(graphics, boxSize);
	paintLines(graphics, boxSize);
	graphics.popState();
}
 
Example 9
Source File: DropShadowRectangle.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private void drawShadowLayer(Rectangle rectangle, Graphics graphics,
		int offset, Color color) {

	// Save the state of the graphics object
	graphics.pushState();
	graphics.setLineWidth(0);
	graphics.setBackgroundColor(color);
	Rectangle shadowLayer = new Rectangle(rectangle);
	shadowLayer.x += offset;
	shadowLayer.y += offset;
	graphics.fillRoundRectangle(shadowLayer, corner.width,
			corner.height);
	// Restore the start of the graphics object
	graphics.popState();
}
 
Example 10
Source File: DropShadowRectangle.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private void drawShadowLayer(final Rectangle rectangle, final Graphics graphics, final int offset, final Color color) {

        // Save the state of the graphics object
        graphics.pushState();
        graphics.setLineWidth(0);
        graphics.setBackgroundColor(color);
        final Rectangle shadowLayer = new Rectangle(rectangle);
        shadowLayer.x += offset;
        shadowLayer.y += offset;

        final Dimension cornerDimensions = getCornerDimensions();
        graphics.fillRoundRectangle(shadowLayer, cornerDimensions.width, cornerDimensions.height);
        // Restore the start of the graphics object
        graphics.popState();
    }
 
Example 11
Source File: Trace.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	super.paintFigure(graphics);
	graphics.pushState();
	try {
		paintInternalFigure(graphics);
	} finally {
		graphics.popState();
	}
}
 
Example 12
Source File: DropShadowRectangle.java    From erflute with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void drawShadowLayer(Rectangle rectangle, Graphics graphics, int offset, Color color) {
    // Save the state of the graphics object
    graphics.pushState();
    graphics.setLineWidth(0);
    graphics.setBackgroundColor(color);
    final Rectangle shadowLayer = new Rectangle(rectangle);
    shadowLayer.x += offset;
    shadowLayer.y += offset;
    graphics.fillRoundRectangle(shadowLayer, corner.width, corner.height);
    // Restore the start of the graphics object
    graphics.popState();
}
 
Example 13
Source File: Legend.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void outlineShape(Graphics graphics) {
	if (!isVisible() || !drawBorder)
		return;
	
	graphics.pushState();
	if (!traceList.isEmpty()) {
		Color fg = traceList.get(0).getYAxis().getForegroundColor();
		if (fg == null)
			fg = ColorConstants.black;
		graphics.setForegroundColor(fg);
	}
	super.outlineShape(graphics);
	graphics.popState();
}
 
Example 14
Source File: ReportPrintGraphicalViewerOperation.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Prints the pages based on the current print mode.
 * 
 * @see org.eclipse.draw2d.PrintOperation#printPages()
 */
protected void printPages( )
{
	Graphics graphics = getFreshGraphics( );
	IFigure figure = getPrintSource( );
	setupPrinterGraphicsFor( graphics, figure );
	Rectangle bounds = figure.getBounds( );
	int x = bounds.x, y = bounds.y;
	Rectangle clipRect = new Rectangle( );
	while ( y < bounds.y + bounds.height )
	{
		while ( x < bounds.x + bounds.width )
		{
			graphics.pushState( );
			graphics.translate( -x, -y );
			graphics.getClip( clipRect );
			clipRect.setLocation( x, y );
			graphics.clipRect( clipRect );
			figure.paint( graphics );
			graphics.popState( );
			x += clipRect.width;
			if ( x == 0 )
			{
				return;
			}
		}
		x = bounds.x;
		y += clipRect.height;
	}
}
 
Example 15
Source File: AlphaLabel.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	graphics.pushState();
	graphics.setAlpha(alpha);
	graphics.fillRectangle(bounds);
	graphics.popState();
	super.paintFigure(graphics);
}
 
Example 16
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 17
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 18
Source File: SyntaxColoringLabel.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void paintText(Graphics g, String draw, int x, int y, int bidiLevel) {
	if (!highlight) {
		super.paintText(g, draw, x, y, bidiLevel);
		return;
	}
	if (ranges.length == 0) {
		draw = replaceTabs(draw);
		super.paintText(g, draw, x, y, bidiLevel);
		return;
	}
	if (bidiLevel == -1) {
		String originalDraw = draw;
		int paintOffset = 0;
		int lineOffset = getText().indexOf(originalDraw, Math.min(fromIndex, getText().length() - 1));
		fromIndex += originalDraw.length();
		if (lineOffset == -1) {
			// This may happen if the string is truncated with '..'
			originalDraw = replaceTabs(originalDraw);
			super.paintText(g, originalDraw, x, y, bidiLevel);
			return;
		}
		try {
			g.pushState();
			g.setFont(getFont());
			for (StyleRange range : ranges) {
				int beginIndex = range.start - lineOffset;
				if (beginIndex > draw.length()) {
					break;
				}
				Font font = SWT.BOLD == (range.fontStyle & SWT.BOLD) ? boldFont : getFont();
				if (font != g.getFont()) {
					g.setFont(font);
				}
				g.setForegroundColor(range.foreground != null ? range.foreground : getForegroundColor());
				g.setBackgroundColor(range.background != null ? range.background : getBackgroundColor());
				int endIndex = beginIndex + range.length;
				String substring = draw.substring(beginIndex > 0 ? beginIndex : 0,
						Math.min(endIndex > 0 ? endIndex : 0, draw.length()));
				substring = replaceTabs(substring);
				g.drawText(substring, x + paintOffset, y);

				int offset = getTextExtend(g.getFont(), substring);
				paintOffset += offset;
			}
		} finally {
			g.popState();
		}
	} else {
		super.paintText(g, draw, x, y, bidiLevel);
	}
}
 
Example 19
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 20
Source File: GraphicsUtil.java    From statecharts with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * This function fills a rectangle with a vertical gradient. This implementation does not use the 
 * gradient mechanism based on background patterns since they do not work stable on all systems.
 *   
 * @param graphics
 * @param bounds
 * @param c1
 * @param c2
 */
public static void fillVerticalGradientRectangle(Graphics graphics, Rectangle bounds, Color c1, Color c2) {
	
	graphics.pushState();
	
	graphics.setForegroundColor(c2);
	graphics.setBackgroundColor(c1);
			
	graphics.fillGradient(bounds.x, bounds.y, bounds.width, bounds.height, true);
					
	graphics.popState();
}