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

The following examples show how to use org.eclipse.draw2d.Graphics#drawText() . 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: 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 2
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 3
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 4
Source File: LinearScaleTickLabels2.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void drawYTick(Graphics graphics) {
	// draw tick labels
	ITicksProvider ticks = getTicksProvider();
	final int imax = ticks.getMajorCount();
	if (imax < 1)
		return;
	final boolean hasNegative = ticks.getLabel(0).startsWith(MINUS);
	final int minus = getScale().getDimension(MINUS).width;
	for (int i = 0; i < imax; i++) {
		if (ticks.isVisible(i)) {
			String text = ticks.getLabel(i);
			int x = (hasNegative && !text.startsWith(MINUS)) ? minus : 0;
			graphics.drawText(text, x, ticks.getLabelPosition(i));
		}
	}
}
 
Example 5
Source File: ProcessFigure.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private void paintTable(Graphics graphics) {
	graphics.setForegroundColor(LINE_COLOR);
	int margin = 5;
	int width = getSize().width;
	int height = getSize().height;
	int x = getLocation().x;
	int y = getLocation().y;
	graphics.drawLine(new Point(x + margin, y + MINIMUM_HEIGHT
			+ TEXT_HEIGHT + MARGIN_HEIGHT), new Point(x + width - margin,
					y
							+ MINIMUM_HEIGHT + TEXT_HEIGHT + MARGIN_HEIGHT));
	if (height - margin > MINIMUM_HEIGHT + margin)
		graphics.drawLine(new Point(x + width / 2, y + MINIMUM_HEIGHT + margin), new Point(x + width / 2, y
				+ height - margin));
	graphics.setForegroundColor(TEXT_COLOR);
	graphics.drawText(M.Inputs, new Point(x + width / 6, y + MINIMUM_HEIGHT + MARGIN_HEIGHT));
	graphics.drawText(M.Outputs, new Point(x + 2 * width / 3, y + MINIMUM_HEIGHT + MARGIN_HEIGHT));
	graphics.setForegroundColor(ColorConstants.black);
}
 
Example 6
Source File: CellFigure.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void drawBlankString( Graphics g, String s )
{
	TextLayout tl = new TextLayout( Display.getCurrent( ) );

	// bidi_hcg: Apply text direction
	tl.setOrientation( this.rtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT );
	
	tl.setText( s );
	Rectangle rc = tl.getBounds( );

	int left = ( getClientArea( ).width - rc.width ) / 2;
	int top = ( getClientArea( ).height - rc.height ) / 2;

	g.drawText( s, getClientArea( ).x + left, getClientArea( ).y + top );
	tl.dispose();
}
 
Example 7
Source File: TimeAxisFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void paintMarkers(Graphics graphics) {

		final Rectangle bounds = getBounds();
		graphics.setForegroundColor(ColorConstants.darkGray);
		graphics.setLineStyle(SWT.LINE_SOLID);

		final Insets insets = RootFigure.getFigure(this, TracksFigure.class).getInsets();
		final ITimelineStyleProvider styleProvider = RootFigure.getRootFigure(this).getStyleProvider();

		final Map<Double, Integer> markerPositions = getDetailFigure().getMarkerPositions();
		for (final Entry<Double, Integer> entry : markerPositions.entrySet()) {
			final String label = styleProvider.getTimeLabel(entry.getKey(), TimeUnit.NANOSECONDS);
			final int textWidth = FigureUtilities.getTextWidth(label, graphics.getFont());

			graphics.drawLine(entry.getValue() + bounds.x() + insets.left, bounds.y, entry.getValue() + bounds.x() + insets.left, bounds.y + 5);
			graphics.drawText(label, (entry.getValue() + bounds.x() + insets.left) - (textWidth / 2), bounds.y + 5);
		}
	}
 
Example 8
Source File: GraphicsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw vertical text.
 * 
 * @param graphics
 *            draw2D graphics.
 * @param text
 *            text to be drawn.
 * @param x
 *            the x coordinate of the text, which is the left upper corner.
 * @param y
 *            the y coordinate of the text, which is the left upper corner.
 */
