Java Code Examples for org.eclipse.swt.graphics.FontMetrics#getHeight()

The following examples show how to use org.eclipse.swt.graphics.FontMetrics#getHeight() . 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: DesignerRepresentation.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showNullChart( Dimension dSize )
{
	// Display error message for null chart. This behavior is consistent
	// with invalid table.
	String MSG = Messages.getString( "DesignerRepresentation.msg.InvalidChart" ); //$NON-NLS-1$
	logger.log( ILogger.ERROR,
			Messages.getString( "DesignerRepresentation.log.UnableToFind" ) ); //$NON-NLS-1$

	Device dv = Display.getCurrent( );
	Font font = FontManager.getFont( "Dialog", 10, SWT.ITALIC ); //$NON-NLS-1$
	gc.setFont( font );
	FontMetrics fm = gc.getFontMetrics( );
	gc.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	gc.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	gc.fillRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
	gc.drawRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
	String[] texts = splitOnBreaks( MSG, font, dSize.width - 10 );
	int y = 5;
	for ( String text : texts )
	{
		gc.drawText( text, 5, y );
		y += fm.getHeight( );
	}
}
 
Example 2
Source File: TextPrint.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private Point maxExtent(String[] text) {
	Font oldFont = gc.getFont();
	try {
		initGC();

		FontMetrics fm = gc.getFontMetrics();
		int maxWidth = 0;

		for (int i = 0; i < text.length; i++) {
			String textPiece = text[i];
			maxWidth = Math.max(maxWidth, gc.stringExtent(textPiece).x);
		}

		return new Point(maxWidth, fm.getHeight());
	} finally {
		restoreGC(oldFont);
	}
}
 
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: TimeSlot.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public Point computeSize(int wHint, int hHint, boolean changed) {
	if (preferredSize.x == -1 || changed) {
		preferredSize.x = getSize().x;
		Display display = Display.getCurrent();
		GC gc = new GC(display);
		try {
			Font font = display.getSystemFont();
			gc.setFont(font);
			FontMetrics fm = gc.getFontMetrics();
			preferredSize.y = fm.getHeight();
		} finally {
			gc.dispose();
		}
	}
	return preferredSize;
}
 
Example 6
Source File: DQSystemInfoPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void setGridData(Control control, int heightFactor, int widthFactor) {
	GC gc = new GC(control);
	try {
		gc.setFont(control.getFont());
		FontMetrics fm = gc.getFontMetrics();
		GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
		gd.heightHint = heightFactor * fm.getHeight();
		gd.widthHint = widthFactor * fm.getHeight();
		control.setLayoutData(gd);
	} finally {
		gc.dispose();
	}
}
 
Example 7
Source File: TreeThemer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void addMeasureItemListener()
{
	if (controlIsDisposed())
	{
		return;
	}

	final Tree tree = getTree();
	// Hack to force a specific row height and width based on font
	measureItemListener = new Listener()
	{
		public void handleEvent(Event event)
		{
			if (!useEditorFont())
			{
				return;
			}
			Font font = JFaceResources.getFont(IThemeManager.VIEW_FONT_NAME);
			if (font == null)
			{
				font = JFaceResources.getTextFont();
			}
			if (font != null)
			{
				event.gc.setFont(font);
				FontMetrics metrics = event.gc.getFontMetrics();
				int height = metrics.getHeight() + 2;
				TreeItem item = (TreeItem) event.item;
				int width = event.gc.stringExtent(item.getText()).x + 24; // minimum width we need for text plus eye
				event.height = height;
				if (width > event.width)
				{
					event.width = width;
				}
			}
		}
	};
	tree.addListener(SWT.MeasureItem, measureItemListener);
}
 
Example 8
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 9
Source File: TextPrint.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private PrintPiece internalNext(int width, int height) {
	FontMetrics fm = gc.getFontMetrics();

	final int lineHeight = fm.getHeight();
	if (height < lineHeight)
		return null;

	final int maxLines = height / lineHeight;
	String[] nextLines = nextLines(width, maxLines);
	if (nextLines.length == 0)
		return null;

	int maxWidth = maxExtent(nextLines).x;
	Point size = new Point(maxWidth, nextLines.length * lineHeight);
	int ascent = fm.getAscent() + fm.getLeading();

	return new TextPiece(device, style, nextLines, size, ascent);
}
 
