Java Code Examples for org.eclipse.swt.graphics.GC#getFontMetrics()

The following examples show how to use org.eclipse.swt.graphics.GC#getFontMetrics() . 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: AbstractDebugVariableCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Draw square of the given rgb.
 *
 * @param rgb        the rgb color
 * @param gc         the graphic context
 * @param textWidget the text widget
 * @param x          the location y
 * @param y          the location y
 * @return the square width.
 */
private int drawSquare(RGB rgb, GC gc, StyledText textWidget, int x, int y) {
	FontMetrics fontMetrics = gc.getFontMetrics();
	int size = getSquareSize(fontMetrics);
	x += fontMetrics.getLeading();
	y += fontMetrics.getDescent();

	Rectangle rect = new Rectangle(x, y, size, size);

	// Fill square
	gc.setBackground(getColor(rgb, textWidget.getDisplay()));
	gc.fillRectangle(rect);

	// Draw square box
	gc.setForeground(textWidget.getForeground());
	gc.drawRectangle(rect);
	return getSquareWidth(gc.getFontMetrics());
}
 
Example 2
Source File: CommonLineNumberRulerColumn.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the difference between the baseline of the widget and the
 * baseline as specified by the font for <code>gc</code>. When drawing
 * line numbers, the returned bias should be added to obtain text lined up
 * on the correct base line of the text widget.
 *
 * @param gc the <code>GC</code> to get the font metrics from
 * @param widgetLine the widget line
 * @return the baseline bias to use when drawing text that is lined up with
 *         <code>fCachedTextWidget</code>
 * @since 3.2
 */
private int getBaselineBias(GC gc, int widgetLine) {
	/*
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951
	 * widget line height may be more than the font height used for the
	 * line numbers, since font styles (bold, italics...) can have larger
	 * font metrics than the simple font used for the numbers.
	 */
	int offset= fCachedTextWidget.getOffsetAtLine(widgetLine);
	int widgetBaseline= fCachedTextWidget.getBaseline(offset);

	FontMetrics fm= gc.getFontMetrics();
	int fontBaseline= fm.getAscent() + fm.getLeading();
	int baselineBias= widgetBaseline - fontBaseline;
	return Math.max(0, baselineBias);
}
 
Example 3
Source File: IndentFoldingStrategy.java    From typescript.java with MIT License 6 votes vote down vote up
/**
 * Does not paint hidden annotations. Annotations are hidden when they
 * only span one line.
 * 
 * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC,
 *      org.eclipse.swt.widgets.Canvas,
 *      org.eclipse.swt.graphics.Rectangle)
 */
@Override
public void paint(GC gc, Canvas canvas, Rectangle rectangle) {
	/* workaround for BUG85874 */
	/*
	 * only need to check annotations that are expanded because hidden
	 * annotations should never have been given the chance to collapse.
	 */
	if (!isCollapsed()) {
		// working with rectangle, so line height
		FontMetrics metrics = gc.getFontMetrics();
		if (metrics != null) {
			// do not draw annotations that only span one line and
			// mark them as not visible
			if ((rectangle.height / metrics.getHeight()) <= 1) {
				visible = false;
				return;
			}
		}
	}
	visible = true;
	super.paint(gc, canvas, rectangle);
}
 
Example 4
Source File: SwtUtil.java    From AppleCommander with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Setup some sensible paging information.
 */
public static void setupPagingInformation(ScrolledComposite composite) {
	GC gc = new GC(composite);
	FontMetrics fontMetrics = gc.getFontMetrics();
	gc.dispose();
	int fontHeight = fontMetrics.getHeight();
	int fontWidth = fontMetrics.getAverageCharWidth();
	Rectangle clientArea = composite.getClientArea();
	int lines = clientArea.height / fontHeight;
	int pageHeight = lines * fontHeight;
	int pageWidth = clientArea.width - fontWidth; 
	composite.getVerticalBar().setIncrement(fontHeight);
	composite.getVerticalBar().setPageIncrement(pageHeight);
	composite.getHorizontalBar().setIncrement(fontWidth);
	composite.getHorizontalBar().setPageIncrement(pageWidth);
}
 
Example 5
Source File: WhitespaceCharacterPainter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw string at widget offset.
 * 
 * @param gc
 * @param offset
 *            the widget offset
 * @param s
 *            the string to be drawn
 * @param fg
 *            the foreground color
 */
