1. /*
  2. * @(#)Caret.java 1.24 01/11/29
  3. *
  4. * Copyright 2002 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.Graphics;
  9. import java.awt.Point;
  10. import javax.swing.Action;
  11. import javax.swing.event.ChangeListener;
  12. /**
  13. * A place within a document view that represents where
  14. * things can be inserted into the document model. It gives a
  15. * way to navigate through the document view while abstracting
  16. * away the details of how the view is arranged. This can
  17. * be useful because some views may filter out portions of
  18. * the associated model, and some views may not allow navigation
  19. * in certain areas such as read-only areas.
  20. *
  21. * @author Timothy Prinzing
  22. * @version 1.24 11/29/01
  23. */
  24. public interface Caret {
  25. /**
  26. * Called when the UI is being installed into the
  27. * interface of a JTextComponent. This can be used
  28. * to gain access to the model that is being navigated
  29. * by the implementation of this interface.
  30. *
  31. * @param c the JTextComponent
  32. */
  33. public void install(JTextComponent c);
  34. /**
  35. * Called when the UI is being removed from the
  36. * interface of a JTextComponent. This is used to
  37. * unregister any listeners that were attached.
  38. *
  39. * @param c the JTextComponent
  40. */
  41. public void deinstall(JTextComponent c);
  42. /**
  43. * Renders the caret.
  44. *
  45. * @param g the graphics context
  46. */
  47. public void paint(Graphics g);
  48. /**
  49. * Adds a listener to track whenever the caret position
  50. * has been changed.
  51. *
  52. * @param l the change listener
  53. */
  54. public void addChangeListener(ChangeListener l);
  55. /**
  56. * Removes a listener that was tracking caret position changes.
  57. *
  58. * @param l the change listener
  59. */
  60. public void removeChangeListener(ChangeListener l);
  61. /**
  62. * Determines if the caret is currently visible.
  63. *
  64. * @return true if the caret is visible else false
  65. */
  66. public boolean isVisible();
  67. /**
  68. * Sets the visibility of the caret.
  69. *
  70. * @param v true if the caret should be shown,
  71. * and false if the caret should be hidden
  72. */
  73. public void setVisible(boolean v);
  74. /**
  75. * Determines if the selection is currently visible.
  76. *
  77. * @return true if the caret is visible else false
  78. */
  79. public boolean isSelectionVisible();
  80. /**
  81. * Sets the visibility of the selection
  82. *
  83. * @param v true if the caret should be shown,
  84. * and false if the caret should be hidden
  85. */
  86. public void setSelectionVisible(boolean v);
  87. /**
  88. * Saves the current caret position. This is used when
  89. * caret up or down actions occur, moving between lines
  90. * that have uneven end positions.
  91. *
  92. * @param p the Point to use for the saved position
  93. */
  94. public void setMagicCaretPosition(Point p);
  95. /**
  96. * Gets the current caret position.
  97. *
  98. * @return the position
  99. * @see #setMagicCaretPosition
  100. */
  101. public Point getMagicCaretPosition();
  102. /**
  103. * Sets the blink rate of the caret. This determines if
  104. * and how fast the caret blinks, commonly used as one
  105. * way to attract attention to the caret.
  106. *
  107. * @param rate the delay in milliseconds >= 0. If this is
  108. * zero the caret will not blink.
  109. */
  110. public void setBlinkRate(int rate);
  111. /**
  112. * Gets the blink rate of the caret. This determines if
  113. * and how fast the caret blinks, commonly used as one
  114. * way to attract attention to the caret.
  115. *
  116. * @returns the delay in milliseconds >= 0. If this is
  117. * zero the caret will not blink.
  118. */
  119. public int getBlinkRate();
  120. /**
  121. * Fetches the current position of the caret.
  122. *
  123. * @return the position >= 0
  124. */
  125. public int getDot();
  126. /**
  127. * Fetches the current position of the mark. If there
  128. * is a selection, the mark will not be the same as
  129. * the dot.
  130. *
  131. * @return the position >= 0
  132. */
  133. public int getMark();
  134. /**
  135. * Sets the caret position to some position. This
  136. * causes the mark to become the same as the dot,
  137. * effectively setting the selection range to zero.
  138. *
  139. * @param dot the new position to set the caret to >= 0
  140. */
  141. public void setDot(int dot);
  142. /**
  143. * Moves the caret position to some other position,
  144. * leaving behind the mark. This is useful for
  145. * making selections.
  146. *
  147. * @param dot the new position to move the caret to >= 0
  148. */
  149. public void moveDot(int dot);
  150. };