home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.5 KB | 118 lines |
- // Pages.java
- // 27.02.96
- //
- // implements multiple Page objects
-
- package cybcerone.utils;
-
- import java.util.Vector;
-
- /**
- * This class is used to store multiple Page objects in a single
- * object. Better than a PageVector because it lets you easily
- * create and flip through those pages.
- *
- * @see Page
- */
- class Pages {
-
- private PageVector pages = new PageVector ();
- private int maxLines;
- private boolean growable = false;
-
- private int currentPage = 0;
-
- /**
- * all new pages created will be of the specified maximum length
- */
- Pages (int maxLines) {
- this.maxLines = maxLines;
- pages.addElement (new Page (maxLines));
- growable = true;
- }
-
- /**
- * Creates as many Page objects as necessary, each of maximum size
- * maxLines, to hold this PaintableVector
- */
- Pages (PaintableVector theItems, int maxLines) {
- this (theItems, 0, theItems.size () - 1, maxLines);
- }
-
- /**
- * Same as above, but lets you specify first and last elements (inclusive).
- * Assumes first and last are valid indices.
- */
- Pages (PaintableVector theItems, int first, int last, int maxLines) {
- this.maxLines = maxLines;
-
- for (int remaining = last - first + 1;
- remaining > maxLines;
- remaining -= maxLines) {
- pages.addElement (new Page (theItems, first, first + maxLines - 1));
- first += maxLines;
- }
-
- pages.addElement (new Page (theItems, first, last));
- }
-
- /**
- * Adds a new element. If a new Page must be created, so be it.
- */
- boolean addLine (Paintable newLine) {
- if (growable == true) {
- if (!pages.lastElement().addLine (newLine)) {
- pages.addElement (new Page (maxLines));
- pages.lastElement().addLine (newLine);
- }
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Returns the current page, by default the first one.
- */
- Page getCurrentPage () {
- return pages.elementAt (currentPage);
- }
-
- /**
- * Checks to see if there is a previous page.
- */
- boolean hasPreviousPage () {
- return (currentPage != 0);
- }
-
- /**
- * Checks to see if there is a next page.
- */
- boolean hasNextPage () {
- return (currentPage < pages.size () - 1);
- }
-
- /**
- * Flips to the previous page and returns that page.
- */
- Page flipToPrevious () {
- if (hasPreviousPage ())
- currentPage--;
- return getCurrentPage ();
- }
-
- /**
- * Flips to the next page and returns it.
- */
- Page flipToNext () {
- if (hasNextPage ())
- currentPage++;
- return getCurrentPage ();
- }
-
- }
-
-
-
-
-