本文整理汇总了Java中org.eclipse.swt.graphics.TextLayout.setStyle方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.setStyle方法的具体用法?Java TextLayout.setStyle怎么用?Java TextLayout.setStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.TextLayout
的用法示例。
在下文中一共展示了TextLayout.setStyle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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();
}
示例5: 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;
}
示例6: appendNonprintingStyle
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
private void appendNonprintingStyle(TextLayout layout) {
TextStyle style = new TextStyle(font, GUIHelper.getColor(new RGB(100, 100, 100)), null);
String s = layout.getText();
Matcher matcher = Constants.NONPRINTING_PATTERN.matcher(s);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
// style.metrics = new GlyphMetrics(10, 0, 1);
layout.setStyle(style, start, end - 1);
}
}
示例7: 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;
}
示例8: 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;
}
示例9: parseSyntax
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
@Override
public void parseSyntax(TextLayout layout, int rowIndex, boolean selected, boolean highlighted )
{
// Obtain the text to parse
String text = layout.getText();
// Do not process null or blank text
if (text == null || text.length() == 0)
return;
// Default style
if (selected)
{
layout.setStyle(m_scheme.getSelectedStyle(), 0, text.length());
return;
}
else if (highlighted)
{
layout.setStyle(m_scheme.getHighlightedStyle(), 0, text.length());
return;
}
else
{
layout.setStyle(m_scheme.getDefaultStyle(), 0, text.length());
}
// Create a source for the tokenizer with the text
StringSource source = new StringSource(text);
// Create the tokenizer using the current configuration
StandardTokenizer tokenizer = new StandardTokenizer(m_properties);
// Assign the source
tokenizer.setSource(source);
try
{
// For each token recognised in the text
while (tokenizer.hasMoreToken())
{
Token token = tokenizer.nextToken();
int type = token.getType();
// This is the token text
String word = tokenizer.currentImage();
// When the image is null, we are processing EOL
if (word == null)
break;
boolean isDocStringTag1 = (type == Token.SPECIAL_SEQUENCE && word.equals("\"\"\""));
boolean isDocStringTag2 = (type == Token.SPECIAL_SEQUENCE && word.equals("'''"));
boolean isDocString = false;
if (m_currentCodeId != null)
{
ISyntaxAreas areas = m_syntaxAreas.get(m_currentCodeId);
if (areas != null)
{
isDocString = areas.isInCommentBlock(rowIndex);
}
}
// Find the applicable style, depending on the token type
TextStyle toApply = null;
if (isDocString || isDocStringTag1 || isDocStringTag2)
{
toApply = m_scheme.getStyle(TokenTypes.COMMENT);
}
else
{
toApply = getApplicableStyle(word, type);
}
// If no style is returned, continue to next token
if (toApply == null)
continue;
// Get the applicable range (find token position)
Range range = getApplicableRange(text, word, token);
// Apply the style to the layout
layout.setStyle(toApply, range.start, range.end);
}
// Close tokenizer
tokenizer.close();
tokenizer = null;
}
catch (TokenizerException e)
{
e.printStackTrace();
}
}
示例10: draw
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
// convert the value to a string
String s = convertValue(row, column);
Color fg = gc.getForeground();
Color bg = gc.getBackground();
Font font = gc.getFont();
// draw comment marker if comment is present and not printing
if (!printing && getComment(row, column) != null) {
drawCommentMarker(gc, drawingArea, _commentColor, COMMENTMARKER_SIZE);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
gc.setForeground(fg);
gc.setBackground(bg);
gc.setFont(font);
if (s != null) {
if (selected && !printing) {
gc.setBackground(SELECTIONCOLOR);
} else {
gc.setBackground(getBackgroundColor(cellStyle, printing));
}
gc.setForeground(getForegroundColor(cellStyle, printing));
gc.setFont(getFont(cellStyle, printing, gc.getFont()));
drawCellString(gc, rect, s, cellStyle);
if (s.indexOf("we") != -1) {
TextLayout textLayout = new TextLayout(gc.getDevice());
textLayout.setText(s);
textLayout.setFont(gc.getFont());
textLayout.setWidth(rect.width);
Color color = new Color(gc.getDevice(), 150, 100, 100);
Font font2 = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont()
.getFontData()[0].getHeight(), SWT.ITALIC);
TextStyle style = new TextStyle(font2, color, null);
for (int i = 1; i < s.length(); i++) {
int j = indexOf(s, "we", i, false);
if (j != -1) {
textLayout.setStyle(style, j, j + 3);
} else {
break;
}
}
gc.fillRectangle(rect);
textLayout.draw(gc, rect.x, rect.y);
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
}
}
}
示例11: zoomTextLayout
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
private TextLayout zoomTextLayout(TextLayout layout) {
TextLayout zoomed = new TextLayout(Display.getCurrent());
zoomed.setText(layout.getText());
int zoomWidth = -1;
if (layout.getWidth() != -1)
zoomWidth = ((int) (layout.getWidth() * zoom));
if (zoomWidth < -1 || zoomWidth == 0)
return null;
zoomed.setFont(zoomFont(layout.getFont()));
zoomed.setAlignment(layout.getAlignment());
zoomed.setAscent(layout.getAscent());
zoomed.setDescent(layout.getDescent());
zoomed.setOrientation(layout.getOrientation());
zoomed.setSegments(layout.getSegments());
zoomed.setSpacing(layout.getSpacing());
zoomed.setTabs(layout.getTabs());
zoomed.setWidth(zoomWidth);
int length = layout.getText().length();
if (length > 0) {
int start = 0, offset = 1;
TextStyle style = null, lastStyle = layout.getStyle(0);
for (; offset <= length; offset++) {
if (offset != length
&& (style = layout.getStyle(offset)) == lastStyle)
continue;
int end = offset - 1;
if (lastStyle != null) {
TextStyle zoomedStyle = new TextStyle(
zoomFont(lastStyle.font), lastStyle.foreground,
lastStyle.background);
zoomedStyle.metrics = lastStyle.metrics;
zoomedStyle.rise = lastStyle.rise;
zoomedStyle.strikeout = lastStyle.strikeout;
zoomedStyle.underline = lastStyle.underline;
zoomed.setStyle(zoomedStyle, start, end);
}
lastStyle = style;
start = offset;
}
}
return zoomed;
}