1. /*
  2. * @(#)Scrollable.java 1.12 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import java.awt.Dimension;
  9. import java.awt.Rectangle;
  10. /**
  11. * An interface that provides information to a scrolling container
  12. * like JScrollPane. A complex component that's likely to be used
  13. * as a viewing a JScrollPane viewport (or other scrolling container)
  14. * should implement this interface.
  15. *
  16. * @see JViewport
  17. * @see JScrollPane
  18. * @see JScrollBar
  19. * @version 1.12 12/19/03
  20. * @author Hans Muller
  21. */
  22. public interface Scrollable
  23. {
  24. /**
  25. * Returns the preferred size of the viewport for a view component.
  26. * For example, the preferred size of a <code>JList</code> component
  27. * is the size required to accommodate all of the cells in its list.
  28. * However, the value of <code>preferredScrollableViewportSize</code>
  29. * is the size required for <code>JList.getVisibleRowCount</code> rows.
  30. * A component without any properties that would affect the viewport
  31. * size should just return <code>getPreferredSize</code> here.
  32. *
  33. * @return the preferredSize of a <code>JViewport</code> whose view
  34. * is this <code>Scrollable</code>
  35. * @see JViewport#getPreferredSize
  36. */
  37. Dimension getPreferredScrollableViewportSize();
  38. /**
  39. * Components that display logical rows or columns should compute
  40. * the scroll increment that will completely expose one new row
  41. * or column, depending on the value of orientation. Ideally,
  42. * components should handle a partially exposed row or column by
  43. * returning the distance required to completely expose the item.
  44. * <p>
  45. * Scrolling containers, like JScrollPane, will use this method
  46. * each time the user requests a unit scroll.
  47. *
  48. * @param visibleRect The view area visible within the viewport
  49. * @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
  50. * @param direction Less than zero to scroll up/left, greater than zero for down/right.
  51. * @return The "unit" increment for scrolling in the specified direction.
  52. * This value should always be positive.
  53. * @see JScrollBar#setUnitIncrement
  54. */
  55. int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction);
  56. /**
  57. * Components that display logical rows or columns should compute
  58. * the scroll increment that will completely expose one block
  59. * of rows or columns, depending on the value of orientation.
  60. * <p>
  61. * Scrolling containers, like JScrollPane, will use this method
  62. * each time the user requests a block scroll.
  63. *
  64. * @param visibleRect The view area visible within the viewport
  65. * @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
  66. * @param direction Less than zero to scroll up/left, greater than zero for down/right.
  67. * @return The "block" increment for scrolling in the specified direction.
  68. * This value should always be positive.
  69. * @see JScrollBar#setBlockIncrement
  70. */
  71. int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction);
  72. /**
  73. * Return true if a viewport should always force the width of this
  74. * <code>Scrollable</code> to match the width of the viewport.
  75. * For example a normal
  76. * text view that supported line wrapping would return true here, since it
  77. * would be undesirable for wrapped lines to disappear beyond the right
  78. * edge of the viewport. Note that returning true for a Scrollable
  79. * whose ancestor is a JScrollPane effectively disables horizontal
  80. * scrolling.
  81. * <p>
  82. * Scrolling containers, like JViewport, will use this method each
  83. * time they are validated.
  84. *
  85. * @return True if a viewport should force the Scrollables width to match its own.
  86. */
  87. boolean getScrollableTracksViewportWidth();
  88. /**
  89. * Return true if a viewport should always force the height of this
  90. * Scrollable to match the height of the viewport. For example a
  91. * columnar text view that flowed text in left to right columns
  92. * could effectively disable vertical scrolling by returning
  93. * true here.
  94. * <p>
  95. * Scrolling containers, like JViewport, will use this method each
  96. * time they are validated.
  97. *
  98. * @return True if a viewport should force the Scrollables height to match its own.
  99. */
  100. boolean getScrollableTracksViewportHeight();
  101. }