use of org.eclipse.swt.graphics.TextStyle in project translationstudio8 by heartsome.
the class HsMultiCellEditor method highLightedErrorWord.
/**
* 实时拼检查时高亮错误单词 robert 2013-01-21
* @param terms
*/
public void highLightedErrorWord(String tgtText, List<SingleWord> errorWordList) {
if (!isValid()) {
return;
}
List<StyleRange> ranges = new ArrayList<StyleRange>();
TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null, null);
for (SingleWord singleWord : errorWordList) {
Matcher match = PlaceHolderEditModeBuilder.PATTERN.matcher(singleWord.getWord());
// 这里是处理一个单词中有一个或多个标记,从而导致标记绘画失败的BUG,如果其中有标记,那么这个 StyleRange 就应该被切断
boolean hasTag = false;
int index = 0;
while (match.find()) {
StyleRange range = getErrorWordRange(style, singleWord.getStart() + index, match.start() - index);
ranges.add(range);
index = match.end();
hasTag = true;
}
if (hasTag) {
if (index < singleWord.getLength()) {
StyleRange range = getErrorWordRange(style, singleWord.getStart() + index, singleWord.getLength() - index);
ranges.add(range);
}
} else {
ranges.add(getErrorWordRange(style, singleWord.getStart(), singleWord.getLength()));
}
}
refreshErrorWordsStyle(ranges);
}
use of org.eclipse.swt.graphics.TextStyle in project translationstudio8 by heartsome.
the class HsMultiCellEditor method highlightedTerms.
public void highlightedTerms(List<String> terms) {
if (!isValid()) {
return;
}
StyledText styledText = cellEditor.viewer.getTextWidget();
String text = styledText.getText();
char[] source = text.toCharArray();
List<StyleRange> ranges = new ArrayList<StyleRange>();
TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null, ColorConfigBean.getInstance().getHighlightedTermColor());
for (String term : terms) {
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "");
term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "");
}
ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
}
for (StyleRange range : ranges) {
styledText.setStyleRange(range);
}
}
use of org.eclipse.swt.graphics.TextStyle in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method getTemplateLabel.
protected StyledString getTemplateLabel(Template template) {
Styler nameStyle = new StyledString.Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.foreground = new Color(Display.getCurrent(), new RGB(80, 80, 255));
}
};
Styler descriptionStyle = new StyledString.Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
textStyle.foreground = new Color(Display.getCurrent(), new RGB(120, 120, 120));
}
};
return new StyledString(template.getName(), nameStyle).append(": ", descriptionStyle).append(template.getDescription(), descriptionStyle);
}
use of org.eclipse.swt.graphics.TextStyle in project eclipse.platform.text by eclipse.
the class BrowserInformationControl method createTextLayout.
/**
* 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
// $NON-NLS-1$
fTextLayout.setText(" ");
int tabWidth = fTextLayout.getBounds().width;
fTextLayout.setTabs(new int[] { tabWidth });
// $NON-NLS-1$
fTextLayout.setText("");
}
use of org.eclipse.swt.graphics.TextStyle in project yamcs-studio by yamcs.
the class RCPSSTextLayout method addStyle.
/**
* {@inheritDoc}
*/
@Override
public void addStyle(Font font, Color color, int x, int y) {
TextStyle textStyle = new TextStyle(font, color, null);
textLayout.setStyle(textStyle, x, y);
}
Aggregations