home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / utils / scrollingpaper.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  3.0 KB  |  118 lines

  1. // ScrollingPaper.java
  2. // 28.02.96
  3. //
  4. // this is like Paper, except you can scroll up and down
  5.  
  6. package cybcerone.utils;
  7.  
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10. import java.awt.Event;
  11.  
  12. /**
  13.  * This is paper that handles scrolling up and down.
  14.  */
  15. public class ScrollingPaper extends Paper {
  16.   private static final String upButtonFile = imagePath + "buttonUp.gif";
  17.   private static final String downButtonFile = imagePath + "buttonDown.gif";
  18.  
  19.   private static final Rectangle upButtonPlacement = 
  20.     scale (688, 15, 32, 32);
  21.   private static final Rectangle downButtonPlacement =
  22.     scale (688, 621 - 5, 32, 32);
  23.  
  24.   /** The up button. */
  25.   protected PaperButton upButton;
  26.  
  27.   /** The down button. */
  28.   protected PaperButton downButton;
  29.  
  30.   /** The pages we can scroll through. */
  31.   protected Pages pages;
  32.  
  33.  
  34.   /**
  35.    * Make me happen.
  36.    */
  37.   public ScrollingPaper (String id, String statusText, Appletlike app) {
  38.     super (id, statusText, app);
  39.  
  40.     upButton = new PaperButton (app.getImage (upButtonFile, 2), 
  41.                 upButtonPlacement);
  42.     downButton = new PaperButton (app.getImage (downButtonFile, 2),
  43.                   downButtonPlacement);
  44.   }
  45.  
  46.   /**
  47.    * Set the data at my disposal.  Naturally, I'll fill my pages with
  48.    * it and show you the first page.
  49.    */
  50.   public void setData (PaintableVector theData) {
  51.     this.theData = theData;
  52.     pages = new Pages (theData, maxLines);
  53.     currentPage = pages.getCurrentPage ();
  54.     repaint ();
  55.   }
  56.   
  57.   /**
  58.    * Do that data-setting action, but this time I'll only fill
  59.    * my pages with what's between first and last (inclusive).
  60.    */
  61.   public void setDataRange (PaintableVector theData, int first, int last) {
  62.     this.theData = theData;
  63.     pages = new Pages (theData, first, last, maxLines);
  64.     currentPage = pages.getCurrentPage ();
  65.     repaint ();
  66.   }
  67.  
  68.   public void clearPages () {
  69.     pages = new Pages (maxLines);
  70.     currentPage = pages.getCurrentPage ();
  71.   }
  72.  
  73.   public boolean addLine (Paintable element) {
  74.     return pages.addLine (element);
  75.   }
  76.  
  77.   /**
  78.    * Paint me, and if I have scrolling buttons, paint them too.
  79.    */
  80.   public void paint (Graphics g) {
  81.     super.paint (g);
  82.     paintButtons (g);
  83.   }
  84.  
  85.   /**
  86.    * Paint those scrolling buttons, if they ought to be there.
  87.    */
  88.   protected void paintButtons (Graphics g) {
  89.     if (pages != null) {
  90.       if (pages.hasPreviousPage ())
  91.     upButton.paint (g, this);
  92.       if (pages.hasNextPage ())
  93.     downButton.paint (g, this);
  94.     }
  95.   }
  96.  
  97.   /**
  98.    * If the user clicked on a button, then I'll flip either forwards
  99.    * or backwards.  Otherwise, I'll let Paper handle this.
  100.    */
  101.   public boolean mouseDown (Event evt, int x, int y) {
  102.     Object item;
  103.     
  104.     if (pages != null) {
  105.       if (pages.hasPreviousPage () && upButton.inside (x, y))
  106.     currentPage = pages.flipToPrevious ();
  107.       else if (pages.hasNextPage () && downButton.inside (x, y))
  108.     currentPage = pages.flipToNext ();
  109.       else
  110.     return super.mouseDown (evt, x, y);
  111.       repaint ();
  112.       return true;
  113.     } else {
  114.       return super.mouseDown (evt, x, y);
  115.     }
  116.   }
  117. }
  118.