王吉元-NWPU

导航

 

1. 在public class XMLConfiguration中添加扫描函数:

protected ValueScanner getValueScanner() {
if (valuescanner == null) {
valuescanner = new ValueScanner(colorManager);
valuescanner.setDefaultReturnToken(
new Token(
new TextAttribute(
colorManager.getColor(IXMLColorConstants.DEFAULT))));
}
return valuescanner;
}

2. 在getPresentationReconciler函数中添加:

dr = new DefaultDamagerRepairer(getValueScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

3. 最后添加两个类:ValueScanner和WordDetector:

public class ValueScanner extends RuleBasedScanner{

String[]keywords = {"continent","country","hi","int"};

String[] funwords = {"short","long","double","long long",
"char","float","boolean","octet","string",
"unsigned short","unsigned long","unsigned long long"};

public ValueScanner(ColorManager manager)
{
IToken keywordToken =
new Token(
new TextAttribute(manager.getColor(IXMLColorConstants.STRING)));//IXMLColorConstants.STRING指定颜色

IToken funwordToken =
new Token(
new TextAttribute(manager.getColor(IXMLColorConstants.TAG)));

WordRule keywordRule = new WordRule(new WordDetector());
for(int i=0;i<keywords.length;i++)
{
keywordRule.addWord(keywords[i], keywordToken);
}
for(int i=0;i<funwords.length;i++)
{
keywordRule.addWord(funwords[i], funwordToken);
}
setRules(new IRule[]{keywordRule});
}
}

//******************************************************************

public class WordDetector implements IWordDetector{

public boolean isWordStart(char c){
return Character.isLetter(c);
}

public boolean isWordPart(char c){
return Character.isLetterOrDigit(c);
}
}

4. 打完手工。

posted on 2013-03-01 08:57  王吉元  阅读(360)  评论(0编辑  收藏  举报