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

  1. // HappeningPanel.java
  2. // 26.03.96
  3. //
  4. // things that are happening on or around campus
  5.  
  6. package cybcerone.main;
  7.  
  8. import java.awt.Color;
  9. import java.util.Enumeration;
  10.  
  11. import cybcerone.utils.Date;
  12. import cybcerone.utils.Appletlike;
  13. import cybcerone.utils.SuperPanel;
  14. import cybcerone.utils.ManifVector;
  15. import cybcerone.utils.Manif;
  16.  
  17. /**
  18.  * The common root of the NowPanel and the TodayPanel.
  19.  */
  20. abstract class HappeningPanel extends SuperPanel {
  21.   protected static final String imagePath = MainPanel.imagePath;
  22.  
  23.   protected static final Color gray = new Color (190, 190, 190);
  24.   
  25.   private ManifVector allTheEvents;
  26.   private ManifVector theEvents;
  27.  
  28.   HappeningPanel (String id, String statusText, Appletlike app) {
  29.     super (id, statusText, app);
  30.   }
  31.  
  32.   /** All the events in the database. */
  33.   public ManifVector getAllTheEvents () { return allTheEvents; }
  34.  
  35.   /** The events pertinent to this panel. */
  36.   public synchronized ManifVector getTheEvents () { return theEvents; }
  37.  
  38.   /** Set the events pertinent to this panel. */
  39.   public synchronized void setTheEvents (ManifVector theEvents) {
  40.     this.theEvents = theEvents;
  41.   }
  42.  
  43.   /**
  44.    * Override this to handle ManifVector's.
  45.    */
  46.   public void update (Object updateVal) {
  47.     if (updateVal instanceof ManifVector)
  48.       update ((ManifVector) updateVal);
  49.     else
  50.       super.update (updateVal);
  51.   }
  52.  
  53.   private void update (ManifVector events) {
  54.     allTheEvents = events;
  55.     update ();
  56.   }
  57.  
  58.   /* find the events happening in the time period between pastDate and
  59.    * futureDate */
  60.   public void update () {
  61.     if (allTheEvents != null) {
  62.       
  63.       setTheEvents (findEvents ());
  64.       
  65.       if (getTheEvents().size () > 0)
  66.     show ();
  67.       else
  68.     hide ();
  69.     }
  70.   }
  71.  
  72.   public ManifVector findEvents () {
  73.     Date now = new Date ();
  74.     Date past = pastDate (now);
  75.     Date future = futureDate (now);
  76.  
  77.     Manif theManif;
  78.     ManifVector events = new ManifVector ();
  79.     
  80.     for (Enumeration e = getAllTheEvents().elements ();
  81.      e.hasMoreElements ();) {
  82.       theManif = (Manif)e.nextElement ();
  83.       if (happeningBetween (theManif, past, future)) {
  84.     events.addElement (theManif);
  85.       }
  86.     }
  87.     return events;
  88.   }
  89.  
  90.   /** is this event happening between these two dates/times? */
  91.   private boolean happeningBetween (Manif theManif, Date past, Date future) {
  92.     Date time = theManif.getDateAndTime ();
  93.  
  94.     if (time != null)
  95.       return (time.after (past) && time.before (future));
  96.     else
  97.       return false;
  98.   }
  99.  
  100.   /**
  101.    * Events that took place this long ago are still relevant.
  102.    */
  103.   abstract protected Date pastDate (Date now);
  104.  
  105.   /**
  106.    * Events that will take place this far ahead in the future
  107.    * are relevant to this panel.
  108.    */
  109.   abstract protected Date futureDate (Date now);
  110.   
  111. }
  112.