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

  1. // Manif.java
  2. // 13.03.96
  3. //
  4. // all the info to represent one event (manifestation)
  5.  
  6. package cybcerone.utils;
  7.  
  8. import java.util.Vector;
  9. import java.awt.Graphics;
  10. import java.awt.image.ImageObserver;
  11. import java.io.DataInputStream;
  12. import java.io.IOException;
  13.  
  14. /** 
  15.  * One of the base objects, an event (Manifestation in French)
  16.  */
  17. public class Manif implements Literate, Paintable, Mapable {
  18.  
  19.   String eventType;      // ET 
  20.   String title;          // TE
  21.   String batiment;       // BA
  22.   String day;            // JD
  23.   String month;          // MD
  24.   String year;           // AD
  25.   String faculte;        // FJ
  26.   String champBatiment;  // CB
  27.   String noSalle;        // NS
  28.   String hour;           // TH
  29.   String minute;         // TM
  30.   String personTitle;    // TP
  31.   String personName;     // NA
  32.   String personTitleSup; // TS
  33.   String rattache;       // RA
  34.   String instit;         // IN
  35.   String champInstit;    // CI
  36.   String contactName;    // NC
  37.   String telephone;      // TL
  38.   String fax;            // FX
  39.   String email;          // EM
  40.   String delai;          // DL
  41.   String finance;        // FI
  42.   String plusieursJours; // PJ
  43.   String endDay;         // JF
  44.   String endMonth;       // MF
  45.   String endYear;        // AF
  46.   String groupTitle;     // TG
  47.   String groupFilename;  // GF
  48.   String manifType;      // MT
  49.   String soustit;        // ST
  50.   String comments = "";  // CM
  51.  
  52.   private String shortTitle;
  53.   private Date startDate;
  54.   private Date time;
  55.  
  56.   private static final int xOffset = Scaler.scale (15);
  57.  
  58.   /** for reading */
  59.   public Manif () {
  60.   }
  61.  
  62.   public Manif (DataInputStream inStream) throws IOException {
  63.     String line = inStream.readLine ();
  64.  
  65.     while (line != null && !line.startsWith ("===")) {
  66.       decode (line);
  67.       line = inStream.readLine ();
  68.     }
  69.  
  70.     if (title != null) {
  71.       makeShortTitle ();
  72.       startDate = new Date (Integer.parseInt (year) - 1900,
  73.                 Integer.parseInt (month) - 1,
  74.                 Integer.parseInt (day));
  75.  
  76.       if (hour == null || minute == null)
  77.     time = null;
  78.       else 
  79.     time = new Date (Integer.parseInt (year) - 1900,
  80.              Integer.parseInt (month) - 1,
  81.              Integer.parseInt (day),
  82.              Integer.parseInt (hour),
  83.              Integer.parseInt (minute));
  84.       
  85.     }
  86.     
  87.   }
  88.   
  89.   private void decode (String line) {
  90.     String field = "";
  91.     String value = "";
  92.  
  93.  
  94.     if (line.length () > 2) field = line.substring (0, 3);
  95.     if (line.length () > 3) value = line.substring (4);
  96.  
  97.     if (field.equals ("ET:")) eventType = value;
  98.     else if (field.equals ("TE:")) title = value;
  99.     else if (field.equals ("BA:")) batiment = value;
  100.     else if (field.equals ("JD:")) day = value;
  101.     else if (field.equals ("MD:")) month = value;
  102.     else if (field.equals ("AD:")) year = value;
  103.     else if (field.equals ("FJ:")) faculte = value;
  104.     else if (field.equals ("CB:")) champBatiment = value;
  105.     else if (field.equals ("NS:")) noSalle = value;
  106.     else if (field.equals ("TH:")) hour = value;
  107.     else if (field.equals ("TM:")) minute = value;
  108.     else if (field.equals ("TP:")) personTitle = value;
  109.     else if (field.equals ("NA:")) personName = value;
  110.     else if (field.equals ("TS:")) personTitleSup = value;
  111.     else if (field.equals ("RA:")) rattache = value;
  112.     else if (field.equals ("IN:")) instit = value;
  113.     else if (field.equals ("CI:")) champInstit = value;
  114.     else if (field.equals ("NC:")) contactName = value;
  115.     else if (field.equals ("TL:")) telephone = value;
  116.     else if (field.equals ("FX:")) fax = value;
  117.     else if (field.equals ("EM:")) email = value;
  118.     else if (field.equals ("DL:")) delai = value;
  119.     else if (field.equals ("FI:")) finance = value;
  120.     else if (field.equals ("PJ:")) plusieursJours = value;
  121.     else if (field.equals ("JF:")) endDay = value;
  122.     else if (field.equals ("MF:")) endMonth = value;
  123.     else if (field.equals ("AF:")) endYear = value;
  124.     else if (field.equals ("TG:")) groupTitle = value;
  125.     else if (field.equals ("GF:")) groupFilename = value;
  126.     else if (field.equals ("MT:")) { 
  127.       manifType = value;
  128.     } else if (field.equals ("ST:")) {
  129.       soustit = value;
  130.     } else if (field.equals ("CM:")) comments += value;
  131.     else if (line.length() > 0) {
  132.       if (comments.length () > 0)
  133.     comments += " ";
  134.       comments += line;
  135.     }
  136.   }
  137.  
  138.   public Object read (DataInputStream inStream) throws IOException {
  139.     Manif theManif = new Manif (inStream);
  140.  
  141.     if (theManif.title == null)
  142.       return null;
  143.     else
  144.       return (theManif);
  145.   }
  146.   
  147.   public void paint (Graphics g, int x, int y, ImageObserver observer) {
  148.     g.drawString (shortTitle, x + xOffset, y);
  149.   }
  150.  
  151.   private void makeShortTitle () {
  152.     if (title.length () > 68)
  153.       shortTitle = title.substring (0, 66) + "...";
  154.     else
  155.       shortTitle = title;
  156.   }    
  157.  
  158.   public String toString () {
  159.     return ("Manif[" + shortTitle + ", " + time + ", " + faculte + 
  160.         ", " + batiment + "]");
  161.   }
  162.  
  163.   /**
  164.    * Returns true if this event takes place between these two
  165.    * dates (inclusive on begin, exclusive on end).
  166.    */
  167.   public boolean between (Date begin, Date end) {
  168.     return (sameDay (begin) || 
  169.         (startDate.after (begin) && startDate.before (end)));
  170.   }
  171.  
  172.   /** Returns true if this event takes place after this date (exclusive) */
  173.   public boolean after (Date when) {
  174.     return (startDate.after (when));
  175.   }
  176.  
  177.   /** Returns true if this event takes place or or after this date */
  178.   public boolean onOrAfter (Date when) {
  179.     return (sameDay (when) || startDate.after (when));
  180.   }
  181.  
  182.   /** Returns true if this event takes place on the given day */
  183.   public boolean sameDay (Date when) {
  184.     return (startDate.getDate () == when.getDate () &&
  185.         startDate.getMonth () == when.getMonth () &&
  186.         startDate.getYear () == when.getYear ());
  187.   }
  188.  
  189.   public String getFaculte () { return faculte; }
  190.   public Date getStartDate () { return startDate; }
  191.  
  192.   public String getMapName () {
  193.     if (batiment.equals ("BFSH2")) {
  194.       if (noSalle != null && Character.isDigit (noSalle.charAt (0)))
  195.     return (batiment + "_" + noSalle.charAt (0));
  196.       else
  197.     return (batiment + "_2");
  198.     } else
  199.       return batiment;
  200.   }
  201.  
  202.   public String getZoneName () {
  203.     return null;
  204.   }
  205.  
  206.   public String getTitle () {
  207.     return title;
  208.   }
  209.  
  210.   public String getGroupTitle () {
  211.     return groupTitle;
  212.   }
  213.  
  214.   public String getTime () {
  215.     if (hour != null && minute != null)
  216.       return (hour + "h" + minute);
  217.     else
  218.       return null;
  219.   }
  220.  
  221.   public String getPerson () {
  222.     String retVal = "";
  223.  
  224.     if (personName != null) {
  225.       if (personTitle != null && !personTitle.equals ("AUC")) {
  226.     if (personTitle.equals ("DR")) retVal += "Dr. ";
  227.     else if (personTitle.equals ("PRF")) retVal += "Prof. ";
  228.       }
  229.       retVal += personName;
  230.       if (personTitleSup != null)
  231.     retVal += ", " + personTitleSup;
  232.       
  233.       return retVal;
  234.     } else
  235.       return null;
  236.   }
  237.  
  238.   public String getWhere () {
  239.     String retVal = "";
  240.  
  241.     if (batiment != null && !batiment.equals ("Z"))
  242.       retVal += batiment;
  243.     if (champBatiment != null) {
  244.       if (retVal.length () > 0)
  245.     retVal += " ";
  246.       retVal += champBatiment;
  247.     }
  248.     if (noSalle != null) {
  249.       if (retVal.length () > 0)
  250.     retVal += " ";
  251.       retVal += noSalle;
  252.     }
  253.     if (telephone != null) {
  254.       if (retVal.length () > 0)
  255.     retVal += ", ";
  256.       retVal += "tel " + telephone;
  257.     }
  258.     
  259.     if (retVal.length () > 0)
  260.       return retVal;
  261.     else
  262.       return null;
  263.   }
  264.  
  265.   public String getDate () {
  266.     return (startDate.getDate () + "/" + 
  267.         (startDate.getMonth () + 1) + "/" +
  268.         startDate.getYear ());
  269.   }
  270.   
  271.   public String getComments () {
  272.     String retVal = "";
  273.  
  274.     if (soustit != null)
  275.       retVal += soustit;
  276.     if (comments.length () > 0) {
  277.       if (retVal.length () > 0)
  278.     retVal += ", ";
  279.       retVal += comments;
  280.     }
  281.  
  282.     return retVal;
  283.   }
  284.  
  285.   public MapInfoPanel getMapInfoPanel (Appletlike app) {
  286.     ManifInfoPanel thePanel = new ManifInfoPanel (app);
  287.     thePanel.setData (this);
  288.     return thePanel;
  289.   }
  290.  
  291.   public String getRattache () {
  292.     return rattache;
  293.   }
  294.  
  295.   public Date getDateAndTime () { return time; }
  296. }
  297.