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

The following examples show how to use org.eclipse.draw2d.Graphics#setFont() . 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: LinearScaleTickLabels.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draw the Y tick. To be overridden if needed.
 *
 * @param graphics
 *            the graphics context
 */
protected void drawYTick(Graphics graphics) {
	// draw tick labels
	graphics.setFont(scale.getFont());
	int fontHeight = ticks.getMaxHeight();
	for (int i = 0; i < ticks.getPositions().size(); i++) {
		if (ticks.getLabels().isEmpty()) {
			break;
		}

		if (ticks.isVisible(i)) {
			String label = ticks.getLabel(i);
			int x = 0;
			if (ticks.getLabel(0).startsWith(MINUS) && !label.startsWith(MINUS)) {
				x += FigureUtilities.getTextExtents(MINUS, getFont()).width;
			}
			int y = (int) Math.ceil(scale.getLength() - ticks.getPosition(i) - fontHeight / 2.0);
			graphics.drawText(label, x, y);
		}
	}
}
 
Example 2
Source File: ReportPrintGraphicalViewerOperation.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets up Graphics object for the given IFigure.
 * 
 * @param graphics
 *            The Graphics to setup
 * @param figure
 *            The IFigure used to setup graphics
 */
protected void setupPrinterGraphicsFor( Graphics graphics, IFigure figure )
{
	// Because the ScaleGraphics don't support the scale(float h,float v),so
	// now suppoer fit the page.
	Rectangle printRegion = getPrintRegion( );

	Rectangle bounds = figure.getBounds( );
	double xScale = (double) printRegion.width / bounds.width;
	double yScale = (double) printRegion.height / bounds.height;
	graphics.scale( Math.min( xScale, yScale ) );

	// float xScale = (float) printRegion.width / bounds.width;
	// float yScale = (float) printRegion.height / bounds.height;
	// graphics.scale( xScale, yScale );

	graphics.setForegroundColor( figure.getForegroundColor( ) );
	graphics.setBackgroundColor( figure.getBackgroundColor( ) );
	graphics.setFont( figure.getFont( ) );
}
 
Example 3
Source File: ProcessFigure.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private void drawTexts(Graphics g, String single, String total) {
	Point loc = getLocation();
	Font normalFont = g.getFont();
	Font boldFont = getBoldFont(normalFont);
	g.setFont(boldFont);
	Color black = g.getForegroundColor();
	g.setForegroundColor(Colors.white());
	String name = Strings.cut(node.getName(), 30);
	g.drawText(name, loc.x + 5, loc.y + 5);
	g.setFont(normalFont);
	g.drawText(M.DirectContribution + ":", loc.x + 5, loc.y + 35);
	g.drawText(single, loc.x + 5, loc.y + 50);
	g.drawText(M.UpstreamTotal + ":", loc.x + 5, loc.y + 80);
	g.drawText(total, loc.x + 5, loc.y + 95);
	g.setForegroundColor(black);
}
 
Example 4
Source File: ProductSystemFigure.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private void paintInfoBox(Graphics g) {
	g.pushState();
	Font normalFont = g.getFont();
	Font infoFont = getInfoFont(normalFont);
	g.setFont(infoFont);
	Object selection = node.selection;
	double cutoffValue = node.cutoff * 100;
	String cutoffText = M.DontShowSmallerThen + " "
			+ Numbers.format(cutoffValue, 3) + "%";
	if (selection != null) {
		g.drawText(M.ProductSystem + ": "
				+ node.productSystem.name, new Point(5, 5));
		String label = selectionLabel(selection);
		g.drawText(label, new Point(5, 30));
		g.drawText(cutoffText, new Point(5, 60));

	} else {
		g.drawText(M.NoAnalysisOptionsSet, new Point(5, 5));
		g.drawText(M.ClickHereToChangeDisplay, new Point(5, 30));
	}
	g.setFont(normalFont);
	drawColorScale(g);
	g.popState();
}
 
Example 5
Source File: RoundScaleTickLabels.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw the tick labels.
 * 
 * @param grahics
 *            the graphics context
 */
private void drawTickLabels(Graphics graphics) {
    // draw tick labels
    graphics.setFont(scale.getFont());
    for (int i = 0; i < tickLabelPositions.size(); i++) {
        if (tickLabelVisibilities.get(i) == true) {
            String text = tickLabels.get(i);
            graphics.drawText(text, tickLabelAreas.get(i).x, tickLabelAreas.get(i).y);
        }
    }
}
 