private void draw(GC gc, int offset, String s, Color fg)
{
	// Compute baseline delta (see
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640)
	int baseline = fTextWidget.getBaseline(offset);
	FontMetrics fontMetrics = gc.getFontMetrics();
	int fontBaseline = fontMetrics.getAscent() + fontMetrics.getLeading();
	int baslineDelta = baseline - fontBaseline;

	Point pos = fTextWidget.getLocationAtOffset(offset);
	gc.setForeground(fg);
	gc.drawString(s, pos.x, pos.y + baslineDelta, true);
}
 
Example 6
Source File: PixelConverter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public PixelConverter(Control control) {
	GC gc = new GC(control);
       try {
           gc.setFont(control.getFont());
           fFontMetrics= gc.getFontMetrics();
       } finally {
           gc.dispose();
       }
}
 
Example 7
Source File: ParameterExpandBar.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
void computeBandHeight() {
	if (getFont() == null) { return; }
	final GC gc = new GC(this);
	final FontMetrics metrics = gc.getFontMetrics();
	gc.dispose();
	bandHeight = Math.max(ParameterExpandItem.CHEVRON_SIZE, metrics.getHeight());
}
 
Example 8
Source File: BookmarkRulerColumn.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private int getBaselineBias(GC gc, int widgetLine) {
    /*
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951
     * widget line height may be more than the font height used for the
     * line numbers, since font styles (bold, italics...) can have larger
     * font metrics than the simple font used for the numbers.
     */
    int offset= fCachedTextWidget.getOffsetAtLine(widgetLine);
    int widgetBaseline= fCachedTextWidget.getBaseline(offset);

    FontMetrics fm= gc.getFontMetrics();
    int fontBaseline= fm.getAscent() + fm.getLeading();
    int baselineBias= widgetBaseline - fontBaseline;
    return Math.max(0, baselineBias);
}
 
Example 9
Source File: SWTFactory.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static int getCharHeight(Control ctr) {
      GC gc = new GC(ctr);
      FontMetrics fm;
      try {
      	gc.setFont(JFaceResources.getDialogFont());
      	fm = gc.getFontMetrics();
} finally {
	gc.dispose();
}
      return fm.getHeight();
  }
 
Example 10
Source File: TestProgressBar.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Paint.
 */
protected void onPaint(GC gc) {
	final Rectangle b = getBounds();

	final TestStatus status = counter != null ? counter.getAggregatedStatus() : null;
	if (status != null) {

		final int total = Math.max(expectedTotal, counter.getTotal()); // this is our 100% value
		final int value = counter.getTotal(); // current value
		final int totalPx = b.width;
		final int valuePx = Math.round(totalPx * (((float) value) / ((float) total)));

		gc.setBackground(getColorForStatus(status));
		gc.fillRectangle(0, 0, valuePx, b.height);

		gc.setBackground(getBackground());
		gc.fillRectangle(0 + valuePx, 0, b.width - valuePx, b.height);
	} else {
		// clear
		gc.setBackground(getBackground());
		gc.fillRectangle(b);
	}

	if (counter != null) {
		final FontMetrics fm = gc.getFontMetrics();
		gc.setForeground(getForeground());
		final int pending = expectedTotal > 0 ? expectedTotal - counter.getTotal() : -1;
		gc.drawString(counter.toString(true, pending, SWT.RIGHT),
				4, b.height / 2 - fm.getHeight() / 2 - fm.getDescent(), true);
	}
}
 
Example 11
Source File: BoldPaintInstruction.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(GC gc) {
	// apply the font
	paint(gc, null);
	// return the metrics
	return gc.getFontMetrics();
}
 