public static final void drawVerticalText(Graphics graphics, String text, int x, int y, boolean upToDown) {
	try {
		if (SWT.getPlatform().startsWith("rap")) //$NON-NLS-1$
			throw new Exception();
		try {
			graphics.pushState();
			graphics.translate(x, y);
			if (upToDown) {
				graphics.rotate(90);
				graphics.drawText(text, 0, -FigureUtilities.getTextExtents(text, graphics.getFont()).height);
			} else {
				graphics.rotate(270);
				graphics.drawText(text, -FigureUtilities.getTextWidth(text, graphics.getFont()), 0);
			}
		} finally {
			graphics.popState();
		}
	} catch (Exception e) {// If rotate is not supported by the graphics.
		// final Dimension titleSize = FigureUtilities.getTextExtents(text,
		// graphics.getFont());

		// final int w = titleSize.height;
		// final int h = titleSize.width + 1;
		Image image = null;
		try {
			image = SingleSourceHelper2.createVerticalTextImage(text, graphics.getFont(),
					graphics.getForegroundColor().getRGB(), upToDown);
			graphics.drawImage(image, x, y);

		} finally {
			if (image != null)
				image.dispose();
		}
	}
}
 
Example 9
Source File: ProductSystemFigure.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void drawColorScale(Graphics graphics) {
	int x = 25;
	int y = 140;
	for (int i = -100; i < 100; i += 2) {
		graphics.setBackgroundColor(Colors.getForContribution(i / 100d));
		int posX = x + 3 * ((100 + i) / 2);
		graphics.fillRectangle(new Rectangle(posX, y, 4, 20));
	}

	// draw percentage texts
	graphics.drawText(M.Sankey_ScaleDescription, x + 35, y + 22);
	graphics.drawLine(x, y, x + 300, y);
	for (int i = 0; i <= 20; i++) {
		int height = 0;
		if (i == 0 || i == 20) {
			height = 19;
		} else if (i % 2 == 0) {
			height = 12;
		} else {
			height = 6;
		}
		graphics.drawLine(x + 15 * i, y, x + 15 * i, y + height);
		String percentage = "" + (i * 10 - 100);
		if (i % 2 == 0) {
			int left = 5 * (percentage.length() - 1);
			if (i == 10) {
				left += 2;
			} else if (i == 0 || i == 20) {
				left -= 1;
			}
			graphics.drawText(percentage, x + 15 * i - left, y - 16);
		}
	}
}
 
Example 10
Source File: StatisticFigure.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void paintChartFrame(Graphics graphics) {
	graphics.drawLine(marginLeft, getSize().height - marginBottom,
			getSize().width - marginRight, getSize().height - marginBottom);
	graphics.drawLine(marginLeft, marginTop, marginLeft, getSize().height
			- marginBottom);
	graphics.drawText(Numbers.format(hist.statistics.min, 3),
			marginLeft, getSize().height - marginBottom + 10);
	graphics.drawText(Numbers.format(hist.statistics.max, 3),
			getSize().width - marginRight - 40, getSize().height
					- marginBottom + 10);
	graphics.drawText(
			Integer.toString(hist.getMaxAbsoluteFrequency()), 15,
			marginTop + 5);
	graphics.drawText("0", 15, getSize().height - marginBottom - 15);
}
 
Example 11
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 12
Source File: LinearScaleTickLabels2.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void drawXTick(Graphics graphics) {
	// draw tick labels
	ITicksProvider ticks = getTicksProvider();
	final int imax = getTicksProvider().getMajorCount();
	for (int i = 0; i < imax; i++) {
		if (ticks.isVisible(i)) {
			graphics.drawText(ticks.getLabel(i), ticks.getLabelPosition(i), 0);
		}
	}
}
 
Example 13
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 14
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	boolean support3D = false;
	if(effect3D)
		 support3D = GraphicsUtil.testPatternSupported(graphics);
	
	if(effect3D && support3D){
		graphics.setBackgroundColor(fillColor);
		super.fillShape(graphics);
		//int l = (int) ((bounds.width - lineWidth)*0.293/2);
		Pattern backPattern = null;
		
		 backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
			bounds.x + lineWidth, bounds.y + lineWidth, 
			bounds.x+bounds.width-lineWidth, bounds.y+bounds.height-lineWidth,
			WHITE_COLOR,255, fillColor, 0);			
		graphics.setBackgroundPattern(backPattern);
		super.fillShape(graphics);
		backPattern.dispose();
		
	}else{
		graphics.setBackgroundColor(fillColor);				
		super.fillShape(graphics);
	}				
	
	String valueString = getValueText();
	Dimension valueSize = 
		FigureUtilities.getTextExtents(valueString, getFont());
	if(valueSize.width < bounds.width) {				
		graphics.setForegroundColor(contrastFillColor);
		graphics.drawText(valueString, new Point(
				bounds.x + bounds.width/2 - valueSize.width/2,
				bounds.y + bounds.height/2 - valueSize.height/2));				
	}			
}
 
Example 15
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 16
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 17
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 18
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;
		}
	}
}