Example 6
Source File: LinearScaleTickLabels.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw the X tick. To be overridden if needed.
 *
 * @param graphics
 *            the graphics context
 */
protected void drawXTick(Graphics graphics) {
	// draw tick labels
	graphics.setFont(scale.getFont());
	for (int i = 0; i < ticks.getPositions().size(); i++) {
		if (ticks.isVisible(i) == true) {
			String text = ticks.getLabel(i);
			int fontWidth = FigureUtilities.getTextExtents(text, getFont()).width;
			int x = (int) Math.ceil(ticks.getLabelPosition(i) - fontWidth / 2.0);// +
																					// offset);
			graphics.drawText(text, x, 0);
		}
	}
}
 
Example 7
Source File: LinearScaleTickLabels.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {
	graphics.translate(bounds.x, bounds.y);
	graphics.setFont(getFont());
	if (scale.isHorizontal()) {
		drawXTick(graphics);
	} else {
		drawYTick(graphics);
	}

	super.paintClientArea(graphics);
}
 
Example 8
Source File: PrintERDiagramOperation.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void setupPrinterGraphicsFor(final Graphics graphics, final IFigure figure) {
    final ERDiagram diagram = getDiagram();
    final PageSetting pageSetting = diagram.getPageSetting();

    final double dpiScale = (double) getPrinter().getDPI().x / Display.getCurrent().getDPI().x * pageSetting.getScale() / 100;

    final Rectangle printRegion = getPrintRegion();
    // put the print region in display coordinates
    printRegion.width /= dpiScale;
    printRegion.height /= dpiScale;

    final Rectangle bounds = figure.getBounds();
    final double xScale = (double) printRegion.width / bounds.width;
    final double yScale = (double) printRegion.height / bounds.height;
    switch (getPrintMode()) {
        case FIT_PAGE:
            graphics.scale(Math.min(xScale, yScale) * dpiScale);
            break;
        case FIT_WIDTH:
            graphics.scale(xScale * dpiScale);
            break;
        case FIT_HEIGHT:
            graphics.scale(yScale * dpiScale);
            break;
        default:
            graphics.scale(dpiScale);
    }
    graphics.setForegroundColor(figure.getForegroundColor());
    graphics.setBackgroundColor(figure.getBackgroundColor());
    graphics.setFont(figure.getFont());
}
 
Example 9
Source File: PrintERDiagramOperation.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
    final ERDiagram diagram = getDiagram();
    final PageSettings pageSetting = diagram.getPageSetting();

    final double dpiScale = (double) getPrinter().getDPI().x / Display.getCurrent().getDPI().x * pageSetting.getScale() / 100;

    final Rectangle printRegion = getPrintRegion();
    // put the print region in display coordinates
    printRegion.width /= dpiScale;
    printRegion.height /= dpiScale;

    final Rectangle bounds = figure.getBounds();
    final double xScale = (double) printRegion.width / bounds.width;
    final double yScale = (double) printRegion.height / bounds.height;
    switch (getPrintMode()) {
    case FIT_PAGE:
        graphics.scale(Math.min(xScale, yScale) * dpiScale);
        break;
    case FIT_WIDTH:
        graphics.scale(xScale * dpiScale);
        break;
    case FIT_HEIGHT:
        graphics.scale(yScale * dpiScale);
        break;
    default:
        graphics.scale(dpiScale);
    }
    graphics.setForegroundColor(figure.getForegroundColor());
    graphics.setBackgroundColor(figure.getBackgroundColor());
    graphics.setFont(figure.getFont());
}
 
Example 10
Source File: PrintERDiagramOperation.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
	ERDiagram diagram = this.getDiagram();
	PageSetting pageSetting = diagram.getPageSetting();

	double dpiScale = (double) getPrinter().getDPI().x
			/ Display.getCurrent().getDPI().x * pageSetting.getScale()
			/ 100;

	Rectangle printRegion = getPrintRegion();
	// put the print region in display coordinates
	printRegion.width /= dpiScale;
	printRegion.height /= dpiScale;

	Rectangle bounds = figure.getBounds();
	double xScale = (double) printRegion.width / bounds.width;
	double yScale = (double) printRegion.height / bounds.height;
	switch (getPrintMode()) {
	case FIT_PAGE:
		graphics.scale(Math.min(xScale, yScale) * dpiScale);
		break;
	case FIT_WIDTH:
		graphics.scale(xScale * dpiScale);
		break;
	case FIT_HEIGHT:
		graphics.scale(yScale * dpiScale);
		break;
	default:
		graphics.scale(dpiScale);
	}
	graphics.setForegroundColor(figure.getForegroundColor());
	graphics.setBackgroundColor(figure.getBackgroundColor());
	graphics.setFont(figure.getFont());
}
 
