1. /*
  2. * @(#)TextUI.java 1.31 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf;
  8. import javax.swing.Action;
  9. import javax.swing.BoundedRangeModel;
  10. import java.awt.Point;
  11. import java.awt.Rectangle;
  12. import java.awt.Insets;
  13. import javax.swing.text.*;
  14. /**
  15. * Text editor user interface
  16. *
  17. * @author Timothy Prinzing
  18. * @version 1.31 01/23/03
  19. */
  20. public abstract class TextUI extends ComponentUI
  21. {
  22. /**
  23. * Converts the given location in the model to a place in
  24. * the view coordinate system.
  25. *
  26. * @param pos the local location in the model to translate >= 0
  27. * @return the coordinates as a rectangle
  28. * @exception BadLocationException if the given position does not
  29. * represent a valid location in the associated document
  30. */
  31. public abstract Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException;
  32. /**
  33. * Converts the given location in the model to a place in
  34. * the view coordinate system.
  35. *
  36. * @param pos the local location in the model to translate >= 0
  37. * @return the coordinates as a rectangle
  38. * @exception BadLocationException if the given position does not
  39. * represent a valid location in the associated document
  40. */
  41. public abstract Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException;
  42. /**
  43. * Converts the given place in the view coordinate system
  44. * to the nearest representative location in the model.
  45. *
  46. * @param pt the location in the view to translate. This
  47. * should be in the same coordinate system as the mouse
  48. * events.
  49. * @return the offset from the start of the document >= 0
  50. */
  51. public abstract int viewToModel(JTextComponent t, Point pt);
  52. /**
  53. * Provides a mapping from the view coordinate space to the logical
  54. * coordinate space of the model.
  55. *
  56. * @param pt the location in the view to translate.
  57. * This should be in the same coordinate system
  58. * as the mouse events.
  59. * @param biasReturn
  60. * filled in by this method to indicate whether
  61. * the point given is closer to the previous or the next
  62. * character in the model
  63. *
  64. * @return the location within the model that best represents the
  65. * given point in the view >= 0
  66. */
  67. public abstract int viewToModel(JTextComponent t, Point pt,
  68. Position.Bias[] biasReturn);
  69. /**
  70. * Provides a way to determine the next visually represented model
  71. * location that one might place a caret. Some views may not be visible,
  72. * they might not be in the same order found in the model, or they just
  73. * might not allow access to some of the locations in the model.
  74. *
  75. * @param pos the position to convert >= 0
  76. * @param a the allocated region to render into
  77. * @param direction the direction from the current position that can
  78. * be thought of as the arrow keys typically found on a keyboard.
  79. * This may be SwingConstants.WEST, SwingConstants.EAST,
  80. * SwingConstants.NORTH, or SwingConstants.SOUTH.
  81. * @return the location within the model that best represents the next
  82. * location visual position.
  83. * @exception BadLocationException
  84. * @exception IllegalArgumentException for an invalid direction
  85. */
  86. public abstract int getNextVisualPositionFrom(JTextComponent t,
  87. int pos, Position.Bias b,
  88. int direction, Position.Bias[] biasRet)
  89. throws BadLocationException;
  90. /**
  91. * Causes the portion of the view responsible for the
  92. * given part of the model to be repainted.
  93. *
  94. * @param p0 the beginning of the range >= 0
  95. * @param p1 the end of the range >= p0
  96. */
  97. public abstract void damageRange(JTextComponent t, int p0, int p1);
  98. /**
  99. * Causes the portion of the view responsible for the
  100. * given part of the model to be repainted.
  101. *
  102. * @param p0 the beginning of the range >= 0
  103. * @param p1 the end of the range >= p0
  104. */
  105. public abstract void damageRange(JTextComponent t, int p0, int p1,
  106. Position.Bias firstBias,
  107. Position.Bias secondBias);
  108. /**
  109. * Fetches the binding of services that set a policy
  110. * for the type of document being edited. This contains
  111. * things like the commands available, stream readers and
  112. * writers, etc.
  113. *
  114. * @return the editor kit binding
  115. */
  116. public abstract EditorKit getEditorKit(JTextComponent t);
  117. /**
  118. * Fetches a View with the allocation of the associated
  119. * text component (i.e. the root of the hierarchy) that
  120. * can be traversed to determine how the model is being
  121. * represented spatially.
  122. *
  123. * @return the view
  124. */
  125. public abstract View getRootView(JTextComponent t);
  126. /**
  127. * Returns the string to be used as the tooltip at the passed in location.
  128. *
  129. * @see javax.swing.text.JTextComponent#getToolTipText
  130. * @since 1.4
  131. */
  132. public String getToolTipText(JTextComponent t, Point pt) {
  133. return null;
  134. }
  135. }