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

  1. // BackButton.java
  2. // 19.03.96
  3. //
  4. // the Back button on the control panel
  5.  
  6. package cybcerone.control;
  7.  
  8. import java.awt.Rectangle;
  9. import java.util.Stack;
  10.  
  11. import cybcerone.utils.Appletlike;
  12. import cybcerone.utils.IdPanel;
  13.  
  14. /**
  15.  * Allows the user to go back to previous pages.
  16.  */
  17. class BackButton extends ControlButton {
  18.   private static final Rectangle placement = 
  19.     new Rectangle (354, 0, 80, 100);
  20.   
  21.   private static final String id = "BackButton";
  22.   private static final String statusText = "Click to go Back";
  23.  
  24.   private static final String bgFile = imagePath + "retour_lache.gif";
  25.   private static final String pressedBgFile = imagePath + "retour_presse.gif";
  26.   private static final String disabledBgFile = 
  27.     imagePath + "retour_disabled.gif";
  28.   
  29.   ControlPanel parent;
  30.   Stack history;
  31.  
  32.   BackButton (ControlPanel parent, Appletlike app) {
  33.     super (id, statusText, app);
  34.     reshape (placement);
  35.     this.parent = parent;
  36.  
  37.     setBackground (bgFile, 1);
  38.     setPressedBg (pressedBgFile, 1);
  39.     setDisabledBg (disabledBgFile, 0);
  40.     
  41.     clear ();
  42.   }
  43.  
  44.   /**
  45.    * We're leaving this page, store it so we can get back.
  46.    */
  47.   void update (Object newPanelId) {
  48.     history.push (newPanelId);
  49.     enable ();
  50.   }
  51.   
  52.   /**
  53.    * Takes us back a page.
  54.    */
  55.   protected void doAction () {
  56.     parent.goBack (history.pop ());
  57.     if (history.empty ()) 
  58.       disable ();
  59.   }
  60.  
  61.   /**
  62.    * Back to the initial state.
  63.    */
  64.   public void clear () {
  65.     history = new Stack ();
  66.     disable ();
  67.   }
  68.   
  69. }
  70.