home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.0 KB | 118 lines |
- // ScrollingPaper.java
- // 28.02.96
- //
- // this is like Paper, except you can scroll up and down
-
- package cybcerone.utils;
-
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Event;
-
- /**
- * This is paper that handles scrolling up and down.
- */
- public class ScrollingPaper extends Paper {
- private static final String upButtonFile = imagePath + "buttonUp.gif";
- private static final String downButtonFile = imagePath + "buttonDown.gif";
-
- private static final Rectangle upButtonPlacement =
- scale (688, 15, 32, 32);
- private static final Rectangle downButtonPlacement =
- scale (688, 621 - 5, 32, 32);
-
- /** The up button. */
- protected PaperButton upButton;
-
- /** The down button. */
- protected PaperButton downButton;
-
- /** The pages we can scroll through. */
- protected Pages pages;
-
-
- /**
- * Make me happen.
- */
- public ScrollingPaper (String id, String statusText, Appletlike app) {
- super (id, statusText, app);
-
- upButton = new PaperButton (app.getImage (upButtonFile, 2),
- upButtonPlacement);
- downButton = new PaperButton (app.getImage (downButtonFile, 2),
- downButtonPlacement);
- }
-
- /**
- * Set the data at my disposal. Naturally, I'll fill my pages with
- * it and show you the first page.
- */
- public void setData (PaintableVector theData) {
- this.theData = theData;
- pages = new Pages (theData, maxLines);
- currentPage = pages.getCurrentPage ();
- repaint ();
- }
-
- /**
- * Do that data-setting action, but this time I'll only fill
- * my pages with what's between first and last (inclusive).
- */
- public void setDataRange (PaintableVector theData, int first, int last) {
- this.theData = theData;
- pages = new Pages (theData, first, last, maxLines);
- currentPage = pages.getCurrentPage ();
- repaint ();
- }
-
- public void clearPages () {
- pages = new Pages (maxLines);
- currentPage = pages.getCurrentPage ();
- }
-
- public boolean addLine (Paintable element) {
- return pages.addLine (element);
- }
-
- /**
- * Paint me, and if I have scrolling buttons, paint them too.
- */
- public void paint (Graphics g) {
- super.paint (g);
- paintButtons (g);
- }
-
- /**
- * Paint those scrolling buttons, if they ought to be there.
- */
- protected void paintButtons (Graphics g) {
- if (pages != null) {
- if (pages.hasPreviousPage ())
- upButton.paint (g, this);
- if (pages.hasNextPage ())
- downButton.paint (g, this);
- }
- }
-
- /**
- * If the user clicked on a button, then I'll flip either forwards
- * or backwards. Otherwise, I'll let Paper handle this.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- Object item;
-
- if (pages != null) {
- if (pages.hasPreviousPage () && upButton.inside (x, y))
- currentPage = pages.flipToPrevious ();
- else if (pages.hasNextPage () && downButton.inside (x, y))
- currentPage = pages.flipToNext ();
- else
- return super.mouseDown (evt, x, y);
- repaint ();
- return true;
- } else {
- return super.mouseDown (evt, x, y);
- }
- }
- }
-