# python syntax definition file
# TOKEN_ID=COLOR:IS_BOLD:IS_ITALIC:IS_UNDERLINED
0=0-0-0:false:false:false
1=0-0-0:false:false:false
2=0-0-0:false:false:false
3=0-0-0:false:false:false
4=0-0-0:false:false:false
5=0-0-0:false:false:false
6=0-0-0:false:false:false
7=0-0-0:false:false:false
8=0-0-0:false:false:false
9=0-0-0:false:false:false
10=0-0-0:false:false:false
11=0-0-0:false:false:false
12=0-0-0:false:false:false
public interface PythonLexerConstants {
public static final int DEFAULT = 0;
public static final int KEYWORD1 = 1;
public static final int KEYWORD2 = 2;
public static final int KEYWORD3 = 3;
public static final int INCLUDE = 4;
public static final int LITERAL1 = 5;
public static final int LITERAL2 = 6;
public static final int LITERAL3 = 7;
public static final int LITERAL4 = 8;
public static final int SEPARATOR1 = 9;
public static final int COMMENT1 = 10;
public static final int IDENTIFIER1 = 11;
public static final int OPERATOR = 12;
}
public class PythonLexer implements ILexer, PythonLexerConstants{
//etc.
}
/*
* PythonLexerColorProvider.java
*
* Created on December 15, 2006, 9:05 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package swingutils.text.syntax.impl;
import java.util.Arrays;
import swingutils.text.SimpleStyle;
import swingutils.text.lexers.PythonLexerConstants;
import swingutils.text.syntax.ILexerColorProvider;
import java.awt.Color;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
*
* @author mrcheeks
*/
public class PythonLexerColorProvider implements ILexerColorProvider,
PythonLexerConstants {
private Map styleMap = new HashMap();
/**
* Creates a new instance of JavaLexerColorProviderImpl
*/
public PythonLexerColorProvider() {
Properties props = new Properties();
try {
props.load(getClass().getResourceAsStream("/swingutils/text/lexers/python.properties"));
// # DEFAULT TOKEN ID=0 COLOR=0,0,0 BOLD=true ITALIC=true UNDERLINE=true
// 0=0-0-0:true:true:true
Field[] fields = PythonLexerConstants.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
int value = fields[i].getInt(null);
String property = "" + value;
Object obj = props.getProperty(property);
if (obj != null) {
String[] val = obj.toString().split(":");
SimpleStyle style = new SimpleStyle();
String[] color = val[0].split("-");
System.out.println("0:" + val[0]);
int a = Integer.parseInt(color[0]);
int b = Integer.parseInt(color[1]);
int c = Integer.parseInt(color[2]);
Color _color = new Color(a, b, c);
style.fontColor = _color;
style.bold = val[1].equals("true");
style.italic = val[2].equals("true");
style.underlined = val[3].equals("true");
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public Map getStyleMap() {
return styleMap;
}
private void putValue(int val, SimpleStyle style) {
styleMap.put(new Integer(val), style);
}
}