home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.9 KB | 159 lines |
- // OrientZoom.java
- // 16.03.96
- //
- // the zoom buttons on the orientation page
-
- package cybcerone.orient;
-
- import java.awt.Image;
- import java.awt.Graphics;
- import java.awt.Event;
- import java.awt.Rectangle;
- import java.util.Stack;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.IdPanel;
-
- /**
- * Button that lets you zoom in and out on the map.
- */
- class OrientZoom extends IdPanel {
- private static final Rectangle placement = new Rectangle (734, 598, 290, 70);
-
- private static final String id = "OrientZoom";
- private static final String statusText = "Zoom in and out";
- private static final String iPath = OrientPanel.imagePath;
-
- private static final int OUT_GRAY = 0;
- private static final int OUT_WHITE = 3;
- private static final int OUT_RED = 6;
- private static final int IN_GRAY = 0;
- private static final int IN_WHITE = 1;
- private static final int IN_RED = 2;
-
- private Image[] buttons = new Image [8];
-
- private Maplike currentMap;
-
- private Stack forward;
- private boolean buttonPushed;
- private boolean inPressed, outPressed;
-
- OrientZoom (Appletlike app) {
- super (id, statusText, app);
- reshape (placement);
-
- buttons[OUT_GRAY + IN_GRAY] = app.getImage (iPath + "Zoom_gg.gif", 2);
- buttons[OUT_GRAY + IN_WHITE] = app.getImage (iPath + "Zoom_gj.gif", 2);
- buttons[OUT_GRAY + IN_RED] = app.getImage (iPath + "Zoom_gr.gif", 2);
- buttons[OUT_WHITE + IN_GRAY] = app.getImage (iPath + "Zoom_jg.gif", 2);
- buttons[OUT_WHITE + IN_WHITE] = app.getImage (iPath + "Zoom_jj.gif", 2);
- buttons[OUT_WHITE + IN_RED] = app.getImage (iPath + "Zoom_jr.gif", 2);
- buttons[OUT_RED + IN_GRAY] = app.getImage (iPath + "Zoom_rg.gif", 2);
- buttons[OUT_RED + IN_WHITE] = app.getImage (iPath + "Zoom_rj.gif", 2);
-
- forward = new Stack ();
- }
-
- public void update (Maplike newMap) {
- if (!buttonPushed && !forward.empty ())
- forward = new Stack ();
- buttonPushed = false;
-
- if (newMap instanceof NodeMap)
- update ((NodeMap) newMap);
- else if (newMap instanceof LeafMap)
- update ((LeafMap) newMap);
- else if (newMap instanceof BuildingLevelMap)
- update ((BuildingLevelMap) newMap);
- }
-
- public void update (BuildingLevelMap newMap) {
- currentMap = newMap.getParent ();
- repaint ();
- }
-
- public void update (NodeMap newMap) {
- currentMap = newMap;
- repaint ();
- }
-
- public void update (LeafMap newMap) {
- currentMap = newMap.getParent ();
- repaint ();
- }
-
- public void paint (Graphics g) {
- int in, out;
-
- if (currentMap != null) {
- if (outPressed)
- out = OUT_RED;
- else if (currentMap.getParent () == null)
- out = OUT_GRAY;
- else
- out = OUT_WHITE;
-
- if (inPressed)
- in = IN_RED;
- else if (forward.empty ())
- in = IN_GRAY;
- else
- in = IN_WHITE;
- } else {
- out = OUT_GRAY;
- in = IN_GRAY;
- }
-
- g.drawImage (buttons[out + in], 0, 0, this);
- }
-
- public boolean mouseDown (Event evt, int x, int y) {
- if (x < scale (100) && currentMap.getParent () != null) {
- outPressed = true;
- repaint ();
- } else if (x > scale (190) && !forward.empty ()) {
- inPressed = true;
- repaint ();
- }
- return true;
- }
-
- public boolean mouseUp (Event evt, int x, int y) {
- if (x < scale (100) && outPressed) {
- zoomOut ();
- } else if (x > scale (190) && inPressed) {
- zoomIn ();
- }
-
- inPressed = false;
- outPressed = false;
- repaint ();
- return true;
- }
-
- private void zoomOut () {
- buttonPushed = true;
- forward.push (currentMap);
- app.update (currentMap.getParent().find(currentMap.getName()));
- }
-
- private void zoomIn () {
- Maplike theMap = (Maplike)forward.pop ();
-
- buttonPushed = true;
- if (forward.empty ())
- app.update (theMap);
- else
- app.update (theMap.find(((Maplike)forward.peek ()).getName ()));
- }
-
- public boolean mouseExit (Event evt, int x, int y) {
- inPressed = false;
- outPressed = false;
- repaint ();
- return super.mouseExit (evt, x, y);
- }
-
- }
-