Paging
Posted by Eitan Suez Wed, 07 Mar 2007 23:10:00 GMT
We've all had to implement this feature as developers. Today, many frameworks such as Tapestry for example, will provide components out of the box that will automatically take care of paging a listing on your behalf.
JMatter also provides paging out of the box. When I sat down and started to think about this feature, I saw a certain pattern. One's first, naive implementation of paging might consist of a simple forward and back navigation buttons:
< >
Shortly afterwards comes the request for the ability to navigate to the first and last page in a listing, and so they are added:
<< < > >>
Then embellished, like so:
<< < [Page 3] > >>
Over time, paging has evolved to let you navigate to a number of pages in the vicinity of the current page:
1 2 .. 7 [Page 8] 9 .. 13 14
This is what most web-based applications do today.
What I realized is that paging, taken to its eventual limit, is essentially embodied in the behaviour of a scrollbar. Most scrollbars provide continous scrolling. Whereas in the case of paging, the scrolling is more discrete. The more pages there are, the less this discrete behaviour is apparent. What's nice about today's scrollbars is that their size is inversely proportional to the length of the list. The larger the list, the smaller they are. Scrollbars have the advantage of giving you more of a visual perspective of where you are in the list. And you can simply drag the scrollbutton to any location along its dimension.
JMatter's Swing-based view mechanism defines a view implementation: a component named PageScrollBar which extends Swing's JScrollBar, shown at the bottom of the following listing:

As usual, developers of JMatter applications need not concern themselves with this at all. It's bundled into the framework and it just works. If however you feel the need to customize the way this scrollbar looks or behaves, it's easy enough with a little Swing experience to make the desired revisions.

