1. /*
  2. * @(#)TextUI.java 1.25 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.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.25 11/29/01
  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. * @returns 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. The biasReturn argument will be
  55. * filled in to indicate that the point given is closer to the next
  56. * character in the model or the previous character in the model.
  57. *
  58. * @param x the X coordinate >= 0
  59. * @param y the Y coordinate >= 0
  60. * @param a the allocated region to render into
  61. * @return the location within the model that best represents the
  62. * given point in the view >= 0. The biasReturn argument will be
  63. * filled in to indicate that the point given is closer to the next
  64. * character in the model or the previous character in the model.
  65. */
  66. public abstract int viewToModel(JTextComponent t, Point pt,
  67. Position.Bias[] biasReturn);
  68. /**
  69. * Provides a way to determine the next visually represented model
  70. * location that one might place a caret. Some views may not be visible,
  71. * they might not be in the same order found in the model, or they just
  72. * might not allow access to some of the locations in the model.
  73. *
  74. * @param pos the position to convert >= 0
  75. * @param a the allocated region to render into
  76. * @param direction the direction from the current position that can
  77. * be thought of as the arrow keys typically found on a keyboard.
  78. * This may be SwingConstants.WEST, SwingConstants.EAST,
  79. * SwingConstants.NORTH, or SwingConstants.SOUTH.
  80. * @return the location within the model that best represents the next
  81. * location visual position.
  82. * @exception BadLocationException
  83. * @exception IllegalArgumentException for an invalid direction
  84. */
  85. public abstract int getNextVisualPositionFrom(JTextComponent t,
  86. int pos, Position.Bias b,
  87. int direction, Position.Bias[] biasRet)
  88. throws BadLocationException;
  89. /**
  90. * Causes the portion of the view responsible for the
  91. * given part of the model to be repainted.
  92. *
  93. * @param p0 the beginning of the range >= 0
  94. * @param p1 the end of the range >= p0
  95. */
  96. public abstract void damageRange(JTextComponent t, int p0, int p1);
  97. /**
  98. * Causes the portion of the view responsible for the
  99. * given part of the model to be repainted.
  100. *
  101. * @param p0 the beginning of the range >= 0
  102. * @param p1 the end of the range >= p0
  103. */
  104. public abstract void damageRange(JTextComponent t, int p0, int p1,
  105. Position.Bias firstBias,
  106. Position.Bias secondBias);
  107. /**
  108. * Fetches the binding of services that set a policy
  109. * for the type of document being edited. This contains
  110. * things like the commands available, stream readers and
  111. * writers, etc.
  112. *
  113. * @return the editor kit binding
  114. */
  115. public abstract EditorKit getEditorKit(JTextComponent t);
  116. /**
  117. * Fetches a View with the allocation of the associated
  118. * text component (i.e. the root of the hierarchy) that
  119. * can be traversed to determine how the model is being
  120. * represented spatially.
  121. *
  122. * @return the view
  123. */
  124. public abstract View getRootView(JTextComponent t);
  125. }