Java Code Examples for org.eclipse.swt.graphics.TextLayout#getBounds()

The following examples show how to use org.eclipse.swt.graphics.TextLayout#getBounds() . 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: XbaseInformationControl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates and initializes the text layout used to compute the size hint.
 * 
 * @since 3.2
 */
private void createTextLayout() {
	fTextLayout = new TextLayout(fSashForm.getDisplay());

	// Initialize fonts
	String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
	Font font = JFaceResources.getFont(symbolicFontName);
	fTextLayout.setFont(font);
	fTextLayout.setWidth(-1);
	font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
	fBoldStyle = new TextStyle(font, null, null);

	// Compute and set tab width
	fTextLayout.setText("    "); //$NON-NLS-1$
	int tabWidth = fTextLayout.getBounds().width;
	fTextLayout.setTabs(new int[] { tabWidth });
	fTextLayout.setText(""); //$NON-NLS-1$
}
 
Example 2
Source File: CustomBrowserInformationControl.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and initializes the text layout used to compute the size hint.
 * 
 * @since 3.2
 */
private void createTextLayout()
{
	fTextLayout = new TextLayout(fBrowser.getDisplay());

	// Initialize fonts
	String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
	Font font = JFaceResources.getFont(symbolicFontName);
	fTextLayout.setFont(font);
	fTextLayout.setWidth(-1);
	font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
	fBoldStyle = new TextStyle(font, null, null);

	// Compute and set tab width
	fTextLayout.setText("    "); //$NON-NLS-1$
	int tabWidth = fTextLayout.getBounds().width;
	fTextLayout.setTabs(new int[] { tabWidth });
	fTextLayout.setText(""); //$NON-NLS-1$
}
 
Example 3
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 4
Source File: XGridCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置字体
 * @param font
 *            ;
 */
public void setFont(Font font) {
	TextLayout layout = new TextLayout(Display.getDefault());
	layout.setFont(font);
	StringBuffer tabBuffer = new StringBuffer(tabSize);
	for (int i = 0; i < tabSize; i++) {
		tabBuffer.append(' ');
	}
	layout.setText(tabBuffer.toString());
	tabWidth = layout.getBounds().width;
	layout.dispose();
	this.font = font;
}
 
Example 5
Source File: AttributePainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
	TextLayout layout = getCellTextLayout(cell);
	int contentHeight = layout.getBounds().height;
	layout.dispose();
	contentHeight += topPadding;
	contentHeight += bottomPadding;
	contentHeight += 4;// 加上编辑模式下,StyledTextCellEditor的边框
	return contentHeight;
}
 
Example 6
Source File: TmxEditorTextPainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
	TextLayout layout = getCellTextLayout(cell);
	int contentHeight = layout.getBounds().height;
	layout.dispose();
	tuv = null;
	contentHeight += topPadding;
	contentHeight += bottomPadding;
	contentHeight += 4;// 加上编辑模式下,StyledTextCellEditor的边框
	return contentHeight;
}