home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.8 KB | 161 lines |
- // OrientMap.java
- // 16.03.96
- //
- // the map on the orientation screen
-
- package cybcerone.orient;
-
- import java.util.Vector;
- import java.util.Enumeration;
- import java.awt.Rectangle;
- import java.awt.Point;
- import java.awt.Graphics;
- import java.awt.Event;
- import java.awt.Color;
- import java.awt.Image;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.IdPanel;
-
- /**
- * The pretty complex and poorly commented heart of the mapping module.
- */
- class OrientMap extends IdPanel implements Runnable {
- private static final Rectangle placement = new Rectangle (0, 135, 734, 533);
-
- private static final String id = "OrientMap";
- private static final String statusText = "Click to browse";
-
- private Maplikes theMaps;
- private Maplike currentMap;
- private Zone currentZone;
-
- private Thread flasher;
- private boolean flashOn;
-
- /** to speed up painting */
- private boolean redrawRedBox;
- private Rectangle zone = new Rectangle ();
- private Rectangle clip = new Rectangle ();
- private Point boxPoint = new Point (0, 0);
-
- private final Point anchor = new Point (scale (732), scale (275));
-
- OrientMap (Appletlike app) {
- super (id, statusText, app);
- reshape (placement);
- }
-
- public void setMaps (Maplikes theMaps) {
- this.theMaps = theMaps;
- }
-
- public void start () {
- if (flasher == null) {
- flasher = new Thread (this);
- flasher.start ();
- }
- }
-
- public void stop () {
- if (flasher != null)
- flasher.stop ();
- flasher = null;
- }
-
- public void run () {
- long now;
- long updateTime = 0;
-
- while (flasher != null) {
- if ((updateTime += 333) < (now = System.currentTimeMillis ()))
- updateTime = now;
-
- if (currentZone != null) {
- zone = currentZone.getCoords ();
- clip.reshape (zone.x, zone.y, zone.width, zone.height);
- if (currentMap instanceof LeafMap)
- clip.add (anchor);
- redrawRedBox = true;
- repaint ();
- if (flashOn == true)
- flashOn = false;
- else
- flashOn = true;
- }
-
- try {
- flasher.sleep (updateTime - System.currentTimeMillis ());
- } catch (InterruptedException e) {
- }
- }
- }
-
- public void paint (Graphics g) {
- if (currentMap != null && currentMap.getMap () != null) {
- if (redrawRedBox && currentZone != null && flashOn) {
- redrawRedBox = false;
- g.clipRect (clip.x, clip.y - 1, clip.width + 2, clip.height + 3);
- }
- g.drawImage (currentMap.getMap (), 0, 0, this);
- }
-
- if (currentZone != null && flashOn) {
- g.setColor (Color.red);
- zone = currentZone.getCoords ();
- g.drawRect (zone.x, zone.y, zone.width, zone.height);
- g.drawRect (zone.x + 1, zone.y - 1, zone.width, zone.height);
-
- if (currentMap instanceof LeafMap) {
- boxPoint.move (zone.x + zone.width, zone.y + (zone.height/2));
-
- g.drawLine (boxPoint.x, boxPoint.y, anchor.x, anchor.y);
- g.drawLine (boxPoint.x, boxPoint.y + 1, anchor.x, anchor.y + 1);
- }
- }
- }
-
- private int min (int a, int b) {
- return (a < b ? a : b);
- }
-
- private int max (int a, int b) {
- return (a > b ? a : b);
- }
-
- public void update (Maplike newMap) {
- currentMap = newMap;
- if (newMap instanceof LeafMap)
- update ((LeafMap) newMap);
- else
- currentZone = null;
- redrawRedBox = false;
- repaint ();
- }
-
- public void update (LeafMap newMap) {
- currentZone = newMap.getParent().find(newMap.getName());
- }
-
-
- /** set this as the new highlight zone */
- public void update (Zone highlightZone) {
- currentZone = highlightZone;
- redrawRedBox = false;
- repaint ();
- }
-
- public boolean mouseDown (Event evt, int x, int y) {
- Zone clickedZone = currentMap.find (x, y);
- if (clickedZone != null) {
- Maplike clickedMap = theMaps.findMap (clickedZone.getName ());
- if (clickedMap != null)
- app.update (clickedMap);
- } else if (currentMap instanceof LeafMap) {
- app.update (currentMap.getParent ());
- }
- return true;
- }
-
- }
-