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

  1. // NodeMap.java
  2. // 23.02.96
  3. //
  4. // a standard map
  5.  
  6. package cybcerone.orient;
  7.  
  8. import java.awt.Image;
  9. import java.util.Vector;
  10. import java.util.Enumeration;
  11. import java.io.DataInputStream;
  12. import java.io.IOException;
  13.  
  14. import cybcerone.utils.Appletlike;
  15. import cybcerone.utils.Literate;
  16.  
  17. /**
  18.  * A full-fledged map with children, photos, a legend, etc.
  19.  */
  20. public class NodeMap implements Literate, Maplike {
  21.   private static final String planPath = "plans/";
  22.   private static final String legendPath = "cartouche/";
  23.   private static final String photoPath = "photos/";
  24.   
  25.   private String name;
  26.   private String parent;
  27.   private String description;
  28.  
  29.   private Image map;
  30.   private Image legend;
  31.  
  32.   private Image[] photos;
  33.  
  34.   private Zones children;
  35.   private Zones clickableZones;
  36.  
  37.   private Maplikes theMaps;
  38.  
  39.   /* for reading */
  40.   private Appletlike app;
  41.   private String imagePath;
  42.   private String line;
  43.   private String type;
  44.   
  45.   NodeMap (String name, String parent, String description, 
  46.        Image map, Image legend, Vector photos, Zones children,
  47.        Zones clickableZones) {
  48.     if (photos != null) {
  49.       Image photoArray[] = new Image[photos.size ()];
  50.       photos.copyInto (photoArray);
  51.       this.photos = photoArray;
  52.     }
  53.  
  54.     this.name = name;
  55.     this.parent = parent;
  56.     this.description = description;
  57.     this.map = map;
  58.     this.legend = legend;
  59.     this.children = children;
  60.     this.clickableZones = clickableZones;
  61.   }
  62.   
  63.   public String getName () { return name; }
  64.  
  65.   public Maplike getParent () {
  66.     if (theMaps != null && parent != null) 
  67.       return theMaps.findMap (parent); 
  68.     else
  69.       return null;
  70.   }
  71.  
  72.   public String getDesc () { return description; }
  73.   public Image getMap () { return map; }
  74.   public Image getLegend () { return legend; }
  75.   public Image[] getPhotos () { return photos; }
  76.  
  77.   public void setMaplikes (Maplikes theMaps) {
  78.     this.theMaps = theMaps;
  79.   }
  80.   
  81.   public Zone find (String name) {
  82.     Zone theZone = children.which (name);
  83.     if (theZone == null)
  84.       theZone = clickableZones.which (name);
  85.     return theZone;
  86.   }
  87.  
  88.   public Zone find (int x, int y) {
  89.     Zone theZone = children.which (x, y);
  90.     if (theZone == null && clickableZones != null)
  91.       theZone = clickableZones.which (x, y);
  92.     return theZone;
  93.   }
  94.  
  95.   public String toString () {
  96.     return ("NodeMap[" + name + "]");
  97.   }
  98.  
  99.   /** the reader */
  100.   public NodeMap (Appletlike app, String imagePath) {
  101.     this.app = app;
  102.     this.imagePath = imagePath;
  103.   }
  104.  
  105.   public Object read (DataInputStream inStream) throws IOException {
  106.     name = parent = description = null;
  107.     map = legend = null;
  108.     Vector photos = null;
  109.     children = clickableZones = null;
  110.     
  111.     line = inStream.readLine ();
  112.     
  113.     while (line != null) {
  114.       if (line.startsWith ("TY:")) type = line.substring (3);
  115.       else if (line.startsWith ("NA:")) name = line.substring (3);
  116.       else if (line.startsWith ("AN:")) parent = line.substring (3);
  117.       else if (line.startsWith ("IN:")) description = line.substring (3);
  118.       else if (line.startsWith ("PL:")) 
  119.     map = app.getImage (imagePath + planPath + line.substring (3), 3);
  120.       else if (line.startsWith ("PS:"))
  121.     legend = app.getImage (imagePath + legendPath + line.substring (3), 4);
  122.       else if (line.startsWith ("PH:")) {
  123.     if (photos == null)
  124.       photos = new Vector ();
  125.     photos.addElement 
  126.       (app.getImage (imagePath + photoPath + line.substring (3), 5));
  127.       } else if (line.startsWith ("CZ:")) {
  128.     if (children == null)
  129.       children = new Zones ();
  130.     children.add (new Zone (line.substring (3)));
  131.       } else if (line.startsWith ("ZC:")) {
  132.     if (clickableZones == null)
  133.       clickableZones = new Zones ();
  134.     clickableZones.add (line.substring (3));
  135.       } else if (line.startsWith ("===")) {
  136.     return decodeType (type, name, parent, description,
  137.                map, legend, photos, children, clickableZones);
  138.       }
  139.       line = inStream.readLine ();
  140.     }
  141.     return null;
  142.   }
  143.  
  144.   private Object decodeType (String type, String name, String parent,
  145.                  String description, Image map, Image legend,
  146.                  Vector photos, Zones children, 
  147.                  Zones clickableZones) {
  148.     if (type.equals ("NOEUD")) {
  149.       return new NodeMap (name, parent, description, map, legend,
  150.               photos, children, clickableZones);
  151.     } else if (type.equals ("CDS")) {
  152.       return new LeafMap (name, parent, description, photos);
  153.     } else if (type.equals ("BAT")) {
  154.       return new BuildingLevelMap (name, parent, map, children, 
  155.                    clickableZones);
  156.     } else {
  157.       System.err.println ("NodeMap: ERROR -- don't understand type " + type +
  158.               " in map " + name);
  159.       return null;
  160.     }
  161.   }
  162. }
  163.