KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
2
//
3
// This software is made available under the terms of the "MIT License"
4
// A copy of this license is included with this source distribution
5
// in "license.txt" and is also available at:
6
// http://www.opensource.org/licenses/mit-license.html
7
// Any queries should be directed to Michael Kolling mik@bluej.org
8

9 package bluej.editor.moe;
10
11 /**
12  * MoeSyntaxView.java - adapted from
13  * SyntaxView.java - jEdit's own Swing view implementation
14  * to add Syntax highlighting to the BlueJ programming environment.
15  */

16
17 import javax.swing.text.*;
18
19 import java.awt.*;
20 import bluej.Config;
21 import bluej.prefmgr.PrefMgr;
22 import org.syntax.jedit.*;
23 import org.syntax.jedit.tokenmarker.*;
24
25 /**
26  * A Swing view implementation that colorizes lines of a
27  * SyntaxDocument using a TokenMarker.
28  *
29  * This class should not be used directly; a SyntaxEditorKit
30  * should be used instead.
31  *
32  * @author Slava Pestov
33  * @author Bruce Quig
34  * @author Michael Kolling
35  *
36  * @version $Id: MoeSyntaxView.java,v 1.25 2005/05/02 03:23:32 davmac Exp $
37  */

38
39 public class MoeSyntaxView extends BlueJSyntaxView
40 {
41     // Attributes for lines and document
42
public static final String JavaDoc BREAKPOINT = "break";
43     public static final String JavaDoc STEPMARK = "step";
44
45     static final Image breakImage =
46         Config.getImageAsIcon("image.editor.breakmark").getImage();
47     static final Image stepImage =
48         Config.getImageAsIcon("image.editor.stepmark").getImage();
49     static final Image breakStepImage =
50         Config.getImageAsIcon("image.editor.breakstepmark").getImage();
51
52     /**
53      * Creates a new MoeSyntaxView for painting the specified element.
54      * @param elem The element
55      */

56     public MoeSyntaxView(Element elem)
57     {
58         super(elem);
59     }
60
61     /**
62      * Draw a line for the moe editor.
63      */

64     public void paintTaggedLine(Segment lineText, int lineIndex, Graphics g, int x, int y,
65             SyntaxDocument document, TokenMarker tokenMarker, Color def, Element line)
66     {
67         if(PrefMgr.getFlag(PrefMgr.LINENUMBERS))
68             drawLineNumber(g, lineIndex+1, x, y);
69    
70         // draw breakpoint and/or step image
71

72         if(hasTag(line, BREAKPOINT)) {
73             if(hasTag(line, STEPMARK)) {
74                 g.drawImage(breakStepImage, x-1, y+3-breakStepImage.getHeight(null),
75                             null);
76             }
77             else { // break only
78
g.drawImage(breakImage, x-1, y+3-breakImage.getHeight(null), null);
79             }
80         }
81         else if(hasTag(line, STEPMARK)) {
82             g.drawImage(stepImage, x-1, y+3-stepImage.getHeight(null), null);
83         }
84
85         if(tokenMarker == null) {
86             Utilities.drawTabbedText(lineText, x+BREAKPOINT_OFFSET, y, g, this, 0);
87         }
88         else {
89             paintSyntaxLine(lineText, lineIndex, x+BREAKPOINT_OFFSET, y, g,
90                             document, tokenMarker, def);
91         }
92 }
93
94    /**
95     * redefined paint method to paint breakpoint area
96     *
97     */

98     public void paint(Graphics g, Shape allocation)
99     {
100         // if uncompiled, fill the tag line with grey
101
Rectangle bounds = allocation.getBounds();
102         if(Boolean.FALSE.equals(getDocument().getProperty(MoeEditor.COMPILED))) {
103             g.setColor(Color.lightGray);
104             g.fillRect(0, 0, bounds.x + TAG_WIDTH,
105                        bounds.y + bounds.height);
106         }
107
108         // paint the lines
109
super.paint(g, allocation);
110
111         // paint the tag separator line
112
g.setColor(Color.black);
113         g.drawLine(bounds.x + TAG_WIDTH, 0,
114                    bounds.x + TAG_WIDTH, bounds.y + bounds.height);
115     }
116
117 }
118
Popular Tags