1 22 package bluej.editor.moe; 23 24 import javax.swing.text.*; 25 26 import java.awt.Color ; 27 import bluej.Config; 28 29 import org.syntax.jedit.*; 30 import org.syntax.jedit.tokenmarker.*; 31 32 import java.util.Properties ; 34 35 45 public class MoeSyntaxDocument extends SyntaxDocument 46 { 47 public static final String OUTPUT = "output"; 48 public static final String ERROR = "error"; 49 50 private static Color [] colors = null; 51 52 public MoeSyntaxDocument() 53 { 54 super(getUserColors()); 55 int tabSize = Config.getPropInteger("bluej.editor.tabsize", 4); 57 putProperty(tabSizeAttribute, new Integer (tabSize)); 58 } 59 60 72 public void setParagraphAttributes(int offset, AttributeSet s) 73 { 74 try { 76 writeLock(); 77 78 Element paragraph = getParagraphElement(offset); 79 MutableAttributeSet attr = 80 (MutableAttributeSet) paragraph.getAttributes(); 81 attr.addAttributes(s); 82 } finally { 83 writeUnlock(); 84 } 85 } 86 87 88 89 98 private static Color [] getUserColors() 99 { 100 if(colors == null) { 101 Properties editorProps = Config.moe_user_props; 102 103 colors = new Color [Token.ID_COUNT]; 105 106 String colorStr; 108 int colorInt; 109 110 colorStr = editorProps.getProperty("comment","1a1a80"); 112 try { 113 colorInt = Integer.parseInt(colorStr,16); 114 } 115 catch (NumberFormatException e) { 116 colorInt = 0x1a1a80; 117 } 118 colors[Token.COMMENT1] = new Color (colorInt); 119 120 colorStr = editorProps.getProperty("javadoc","1a1a80"); 122 try { 123 colorInt = Integer.parseInt(colorStr,16); 124 } 125 catch (NumberFormatException e) { 126 colorInt = 0x1a1a80; 127 } 128 colors[Token.COMMENT2] = new Color (colorInt); 129 130 colorStr = editorProps.getProperty("stand-out","ee00bb"); 132 try { 133 colorInt = Integer.parseInt(colorStr,16); 134 } 135 catch (NumberFormatException e) { 136 colorInt = 0xee00bb; 137 } 138 colors[Token.COMMENT3] = new Color (colorInt); 139 140 colorStr = editorProps.getProperty("keyword1","660033"); 142 try { 143 colorInt = Integer.parseInt(colorStr,16); 144 } 145 catch (NumberFormatException e) { 146 colorInt = 0x660033; 147 } 148 colors[Token.KEYWORD1] = new Color (colorInt); 149 150 colorStr = editorProps.getProperty("keyword2","cc8033"); 152 try { 153 colorInt = Integer.parseInt(colorStr,16); 154 } 155 catch (NumberFormatException e) { 156 colorInt = 0xcc8033; 157 } 158 colors[Token.KEYWORD2] = new Color (colorInt); 159 160 colorStr = editorProps.getProperty("keyword3","006699"); 162 try { 163 colorInt = Integer.parseInt(colorStr,16); 164 } 165 catch (NumberFormatException e) { 166 colorInt = 0x006699; 167 } 168 colors[Token.KEYWORD3] = new Color (colorInt); 169 170 colorStr = editorProps.getProperty("primitive","cc0000"); 172 try { 173 colorInt = Integer.parseInt(colorStr,16); 174 } 175 catch (NumberFormatException e) { 176 colorInt = 0xcc0000; 177 } 178 colors[Token.PRIMITIVE] = new Color (colorInt); 179 180 colorStr = editorProps.getProperty("string","339933"); 182 try { 183 colorInt = Integer.parseInt(colorStr,16); 184 } 185 catch (NumberFormatException e) { 186 colorInt = 0x339933; 187 } 188 colors[Token.LITERAL1] = new Color (colorInt); 189 190 colors[Token.LABEL] = new Color (0x990000); 192 colors[Token.OPERATOR] = new Color (0xcc9900); 193 colors[Token.INVALID] = new Color (0xff3300); 194 } 195 return colors; 196 } 197 } 198 | Popular Tags |