KickJava   Java API By Example, From Geeks To Geeks.

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


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.SingleLineRule;
15 import org.eclipse.jface.text.rules.Token;
16 import org.eclipse.jface.text.rules.WhitespaceRule;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18
19 public class XMLScanner extends BasePDEScanner {
20     private Token fProcInstr;
21
22     public XMLScanner(IColorManager manager) {
23         super(manager);
24     }
25     
26     protected void initialize() {
27         fProcInstr = new Token(createTextAttribute(IPDEColorConstants.P_PROC_INSTR));
28         
29         IRule[] rules = new IRule[2];
30         //Add rule for processing instructions
31
rules[0] = new SingleLineRule("<?", "?>", fProcInstr); //$NON-NLS-1$ //$NON-NLS-2$
32
// Add generic whitespace rule.
33
rules[1] = new WhitespaceRule(new XMLWhitespaceDetector());
34         setRules(rules);
35         setDefaultReturnToken(new Token(createTextAttribute(IPDEColorConstants.P_DEFAULT)));
36     }
37     
38     protected Token getTokenAffected(PropertyChangeEvent event) {
39         if (event.getProperty().startsWith(IPDEColorConstants.P_PROC_INSTR))
40             return fProcInstr;
41         return (Token)fDefaultReturnToken;
42     }
43     
44     public boolean affectsTextPresentation(String JavaDoc property) {
45         return property.startsWith(IPDEColorConstants.P_DEFAULT)
46                 || property.startsWith(IPDEColorConstants.P_PROC_INSTR);
47     }
48     
49 }
50
Popular Tags