001    package org.meta_environment.eclipse.tokens;
002    
003    import java.util.HashMap;
004    import java.util.Map;
005    
006    import org.eclipse.imp.parser.IParseController;
007    import org.eclipse.imp.services.ITokenColorer;
008    import org.eclipse.jface.text.IRegion;
009    import org.eclipse.jface.text.TextAttribute;
010    import org.eclipse.swt.SWT;
011    import org.eclipse.swt.graphics.Color;
012    import org.eclipse.swt.widgets.Display;
013    
014    public class TokenColorer implements ITokenColorer {
015            private TextAttribute normal;
016    
017            private Map<String,TextAttribute> map = new HashMap<String,TextAttribute>();
018    
019            public TokenColorer() {
020                    super();
021                    normal = new TextAttribute(Display.getDefault().getSystemColor(
022                                    SWT.COLOR_BLACK), null, SWT.NONE);
023                    
024                map.put("MetaKeyword", new TextAttribute(new Color(Display.getDefault(), 123, 0,
025                                    82), null, SWT.BOLD));
026                map.put("MetaVariable", new TextAttribute(new Color(Display.getDefault(), 0, 0,
027                                    255), null, SWT.ITALIC));
028                map.put("MetaAmbiguity",  new TextAttribute(new Color(Display.getDefault(), 186,
029                                    29, 29), null, SWT.BOLD));
030                    map.put("Todo",new TextAttribute(
031                                    new Color(Display.getDefault(), 123, 157, 198), null, SWT.BOLD));
032                    map.put("Comment",new TextAttribute(new Color(Display.getDefault(), 82, 141,
033                                    115), null, SWT.ITALIC));
034                    map.put("Constant",new TextAttribute(new Color(Display.getDefault(), 139, 0,
035                                    139), null, SWT.NONE));
036                    map.put("Variable",new TextAttribute(new Color(Display.getDefault(), 144, 238,
037                                    144), null, SWT.NONE));
038                    map.put("Identifier",new TextAttribute(new Color(Display.getDefault(), 255, 69,
039                                    0), null, SWT.NONE));
040                    map.put("Type",new TextAttribute(new Color(Display.getDefault(), 255, 127, 36),
041                                    null, SWT.NONE));
042            }
043    
044            public IRegion calculateDamageExtent(IRegion seed) {
045                    return seed;
046            }
047    
048            public TextAttribute getColoring(IParseController controller, Object o) {
049                    if (o instanceof Token) {
050                            Token t = (Token) o;
051                            TextAttribute attr = map.get(t.getCategory());
052                            return attr != null ? attr : normal;
053                    }
054    
055                    return normal;
056            }
057    }