当前位置: 首页>>代码示例>>Java>>正文


Java TextLayout.setText方法代码示例

本文整理汇总了Java中org.eclipse.swt.graphics.TextLayout.setText方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.setText方法的具体用法?Java TextLayout.setText怎么用?Java TextLayout.setText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.swt.graphics.TextLayout的用法示例。


在下文中一共展示了TextLayout.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTextLayout

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * <p>
 * Creates and initializes the text layout used to compute the size hint.
 * </p>
 * 
 * @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("    ");
	int tabWidth = fTextLayout.getBounds().width;
	fTextLayout.setTabs(new int[] {tabWidth});
	
	fTextLayout.setText("");
}
 
开发者ID:DarwinSPL,项目名称:DarwinSPL,代码行数:26,代码来源:DwprofileBrowserInformationControl.java

示例2: createTextLayout

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * 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$
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:24,代码来源:CustomBrowserInformationControl.java

示例3: shortenText

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
public static String shortenText(final GC gc, String text, final int width, final String ellipses) {

		if (gc.textExtent(text, 0).x <= width) {
			return text;
		}

		final int ellipseWidth = gc.textExtent(ellipses, 0).x;
		final int length = text.length();
		final TextLayout layout = new TextLayout(gc.getDevice());
		layout.setText(text);

		int end = layout.getPreviousOffset(length, SWT.MOVEMENT_CLUSTER);
		while (end > 0) {
			text = text.substring(0, end);
			final int l = gc.textExtent(text, 0).x;
			if (l + ellipseWidth <= width) {
				break;
			}
			end = layout.getPreviousOffset(end, SWT.MOVEMENT_CLUSTER);
		}
		layout.dispose();
		return end == 0 ? text.substring(0, 1) : text + ellipses;
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:24,代码来源:UI.java

示例4: getTextLayout

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
public TextLayout getTextLayout(GC gc, GridItem item, int columnIndex, boolean innerTagStyled, boolean drawInnerTag) {
	TextLayout layout = new TextLayout(gc.getDevice());
	layout.setFont(font);
	layout.setTabs(new int[]{tabWidth});
	innerTagFactory.reset();
	
	String displayStr = "";
	try{
		displayStr = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag(item.getText(columnIndex)));
	}catch (NullPointerException e) {
		return null;
	}
	layout.setText(displayStr);
	int width = getBounds().width - leftMargin - rightMargin;
	layout.setWidth(width < 1 ? 1 : width);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setAlignment(SWT.LEFT);
	layout.setOrientation(item.getParent().getOrientation());
	if (displayStr.length() != 0 && innerTagStyled) {
		attachInnertTagStyle(gc, layout, drawInnerTag);
	}
	return layout;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:24,代码来源:XGridCellRenderer.java

示例5: drawBlankString

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
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();
}
 
开发者ID:eclipse,项目名称:birt,代码行数:17,代码来源:CellFigure.java

示例6: getPaintObjectListener

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * Convenience method
 * 
 * @param inWidget
 *            {@link StyledText}
 * @return {@link PaintObjectListener}
 */
public static PaintObjectListener getPaintObjectListener(
        final StyledText inWidget) {
	return new PaintObjectListener() {
		@Override
		public void paintObject(final PaintObjectEvent inEvent) {
			final Display lDisplay = inEvent.display;
			final StyleRange lStyle = inEvent.style;
			final int lPosition = inEvent.x + lStyle.metrics.width
			        - BULLET_WIDTH + 2;
			Font lFont = lStyle.font;
			if (lFont == null)
				lFont = inWidget.getFont();
			final TextLayout lLayout = new TextLayout(lDisplay);
			lLayout.setAscent(inEvent.ascent);
			lLayout.setDescent(inEvent.descent);
			lLayout.setFont(lFont);
			lLayout.setText(String.format("%s.", inEvent.bulletIndex + 1)); //$NON-NLS-1$
			lLayout.draw(inEvent.gc, lPosition, inEvent.y);
			lLayout.dispose();
		}
	};
}
 
