1. /*
  2. * @(#)Highlighter.java 1.22 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.text;
  8. import java.awt.Color;
  9. import java.awt.Graphics;
  10. import java.awt.Shape;
  11. /**
  12. * An interface for an object that allows one to mark up the background
  13. * with colored areas.
  14. *
  15. * @author Timothy Prinzing
  16. * @version 1.22 12/19/03
  17. */
  18. public interface Highlighter {
  19. /**
  20. * Called when the UI is being installed into the
  21. * interface of a JTextComponent. This can be used
  22. * to gain access to the model that is being navigated
  23. * by the implementation of this interface.
  24. *
  25. * @param c the JTextComponent editor
  26. */
  27. public void install(JTextComponent c);
  28. /**
  29. * Called when the UI is being removed from the
  30. * interface of a JTextComponent. This is used to
  31. * unregister any listeners that were attached.
  32. *
  33. * @param c the JTextComponent editor
  34. */
  35. public void deinstall(JTextComponent c);
  36. /**
  37. * Renders the highlights.
  38. *
  39. * @param g the graphics context.
  40. */
  41. public void paint(Graphics g);
  42. /**
  43. * Adds a highlight to the view. Returns a tag that can be used
  44. * to refer to the highlight.
  45. *
  46. * @param p0 the beginning of the range >= 0
  47. * @param p1 the end of the range >= p0
  48. * @param p the painter to use for the actual highlighting
  49. * @return an object that refers to the highlight
  50. * @exception BadLocationException for an invalid range specification
  51. */
  52. public Object addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException;
  53. /**
  54. * Removes a highlight from the view.
  55. *
  56. * @param tag which highlight to remove
  57. */
  58. public void removeHighlight(Object tag);
  59. /**
  60. * Removes all highlights this highlighter is responsible for.
  61. */
  62. public void removeAllHighlights();
  63. /**
  64. * Changes the given highlight to span a different portion of
  65. * the document. This may be more efficient than a remove/add
  66. * when a selection is expanding/shrinking (such as a sweep
  67. * with a mouse) by damaging only what changed.
  68. *
  69. * @param tag which highlight to change
  70. * @param p0 the beginning of the range >= 0
  71. * @param p1 the end of the range >= p0
  72. * @exception BadLocationException for an invalid range specification
  73. */
  74. public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException;
  75. /**
  76. * Fetches the current list of highlights.
  77. *
  78. * @return the highlight list
  79. */
  80. public Highlight[] getHighlights();
  81. /**
  82. * Highlight renderer.
  83. */
  84. public interface HighlightPainter {
  85. /**
  86. * Renders the highlight.
  87. *
  88. * @param g the graphics context
  89. * @param p0 the starting offset in the model >= 0
  90. * @param p1 the ending offset in the model >= p0
  91. * @param bounds the bounding box for the highlight
  92. * @param c the editor
  93. */
  94. public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c);
  95. }
  96. public interface Highlight {
  97. /**
  98. * Gets the starting model offset for the highlight.
  99. *
  100. * @return the starting offset >= 0
  101. */
  102. public int getStartOffset();
  103. /**
  104. * Gets the ending model offset for the highlight.
  105. *
  106. * @return the ending offset >= 0
  107. */
  108. public int getEndOffset();
  109. /**
  110. * Gets the painter for the highlighter.
  111. *
  112. * @return the painter
  113. */
  114. public HighlightPainter getPainter();
  115. }
  116. };