/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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * MarkerHighlight.java - Paints marker highlights in the gutter
- * Copyright (C) 2000, 2001 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.textarea;
- import java.awt.*;
- import java.awt.event.MouseEvent;
- import java.util.Vector;
- import org.gjt.sp.jedit.*;
- public class MarkerHighlight implements TextAreaHighlight
- {
- public MarkerHighlight(JEditTextArea textArea)
- {
- this.textArea = textArea;
- }
- public void paintHighlight(Graphics gfx, int line, int y)
- {
- if(textArea.getBuffer().isLoaded() && highlightEnabled
- && line < textArea.getVirtualLineCount())
- {
- Buffer buffer = textArea.getBuffer();
- if(buffer.getMarkerAtLine(textArea.virtualToPhysical(line)) != null)
- {
- int firstLine = textArea.getFirstLine();
- line -= firstLine;
- FontMetrics fm = textArea.getPainter().getFontMetrics();
- gfx.setColor(markerHighlightColor);
- gfx.fillRect(0,line * fm.getHeight(),textArea.getGutter()
- .getWidth(),fm.getHeight());
- }
- }
- }
- public String getToolTipText(MouseEvent evt)
- {
- if(textArea.getBuffer().isLoaded() && highlightEnabled)
- {
- FontMetrics fm = textArea.getPainter().getFontMetrics();
- int line = textArea.getFirstLine() + evt.getY() / fm.getHeight();
- if(line >= textArea.getVirtualLineCount())
- return null;
- Buffer buffer = textArea.getBuffer();
- Marker marker = buffer.getMarkerAtLine(textArea.virtualToPhysical(line));
- if(marker != null)
- {
- char shortcut = marker.getShortcut();
- if(shortcut == '\0')
- return jEdit.getProperty("view.gutter.marker.no-name");
- else
- {
- String[] args = { String.valueOf(shortcut) };
- return jEdit.getProperty("view.gutter.marker",args);
- }
- }
- }
- return null;
- }
- public Color getMarkerHighlightColor()
- {
- return markerHighlightColor;
- }
- public void setMarkerHighlightColor(Color markerHighlightColor)
- {
- this.markerHighlightColor = markerHighlightColor;
- }
- public boolean isHighlightEnabled()
- {
- return highlightEnabled;
- }
- public void setHighlightEnabled(boolean highlightEnabled)
- {
- this.highlightEnabled = highlightEnabled;
- }
- // private members
- private JEditTextArea textArea;
- private boolean highlightEnabled;
- private Color markerHighlightColor;
- }