开发者ID:aktion-hip,项目名称:relations,代码行数:30,代码来源:Styles.java

示例7: getTextLayout

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
private TextLayout getTextLayout(Plugin plugin, boolean selected) {
    final TextLayout textLayout = new TextLayout(display);
    int length1 = plugin.getName().length();
    String text = plugin.getName() + "\n \n" + plugin.getDescription();
    textLayout.setText(text);
    textLayout.setStyle(selected ? styleTitleSelected : styleTitle, 0, length1);
    textLayout.setStyle(styleGap, length1 + 1, length1 + 2);
    textLayout.setStyle(selected ? styleRowSelected : styleRow, length1 + 3, text.length());
    return textLayout;
}
 
开发者ID:gluonhq,项目名称:ide-plugins,代码行数:11,代码来源:PluginsSWT.java

示例8: updateImage

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
protected void updateImage() {
	Rectangle bounds = getBounds();
	if (bounds.width <= 0 || bounds.height <= 0)
		return;
	TextLayout layout = new TextLayout(Display.getDefault());
	//layout.setFont(getFont());
	layout.setText(getText());
	for (StyleRange styleRange : ranges) {
		//styleRange.background = ColorConstants.white;
		layout.setStyle(styleRange, styleRange.start, styleRange.start
				+ styleRange.length);
	}
	if (image != null && !image.isDisposed()) {
		image.dispose();
	}
	image = new Image(Display.getDefault(), bounds.width, bounds.height);
	
	GC gc = new GC(image);
	gc.setBackground(ColorConstants.red);
	layout.draw(gc, 0, 0);
	image.getImageData().transparentPixel = image.getImageData().palette
			.getPixel(ColorConstants.white.getRGB());

	
	layout.dispose();
	gc.dispose();
}
 
开发者ID:Yakindu,项目名称:statecharts,代码行数:28,代码来源:StyledLabel.java

示例9: shortenText

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * Shorten the given text <code>t</code> so that its length doesn't exceed
 * the given width. The default implementation replaces characters in the
 * center of the original string with an ellipsis ("...").
 * Override if you need a different strategy.
 * 
 * @param gc the gc to use for text measurement
 * @param t the text to shorten
 * @param width the width to shorten the text to, in pixels
 * @return the shortened text
 * Note, this code was copied from 
 *   org.eclipse.swt.custom.CLabel.shortenText()
 */
protected String shortenText(GC gc, String t, int width) {
	if (t == null) return null;
	int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
	if (width<=w) return t;
	int l = t.length();
	int max = l/2;
	int min = 0;
	int mid = (max+min)/2 - 1;
	if (mid <= 0) return t;
	TextLayout layout = new TextLayout (getDisplay());
	layout.setText(t);
	mid = validateOffset(layout, mid);
	while (min < mid && mid < max) {
		String s1 = t.substring(0, mid);
		String s2 = t.substring(validateOffset(layout, l-mid), l);
		int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
		int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
		if (l1+w+l2 > width) {
			max = mid;			
			mid = validateOffset(layout, (max+min)/2);
		} else if (l1+w+l2 < width) {
			min = mid;
			mid = validateOffset(layout, (max+min)/2);
		} else {
			min = max;
		}
	}
	String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l-mid), l);
	layout.dispose();
 	return result;
}
 
开发者ID:MentorEmbedded,项目名称:p2-installer,代码行数:45,代码来源:InfoButton.java

示例10: getCellTextLayout

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
private TextLayout getCellTextLayout(LayerCell cell) {
	int orientation = editor.getTable().getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
	TextLayout layout = new TextLayout(editor.getTable().getDisplay());
	layout.setOrientation(orientation);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setFont(font);
	layout.setAscent(ascent);
	layout.setDescent(descent); // 和 StyledTextEditor 同步
	layout.setTabs(new int[] { tabWidth });

	Rectangle rectangle = cell.getBounds();
	int width = rectangle.width - leftPadding - rightPadding;
	width -= 1;
	if (wrapText && width > 0) {
		layout.setWidth(width);
	}

	String displayText = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag((String) cell.getDataValue()));
	if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
		displayText = displayText.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
		displayText = displayText.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B");
		displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B");
	}
	layout.setText(displayText);
	List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
	for (InnerTagBean innerTagBean : innerTagBeans) {
		String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
		int start = displayText.indexOf(placeHolder);
		if (start == -1) {
			continue;
		}
		TextStyle style = new TextStyle();
		Point rect = tagRender.calculateTagSize(innerTagBean);
		style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2);
		layout.setStyle(style, start, start + placeHolder.length() - 1);
	}

	return layout;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:40,代码来源:TextPainterWithPadding.java

