KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bluej > editor > moe > MoeSyntaxEditorKit


1 /**
2  * MoeSyntaxEditorKit.java - adapted from
3  * SyntaxEditorKit.java - jEdit's own editor kit
4  * to add Syntax highlighting to the BlueJ programming environment.
5  * Copyright (C) 1998, 1999 Slava Pestov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  */

21
22 package bluej.editor.moe;
23
24 import javax.swing.text.*;
25
26 /**
27  * An implementation of <code>EditorKit</code> used for syntax coloring.
28  * This is an adaptation of the SyntaxEditorKit class from JEdit for BlueJ.
29  *
30  * @author Bruce Quig
31  * @author Michael Kolling
32  *
33  * @see org.gjt.sp.jedit.syntax.SyntaxView
34  */

35 public class MoeSyntaxEditorKit extends DefaultEditorKit
36         implements ViewFactory
37 {
38     private boolean isTextEval;
39
40     /**
41      * Create a moe editor kit. There are two modes in which this can operate:
42      * as an editor kit for the standard editor (textEval == false) or as an
43      * editor kit for the text evaluation area (textEval == true).
44      *
45      * @param textEval Indicate whether to operate for the text eval area
46      */

47     public MoeSyntaxEditorKit(boolean textEval)
48     {
49         super();
50         isTextEval = textEval;
51     }
52     
53     /**
54      * Returns an instance of a view factory that can be used for
55      * creating views from elements. This implementation returns
56      * the current instance, because this class already implements
57      * <code>ViewFactory</code>.
58      */

59     public ViewFactory getViewFactory()
60     {
61         return this;
62     }
63
64     /**
65      * Creates a view from an element that can be used for painting that
66      * element. This implementation returns a new <code>SyntaxView</code>
67      * instance.
68      * @param elem The element
69      * @return a new MoeSyntaxView for an element
70      * @see org.gjt.sp.jedit.syntax.SyntaxView
71      */

72     public View create(Element elem)
73     {
74         if(isTextEval)
75             return new bluej.debugmgr.texteval.TextEvalSyntaxView(elem);
76         else
77             return new MoeSyntaxView(elem);
78     }
79
80     /**
81      * Creates a new instance of the default document for this
82      * editor kit. This returns a new instance of
83      * <code>DefaultSyntaxDocument</code>.
84      * @see org.gjt.sp.jedit.syntax.DefaultSyntaxDocument
85      */

86     public Document createDefaultDocument()
87     {
88         return new MoeSyntaxDocument();
89     }
90 }
91
Popular Tags