home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.5 KB | 123 lines |
- // MotdPanel.java
- // 27.03.96
- //
- // Displays the message of the day
-
- package cybcerone.init;
-
- import java.awt.Rectangle;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.Vector;
- import java.util.Enumeration;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.IdPanel;
- import cybcerone.utils.Fonts;
-
- /**
- * Something to read while you're waiting for the initialization to finish.
- */
- class MotdPanel extends IdPanel implements Runnable {
- private static final Rectangle placement =
- new Rectangle (467, 204, 519, 165);
-
- private static final String id = "MotdPanel";
- private static final String statusText = "About Cybcerone";
-
- private static final Color gray = new Color (127, 127, 127);
-
- private final int delay = 2500;
- private final int startY = scale (20);
- private final int yIncr = scale (20);
- private final int maxSize = 8;
-
- private final int x = 5;
- private int y;
-
- private Thread scroller;
-
- private Vector theMessages;
- private Enumeration messages;
- private Vector queue;
-
- public MotdPanel (Appletlike app) {
- super (id, statusText, app);
- reshape (placement);
-
- queue = new Vector ();
- hide ();
- }
-
- public void update (Vector theMessages) {
- this.theMessages = theMessages;
- }
-
- public void start () {
- if (scroller == null) {
- scroller = new Thread (this);
- scroller.start ();
- }
- }
-
- public void stop () {
- if (scroller != null)
- scroller.stop ();
- scroller = null;
- }
-
- /**
- * Add a line to the bottom.
- */
- private void push () {
- if (theMessages != null && theMessages.size () > 0) {
- if (messages == null || !messages.hasMoreElements ()) {
- messages = theMessages.elements ();
- queue.addElement ("");
- } else {
- queue.addElement (messages.nextElement ());
- }
- if (queue.size () == 1)
- show ();
- if (queue.size () > maxSize)
- pop ();
- }
- }
-
- /**
- * Take a line off the top.
- */
- private void pop () {
- queue.removeElementAt (0);
- if (queue.size () < 1)
- hide ();
- }
-
-
- public void run () {
- while (scroller != null) {
- repaint ();
-
- try {
- scroller.sleep (delay);
- } catch (InterruptedException e) {
- }
-
- push ();
- }
- }
-
- public void paint (Graphics g) {
- g.setColor (getBackground ());
- g.fillRect (0, 0, size().width, size().height);
-
- g.setColor (Color.white);
- g.setFont (Fonts.tinyFont);
- y = startY;
- for (int i = 0; i < queue.size (); i++) {
- g.drawString ((String) queue.elementAt (i), x, y);
- y += yIncr;
- }
- }
- }
-