本文整理汇总了Java中org.eclipse.swt.graphics.TextLayout类的典型用法代码示例。如果您正苦于以下问题:Java TextLayout类的具体用法?Java TextLayout怎么用?Java TextLayout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextLayout类属于org.eclipse.swt.graphics包,在下文中一共展示了TextLayout类的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("");
}
示例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$
}
示例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;
}
示例4: getPreferredHeight
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
if (innerTagFactory == null) {
innerTagFactory = new XliffInnerTagFactory(placeHolderBuilder);
}
innerTagFactory.reset();
TextLayout layout = getCellTextLayout(cell);
int counts = layout.getLineCount();
int contentHeight = 0;
for (int i = 0; i < counts; i++) {
contentHeight += layout.getLineBounds(i).height;
}
layout.dispose();
contentHeight += Math.max(counts - 1, 0) * SEGMENT_LINE_SPACING;
contentHeight += 4;// 加上编辑模式下,StyledTextCellEditor的边框
contentHeight += topPadding;
contentHeight += bottomPadding;
return contentHeight;
}
示例5: 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;
}
示例6: drawInnerTag
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
protected void drawInnerTag(GC gc, TextLayout layout) {
String displayStr = layout.getText();
List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
Rectangle bounds = getBounds();
for (InnerTagBean innerTagBean : innerTagBeans) {
String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
int start = displayStr.indexOf(placeHolder);
if (start == -1) {
continue;
}
if (gc != null) {
Point p = layout.getLocation(start, false);
int x = bounds.x + p.x + leftMargin;
x += SEGMENT_LINE_SPACING;
Point tagSize = tagRender.calculateTagSize(innerTagBean);
int lineIdx = layout.getLineIndex(start);
Rectangle r = layout.getLineBounds(lineIdx);
int y = bounds.y + p.y + topMargin + r.height / 2 - tagSize.y /2;
tagRender.draw(gc, innerTagBean, x, y - layout.getAscent());
}
}
}
示例7: configure
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
public static void configure(TextLayout textLayout) {
String text = textLayout.getText();
Document doc = new Document(text);
ITokenScanner scanner = getRecipeScanner(doc);
scanner.setRange(doc, 0, doc.getLength());
IToken token;
while ((token = scanner.nextToken()) != Token.EOF) {
int offset = scanner.getTokenOffset();
int length = scanner.getTokenLength();
Object data = token.getData();
if (data != null && data instanceof TextStyle) {
TextStyle textStyle = (TextStyle) data;
textLayout.setStyle(textStyle, offset, offset + length - 1);
}
}
}
示例8: configure
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
public static void configure(TextLayout textLayout) {
String text = textLayout.getText();
Document doc = new Document(text);
ITokenScanner scanner = getRecipeScanner(doc);
scanner.setRange(doc, 0, doc.getLength());
IToken token;
while ((token = scanner.nextToken()) != Token.EOF) {
int offset = scanner.getTokenOffset();
int length = scanner.getTokenLength();
Object data = token.getData();
if (data != null && data instanceof TextStyle) {
TextStyle textStyle = (TextStyle) data;
textLayout.setStyle(textStyle, offset, offset + length - 1);
}
}
scanner = null;
doc = null;
}
示例9: drawTextLayout
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
/**
* @see Graphics#drawTextLayout(TextLayout, int, int, int, int, Color,
* Color)
*/
public void drawTextLayout(TextLayout layout, int x, int y,
int selectionStart, int selectionEnd, Color selectionForeground,
Color selectionBackground) {
TextLayout scaled = zoomTextLayout(layout);
if (scaled == null) {
return;
}
try {
graphics.drawTextLayout(scaled,
(int) Math.floor(x * zoom + fractionalX),
(int) Math.floor(y * zoom + fractionalY), selectionStart,
selectionEnd, selectionBackground, selectionForeground);
} finally {
scaled.dispose();
}
}
示例10: getPointInBox
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
Point getPointInBox(TextFragmentBox box, int offset, int index,
boolean trailing) {
offset -= box.offset;
offset = Math.min(box.length, offset);
Point result = new Point(0, box.getTextTop());
if (bidiInfo == null) {
if (trailing && offset < box.length)
offset++;
String substring = getText().substring(box.offset,
box.offset + offset);
result.x = getTextUtilities().getTextExtents(substring, getFont()).width;
} else {
TextLayout layout = FlowUtilities.getTextLayout();
layout.setFont(getFont());
String fragString = getBidiSubstring(box, index);
layout.setText(fragString);
offset += getBidiPrefixLength(box, index);
result.x = layout.getLocation(offset, trailing).x;
if (isMirrored())
result.x = box.width - result.x;
}
result.x += box.getX();
return result;
}
示例11: 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(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
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);
if (displayStr.length() != 0 && innerTagStyled) {
attachInnertTagStyle(gc, layout, drawInnerTag);
}
return layout;
}
示例12: 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();
}
示例13: 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();
}
};
}
示例14: 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;
}
示例15: getTextLayout
import org.eclipse.swt.graphics.TextLayout; //导入依赖的package包/类
protected TextLayout getTextLayout(int lineIndex, int orientation, int width, int lineSpacing, Object obj,
Method proceed, Object[] args) throws Exception {
args[0] = lineIndex;
args[1] = orientation;
args[2] = width;
args[3] = lineSpacing;
return (TextLayout) proceed.invoke(obj, args);
}