use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.
the class CustomMessageDialog method setStyle.
private void setStyle() {
for (HashMap<String, Integer> map : list) {
StyleRange styleRange = new StyleRange();
styleRange.start = map.get("start");
styleRange.length = map.get("length");
styleRange.fontStyle = SWT.BOLD;
styleRange.foreground = red;
text.setStyleRange(styleRange);
}
}
use of org.eclipse.swt.custom.StyleRange in project translationstudio8 by heartsome.
the class HsMultiCellEditor method refreshErrorWordsStyle.
/**
* 刷新拼写检查中错误单词的样式
* @param ranges
*/
public void refreshErrorWordsStyle(List<StyleRange> ranges) {
StyledText styledText = cellEditor.viewer.getTextWidget();
List<StyleRange> oldRangeList = new ArrayList<StyleRange>();
for (StyleRange oldRange : styledText.getStyleRanges()) {
if (oldRange.underlineStyle != SWT.UNDERLINE_ERROR) {
oldRangeList.add(oldRange);
}
}
styledText.setStyleRange(null);
styledText.setStyleRanges(oldRangeList.toArray(new StyleRange[oldRangeList.size()]));
if (ranges != null) {
for (StyleRange range : ranges) {
styledText.setStyleRange(range);
}
}
}
use of org.eclipse.swt.custom.StyleRange 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.custom.StyleRange in project translationstudio8 by heartsome.
the class HsMultiCellEditor method getErrorWordRange.
/**
* 根据传入的相关参数获取错误单词的样式 robert 2013-01-22
* @param style
* @param start
* @param length
* @return
*/
private StyleRange getErrorWordRange(TextStyle style, int start, int length) {
StyleRange range = new StyleRange(style);
range.start = start;
range.length = length;
range.underline = true;
range.underlineStyle = SWT.UNDERLINE_ERROR;
range.underlineColor = ColorConfigBean.getInstance().getErrorWordColor();
return range;
}
use of org.eclipse.swt.custom.StyleRange 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);
}
}
Aggregations