示例11: setFont

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * 设置字体
 * @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;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:18,代码来源:XGridCellRenderer.java

示例12: updateTextLayout

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * @param layout
 * @param cell
 * @param applyColors
 * @return the text width delta (0 if the text layout contains no other font)
 */
private int updateTextLayout(TextLayout layout, ViewerCell cell,
		boolean applyColors) {
	layout.setStyle(null, 0, Integer.MAX_VALUE); // clear old styles

	layout.setText(cell.getText());
	layout.setFont(cell.getFont()); // set also if null to clear previous usages
	
	int originalTextWidth = layout.getBounds().width; // text width without any styles
	boolean containsOtherFont= false;
	
	StyleRange[] styleRanges = cell.getStyleRanges();
	if (styleRanges != null) { // user didn't fill styled ranges
		for (int i = 0; i < styleRanges.length; i++) {
			StyleRange curr = prepareStyleRange(styleRanges[i], applyColors);
			layout.setStyle(curr, curr.start, curr.start + curr.length - 1);
			if (curr.font != null) {
				containsOtherFont= true;
			}
		}
	}
	int textWidthDelta = 0;
	if (containsOtherFont) {
		textWidthDelta = layout.getBounds().width - originalTextWidth;
	}
	return textWidthDelta;
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:33,代码来源:StyledCellLabelProvider.java

示例13: getTextLayoutBounds

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * @see TextLayout#getBounds()
 */
protected Rectangle getTextLayoutBounds(String s, Font f, int start, int end) {
	TextLayout textLayout = getTextLayout();
	textLayout.setFont(f);
	textLayout.setText(s);
	return textLayout.getBounds(start, end);
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:10,代码来源:FlowUtilities.java

示例14: paintText

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
protected void paintText(Graphics g, String draw, int x, int y,
		int bidiLevel) {
	if (bidiLevel == -1) {
		g.drawText(draw, x, y);
	} else {
		TextLayout tl = FlowUtilities.getTextLayout();
		if (isMirrored())
			tl.setOrientation(SWT.RIGHT_TO_LEFT);
		tl.setFont(g.getFont());
		tl.setText(draw);
		g.drawTextLayout(tl, x, y);
	}
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:14,代码来源:TextFlow.java

示例15: shortenText

import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
 * 
 *
 * @param gc
 * @param t
 * @param width
 * @return
 */
protected String shortenText(GC gc, String t, int width) {
    if (t == null) return null;
    int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
    if (width <= w) return t;
    int l = t.length();
    int max = l / 2;
    int min = 0;
    int mid = (max + min) / 2 - 1;
    if (mid <= 0) return t;
    TextLayout layout = new TextLayout(getDisplay());
    layout.setText(t);
    mid = validateOffset(layout, mid);
    while (min < mid && mid < max) {
        String s1 = t.substring(0, mid);
        String s2 = t.substring(validateOffset(layout, l - mid), l);
        int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
        int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
        if (l1 + w + l2 > width) {
            max = mid;
            mid = validateOffset(layout, (max + min) / 2);
        } else if (l1 + w + l2 < width) {
            min = mid;
            mid = validateOffset(layout, (max + min) / 2);
        } else {
            min = max;
        }
    }
    String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l - mid), l);
    layout.dispose();
    return result;
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:40,代码来源:ComponentStatusLabel.java


注:本文中的org.eclipse.swt.graphics.TextLayout.setText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。