KickJava   Java API By Example, From Geeks To Geeks.

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


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

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         //Add rule for processing instructions
40
rules[0]= new MultiLineRule("<?", "?>", fProcInstructionToken); //$NON-NLS-1$ //$NON-NLS-2$
41

42         // Add generic whitespace rule.
43
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 JavaDoc 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