home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 5.3 KB | 199 lines |
- // Faculte.java
- // 24.02.96
- //
- // the information for each faculte
-
- package cybcerone.utils;
-
- import java.awt.Graphics;
- import java.awt.image.ImageObserver;
- import java.awt.Image;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.util.Vector;
-
- /**
- * One of the basic objects, contains all the available info on a faculty.
- */
- public class Faculte implements Literate, Paintable, Mapable {
- private String name;
- private String batiment;
- private String telephone;
- private String fax;
- private String co; // I don't know what this is, but it's in the data file
- private int level;
-
- public static final int clipY = Scaler.scale (30);
- public static final int clipWidth = Scaler.scale (683);
- public static final int clipHeight = Scaler.scale (35);
- public static final int iconX = Scaler.scale (688);
-
- private static int indentWidth = Scaler.scale (40);
-
- private Faculte parent = null;
- private FaculteVector children = null;
-
- /** for reading in */
- private static final int numLines = 5;
- private static String lines[] = new String[numLines];
-
- /** for painting */
- private Image icon;
- private static Image leaf;
- private static Image node;
-
- public Faculte getParent () { return parent; }
- public FaculteVector getChildren () { return children; }
- public int getLevel () { return level; }
- public String getName () { return name; }
- public String getBatiment () { return batiment; }
- public String getTelephone () { return telephone; }
- public String getFax () { return fax; }
- public String getContact () { return co; }
-
-
- public static void setIconImages (Image leaf, Image node) {
- Faculte.leaf = leaf;
- Faculte.node = node;
- }
-
- public Faculte (String name, String batiment, String telephone,
- String fax, String co, int level) {
- this.name = name;
- this.batiment = batiment;
- this.telephone = telephone;
- this.fax = fax;
- this.co = co;
- this.level = level;
- icon = leaf;
- }
-
- /** used for TY fields (the name of the groupe) */
- public Faculte (String name) {
- this (name, null, null, null, null, 0);
- }
-
- private Faculte (String lines[]) {
- this (lines[0].substring (3),
- lines[1].substring (3),
- lines[2].substring (3),
- lines[3].substring (3),
- lines[4].substring (3),
- new Integer(lines[0].substring(1,2)).intValue ());
- }
-
- /** used to make an object that will then read itself in */
- public Faculte () {
- }
-
- public String toString () {
- StringBuffer theString = new StringBuffer ();
- theString.append ("Faculte[" + name + ", " + level);
- if (parent != null)
- theString.append (", parent = " + parent.name);
- theString.append ("]");
- return (theString.toString ());
- }
-
- public void paint (Graphics g, int x, int y, ImageObserver observer) {
- Graphics line = g.create (0, y - clipY, clipWidth, clipHeight);
-
- line.drawString (name, x + ((level - 1) * indentWidth), clipY);
- if (icon != null)
- g.drawImage (icon, iconX, y - clipY, observer);
- }
-
- /** adds a child Faculte to this Faculte */
- private void addChild (Faculte child) {
- if (children == null) {
- children = new FaculteVector ();
- icon = node;
- }
- children.addElement (child);
- }
-
- /** reads in a Faculte from inStream */
- public Object read (DataInputStream inStream) throws IOException {
- Faculte theFaculte = read_one (inStream);
-
- if (theFaculte != null) {
- read_helper (inStream, theFaculte);
- }
-
- return theFaculte;
- }
-
- /** recursively goes through the file, builds the tree */
- private static void read_helper (DataInputStream inStream,
- Faculte parent) throws IOException {
- Faculte tempFaculte = read_one (inStream);
-
- if (tempFaculte != null) {
- if (tempFaculte.level == parent.level + 1) {
-
- tempFaculte.parent = parent;
- parent.addChild (tempFaculte);
- read_helper (inStream, parent);
-
- } else if (tempFaculte.level == parent.level + 2) {
-
- Faculte lastChild = parent.children.lastElement ();
- tempFaculte.parent = lastChild;
- lastChild.addChild (tempFaculte);
- read_helper (inStream, lastChild);
-
- } else {
-
- Faculte originalParent = parent;
- while (originalParent.level != tempFaculte.level - 1)
- originalParent = originalParent.parent;
- tempFaculte.parent = originalParent;
- originalParent.addChild (tempFaculte);
- read_helper (inStream, originalParent);
-
- }
- }
- }
-
- /** reads one groupe of info */
- private static Faculte read_one (DataInputStream inStream)
- throws IOException {
-
- lines[0] = inStream.readLine();
-
- /* get rid of comments */
- while (lines[0] != null && (lines[0].startsWith ("#") || lines[0] == ""))
- lines[0] = inStream.readLine();
-
- if (lines[0] != null) {
- if (lines[0].startsWith ("==="))
- return null;
- else if (lines[0].startsWith ("TY:"))
- return new Faculte (lines[0].substring(3));
- else {
- for (int i = 1; i < numLines; i++) {
- lines[i] = inStream.readLine();
- }
- return new Faculte (lines);
- }
- }
- return null;
- }
-
- public String getMapName () {
- if (batiment.startsWith ("BFSH2"))
- return "BFSH2_2";
- else
- return batiment;
- }
-
- public String getZoneName () { return null; }
-
- public MapInfoPanel getMapInfoPanel (Appletlike app) {
- FaculteInfoPanel thePanel = new FaculteInfoPanel (app);
- thePanel.setData (this);
- return thePanel;
- }
-
- }
-