我们正在为特定类型的文件使用自定义编辑器。现在的问题是,我是这个日食相关的新手。我必须突出显示具有特定颜色的单词列表。我在网上查了一些规则,但我没有基本的想法如何使用它们。如果有人帮我如何在自定义编辑器中为给定的单词列表添加特定颜色,那就太棒了。
提前致谢。
答案 0 :(得分:0)
您可以使用此代码将其放入您的协调程序类:`
private final TextAttribute wordAttribute = new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 0, 255));
public static final String[] keywords = { "define your keywords here" };
....................................................................
RuleBasedScanner scanner = new RuleBasedScanner();
IRule[] rules = new IRule[5]; //set as many rules as you want just change the number in the bracket
....................................................................
WordRule rule = new WordRule(new IWordDetector() {//the IWordDetector class is an anonymous class so you'll have to define and override this two functions below as you want
@Override
public boolean isWordStart(char c) {
// TODO Auto-generated method stub
return Character.isJavaIdentifierStart(c);
}
@Override
public boolean isWordPart(char c) {
// TODO Auto-generated method stub
return Character.isJavaIdentifierStart(c);
}
});
for (int i = 0; i < keywords.length; i++) {
rule.addWord(keywords[i], new Token(wordAttribute));
}
rules[0] = rule;
scanner.setRules(rules);
}`
我认为它应该像对待我一样为你的文字着色。