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