ScrollIncrementSupplier.java

  1. package swingtree.api;

  2. import swingtree.UI;
  3. import swingtree.layout.Bounds;

  4. import javax.swing.JScrollBar;
  5. import java.awt.Rectangle;

  6. /**
  7.  *  A supplier of scrollable increments for a {@link javax.swing.JScrollPane}.
  8.  *  which can be passed to the scroll pane configurator API
  9.  *  at {@link UI#scrollPane(Configurator)} using
  10.  *  {@link swingtree.ScrollableComponentDelegate#blockIncrement(ScrollIncrementSupplier)}
  11.  *  or {@link swingtree.ScrollableComponentDelegate#unitIncrement(ScrollIncrementSupplier)}.
  12.  */
  13. @FunctionalInterface
  14. public interface ScrollIncrementSupplier
  15. {
  16.     static ScrollIncrementSupplier none() {
  17.         return Constants.SCROLLABLE_INCREMENT_SUPPLIER_NONE;
  18.     }

  19.     /**
  20.      *  Returns the scroll increment for the given view rectangle, orientation and direction.
  21.      *  This scroll increment may either be a unit increment or a block increment,
  22.      *  see {@link javax.swing.Scrollable#getScrollableUnitIncrement(Rectangle, int, int)}
  23.      *  and {@link javax.swing.Scrollable#getScrollableBlockIncrement(Rectangle, int, int)}
  24.      *  for more information about the parameters. <br>
  25.      *  <b>
  26.      *      This method is not designed to be used anywhere else than in the
  27.      *      {@link swingtree.ScrollableComponentDelegate#blockIncrement(ScrollIncrementSupplier)}
  28.      *      or {@link swingtree.ScrollableComponentDelegate#unitIncrement(ScrollIncrementSupplier)}.
  29.      *  </b>
  30.      *  <br>
  31.      * Components that display logical rows or columns should compute
  32.      * the scroll increment that will completely expose one new row
  33.      * or column, depending on the value of orientation.  Ideally,
  34.      * components should handle a partially exposed row or column by
  35.      * returning the distance required to completely expose the item.
  36.      * <p>
  37.      * Scrolling containers, like JScrollPane, will use this method
  38.      * each time the user requests a unit scroll.
  39.      *
  40.      * @param visibleRectangle The view area visible within the viewport
  41.      * @param orientation Either UI.VERTICAL or UI.HORIZONTAL.
  42.      * @param direction Less than zero to scroll up/left, greater than zero for down/right.
  43.      * @return The "unit" or "block" increment for scrolling in the specified direction.
  44.      *         This value should always be positive.
  45.      * @see JScrollBar#setUnitIncrement
  46.      * @see JScrollBar#setBlockIncrement
  47.      */
  48.     int get(
  49.         Bounds   visibleRectangle,
  50.         UI.Align orientation,
  51.         int      direction
  52.     );
  53. }