KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > text > XMLTagScanner


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.text;
12
13 import org.eclipse.jface.text.rules.IRule;
14 import org.eclipse.jface.text.rules.MultiLineRule;
15 import org.eclipse.jface.text.rules.SingleLineRule;
16 import org.eclipse.jface.text.rules.Token;
17 import org.eclipse.jface.text.rules.WhitespaceRule;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19
20 public class XMLTagScanner extends BasePDEScanner {
21     
22     private Token fStringToken;
23     
24     public XMLTagScanner(IColorManager manager) {
25         super(manager);
26     }
27     
28     protected void initialize() {
29         fStringToken = new Token(createTextAttribute(IPDEColorConstants.P_STRING));
30         IRule[] rules = new IRule[3];
31         // Add rule for single and double quotes
32
rules[0] = new MultiLineRule("\"", "\"", fStringToken, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
33
rules[1] = new SingleLineRule("'", "'", fStringToken, '\\'); //$NON-NLS-1$ //$NON-NLS-2$
34
// Add generic whitespace rule.
35
rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
36         setRules(rules);
37         setDefaultReturnToken(new Token(createTextAttribute(IPDEColorConstants.P_TAG)));
38     }
39     
40     protected Token getTokenAffected(PropertyChangeEvent event) {
41         String JavaDoc property = event.getProperty();
42         if (property.startsWith(IPDEColorConstants.P_STRING))
43             return fStringToken;
44         return (Token)fDefaultReturnToken;
45     }
46
47     public boolean affectsTextPresentation(String JavaDoc property) {
48         return property.startsWith(IPDEColorConstants.P_TAG) || property.startsWith(IPDEColorConstants.P_STRING);
49     }
50
51 }
52
Popular Tags