Java Code Examples for org.eclipse.draw2d.FigureUtilities#getTextWidth()

The following examples show how to use org.eclipse.draw2d.FigureUtilities#getTextWidth() . 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: 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 2
Source File: TextFlow.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void paintSpecial_old( Graphics g, String text, int x, int y,
		boolean firstBox )
{
	if ( firstBox
			&& specialPREFIX.length( ) != 0
			&& text.indexOf( specialPREFIX ) == 0 )
	{
		int with = FigureUtilities.getTextWidth( specialPREFIX, g.getFont( ) );
		Color c = g.getForegroundColor( );

		g.setForegroundColor( ReportColorConstants.textFillColor );

		g.drawString( specialPREFIX, x, y );

		g.setForegroundColor( c );
		g.drawString( text.substring( specialPREFIX.length( ) ),
				x + with,
				y );
	}
	else
	{
		g.drawString( text, x, y );
	}
}