Example 12
Source File: TextPiece.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void paint(final GC gc, final int x, final int y) {
	Font oldFont = gc.getFont();
	Color oldForeground = gc.getForeground();
	Color oldBackground = gc.getBackground();

	final int width = getSize().x;
	final int align = style.getAlignment();

	try {
		boolean transparent = initGC(gc);

		FontMetrics fm = gc.getFontMetrics();
		int lineHeight = fm.getHeight();

		boolean strikeout = style.getStrikeout();
		boolean underline = style.getUnderline();
		int lineThickness = Math.max(1, fm.getDescent() / 3);
		int strikeoutOffset = fm.getLeading() + fm.getAscent() / 2;
		int underlineOffset = ascent + lineThickness;

		for (int i = 0; i < lines.length; i++) {
			String line = lines[i];
			int lineWidth = gc.stringExtent(line).x;
			int offset = getHorzAlignmentOffset(align, lineWidth, width);

			gc.drawString(lines[i], x + offset, y + lineHeight * i,
					transparent);
			if (strikeout || underline) {
				Color saveBackground = gc.getBackground();
				gc.setBackground(gc.getForeground());
				if (strikeout)
					gc.fillRectangle(x + offset, y + lineHeight * i
							+ strikeoutOffset, lineWidth, lineThickness);
				if (underline)
					gc.fillRectangle(x + offset, y + lineHeight * i
							+ underlineOffset, lineWidth, lineThickness);
				gc.setBackground(saveBackground);
			}
		}
	} finally {
		restoreGC(gc, oldFont, oldForeground, oldBackground);
	}
}
 
Example 13
Source File: Chart3DViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void showException( GC g2d, Exception ex )
{
	String sWrappedException = ex.getClass( ).getName( );
	Throwable th = ex;
	while ( ex.getCause( ) != null )
	{
		ex = (Exception) ex.getCause( );
	}
	String sException = ex.getClass( ).getName( );
	if ( sWrappedException.equals( sException ) )
	{
		sWrappedException = null;
	}

	String sMessage = null;
	if ( th instanceof BirtException )
	{
		sMessage = ( (BirtException) th ).getLocalizedMessage( );
	}
	else
	{
		sMessage = ex.getMessage( );
	}

	if ( sMessage == null )
	{
		sMessage = "<null>";//$NON-NLS-1$
	}
	StackTraceElement[] stea = ex.getStackTrace( );
	Point d = this.getSize( );

	Device dv = Display.getCurrent( );
	Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$
	g2d.setFont( fo );
	FontMetrics fm = g2d.getFontMetrics( );
	g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setClipping( 20, 20, d.x - 40, d.y - 40 );
	int x = 25, y = 20 + fm.getHeight( );
	g2d.drawString( "Exception:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	g2d.drawString( sException, x, y );
	x = 25;
	y += fm.getHeight( );
	if ( sWrappedException != null )
	{
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
		g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$
		x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
		g2d.drawString( sWrappedException, x, y );
		x = 25;
		y += fm.getHeight( );
	}
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Message:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) );
	g2d.drawString( sMessage, x, y );
	x = 25;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Trace:", x, y );//$NON-NLS-1$
	x = 40;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) );
	for ( int i = 0; i < stea.length; i++ )
	{
		g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$
				+ stea[i].getMethodName( )
				+ "(...):"//$NON-NLS-1$
				+ stea[i].getLineNumber( ), x, y );
		x = 40;
		y += fm.getHeight( );
	}
	fo.dispose( );
}
 
Example 14
Source File: PixelConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public PixelConverter(Font font) {
	GC gc = new GC(font.getDevice());
	gc.setFont(font);
	fFontMetrics= gc.getFontMetrics();
	gc.dispose();
}
 
Example 15
Source File: JavaScriptViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void showException( GC g2d, Exception ex )
{
	String sWrappedException = ex.getClass( ).getName( );
	Throwable th = ex;
	while ( ex.getCause( ) != null )
	{
		ex = (Exception) ex.getCause( );
	}
	String sException = ex.getClass( ).getName( );
	if ( sWrappedException.equals( sException ) )
	{
		sWrappedException = null;
	}

	String sMessage = null;
	if ( th instanceof BirtException )
	{
		sMessage = ( (BirtException) th ).getLocalizedMessage( );
	}
	else
	{
		sMessage = ex.getMessage( );
	}

	if ( sMessage == null )
	{
		sMessage = "<null>";//$NON-NLS-1$
	}
	StackTraceElement[] stea = ex.getStackTrace( );
	Point d = this.getSize( );

	Device dv = Display.getCurrent( );
	Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$
	g2d.setFont( fo );
	FontMetrics fm = g2d.getFontMetrics( );
	g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setClipping( 20, 20, d.x - 40, d.y - 40 );
	int x = 25, y = 20 + fm.getHeight( );
	g2d.drawString( "Exception:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	g2d.drawString( sException, x, y );
	x = 25;
	y += fm.getHeight( );
	if ( sWrappedException != null )
	{
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
		g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$
		x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
		g2d.drawString( sWrappedException, x, y );
		x = 25;
		y += fm.getHeight( );
	}
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Message:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) );
	g2d.drawString( sMessage, x, y );
	x = 25;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Trace:", x, y );//$NON-NLS-1$
	x = 40;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) );
	for ( int i = 0; i < stea.length; i++ )
	{
		g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$
				+ stea[i].getMethodName( )
				+ "(...):"//$NON-NLS-1$
				+ stea[i].getLineNumber( ), x, y );
		x = 40;
		y += fm.getHeight( );
	}
	fo.dispose( );
}
 
