001: // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
002: //
003: // This software is made available under the terms of the "MIT License"
004: // A copy of this license is included with this source distribution
005: // in "license.txt" and is also available at:
006: // http://www.opensource.org/licenses/mit-license.html
007: // Any queries should be directed to Michael Kolling mik@bluej.org
008:
009: package bluej.editor.moe;
010:
011: /**
012: * MoeSyntaxView.java - adapted from
013: * SyntaxView.java - jEdit's own Swing view implementation
014: * to add Syntax highlighting to the BlueJ programming environment.
015: */
016:
017: import javax.swing.text.*;
018:
019: import java.awt.*;
020: import bluej.Config;
021: import bluej.prefmgr.PrefMgr;
022: import org.syntax.jedit.*;
023: import org.syntax.jedit.tokenmarker.*;
024:
025: /**
026: * A Swing view implementation that colorizes lines of a
027: * SyntaxDocument using a TokenMarker.
028: *
029: * This class should not be used directly; a SyntaxEditorKit
030: * should be used instead.
031: *
032: * @author Slava Pestov
033: * @author Bruce Quig
034: * @author Michael Kolling
035: *
036: * @version $Id: MoeSyntaxView.java 3357 2005-05-02 03:23:33Z davmac $
037: */
038:
039: public class MoeSyntaxView extends BlueJSyntaxView {
040: // Attributes for lines and document
041: public static final String BREAKPOINT = "break";
042: public static final String STEPMARK = "step";
043:
044: static final Image breakImage = Config.getImageAsIcon(
045: "image.editor.breakmark").getImage();
046: static final Image stepImage = Config.getImageAsIcon(
047: "image.editor.stepmark").getImage();
048: static final Image breakStepImage = Config.getImageAsIcon(
049: "image.editor.breakstepmark").getImage();
050:
051: /**
052: * Creates a new MoeSyntaxView for painting the specified element.
053: * @param elem The element
054: */
055: public MoeSyntaxView(Element elem) {
056: super (elem);
057: }
058:
059: /**
060: * Draw a line for the moe editor.
061: */
062: public void paintTaggedLine(Segment lineText, int lineIndex,
063: Graphics g, int x, int y, SyntaxDocument document,
064: TokenMarker tokenMarker, Color def, Element line) {
065: if (PrefMgr.getFlag(PrefMgr.LINENUMBERS))
066: drawLineNumber(g, lineIndex + 1, x, y);
067:
068: // draw breakpoint and/or step image
069:
070: if (hasTag(line, BREAKPOINT)) {
071: if (hasTag(line, STEPMARK)) {
072: g.drawImage(breakStepImage, x - 1, y + 3
073: - breakStepImage.getHeight(null), null);
074: } else { // break only
075: g.drawImage(breakImage, x - 1, y + 3
076: - breakImage.getHeight(null), null);
077: }
078: } else if (hasTag(line, STEPMARK)) {
079: g.drawImage(stepImage, x - 1, y + 3
080: - stepImage.getHeight(null), null);
081: }
082:
083: if (tokenMarker == null) {
084: Utilities.drawTabbedText(lineText, x + BREAKPOINT_OFFSET,
085: y, g, this , 0);
086: } else {
087: paintSyntaxLine(lineText, lineIndex, x + BREAKPOINT_OFFSET,
088: y, g, document, tokenMarker, def);
089: }
090: }
091:
092: /**
093: * redefined paint method to paint breakpoint area
094: *
095: */
096: public void paint(Graphics g, Shape allocation) {
097: // if uncompiled, fill the tag line with grey
098: Rectangle bounds = allocation.getBounds();
099: if (Boolean.FALSE.equals(getDocument().getProperty(
100: MoeEditor.COMPILED))) {
101: g.setColor(Color.lightGray);
102: g.fillRect(0, 0, bounds.x + TAG_WIDTH, bounds.y
103: + bounds.height);
104: }
105:
106: // paint the lines
107: super .paint(g, allocation);
108:
109: // paint the tag separator line
110: g.setColor(Color.black);
111: g.drawLine(bounds.x + TAG_WIDTH, 0, bounds.x + TAG_WIDTH,
112: bounds.y + bounds.height);
113: }
114:
115: }
|