1 14 15 package org.eclipse.ant.internal.ui.editor.text; 16 17 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 18 import org.eclipse.jface.text.rules.IRule; 19 import org.eclipse.jface.text.rules.MultiLineRule; 20 import org.eclipse.jface.text.rules.Token; 21 import org.eclipse.jface.text.rules.WhitespaceRule; 22 import org.eclipse.jface.util.PropertyChangeEvent; 23 import org.eclipse.swt.SWT; 24 25 28 public class AntEditorProcInstrScanner extends AbstractAntEditorScanner { 29 30 Token fProcInstructionToken= null; 31 32 public AntEditorProcInstrScanner() { 33 IRule[] rules =new IRule[2]; 34 fProcInstructionToken = 35 new Token(createTextAttribute(IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR, 36 IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX, 37 IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX)); 38 39 rules[0]= new MultiLineRule("<?", "?>", fProcInstructionToken); 42 rules[1]= new WhitespaceRule(new AntEditorWhitespaceDetector()); 44 45 setRules(rules); 46 47 setDefaultReturnToken(new Token(createTextAttribute(IAntEditorColorConstants.TEXT_COLOR, 48 IAntEditorColorConstants.TEXT_COLOR + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX, 49 IAntEditorColorConstants.TEXT_COLOR + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX))); 50 } 51 52 private Token getTokenAffected(PropertyChangeEvent event) { 53 if (event.getProperty().startsWith(IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR)) { 54 return fProcInstructionToken; 55 } 56 return (Token)fDefaultReturnToken; 57 } 58 59 public void adaptToPreferenceChange(PropertyChangeEvent event) { 60 String property= event.getProperty(); 61 if (property.startsWith(IAntEditorColorConstants.TEXT_COLOR) || property.startsWith(IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR)) { 62 if (property.endsWith(AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX)) { 63 adaptToStyleChange(event, getTokenAffected(event), SWT.BOLD); 64 } else if (property.endsWith(AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX)) { 65 adaptToStyleChange(event, getTokenAffected(event), SWT.ITALIC); 66 } else { 67 adaptToColorChange(event, getTokenAffected(event)); 68 } 69 } 70 } 71 } | Popular Tags |