01: // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
02: //
03: // This software is made available under the terms of the "MIT License"
04: // A copy of this license is included with this source distribution
05: // in "license.txt" and is also available at:
06: // http://www.opensource.org/licenses/mit-license.html
07: // Any queries should be directed to Michael Kolling mik@bluej.org
08:
09: package bluej.editor.moe;
10:
11: import javax.swing.text.*;
12:
13: /**
14: * An implementation of <code>EditorKit</code> used for syntax coloring.
15: * This is an adaptation of the SyntaxEditorKit class from JEdit for BlueJ.
16: *
17: * @author Bruce Quig
18: * @author Michael Kolling
19: *
20: *
21: */
22: public class MoeSyntaxEditorKit extends DefaultEditorKit implements
23: ViewFactory {
24: private boolean isTextEval;
25:
26: /**
27: * Create a moe editor kit. There are two modes in which this can operate:
28: * as an editor kit for the standard editor (textEval == false) or as an
29: * editor kit for the text evaluation area (textEval == true).
30: *
31: * @param textEval Indicate whether to operate for the text eval area
32: */
33: public MoeSyntaxEditorKit(boolean textEval) {
34: super ();
35: isTextEval = textEval;
36: }
37:
38: /**
39: * Returns an instance of a view factory that can be used for
40: * creating views from elements. This implementation returns
41: * the current instance, because this class already implements
42: * <code>ViewFactory</code>.
43: */
44: public ViewFactory getViewFactory() {
45: return this ;
46: }
47:
48: /**
49: * Creates a view from an element that can be used for painting that
50: * element. This implementation returns a new <code>SyntaxView</code>
51: * instance.
52: * @param elem The element
53: * @return a new MoeSyntaxView for an element
54: *
55: */
56: public View create(Element elem) {
57: if (isTextEval)
58: return new bluej.debugmgr.texteval.TextEvalSyntaxView(elem);
59: else
60: return new MoeSyntaxView(elem);
61: }
62:
63: /**
64: * Creates a new instance of the default document for this
65: * editor kit. This returns a new instance of
66: * <code>DefaultSyntaxDocument</code>.
67: *
68: */
69: public Document createDefaultDocument() {
70: return new MoeSyntaxDocument();
71: }
72: }
|