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

  1. // OrientZoom.java
  2. // 16.03.96
  3. //
  4. // the zoom buttons on the orientation page
  5.  
  6. package cybcerone.orient;
  7.  
  8. import java.awt.Image;
  9. import java.awt.Graphics;
  10. import java.awt.Event;
  11. import java.awt.Rectangle;
  12. import java.util.Stack;
  13.  
  14. import cybcerone.utils.Appletlike;
  15. import cybcerone.utils.IdPanel;
  16.  
  17. /** 
  18.  * Button that lets you zoom in and out on the map.
  19.  */
  20. class OrientZoom extends IdPanel {
  21.   private static final Rectangle placement = new Rectangle (734, 598, 290, 70);
  22.  
  23.   private static final String id = "OrientZoom";
  24.   private static final String statusText = "Zoom in and out";
  25.   private static final String iPath = OrientPanel.imagePath;
  26.  
  27.   private static final int OUT_GRAY = 0;
  28.   private static final int OUT_WHITE = 3;
  29.   private static final int OUT_RED = 6;
  30.   private static final int IN_GRAY = 0;
  31.   private static final int IN_WHITE = 1;
  32.   private static final int IN_RED = 2;
  33.  
  34.   private Image[] buttons = new Image [8];
  35.  
  36.   private Maplike currentMap;
  37.  
  38.   private Stack forward;
  39.   private boolean buttonPushed;
  40.   private boolean inPressed, outPressed;
  41.  
  42.   OrientZoom (Appletlike app) {
  43.     super (id, statusText, app);
  44.     reshape (placement);
  45.  
  46.     buttons[OUT_GRAY + IN_GRAY] = app.getImage (iPath + "Zoom_gg.gif", 2);
  47.     buttons[OUT_GRAY + IN_WHITE] = app.getImage (iPath + "Zoom_gj.gif", 2);
  48.     buttons[OUT_GRAY + IN_RED] = app.getImage (iPath + "Zoom_gr.gif", 2);
  49.     buttons[OUT_WHITE + IN_GRAY] = app.getImage (iPath + "Zoom_jg.gif", 2);
  50.     buttons[OUT_WHITE + IN_WHITE] = app.getImage (iPath + "Zoom_jj.gif", 2);
  51.     buttons[OUT_WHITE + IN_RED] = app.getImage (iPath + "Zoom_jr.gif", 2);
  52.     buttons[OUT_RED + IN_GRAY] = app.getImage (iPath + "Zoom_rg.gif", 2);
  53.     buttons[OUT_RED + IN_WHITE] = app.getImage (iPath + "Zoom_rj.gif", 2);
  54.  
  55.     forward = new Stack ();
  56.   }
  57.  
  58.   public void update (Maplike newMap) {
  59.     if (!buttonPushed && !forward.empty ())
  60.       forward = new Stack ();
  61.     buttonPushed = false;
  62.  
  63.     if (newMap instanceof NodeMap)
  64.       update ((NodeMap) newMap);
  65.     else if (newMap instanceof LeafMap)
  66.       update ((LeafMap) newMap);
  67.     else if (newMap instanceof BuildingLevelMap)
  68.       update ((BuildingLevelMap) newMap);
  69.   }
  70.  
  71.   public void update (BuildingLevelMap newMap) {
  72.     currentMap = newMap.getParent ();
  73.     repaint ();
  74.   }
  75.  
  76.   public void update (NodeMap newMap) {
  77.     currentMap = newMap;
  78.     repaint ();
  79.   }
  80.  
  81.   public void update (LeafMap newMap) {
  82.     currentMap = newMap.getParent ();
  83.     repaint ();
  84.   }
  85.   
  86.   public void paint (Graphics g) {
  87.     int in, out;
  88.  
  89.     if (currentMap != null) {
  90.       if (outPressed)
  91.     out = OUT_RED;
  92.       else if (currentMap.getParent () == null)
  93.     out = OUT_GRAY;
  94.       else
  95.     out = OUT_WHITE;
  96.  
  97.       if (inPressed)
  98.     in = IN_RED;
  99.       else if (forward.empty ())
  100.     in = IN_GRAY;
  101.       else
  102.     in = IN_WHITE;
  103.     } else {
  104.       out = OUT_GRAY;
  105.       in = IN_GRAY;
  106.     }
  107.  
  108.     g.drawImage (buttons[out + in], 0, 0, this);
  109.   }
  110.  
  111.   public boolean mouseDown (Event evt, int x, int y) {
  112.     if (x < scale (100) && currentMap.getParent () != null) {
  113.       outPressed = true;
  114.       repaint ();
  115.     } else if (x > scale (190) && !forward.empty ()) {
  116.       inPressed = true;
  117.       repaint ();
  118.     }
  119.     return true;
  120.   }
  121.  
  122.   public boolean mouseUp (Event evt, int x, int y) {
  123.     if (x < scale (100) && outPressed) {
  124.       zoomOut ();
  125.     } else if (x > scale (190) && inPressed) {
  126.       zoomIn ();
  127.     }
  128.  
  129.     inPressed = false;
  130.     outPressed = false;
  131.     repaint ();
  132.     return true;
  133.   }
  134.  
  135.   private void zoomOut () {
  136.     buttonPushed = true;
  137.     forward.push (currentMap);
  138.     app.update (currentMap.getParent().find(currentMap.getName()));
  139.   }
  140.   
  141.   private void zoomIn () {
  142.     Maplike theMap = (Maplike)forward.pop ();
  143.  
  144.     buttonPushed = true;
  145.     if (forward.empty ())
  146.       app.update (theMap);
  147.     else
  148.       app.update (theMap.find(((Maplike)forward.peek ()).getName ()));
  149.   }
  150.  
  151.   public boolean mouseExit (Event evt, int x, int y) {
  152.     inPressed = false;
  153.     outPressed = false;
  154.     repaint ();
  155.     return super.mouseExit (evt, x, y);
  156.   }
  157.       
  158. }
  159.