本文整理汇总了Java中org.eclipse.swt.graphics.TextLayout.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.setFont方法的具体用法?Java TextLayout.setFont怎么用?Java TextLayout.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.TextLayout
的用法示例。
在下文中一共展示了TextLayout.setFont方法的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: 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;
}
示例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(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;
}
示例5: 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;
}
示例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();
}
};
}
示例7: initBidi
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* @param frag
* @param string
* @param font
* @since 3.1
*/
private static void initBidi(TextFragmentBox frag, String string, Font font) {
if (frag.requiresBidi()) {
TextLayout textLayout = getTextLayout();
textLayout.setFont(font);
// $TODO need to insert overrides in front of string.
textLayout.setText(string);
}
}
示例8: 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);
}
示例9: addLeadingWordWidth
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* Calculates the width taken up by the given text before a line-break is
* encountered.
*
* @param text
* the text in which the break is to be found
* @param width
* the width before the next line-break (if one's found; the
* width of all the given text, otherwise) will be added on to
* the first int in the given array
* @return <code>true</code> if a line-break was found
* @since 3.1
*/
boolean addLeadingWordWidth(String text, int[] width) {
if (text.length() == 0)
return false;
// if (Character.isWhitespace(text.charAt(0)))
// return true;
text = 'a' + text + 'a';
// TODO: GEFGWT commented out
// FlowUtilities.LINE_BREAK.setText(text);
// int index = FlowUtilities.LINE_BREAK.next() - 1;
int index = 0;
// GEFGWT commented out
if (index == 0)
return true;
// while (Character.isWhitespace(text.charAt(index)))
// index--;
// boolean result = index < text.length() - 1;
// index should point to the end of the actual text (not including the
// 'a' that was
// appended), if there were no breaks
if (index == text.length() - 1)
index--;
text = text.substring(1, index + 1);
if (bidiInfo == null)
width[0] += getTextUtilities().getTextExtents(text, getFont()).width;
else {
TextLayout textLayout = FlowUtilities.getTextLayout();
textLayout.setFont(getFont());
textLayout.setText(text);
width[0] += textLayout.getBounds().width;
}
return true;
}
示例10: 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);
}
}
示例11: 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;
}
示例12: 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 + "");
displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "");
}
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;
}
示例13: computeSize
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
if (isTree()) {
x += getToggleIndent(item);
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
x += checkRenderer.getBounds().width + insideMargin;
}
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
x += image.getBounds().width + insideMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells
// in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() +
// bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
示例14: computeSize
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
x += image.getBounds().width + 3;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
示例15: computeSize
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}