home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.7 KB | 112 lines |
- // HappeningPanel.java
- // 26.03.96
- //
- // things that are happening on or around campus
-
- package cybcerone.main;
-
- import java.awt.Color;
- import java.util.Enumeration;
-
- import cybcerone.utils.Date;
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.SuperPanel;
- import cybcerone.utils.ManifVector;
- import cybcerone.utils.Manif;
-
- /**
- * The common root of the NowPanel and the TodayPanel.
- */
- abstract class HappeningPanel extends SuperPanel {
- protected static final String imagePath = MainPanel.imagePath;
-
- protected static final Color gray = new Color (190, 190, 190);
-
- private ManifVector allTheEvents;
- private ManifVector theEvents;
-
- HappeningPanel (String id, String statusText, Appletlike app) {
- super (id, statusText, app);
- }
-
- /** All the events in the database. */
- public ManifVector getAllTheEvents () { return allTheEvents; }
-
- /** The events pertinent to this panel. */
- public synchronized ManifVector getTheEvents () { return theEvents; }
-
- /** Set the events pertinent to this panel. */
- public synchronized void setTheEvents (ManifVector theEvents) {
- this.theEvents = theEvents;
- }
-
- /**
- * Override this to handle ManifVector's.
- */
- public void update (Object updateVal) {
- if (updateVal instanceof ManifVector)
- update ((ManifVector) updateVal);
- else
- super.update (updateVal);
- }
-
- private void update (ManifVector events) {
- allTheEvents = events;
- update ();
- }
-
- /* find the events happening in the time period between pastDate and
- * futureDate */
- public void update () {
- if (allTheEvents != null) {
-
- setTheEvents (findEvents ());
-
- if (getTheEvents().size () > 0)
- show ();
- else
- hide ();
- }
- }
-
- public ManifVector findEvents () {
- Date now = new Date ();
- Date past = pastDate (now);
- Date future = futureDate (now);
-
- Manif theManif;
- ManifVector events = new ManifVector ();
-
- for (Enumeration e = getAllTheEvents().elements ();
- e.hasMoreElements ();) {
- theManif = (Manif)e.nextElement ();
- if (happeningBetween (theManif, past, future)) {
- events.addElement (theManif);
- }
- }
- return events;
- }
-
- /** is this event happening between these two dates/times? */
- private boolean happeningBetween (Manif theManif, Date past, Date future) {
- Date time = theManif.getDateAndTime ();
-
- if (time != null)
- return (time.after (past) && time.before (future));
- else
- return false;
- }
-
- /**
- * Events that took place this long ago are still relevant.
- */
- abstract protected Date pastDate (Date now);
-
- /**
- * Events that will take place this far ahead in the future
- * are relevant to this panel.
- */
- abstract protected Date futureDate (Date now);
-
- }
-