PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
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
  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. package org.gjt.sp.jedit.textarea;
  20. import java.awt.*;
  21. import java.awt.event.MouseEvent;
  22. import java.util.Vector;
  23. import org.gjt.sp.jedit.*;
  24. public class MarkerHighlight implements TextAreaHighlight
  25. {
  26. public MarkerHighlight(JEditTextArea textArea)
  27. {
  28. this.textArea = textArea;
  29. }
  30. public void paintHighlight(Graphics gfx, int line, int y)
  31. {
  32. if(textArea.getBuffer().isLoaded() && highlightEnabled
  33. && line < textArea.getVirtualLineCount())
  34. {
  35. Buffer buffer = textArea.getBuffer();
  36. if(buffer.getMarkerAtLine(textArea.virtualToPhysical(line)) != null)
  37. {
  38. int firstLine = textArea.getFirstLine();
  39. line -= firstLine;
  40. FontMetrics fm = textArea.getPainter().getFontMetrics();
  41. gfx.setColor(markerHighlightColor);
  42. gfx.fillRect(0,line * fm.getHeight(),textArea.getGutter()
  43. .getWidth(),fm.getHeight());
  44. }
  45. }
  46. }
  47. public String getToolTipText(MouseEvent evt)
  48. {
  49. if(textArea.getBuffer().isLoaded() && highlightEnabled)
  50. {
  51. FontMetrics fm = textArea.getPainter().getFontMetrics();
  52. int line = textArea.getFirstLine() + evt.getY() / fm.getHeight();
  53. if(line >= textArea.getVirtualLineCount())
  54. return null;
  55. Buffer buffer = textArea.getBuffer();
  56. Marker marker = buffer.getMarkerAtLine(textArea.virtualToPhysical(line));
  57. if(marker != null)
  58. {
  59. char shortcut = marker.getShortcut();
  60. if(shortcut == '\0')
  61. return jEdit.getProperty("view.gutter.marker.no-name");
  62. else
  63. {
  64. String[] args = { String.valueOf(shortcut) };
  65. return jEdit.getProperty("view.gutter.marker",args);
  66. }
  67. }
  68. }
  69. return null;
  70. }
  71. public Color getMarkerHighlightColor()
  72. {
  73. return markerHighlightColor;
  74. }
  75. public void setMarkerHighlightColor(Color markerHighlightColor)
  76. {
  77. this.markerHighlightColor = markerHighlightColor;
  78. }
  79. public boolean isHighlightEnabled()
  80. {
  81. return highlightEnabled;
  82. }
  83. public void setHighlightEnabled(boolean highlightEnabled)
  84. {
  85. this.highlightEnabled = highlightEnabled;
  86. }
  87. // private members
  88. private JEditTextArea textArea;
  89. private boolean highlightEnabled;
  90. private Color markerHighlightColor;
  91. }