Example 16
Source File: CurveFittingViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void showException( GC g2d, Exception ex )
{
	String sWrappedException = ex.getClass( ).getName( );
	Throwable th = ex;
	while ( ex.getCause( ) != null )
	{
		ex = (Exception) ex.getCause( );
	}
	String sException = ex.getClass( ).getName( );
	if ( sWrappedException.equals( sException ) )
	{
		sWrappedException = null;
	}

	String sMessage = null;
	if ( th instanceof BirtException )
	{
		sMessage = ( (BirtException) th ).getLocalizedMessage( );
	}
	else
	{
		sMessage = ex.getMessage( );
	}

	if ( sMessage == null )
	{
		sMessage = "<null>";//$NON-NLS-1$
	}
	StackTraceElement[] stea = ex.getStackTrace( );
	Point d = this.getSize( );

	Device dv = Display.getCurrent( );
	Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$
	g2d.setFont( fo );
	FontMetrics fm = g2d.getFontMetrics( );
	g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setClipping( 20, 20, d.x - 40, d.y - 40 );
	int x = 25, y = 20 + fm.getHeight( );
	g2d.drawString( "Exception:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	g2d.drawString( sException, x, y );
	x = 25;
	y += fm.getHeight( );
	if ( sWrappedException != null )
	{
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
		g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$
		x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
		g2d.drawString( sWrappedException, x, y );
		x = 25;
		y += fm.getHeight( );
	}
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Message:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) );
	g2d.drawString( sMessage, x, y );
	x = 25;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Trace:", x, y );//$NON-NLS-1$
	x = 40;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) );
	for ( int i = 0; i < stea.length; i++ )
	{
		g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$
				+ stea[i].getMethodName( )
				+ "(...):"//$NON-NLS-1$
				+ stea[i].getLineNumber( ), x, y );
		x = 40;
		y += fm.getHeight( );
	}
	fo.dispose( );
}
 
Example 17
Source File: SwtChartViewerSelector.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void showException( GC g2d, Exception ex )
{
	String sWrappedException = ex.getClass( ).getName( );
	Throwable th = ex;
	while ( ex.getCause( ) != null )
	{
		ex = (Exception) ex.getCause( );
	}
	String sException = ex.getClass( ).getName( );
	if ( sWrappedException.equals( sException ) )
	{
		sWrappedException = null;
	}

	String sMessage = null;
	if ( th instanceof BirtException )
	{
		sMessage = ( (BirtException) th ).getLocalizedMessage( );
	}
	else
	{
		sMessage = ex.getMessage( );
	}

	if ( sMessage == null )
	{
		sMessage = "<null>";//$NON-NLS-1$
	}
	StackTraceElement[] stea = ex.getStackTrace( );
	Point d = this.getSize( );

	Device dv = Display.getCurrent( );
	Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$
	g2d.setFont( fo );
	FontMetrics fm = g2d.getFontMetrics( );
	g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setClipping( 20, 20, d.x - 40, d.y - 40 );
	int x = 25, y = 20 + fm.getHeight( );
	g2d.drawString( "Exception:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	g2d.drawString( sException, x, y );
	x = 25;
	y += fm.getHeight( );
	if ( sWrappedException != null )
	{
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
		g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$
		x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
		g2d.drawString( sWrappedException, x, y );
		x = 25;
		y += fm.getHeight( );
	}
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Message:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) );
	g2d.drawString( sMessage, x, y );
	x = 25;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Trace:", x, y );//$NON-NLS-1$
	x = 40;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) );
	for ( int i = 0; i < stea.length; i++ )
	{
		g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$
				+ stea[i].getMethodName( ) + "(...):"//$NON-NLS-1$
				+ stea[i].getLineNumber( ), x, y );
		x = 40;
		y += fm.getHeight( );
	}
	fo.dispose( );
}
 
