home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / init / motdpanel.java < prev   
Encoding:
Java Source  |  1996-08-14  |  2.5 KB  |  123 lines

  1. // MotdPanel.java
  2. // 27.03.96
  3. //
  4. // Displays the message of the day
  5.  
  6. package cybcerone.init;
  7.  
  8. import java.awt.Rectangle;
  9. import java.awt.Color;
  10. import java.awt.Graphics;
  11. import java.util.Vector;
  12. import java.util.Enumeration;
  13.  
  14. import cybcerone.utils.Appletlike;
  15. import cybcerone.utils.IdPanel;
  16. import cybcerone.utils.Fonts;
  17.  
  18. /**
  19.  * Something to read while you're waiting for the initialization to finish.
  20.  */
  21. class MotdPanel extends IdPanel implements Runnable {
  22.   private static final Rectangle placement = 
  23.     new Rectangle (467, 204, 519, 165);
  24.  
  25.   private static final String id = "MotdPanel";
  26.   private static final String statusText = "About Cybcerone";
  27.  
  28.   private static final Color gray = new Color (127, 127, 127);
  29.  
  30.   private final int delay = 2500;
  31.   private final int startY = scale (20);
  32.   private final int yIncr = scale (20);
  33.   private final int maxSize = 8;
  34.  
  35.   private final int x = 5;
  36.   private int y;
  37.  
  38.   private Thread scroller;
  39.  
  40.   private Vector theMessages;
  41.   private Enumeration messages;
  42.   private Vector queue;
  43.  
  44.   public MotdPanel (Appletlike app) {
  45.     super (id, statusText, app);
  46.     reshape (placement);
  47.  
  48.     queue = new Vector ();
  49.     hide ();
  50.   }
  51.  
  52.   public void update (Vector theMessages) {
  53.     this.theMessages = theMessages;
  54.   }
  55.  
  56.   public void start () {
  57.     if (scroller == null) {
  58.       scroller = new Thread (this);
  59.       scroller.start ();
  60.     }
  61.   }
  62.  
  63.   public void stop () {
  64.     if (scroller != null) 
  65.       scroller.stop ();
  66.     scroller = null;
  67.   }
  68.  
  69.   /**
  70.    * Add a line to the bottom.
  71.    */
  72.   private void push () {
  73.     if (theMessages != null && theMessages.size () > 0) {
  74.       if (messages == null || !messages.hasMoreElements ()) {
  75.     messages = theMessages.elements ();
  76.     queue.addElement ("");
  77.       } else {
  78.     queue.addElement (messages.nextElement ());
  79.       }
  80.       if (queue.size () == 1)
  81.     show ();
  82.       if (queue.size () > maxSize)
  83.     pop ();
  84.     }
  85.   }
  86.   
  87.   /**
  88.    * Take a line off the top.
  89.    */
  90.   private void pop () {
  91.     queue.removeElementAt (0);
  92.     if (queue.size () < 1)
  93.       hide ();
  94.   }
  95.   
  96.  
  97.   public void run () {
  98.     while (scroller != null) {
  99.       repaint ();
  100.       
  101.       try {
  102.     scroller.sleep (delay);
  103.       } catch (InterruptedException e) {
  104.       }
  105.       
  106.       push ();
  107.     }
  108.   }
  109.  
  110.   public void paint (Graphics g) {
  111.     g.setColor (getBackground ());
  112.     g.fillRect (0, 0, size().width, size().height);
  113.  
  114.     g.setColor (Color.white);
  115.     g.setFont (Fonts.tinyFont);
  116.     y = startY;
  117.     for (int i = 0; i < queue.size (); i++) {
  118.       g.drawString ((String) queue.elementAt (i), x, y);
  119.       y += yIncr;
  120.     }
  121.   }
  122. }
  123.