home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.5 KB | 163 lines |
- // NodeMap.java
- // 23.02.96
- //
- // a standard map
-
- package cybcerone.orient;
-
- import java.awt.Image;
- import java.util.Vector;
- import java.util.Enumeration;
- import java.io.DataInputStream;
- import java.io.IOException;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.Literate;
-
- /**
- * A full-fledged map with children, photos, a legend, etc.
- */
- public class NodeMap implements Literate, Maplike {
- private static final String planPath = "plans/";
- private static final String legendPath = "cartouche/";
- private static final String photoPath = "photos/";
-
- private String name;
- private String parent;
- private String description;
-
- private Image map;
- private Image legend;
-
- private Image[] photos;
-
- private Zones children;
- private Zones clickableZones;
-
- private Maplikes theMaps;
-
- /* for reading */
- private Appletlike app;
- private String imagePath;
- private String line;
- private String type;
-
- NodeMap (String name, String parent, String description,
- Image map, Image legend, Vector photos, Zones children,
- Zones clickableZones) {
- if (photos != null) {
- Image photoArray[] = new Image[photos.size ()];
- photos.copyInto (photoArray);
- this.photos = photoArray;
- }
-
- this.name = name;
- this.parent = parent;
- this.description = description;
- this.map = map;
- this.legend = legend;
- this.children = children;
- this.clickableZones = clickableZones;
- }
-
- public String getName () { return name; }
-
- public Maplike getParent () {
- if (theMaps != null && parent != null)
- return theMaps.findMap (parent);
- else
- return null;
- }
-
- public String getDesc () { return description; }
- public Image getMap () { return map; }
- public Image getLegend () { return legend; }
- public Image[] getPhotos () { return photos; }
-
- public void setMaplikes (Maplikes theMaps) {
- this.theMaps = theMaps;
- }
-
- public Zone find (String name) {
- Zone theZone = children.which (name);
- if (theZone == null)
- theZone = clickableZones.which (name);
- return theZone;
- }
-
- public Zone find (int x, int y) {
- Zone theZone = children.which (x, y);
- if (theZone == null && clickableZones != null)
- theZone = clickableZones.which (x, y);
- return theZone;
- }
-
- public String toString () {
- return ("NodeMap[" + name + "]");
- }
-
- /** the reader */
- public NodeMap (Appletlike app, String imagePath) {
- this.app = app;
- this.imagePath = imagePath;
- }
-
- public Object read (DataInputStream inStream) throws IOException {
- name = parent = description = null;
- map = legend = null;
- Vector photos = null;
- children = clickableZones = null;
-
- line = inStream.readLine ();
-
- while (line != null) {
- if (line.startsWith ("TY:")) type = line.substring (3);
- else if (line.startsWith ("NA:")) name = line.substring (3);
- else if (line.startsWith ("AN:")) parent = line.substring (3);
- else if (line.startsWith ("IN:")) description = line.substring (3);
- else if (line.startsWith ("PL:"))
- map = app.getImage (imagePath + planPath + line.substring (3), 3);
- else if (line.startsWith ("PS:"))
- legend = app.getImage (imagePath + legendPath + line.substring (3), 4);
- else if (line.startsWith ("PH:")) {
- if (photos == null)
- photos = new Vector ();
- photos.addElement
- (app.getImage (imagePath + photoPath + line.substring (3), 5));
- } else if (line.startsWith ("CZ:")) {
- if (children == null)
- children = new Zones ();
- children.add (new Zone (line.substring (3)));
- } else if (line.startsWith ("ZC:")) {
- if (clickableZones == null)
- clickableZones = new Zones ();
- clickableZones.add (line.substring (3));
- } else if (line.startsWith ("===")) {
- return decodeType (type, name, parent, description,
- map, legend, photos, children, clickableZones);
- }
- line = inStream.readLine ();
- }
- return null;
- }
-
- private Object decodeType (String type, String name, String parent,
- String description, Image map, Image legend,
- Vector photos, Zones children,
- Zones clickableZones) {
- if (type.equals ("NOEUD")) {
- return new NodeMap (name, parent, description, map, legend,
- photos, children, clickableZones);
- } else if (type.equals ("CDS")) {
- return new LeafMap (name, parent, description, photos);
- } else if (type.equals ("BAT")) {
- return new BuildingLevelMap (name, parent, map, children,
- clickableZones);
- } else {
- System.err.println ("NodeMap: ERROR -- don't understand type " + type +
- " in map " + name);
- return null;
- }
- }
- }
-