PageRenderTime 86ms CodeModel.GetById 42ms app.highlight 7ms RepoModel.GetById 25ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/textarea/MarkerHighlight.java

#
Java | 104 lines | 72 code | 13 blank | 19 comment | 12 complexity | fc8bb48c66067e21347f3ffd329394ba MD5 | raw file
  1/*
  2 * MarkerHighlight.java - Paints marker highlights in the gutter
  3 * Copyright (C) 2000, 2001 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package org.gjt.sp.jedit.textarea;
 21
 22import java.awt.*;
 23import java.awt.event.MouseEvent;
 24import java.util.Vector;
 25import org.gjt.sp.jedit.*;
 26
 27public class MarkerHighlight implements TextAreaHighlight
 28{
 29	public MarkerHighlight(JEditTextArea textArea)
 30	{
 31		this.textArea = textArea;
 32	}
 33
 34	public void paintHighlight(Graphics gfx, int line, int y)
 35	{
 36		if(textArea.getBuffer().isLoaded() && highlightEnabled
 37			&& line < textArea.getVirtualLineCount())
 38		{
 39			Buffer buffer = textArea.getBuffer();
 40			if(buffer.getMarkerAtLine(textArea.virtualToPhysical(line)) != null)
 41			{
 42				int firstLine = textArea.getFirstLine();
 43				line -= firstLine;
 44
 45				FontMetrics fm = textArea.getPainter().getFontMetrics();
 46				gfx.setColor(markerHighlightColor);
 47				gfx.fillRect(0,line * fm.getHeight(),textArea.getGutter()
 48					.getWidth(),fm.getHeight());
 49			}
 50		}
 51	}
 52
 53	public String getToolTipText(MouseEvent evt)
 54	{
 55		if(textArea.getBuffer().isLoaded() && highlightEnabled)
 56		{
 57			FontMetrics fm = textArea.getPainter().getFontMetrics();
 58			int line = textArea.getFirstLine() + evt.getY() / fm.getHeight();
 59			if(line >= textArea.getVirtualLineCount())
 60				return null;
 61
 62			Buffer buffer = textArea.getBuffer();
 63			Marker marker = buffer.getMarkerAtLine(textArea.virtualToPhysical(line));
 64			if(marker != null)
 65			{
 66				char shortcut = marker.getShortcut();
 67				if(shortcut == '\0')
 68					return jEdit.getProperty("view.gutter.marker.no-name");
 69				else
 70				{
 71					String[] args = { String.valueOf(shortcut) };
 72					return jEdit.getProperty("view.gutter.marker",args);
 73				}
 74			}
 75		}
 76
 77		return null;
 78	}
 79
 80	public Color getMarkerHighlightColor()
 81	{
 82		return markerHighlightColor;
 83	}
 84
 85	public void setMarkerHighlightColor(Color markerHighlightColor)
 86	{
 87		this.markerHighlightColor = markerHighlightColor;
 88	}
 89
 90	public boolean isHighlightEnabled()
 91	{
 92		return highlightEnabled;
 93	}
 94
 95	public void setHighlightEnabled(boolean highlightEnabled)
 96	{
 97		this.highlightEnabled = highlightEnabled;
 98	}
 99
100	// private members
101	private JEditTextArea textArea;
102	private boolean highlightEnabled;
103	private Color markerHighlightColor;
104}