KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > editor > xml > XMLStyleTokens


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.editor.xml;
18
19 import javax.swing.text.Document JavaDoc;
20 import javax.swing.text.StyledEditorKit JavaDoc;
21 import java.awt.*;
22
23 /**
24  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Nov 16, 2004
25  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
26  */

27 public class XMLStyleTokens extends StyleTokens {
28     public static final String JavaDoc TAG = "tag";
29     public static final String JavaDoc TEXT = "text";
30     public static final String JavaDoc COMMENT = "comment";
31     private static final String JavaDoc ATTRIBUTE = "attribute";
32
33     public XMLStyleTokens() {
34
35         //"([^ >]*)=\""
36
// "<[^ >]* ([^ >])?"
37
// "(\\w)+=\"?:[^\"]*\"
38
addTokenType(COMMENT, "<!--[^--]*-->", Color.gray, false);
39         addTokenType(TAG, "<[^ >]*|[\\?]?>", new Color(0,0,132), true);
40         addTokenType(TEXT, "\"(?:\\\\.|[^\"\\\\])*\"", new Color(72,125,55), true);
41         addTokenType(ATTRIBUTE, "\\w+(?<=)", Color.red, false);
42     }
43
44     public static class Kit extends StyledEditorKit JavaDoc {
45         public Document JavaDoc createDefaultDocument() {
46             return new EditorDocument(new XMLStyleTokens());
47         }
48     }
49 }
50
51
Popular Tags