Example 11
Source File: Axis.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void paintClientArea(final Graphics graphics) {
	// Don't do anything when hidden
	if (!isVisible())
		return;

	super.paintClientArea(graphics);

	// graphics.pushState();
	if (title != null) {
		graphics.setFont(titleFont);
		final Dimension titleSize = FigureUtilities.getTextExtents(title, titleFont);
		if (isHorizontal()) {
			if (getTickLabelSide() == LabelSide.Primary)
				graphics.drawText(title, bounds.x + bounds.width / 2 - titleSize.width / 2,
						bounds.y + bounds.height - titleSize.height);
			else
				graphics.drawText(title, bounds.x + bounds.width / 2 - titleSize.width / 2, bounds.y);
		} else {
			final int w = titleSize.height;
			final int h = titleSize.width + 1;

			if (getTickLabelSide() == LabelSide.Primary) {
				GraphicsUtil.drawVerticalText(graphics, title, bounds.x, bounds.y + bounds.height / 2 - h / 2,
						false);
			} else {
				GraphicsUtil.drawVerticalText(graphics, title, bounds.x + bounds.width - w,
						bounds.y + bounds.height / 2 - h / 2, true);
			}
		}
	}
	// graphics.popState();

	// Show the start/end cursor or the 'rubberband' of a zoom operation?
	if (armed && end != null && start != null) {
		switch (zoomType) {
		case RUBBERBAND_ZOOM:
		case HORIZONTAL_ZOOM:
		case VERTICAL_ZOOM:
		case DYNAMIC_ZOOM:
			graphics.setLineStyle(SWTConstants.LINE_DOT);
			graphics.setLineWidth(1);
			graphics.setForegroundColor(revertBackColor);
			graphics.drawRectangle(start.x, start.y, end.x - start.x - 1, end.y - start.y - 1);
			break;

		default:
			break;
		}
	}
}
 
Example 12
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 13
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 14
Source File: RowHandle.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void paintFigure( Graphics graphics )
{
	if ( isSelect( ) )
	{
		graphics.setBackgroundColor( ReportColorConstants.SelctionFillColor );
	}
	else
	{
		graphics.setBackgroundColor( ReportColorConstants.TableGuideFillColor );
	}

	graphics.setLineStyle( SWT.LINE_SOLID );
	Rectangle bounds = getBounds( ).getCopy( ).resize( -1, -1 );
	graphics.fillRectangle( bounds );

	Font font = FontManager.getFont( "Dialog", 7, SWT.NORMAL );//$NON-NLS-1$

	graphics.setFont( font );

	Image image = getImage( );
	if ( image == null )
		return;

	graphics.setForegroundColor( ColorConstants.white );
	graphics.setXORMode( true );
	
	org.eclipse.swt.graphics.Rectangle rect = image.getBounds( );
	int x = bounds.x + ( bounds.width - rect.width ) / 2;
	int y = bounds.y + ( bounds.height - rect.height ) / 2;
	graphics.drawImage( image, x, y );

	TableEditPart part = (TableEditPart) getOwner( );
	RowHandleAdapter rowHandleAdapter = HandleAdapterFactory.getInstance( )
			.getRowHandleAdapter( part.getRow( getRowNumber( ) ) );
	String type = rowHandleAdapter.getType( );
	String displayName = rowHandleAdapter.getDisplayName( );

	if ( TableHandleAdapter.TABLE_GROUP_HEADER.equals( type )
			|| TableHandleAdapter.TABLE_GROUP_FOOTER.equals( type ) )
	{
		graphics.drawString( displayName, x + rect.width + 2, y + 2 );
	}

	graphics.setBackgroundColor( ColorConstants.black );

	//		ReportFigureUtilities.paintBevel( graphics,
	//				getBounds( ).getCopy( ),
	//				true );

	graphics.setXORMode( false );
}