org.eclipse.swt.graphics.FontMetrics Java Examples

The following examples show how to use org.eclipse.swt.graphics.FontMetrics. 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: SelectionButtonDialogField.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public Control[] doFillIntoGrid( Composite parent, int nColumns )
{
	assertEnoughColumns( nColumns );

	Button button = getSelectionButton( parent );
	GridData gd = new GridData( );
	gd.horizontalSpan = nColumns;
	gd.horizontalAlignment = GridData.FILL;
	if ( fButtonStyle == SWT.PUSH )
	{
		GC gc = new GC( button.getFont( ).getDevice( ) );
		gc.setFont( button.getFont( ) );
		FontMetrics fFontMetrics = gc.getFontMetrics( );
		gc.dispose( );
		int widthHint = Dialog.convertHorizontalDLUsToPixels( fFontMetrics,
				IDialogConstants.BUTTON_WIDTH );
		gd.widthHint = Math.max( widthHint,
				button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x );
	}

	button.setLayoutData( gd );

	return new Control[]{
		button
	};
}
 
Example #2
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 #3
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 #4
Source File: AbstractInformationControl.java    From typescript.java with MIT License 6 votes vote down vote up
/**
 * @param parent
 *            parent control
 */
private void createFilterText(Composite parent) {
	// Create the widget
	filterText = new Text(parent, SWT.NONE);
	// Set the font
	GC gc = new GC(parent);
	gc.setFont(parent.getFont());
	FontMetrics fontMetrics = gc.getFontMetrics();
	gc.dispose();
	// Create the layout
	GridData data = new GridData(GridData.FILL_HORIZONTAL);
	data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
	data.horizontalAlignment = GridData.FILL;
	data.verticalAlignment = GridData.CENTER;
	filterText.setLayoutData(data);
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: ResetSpanStylePaintInstruction.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(GC gc) {
	if (span.types.contains(SpanType.FONT)) {
		gc.setFont(this.state.pollPreviousFont());
	}
	return gc.getFontMetrics();
}
 
Example #19
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 #20
Source File: ItalicPaintInstruction.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 #21
Source File: SpanStylePaintInstruction.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FontMetrics getFontMetrics(GC gc) {
	if (this.fontSize != null || this.fontType != null) {
		Font currentFont = gc.getFont();
		this.state.addPreviousFont(currentFont);
		gc.setFont(ResourceHelper.getFont(currentFont, this.fontType, this.fontSize));
	}
	return gc.getFontMetrics();
}
 
Example #22
Source File: LinePainter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public FontMetrics getBiggestMetrics() {
	return this.biggestMetrics;
}
 
Example #23
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 #24
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 #25
Source File: GlobalActions.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void printPatient(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();
			gc.drawString(Messages.GlobalActions_PatientIDLabelText + patient.getPatCode(), 0,
				0); //$NON-NLS-1$
			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 #26
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 #27
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 #28
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 #29
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 #30
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( );
}