home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / dogear.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  5.6 KB  |  182 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.         Written by the Personal Journal developers of Dow Jones & Company, Inc.
  4.  
  5.     Dow Jones makes no representations or warranties about 
  6.     the suitability of this software, either express or 
  7.     implied, including but not limited to the implied warranties 
  8.     of merchantability, fitness for a particular purpose, 
  9.     or non-infringement.  Dow Jones will not be liable for 
  10.     any damages suffered by a user as a result of using, 
  11.     modifying or distributing this software or its derivatives.
  12.  
  13.  
  14.         @(#)DogEar.java
  15.  
  16.         The page turner control used to step through the pages of PJ
  17.                 one by one.  It has a picture of a dog-eared page, hence the name.
  18.         Maybe, I should have called it PageTurner, se la guerre.
  19.  
  20.  
  21.         Authors:
  22.  
  23.         Ted S.      Ted Skolnick
  24.         jlee        James Lee
  25.  
  26.         Version Ident:
  27.  
  28.         $Header$
  29.  
  30.  
  31.         History:
  32.  
  33.         0.00 2-feb-1996 Ted S.     Initial Creation
  34.         0.01 23-Feb-96  Ted S.     Made use of nextView method to turn pages.
  35.               4-Mar-96  jlee       Replace CheckboxNb with TabNotebook.
  36.  
  37. ---------------------------------------------------------------------------*/
  38.  
  39. package pj.awt;
  40.  
  41.  
  42. import pj.awt.PjImages;
  43. import pj.awt.TabNotebook;
  44. import pj.net.RemoteImage;
  45. import pj.net.RemoteString;
  46. import pj.net.RemoteURL;
  47.  
  48. import java.net.MalformedURLException;
  49. import java.net.URL;
  50. import java.awt.Panel;
  51. import java.awt.*;
  52.  
  53. /**
  54.  * Fill me in with description
  55.  *
  56.  * @see
  57.  * @see
  58.  * @version 0.00 03-Jan-96
  59.  * @author Ted Skolnick
  60. */
  61. public class DogEar extends Canvas
  62.         {
  63.  
  64.         // --- Class variables
  65.  
  66.         private static final short IDB_PAGE_BOTH            = 0; //both, up
  67.         private static final short IDB_PAGE_RIGHT_DOWN      = 1; // both, right down
  68.         private static final short IDB_PAGE_LEFT_DOWN       = 2;  // both, left down
  69.  
  70.         private static Image ImageList[];
  71.  
  72.         private static final int iMinWidth  = 34;
  73.         private static final int iMinHeight = 34;
  74.  
  75.         // --- Instance variables
  76.  
  77.         private short miCurrentImage;
  78.         private boolean mbClickPrev;
  79.         private TabNotebook notebook;
  80.  
  81.  
  82.  
  83.         // --- Public constructors
  84.         /**
  85.          * @param ImagesIn - PJ's repository for all images, DogEar takes the ones it needs.
  86.          * @param Notebook - The notebook to step through when a page turner is pressed.
  87.          */
  88.         public DogEar( PjImages ImagesIn, TabNotebook Nb )
  89.                 {
  90.                 notebook = Nb;
  91.  
  92.                 // Load up DogEar with images.
  93.                 ImageList = new Image[3];
  94.                 ImageList[IDB_PAGE_BOTH]=
  95.                                 ImagesIn.imagespecs()[ PjImages.idxDogEarBothUp ].getImage();
  96.                 ImageList[IDB_PAGE_RIGHT_DOWN]=
  97.                                 ImagesIn.imagespecs()[ PjImages.idxDogEarRightDown ].getImage();
  98.                 ImageList[IDB_PAGE_LEFT_DOWN]=
  99.                                 ImagesIn.imagespecs()[ PjImages.idxDogEarLeftDown ].getImage();
  100.  
  101.                 // Init to show both pages in the up position.
  102.                 SetImage(IDB_PAGE_BOTH);
  103.  
  104.                 System.out.println("Debug-DogEar:constructed");
  105.                 }
  106.  
  107.         // --- Public operations
  108.  
  109.         // Draw the control in its current state.
  110.         public void paint( Graphics g )
  111.                 {
  112.                 g.drawImage( ImageList[ miCurrentImage ], 0, 0, iMinWidth, iMinHeight, this );
  113.                 }
  114.  
  115.  
  116.         // Make it look like the user pressed down on the page turner,
  117.         //  and remember which side ( prev or next ) was pressed.
  118.         public boolean mouseDown( Event e, int x, int y )
  119.                 {
  120.                 mbClickPrev = IsOverPrev( x );
  121.                 if ( mbClickPrev )
  122.                     {
  123.                     SetImage(IDB_PAGE_LEFT_DOWN);
  124.                     }
  125.                 else
  126.                     {
  127.                     SetImage(IDB_PAGE_RIGHT_DOWN);
  128.                     }
  129.  
  130.                 return true;
  131.                 }
  132.  
  133.         // When the user releases the mouse, then tell the notebook to change pages.
  134.         public boolean mouseUp( Event e, int x, int y )
  135.                 {
  136.  
  137.                 SetImage(IDB_PAGE_BOTH);
  138.                 if (mbClickPrev)
  139.                     notebook.previousView();
  140.                 else
  141.                     notebook.nextView();
  142.  
  143.                 return true;
  144.                 }
  145.  
  146.  
  147.         // Tell java how much space this control requires.
  148.         public Dimension preferredSize()
  149.                 {
  150.                 //System.out.println("Debug pS ");
  151.                 return minimumSize();
  152.                 }
  153.  
  154.         // Tell java how much space this control requires.
  155.         public Dimension minimumSize()
  156.                 {
  157.                 //System.out.println("Debug Dimension ");
  158.                 return new Dimension(iMinWidth,iMinHeight);
  159.                 }
  160.  
  161.         // --- Private operations
  162.  
  163.         private void SetImage( short nNewImage )
  164.                 {
  165.                 // Set the current image, and redraw the control.
  166.                 miCurrentImage = nNewImage;
  167.  
  168.                 repaint();
  169.                 }
  170.  
  171.         // Is the mouse over the previous button?, if not it is over next.
  172.         private boolean IsOverPrev( int x )
  173.                 {
  174.                 // The previous button is the left half of the control.
  175.                 return ( x < ( iMinWidth/2 ) );
  176.                 }
  177.  
  178.  
  179.     } // DogEar
  180.  
  181.  
  182.