1 11 12 package org.eclipse.ant.internal.ui.editor.text; 13 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.ColorManager; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.resource.StringConverter; 18 import org.eclipse.jface.text.TextAttribute; 19 import org.eclipse.jface.text.rules.RuleBasedScanner; 20 import org.eclipse.jface.text.rules.Token; 21 import org.eclipse.jface.util.PropertyChangeEvent; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.graphics.Color; 24 import org.eclipse.swt.graphics.RGB; 25 26 public abstract class AbstractAntEditorScanner extends RuleBasedScanner { 27 28 protected void adaptToColorChange(PropertyChangeEvent event, Token token) { 29 RGB rgb= null; 30 31 Object value= event.getNewValue(); 32 if (value instanceof RGB) { 33 rgb= (RGB) value; 34 } else if (value instanceof String ) { 35 rgb= StringConverter.asRGB((String ) value); 36 } 37 38 if (rgb != null) { 39 TextAttribute attr= (TextAttribute) token.getData(); 40 token.setData(new TextAttribute(ColorManager.getDefault().getColor(rgb), attr.getBackground(), attr.getStyle())); 41 } 42 } 43 44 protected void adaptToStyleChange(PropertyChangeEvent event, Token token, int styleAttribute) { 45 if (token == null) { 46 return; 47 } 48 boolean eventValue= false; 49 Object value= event.getNewValue(); 50 if (value instanceof Boolean ) { 51 eventValue= ((Boolean ) value).booleanValue(); 52 } else if (IPreferenceStore.TRUE.equals(value)) { 53 eventValue= true; 54 } 55 56 TextAttribute attr= (TextAttribute) token.getData(); 57 boolean activeValue= (attr.getStyle() & styleAttribute) == styleAttribute; 58 if (activeValue != eventValue) { 59 token.setData(new TextAttribute(attr.getForeground(), attr.getBackground(), eventValue ? attr.getStyle() | styleAttribute : attr.getStyle() & ~styleAttribute)); 60 } 61 } 62 63 protected TextAttribute createTextAttribute(String colorID, String boldKey, String italicKey) { 64 Color color= null; 65 if (colorID != null) { 66 color= AntUIPlugin.getPreferenceColor(colorID); 67 } 68 IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore(); 69 int style= store.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL; 70 if (store.getBoolean(italicKey)) { 71 style |= SWT.ITALIC; 72 } 73 74 return new TextAttribute(color, null, style); 75 } 76 } 77 | Popular Tags |