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

  1. // NowEventPanel.java
  2. // 26.03.96
  3. //
  4. // one of the events on the NowPanel
  5.  
  6. package cybcerone.main;
  7.  
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.Color;
  11.  
  12. import cybcerone.utils.Date;
  13. import cybcerone.utils.Appletlike;
  14. import cybcerone.utils.IdPanel;
  15. import cybcerone.utils.ScrollingPanel;
  16. import cybcerone.utils.Manif;
  17. import cybcerone.utils.Fonts;
  18.  
  19. /**
  20.  * The sub-subpanel for events that are happening now.
  21.  */
  22. class NowEventPanel extends IdPanel {
  23.   private Image ledsOn, ledsOff;
  24.   private String time, faculte;
  25.  
  26.   private ScrollingPanel titlePanel;
  27.   private boolean lightsOn;
  28.  
  29.   /* for double buffering */
  30.   private Image offscreenImg;
  31.   private Graphics offscreenG;
  32.  
  33.   private static Color gray = new Color (190, 190, 190);
  34.  
  35.   NowEventPanel (String id, String statusText, Image ledsOn, Image ledsOff, 
  36.          Appletlike app) {
  37.     super (id, statusText, app);
  38.     
  39.     this.ledsOn = ledsOn;
  40.     this.ledsOff = ledsOff;
  41.  
  42.     add (titlePanel = new ScrollingPanel (id, statusText, app));
  43.     titlePanel.reshape (scale (246), 0, scale (522), scale (26));
  44.     titlePanel.setFont (Fonts.smallFont);
  45.     titlePanel.setColor (gray);
  46.     
  47.     hide ();
  48.   }
  49.  
  50.   public boolean isValid () {
  51.     return (faculte != null);
  52.   }
  53.  
  54.   public void setTitleBg (String titleBgFile) {
  55.     titlePanel.setBackground (titleBgFile, 2);
  56.   }
  57.   
  58.   public void setManif (Manif theManif) {
  59.     if (theManif != null) {
  60.       titlePanel.setText (theManif.getTitle ());
  61.       titlePanel.setNext (theManif);
  62.       
  63.       setTime (theManif);
  64.       setFaculte (theManif);
  65.  
  66.       show ();
  67.       repaint ();
  68.     } else {
  69.       hide ();
  70.       faculte = null;
  71.     }
  72.   }
  73.   
  74.   /* makes this a copy of other */
  75.   public void copyFrom (NowEventPanel other) {
  76.     titlePanel.setText (other.titlePanel);
  77.     time = other.time;
  78.     faculte = other.faculte;
  79.   }
  80.   
  81.   private void setTime (Manif theManif) {
  82.     Date when = theManif.getDateAndTime ();
  83.     if (when != null) {
  84.       String minutes = String.valueOf (when.getMinutes ());
  85.       if (minutes.length () < 2) 
  86.     minutes = "0" + minutes;
  87.       String hours = String.valueOf (when.getHours ());
  88.       if (hours.length () < 2)
  89.     hours = " " + hours;
  90.       time = hours + "H" + minutes;
  91.     } else {
  92.       time = "";
  93.     }
  94.   }
  95.   
  96.   private void setFaculte (Manif theManif) {
  97.     faculte = theManif.getFaculte ();
  98.   }
  99.  
  100.   public void stop () {
  101.     super.stop ();
  102.     if (isShowing ())
  103.       turnLightsOff ();
  104.   }
  105.   
  106.   public void turnLightsOn () {
  107.     lightsOn = true;
  108.     repaint ();
  109.   }
  110.   
  111.   public void turnLightsOff () {
  112.     lightsOn = false;
  113.     repaint ();
  114.   }
  115.   
  116.   public void paint (Graphics g) {
  117.     if (lightsOn)
  118.       g.drawImage (ledsOn, 0, 0, this);
  119.     else
  120.       g.drawImage (ledsOff, 0, 0, this);
  121.     
  122.     g.setFont (Fonts.smallFont);
  123.     
  124.     if (time != null && faculte != null) {
  125.       g.setColor (gray);
  126.       g.drawString (time, scale (86), scale (23));
  127.     
  128.       g.setColor (Color.white);
  129.       g.drawString (faculte, scale (149), scale (23));
  130.     }
  131.   }
  132.   
  133.   public void update (Graphics g) {
  134.     // for double buffering;
  135.     if (offscreenG == null) {
  136.       offscreenImg = createImage (size().width, size().height);
  137.       offscreenG = offscreenImg.getGraphics ();
  138.     }
  139.  
  140.     offscreenG.setColor (getBackground ());
  141.     offscreenG.fillRect (0, 0, size().width, size().height);
  142.     paint (offscreenG);
  143.     g.drawImage (offscreenImg, 0, 0, this);
  144.   }
  145. }
  146.