KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > text > AntEditorTagScanner


1 /*******************************************************************************
2  * Copyright (c) 2002, 2005 GEBIT Gesellschaft fuer EDV-Beratung
3  * und Informatik-Technologien mbH,
4  * Berlin, Duesseldorf, Frankfurt (Germany) and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * GEBIT Gesellschaft fuer EDV-Beratung und Informatik-Technologien mbH - initial API and implementation
12  * IBM Corporation - bug 31796, bug 24108, bug 47139
13  *******************************************************************************/

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.SingleLineRule;
21 import org.eclipse.jface.text.rules.Token;
22 import org.eclipse.jface.text.rules.WhitespaceRule;
23 import org.eclipse.jface.util.PropertyChangeEvent;
24 import org.eclipse.swt.SWT;
25
26 /**
27  * The scanner to tokenize for strings and tags
28  */

29 public class AntEditorTagScanner extends AbstractAntEditorScanner {
30
31     private Token fStringToken;
32     
33     public AntEditorTagScanner() {
34         fStringToken= new Token(
35                 createTextAttribute(IAntEditorColorConstants.STRING_COLOR,
36                         IAntEditorColorConstants.STRING_COLOR + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX,
37                         IAntEditorColorConstants.STRING_COLOR + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX));
38                     
39         IRule[] rules= new IRule[3];
40
41         // Add rule for single and double quotes
42
rules[0]= new MultiLineRule("\"", "\"", fStringToken, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
43
rules[1]= new SingleLineRule("'", "'", fStringToken, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
44

45         // Add generic whitespace rule.
46
rules[2]= new WhitespaceRule(new AntEditorWhitespaceDetector());
47
48         setRules(rules);
49         
50         setDefaultReturnToken(
51                 new Token(createTextAttribute(IAntEditorColorConstants.TAG_COLOR,
52                         IAntEditorColorConstants.TAG_COLOR + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX,
53                         IAntEditorColorConstants.TAG_COLOR + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX)));
54     }
55     
56     public void adaptToPreferenceChange(PropertyChangeEvent event) {
57         String JavaDoc property= event.getProperty();
58         if (property.startsWith(IAntEditorColorConstants.TAG_COLOR) || property.startsWith(IAntEditorColorConstants.STRING_COLOR)) {
59             if (property.endsWith(AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX)) {
60                 adaptToStyleChange(event, getTokenAffected(event), SWT.BOLD);
61             } else if (property.endsWith(AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX)) {
62                 adaptToStyleChange(event, getTokenAffected(event), SWT.ITALIC);
63             } else {
64                 adaptToColorChange(event, getTokenAffected(event));
65             }
66         }
67     }
68     
69     private Token getTokenAffected(PropertyChangeEvent event) {
70         String JavaDoc property= event.getProperty();
71         if (property.startsWith(IAntEditorColorConstants.STRING_COLOR)) {
72             return fStringToken;
73         }// else if (property.startsWith(IAntEditorColorConstants.TAG_COLOR)) {
74
return (Token)fDefaultReturnToken;
75         //}
76
}
77 }
78
Popular Tags