Example 18
Source File: JavaViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void showException( GC g2d, Exception ex )
{
	String sWrappedException = ex.getClass( ).getName( );
	Throwable th = ex;
	while ( ex.getCause( ) != null )
	{
		ex = (Exception) ex.getCause( );
	}
	String sException = ex.getClass( ).getName( );
	if ( sWrappedException.equals( sException ) )
	{
		sWrappedException = null;
	}

	String sMessage = null;
	if ( th instanceof BirtException )
	{
		sMessage = ( (BirtException) th ).getLocalizedMessage( );
	}
	else
	{
		sMessage = ex.getMessage( );
	}

	if ( sMessage == null )
	{
		sMessage = "<null>";//$NON-NLS-1$
	}
	StackTraceElement[] stea = ex.getStackTrace( );
	Point d = this.getSize( );

	Device dv = Display.getCurrent( );
	Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$
	g2d.setFont( fo );
	FontMetrics fm = g2d.getFontMetrics( );
	g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 );
	g2d.setClipping( 20, 20, d.x - 40, d.y - 40 );
	int x = 25, y = 20 + fm.getHeight( );
	g2d.drawString( "Exception:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	g2d.drawString( sException, x, y );
	x = 25;
	y += fm.getHeight( );
	if ( sWrappedException != null )
	{
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
		g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$
		x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$
		g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
		g2d.drawString( sWrappedException, x, y );
		x = 25;
		y += fm.getHeight( );
	}
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Message:", x, y );//$NON-NLS-1$
	x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) );
	g2d.drawString( sMessage, x, y );
	x = 25;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	y += 10;
	g2d.drawString( "Trace:", x, y );//$NON-NLS-1$
	x = 40;
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) );
	for ( int i = 0; i < stea.length; i++ )
	{
		g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$
				+ stea[i].getMethodName( )
				+ "(...):"//$NON-NLS-1$
				+ stea[i].getLineNumber( ), x, y );
		x = 40;
		y += fm.getHeight( );
	}
	fo.dispose( );
}
 
Example 19
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void printAdr(final Kontakt k){
	// 25.01.2010 patch tschaller: there was always the printer selection
	// dialog. With printEtikette it wasn't so I copied the hardcoded string
	// from there
	// PrinterData pd =
	// getPrinterData(Messages.getString("GlobalActions.printersticker"));
	// //$NON-NLS-1$
	PrinterData pd = getPrinterData("Etiketten"); //$NON-NLS-1$
	if (pd != null) {
		// 25.01.2010 patch tschaller: page orientation of printer driver is
		// not handled correctly (we always get porttrait even when the
		// printer settings have landscape stored)
		Integer iOrientation = -1;
		String sOrientation = CoreHub.localCfg.get("Drucker/Etiketten/Ausrichtung", null); //$NON-NLS-1$
		try {
			iOrientation = Integer.parseInt(sOrientation);
		} catch (NumberFormatException ex) {}
		if (iOrientation != -1)
			pd.orientation = iOrientation;
		Printer prn = new Printer(pd);
		if (prn.startJob("Etikette drucken") == true) { //$NON-NLS-1$
			GC gc = new GC(prn);
			int y = 0;
			prn.startPage();
			FontMetrics fmt = gc.getFontMetrics();
			String pers = k.getPostAnschrift(true);
			String[] lines = pers.split("\n"); //$NON-NLS-1$
			for (String line : lines) {
				gc.drawString(line, 0, y);
				y += fmt.getHeight();
			}
			gc.dispose();
			prn.endPage();
			prn.endJob();
			prn.dispose();
		} else {
			MessageDialog.openError(mainWindow.getShell(),
				Messages.GlobalActions_PrinterErrorTitle,
				Messages.GlobalActions_PrinterErrorMessage); //$NON-NLS-1$ //$NON-NLS-2$
			
		}
		
	}
}
 
Example 20
Source File: JavaEditorColoringConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
* Initializes the computation of horizontal and vertical dialog units based on the size of
* current font.
* <p>
* This method must be called before any of the dialog unit based conversion methods are called.
* </p>
*
* @param testControl a control from which to obtain the current font
*/
  private void initializeDialogUnits(Control testControl) {
      // Compute and store a font metric
      GC gc = new GC(testControl);
      gc.setFont(JFaceResources.getDialogFont());
      fFontMetrics = gc.getFontMetrics();
      gc.dispose();
  }