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

  1. // MainPanel.java
  2. // 27.02.96
  3. //
  4. // the main screen
  5.  
  6. package cybcerone.main;
  7.  
  8. import java.awt.Image;
  9. import java.awt.Event;
  10. import java.util.Vector;
  11.  
  12.  
  13. import cybcerone.credit.CreditPanel;
  14. import cybcerone.utils.SuperPanel;
  15. import cybcerone.utils.Appletlike;
  16. import cybcerone.utils.ManifVector;
  17. import cybcerone.utils.Manif;
  18. import cybcerone.utils.Date;
  19. import cybcerone.utils.Buttons;
  20. import cybcerone.utils.Button;
  21.  
  22. import cybcerone.person.PersonPanel;
  23. import cybcerone.orient.PreorientPanel;
  24. import cybcerone.faculte.FacultePanel;
  25. import cybcerone.manif.ManifPanel;
  26.  
  27. /**
  28.  * The main screen.
  29.  */
  30. public class MainPanel extends SuperPanel implements Runnable {
  31.   public static final String id = "main";
  32.   public static final String imagePath = "pdg/";
  33.  
  34.   private static final String statusText = "Welcome to Cybcerone";
  35.   private static final String bgFile = imagePath + "fond_pdg.gif";
  36.  
  37.   private static final String eventFile = "events/live.events";
  38.   private static final String ledsOnFile = imagePath + "leds2_on.gif";
  39.   private static final String ledsOffFile = imagePath + "leds2_off.gif";
  40.   
  41.   private TsolPanel tsol;
  42.   private NowPanel now;
  43.   private TodayPanel today;
  44.  
  45.   Thread updater;
  46.  
  47.   private Buttons theButtons;
  48.  
  49.   public MainPanel (Appletlike app) {
  50.     super (id, statusText, app);
  51.     setBackground (bgFile, 1);
  52.     setNext (CreditPanel.id);
  53.  
  54.     Image ledsOn = getImage (ledsOnFile, 2);
  55.     Image ledsOff = getImage (ledsOffFile, 2);
  56.  
  57.     /*
  58.     add (new PersonButton (this));
  59.     add (new FaculteButton (this));
  60.     add (new OrientButton (this));
  61.     add (new ManifButton (this));
  62.     */
  63.     
  64.     theButtons = new Buttons ();
  65.     theButtons.addButton
  66.       (new Button (PersonPanel.id, "Directory of the University staff", 
  67.            0, 0, 217, 211));
  68.     theButtons.addButton 
  69.       (new Button (PreorientPanel.id, "Maps and orientation", 
  70.            806, 0, 217, 211));
  71.     theButtons.addButton 
  72.       (new Button (FacultePanel.id, 
  73.            "Organizational chart of faculties and services",
  74.            806, 213, 217, 206));
  75.     theButtons.addButton 
  76.       (new Button (ManifPanel.id, "Calendar of events", 0, 213, 217, 206));
  77.  
  78.     add (tsol = new TsolPanel (this));
  79.     add (now = new NowPanel (ledsOn, ledsOff, this));
  80.     add (today = new TodayPanel (ledsOn, this));
  81.  
  82.     getData (eventFile, new Manif (), this);
  83.   }
  84.  
  85.   public void update (Vector theData) {
  86.     Object first = theData.firstElement ();
  87.     
  88.     update (new ManifVector (theData));
  89.   }
  90.   
  91.   public void update (ManifVector events) {
  92.     now.update (events);
  93.     today.update (events);
  94.   }
  95.  
  96.   public void start () {
  97.     super.start ();
  98.     if (updater == null) {
  99.       updater = new Thread (this);
  100.       updater.start ();
  101.     }
  102.   }
  103.  
  104.   public void stop () {
  105.     super.stop ();
  106.     if (updater != null)
  107.       updater.stop ();
  108.     updater = null;
  109.   }
  110.  
  111.   /** Sleep until tomorrow, then reload the event file */
  112.   public void run () {
  113.     while (updater != null) {
  114.       Date today = new Date ();
  115.       Date tomorrow = new Date (today.getYear (), today.getMonth (), 
  116.                 today.getDate () + 1);
  117.       try {
  118.     updater.sleep (tomorrow.getTime () - today.getTime ());
  119.       } catch (InterruptedException e) {
  120.       }
  121.       
  122.       getData (eventFile, new Manif (), this);
  123.     }
  124.   }
  125.  
  126.   public boolean mouseMove (Event evt, int x, int y) {
  127.     Button theButton = theButtons.which (x, y);
  128.  
  129.     if (theButton != null)
  130.       app.showStatus (theButton.getStatusText ());
  131.     else if (locate (x, y) == null)
  132.       app.showStatus (statusText);
  133.     return true;
  134.   }
  135.  
  136.   public boolean mouseDown (Event evt, int x, int y) {
  137.     Button theButton = theButtons.which (x, y);
  138.  
  139.     if (theButton != null) {
  140.       app.update (theButton.getNext ());
  141.       return true;
  142.     } else
  143.       return super.mouseDown (evt, x, y);
  144.   }
  145. }
  146.  
  147.  
  148.  
  149.