Example 10
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 11
Source File: TextPaintInstruction.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void paint(GC gc, Rectangle area) {
	if (!this.state.isRendering()) {
		return;
	}

	FontMetrics metrics = gc.getFontMetrics();
	FontMetrics metricsToUse = metrics;
	int baseline = metrics.getAscent() + metrics.getLeading();

	int yAdvance = 0;
	if (this.state.getCurrentLineHeight() > metrics.getHeight()) {
		int biggerBaseline = this.state.getCurrentBiggestFontMetrics().getAscent() + this.state.getCurrentBiggestFontMetrics().getLeading();
		yAdvance = biggerBaseline - baseline;

		metricsToUse = this.state.getCurrentBiggestFontMetrics();
	}

	Point pointer = this.state.getPointer();

	// on alignment justify render word by word
	int textLength = 0;
	if (TextAlignment.JUSTIFY.equals(this.state.getTextAlignment())) {
		LinePainter line = this.state.getCurrentLine();
		for (String word : this.words) {
			gc.drawText(word, pointer.x, pointer.y + yAdvance, (!this.state.hasPreviousBgColor()));
			int length = gc.textExtent(word).x + line.getNextJustifySpace();
			pointer.x += length;
			textLength += length;
		}
	} else {
		textLength = getTextLength(gc);
		gc.drawText(text, pointer.x, pointer.y + yAdvance, (!this.state.hasPreviousBgColor()));
	}

	if (this.state.isUnderlineActive()) {
		int underlineY = pointer.y + baseline + yAdvance + (metricsToUse.getDescent() / 2);
		gc.drawLine(pointer.x, underlineY, pointer.x + textLength, underlineY);
	}
	if (this.state.isStrikethroughActive()) {
		int strikeY = pointer.y + yAdvance + (metrics.getHeight() / 2) + (metrics.getLeading() / 2);
		gc.drawLine(pointer.x, strikeY, pointer.x + textLength, strikeY);
	}

	if (!TextAlignment.JUSTIFY.equals(this.state.getTextAlignment())) {
		pointer.x += textLength;
	}
}
 
Example 12
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 13
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 14
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 15
Source File: DialChartViewer.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: 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 17
Source File: DesignerRepresentation.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Show the exception message that prevented to draw the chart
 * 
 * @param g2d
 * @param ex
 *            The exception that occured
 */
private final void showException( GC g2d, Exception ex )
{
	Point pTLC = new Point( 0, 0 );

	// String sWrappedException = ex.getClass( ).getName( );
	Throwable th = ex;

	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( );
	Dimension d = getSize( );

	Device dv = Display.getCurrent( );
	Font fo = new Font( dv, "Courier", SWT.BOLD, 12 ); //$NON-NLS-1$
	g2d.setFont( fo );
	FontMetrics fm = g2d.getFontMetrics( );
	g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	g2d.fillRectangle( pTLC.x + 20,
			pTLC.y + 20,
			d.width - 40,
			d.height - 40 );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawRectangle( pTLC.x + 20,
			pTLC.y + 20,
			d.width - 40,
			d.height - 40 );
	Region rgPrev = new Region( );
	g2d.getClipping( rgPrev );
	g2d.setClipping( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 );
	int x = pTLC.x + 25, y = pTLC.y + 20 + fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) );
	g2d.drawString( ERROR_MSG, x, y );
	y += fm.getHeight( );
	g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	g2d.drawText( sMessage, x, y );

	g2d.setClipping( rgPrev );
	rgPrev.dispose( );
	fo.dispose( );
}
 
Example 18
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void printPatientAuftragsnummer(final Patient patient){
	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(Messages.GlobalActions_PrintLabelJobName) == true) { //$NON-NLS-1$
			GC gc = new GC(prn);
			int y = 0;
			prn.startPage();
			String pid = StringTool.addModulo10(patient.getPatCode()) + "-" //$NON-NLS-1$
				+ new TimeTool().toString(TimeTool.TIME_COMPACT);
			gc.drawString(Messages.GlobalActions_OrderID + ": " + pid, 0, 0); //$NON-NLS-1$ //$NON-NLS-2$
			FontMetrics fmt = gc.getFontMetrics();
			y += fmt.getHeight();
			String pers = patient.getPersonalia();
			gc.drawString(pers, 0, y);
			y += fmt.getHeight();
			gc.drawString(patient.getAnschrift().getEtikette(false, false), 0, y);
			y += fmt.getHeight();
			StringBuilder tel = new StringBuilder();
			tel.append(Messages.GlobalActions_PhoneHomeLabelText)
				.append(patient.get("Telefon1")) //$NON-NLS-1$ //$NON-NLS-2$
				.append(Messages.GlobalActions_PhoneWorkLabelText)
				.append(patient.get("Telefon2")) //$NON-NLS-1$ //$NON-NLS-2$
				.append(Messages.GlobalActions_PhoneMobileLabelText)
				.append(patient.get("Natel")); //$NON-NLS-1$ //$NON-NLS-2$
			gc.drawString(tel.toString(), 0, y);
			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 19
Source File: SWTUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the number of pixels corresponding to the height of the given
 * number of characters.
 * <p>
 * The required <code>FontMetrics</code> parameter may be created in the
 * following way: <code>
 *  GC gc = new GC(control);
 *  gc.setFont(control.getFont());
 *  fontMetrics = gc.getFontMetrics();
 *  gc.dispose();
 * </code>
 * </p>
 * 
 * Note: This code was taken from org.eclipse.jface.dialogs.Dialog.
 * 
 * @param fontMetrics used in performing the conversion
 * @param chars the number of characters
 * @return the number of pixels
 */
public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, int chars) {
  return fontMetrics.getHeight() * chars;
}
 
Example 20
Source File: AbstractDebugVariableCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the colorized square size.
 *
 * @param fontMetrics
 * @return the colorized square size.
 */
public static int getSquareSize(FontMetrics fontMetrics) {
	return fontMetrics.getHeight() - 2 * fontMetrics.getDescent();
}