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

The following examples show how to use org.eclipse.draw2d.Graphics#pushState() . 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: DeepHistoryFigure.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void outlineShape(Graphics graphics) {
	graphics.pushState();
	//Outline with foreground
	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 * OFFSET), (int) (-bounds.height * HEIGHT_RATIO)),
			bounds.getCenter().getTranslated((int) (bounds.width * OFFSET), (int) (bounds.height * HEIGHT_RATIO)));
	graphics.drawLine(bounds.getCenter().getTranslated((int) (-bounds.width * WIDTH_RATIO), 0), bounds.getCenter()
			.getTranslated((int) (bounds.width * OFFSET), 0));

	// draw the '*' character
	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 * OFFSET)));
	graphics.drawLine(bounds.getCenter().getTranslated((int) (bounds.width * 0.15), (int) (-bounds.height * 0.20)),
			bounds.getCenter().getTranslated((int) (bounds.width * 0.35), (int) (-bounds.height * 0.10)));
	graphics.drawLine(bounds.getCenter().getTranslated((int) (bounds.width * 0.35), (int) (-bounds.height * 0.20)),
			bounds.getCenter().getTranslated((int) (bounds.width * 0.15), (int) (-bounds.height * 0.10)));
	graphics.popState();
}
 
Example 2
Source File: Grid.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	super.paintFigure(graphics);
	graphics.pushState();
	if (axis.isShowMajorGrid()) {
		graphics.setLineStyle(axis.isDashGridLine() ? SWTConstants.LINE_DASH : SWTConstants.LINE_SOLID);
		graphics.setForegroundColor(axis.getMajorGridColor());
		graphics.setLineWidth(1);
		for (int pos : axis.getScaleTickLabels().getTickLabelPositions()) {
			if (axis.isHorizontal())
				graphics.drawLine(axis.getBounds().x + pos, bounds.y + bounds.height, axis.getBounds().x + pos,
						bounds.y);
			else
				graphics.drawLine(bounds.x, axis.getBounds().y + axis.getBounds().height - pos,
						bounds.x + bounds.width, axis.getBounds().y + axis.getBounds().height - pos);
		}
	}
	graphics.popState();
}
 
Example 3
Source File: PrintERDiagramOperation.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void printPages() {
	Graphics graphics = getFreshPrinterGraphics();
	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();
			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: 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 5
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 6
Source File: PrintERDiagramOperation.java    From erflute with Apache License 2.0 6 votes vote down vote up
@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 7
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 8
Source File: ROIFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	if(roiInfoProvider!=null && roiDataBounds!=null){
		String text = roiInfoProvider.getROIInfo(roiDataBounds.x, roiDataBounds.y, 
				roiDataBounds.width, roiDataBounds.height);
		Dimension size = TextUtilities.INSTANCE.getTextExtents(text, getFont());
		graphics.pushState();
		graphics.translate(getLocation());
		graphics.fillRectangle(roiGeoBounds.x, roiGeoBounds.y - size.height, size.width, size.height);
		graphics.drawText(text, roiGeoBounds.x, roiGeoBounds.y - size.height);
		graphics.popState();
	}
	super.paintFigure(graphics);
	
}
 
Example 9
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 10
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 11
Source File: ProcessFigure.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	graphics.pushState();
	double contribution = node.upstreamContribution;
	Color color = Colors.getForContribution(contribution);
	graphics.setBackgroundColor(color);
	paintBody(graphics);
	graphics.popState();
}
 
Example 12
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 13
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 14
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 15
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 16
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 17
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 18
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 19
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 20
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();
}