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